本文介绍了GetExternalLoginInfoAsync总是返回null当我尝试使用Facebook或谷歌登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有 OWIN
验证问题。我总是收到来自空值GetExternalLoginInfoAsync()
当我使用Facebook或谷歌试图日志。
I have problem with OWIN
Authentication. I always receive null value from GetExternalLoginInfoAsync()
when i trying log in using Facebook or Google.
但有一些神秘的情况下。当我打开提琴手..我用这个方法得到正确的数据。
我无法得到的原因。
var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync();
在此先感谢!
推荐答案
我加入这个code解决我的问题。
I have solved my problem by adding this code
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的授权登录时不要使用小提琴手。您将收到错误。
Notice: don't use fiddler when logging with twitter authorization. You will receive error.
这篇关于GetExternalLoginInfoAsync总是返回null当我尝试使用Facebook或谷歌登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!