【发布时间】:2018-06-04 11:44:06
【问题描述】:
我被要求创建一个“身份验证/授权”中间人或代理作为 http、MVC Web 应用程序,以便可以将其用于我们组织中的多个应用程序以进行身份验证/授权目的。意味着,用户将在此代理应用程序上注册、登录,一旦确认经过身份验证的授权用户,他将相应地被重定向到客户端应用程序。这是用例。
我选择 OAuth 和 OWIN 在 MVC 应用程序中开发此代理,这意味着一旦用户成功通过身份验证,OAuth(Authorization) 将发出访问令牌 + 刷新令牌。我在 Oauth 授权服务器的登录控制器中使用正常、简单、最小的身份验证逻辑,如下所示:
public class AccountController : Controller
{
public ActionResult Login()
{
var authentication = HttpContext.GetOwinContext().Authentication;
if (Request.HttpMethod == "POST")
{
var isPersistent = !string.IsNullOrEmpty(Request.Form.Get("isPersistent"));
if (!string.IsNullOrEmpty(Request.Form.Get("submit.Signin")))
{
var user = Constants.Users.UserCollection.Where(u => u.Email.ToLower() == Request.Form["username"].ToLower().Trim() && u.Password == Request.Form["password"].Trim());
if (user.Count() > 0)
{
authentication.SignIn(
new AuthenticationProperties { IsPersistent = isPersistent },
new ClaimsIdentity(new[]
{ new Claim(ClaimsIdentity.DefaultNameClaimType, Request.Form["username"]),
new Claim("DisplayName", user.FirstOrDefault().DisplayName) } , "Application"));
}
}
}
return View();
}
这是我用于开发此概念应用程序的 MSFT 示例应用程序。 https://docs.microsoft.com/en-us/aspnet/aspnet/overview/owin-and-katana/owin-oauth-20-authorization-server.
我的问题是:我在很多文章中读到过,使用 Oauth 身份验证不好,否则使用 OPENID Connect 处理身份验证。坦率地说,我不使用 OPENID Connect,我不确定为我的组织创建 OPENID 提供程序的必要性,因为该服务将仅由我们组织的客户使用 - 少于 200,000 个用户。我们几乎不需要用户注册和登录,这个帐户需要在我们组织的不同 Web 应用程序中使用。请在这里帮助我输入您的信息。提前致谢。
【问题讨论】:
标签: asp.net-mvc oauth-2.0 owin openid-connect dotnetopenauth