【发布时间】:2018-03-14 06:19:45
【问题描述】:
我实现了一个基本的 owin OAuth 身份验证过程(使用 Google 和 Facebook),但我有点担心外部 LoginCallback 中的“登录信息”是否足够安全以供使用,我是否必须做任何事情别的 ?这里是“结束”AccountController 代码,但主要内容是在遵循此模式/示例时完成的:
谢谢!
private const string XsrfKey = "XsrfId";
internal class ChallengeResult : HttpUnauthorizedResult
{
public ChallengeResult(string provider, string redirectUri)
: this(provider, redirectUri, null)
{
}
public ChallengeResult(string provider, string redirectUri, string userId)
{
LoginProvider = provider;
RedirectUri = redirectUri;
UserId = userId;
}
public string LoginProvider { get; set; }
public string RedirectUri { get; set; }
public string UserId { get; set; }
public override void ExecuteResult(ControllerContext context)
{
var properties = new AuthenticationProperties { RedirectUri = RedirectUri };
if (UserId != null)
{
properties.Dictionary[XsrfKey] = UserId;
}
context.HttpContext.GetOwinContext().Authentication.Challenge(properties, LoginProvider);
}
}
[HttpPost]
[AllowAnonymous]
public ActionResult ExternalLogin(string provider, string returnUrl)
{
ChallengeResult r = new ChallengeResult(provider, Url.Action("ExternalLoginCallback", "Users", new { ReturnUrl = returnUrl }));
return r;
}
[AllowAnonymous]
public async Task<ActionResult> ExternalLoginCallback(string returnUrl)
{
if (returnUrl == null) returnUrl = string.Empty; // just to reduce validation below...
// Get login info
var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync();
if (loginInfo == null)
{
// if none, return to login page
return RedirectToAction("Login");
}
else
{
// is this login info safe and thrustable to create or login the user
string username = loginInfo.Login.LoginProvider + "_ " + loginInfo.Login.ProviderKey;
}
}
【问题讨论】:
标签: asp.net-mvc oauth owin