OWIN
身份验证有问题。当我尝试使用 Facebook 或 Google 登录时,我总是从 GetExternalLoginInfoAsync()
收到空值。
但是有一些神秘的情况。当我打开 Fiddler 时。我使用这种方法获得了正确的数据。
找不到原因
var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync();
提前致谢!!
最佳答案
我已经通过添加这段代码解决了我的问题
context.RequestContext.HttpContext.Response.SuppressFormsAuthenticationRedirect = true;
在类里面:
private 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)
{
// this line fixed the problem with returing null
context.RequestContext.HttpContext.Response.SuppressFormsAuthenticationRedirect = true;
var properties = new AuthenticationProperties() { RedirectUri = RedirectUri };
if (UserId != null)
{
properties.Dictionary[XsrfKey] = UserId;
}
context.HttpContext.GetOwinContext().Authentication.Challenge(properties, LoginProvider);
}
}
它解决了我返回 NULL
的问题。
注意:使用 twitter 授权登录时不要使用 fiddler。您将收到错误消息。
关于c# - 当我尝试使用 Facebook 或 Google 登录时,GetExternalLoginInfoAsync 始终返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25402008/