GetExternalLoginInfoAsync总是返回空,当我尝试登录使用Facebook或谷歌

本文关键字:登录 Facebook 谷歌 返回 GetExternalLoginInfoAsync | 更新日期: 2023-09-27 18:18:58

我有一个OWIN认证的问题。当我尝试使用Facebook或Google登录时,我总是收到GetExternalLoginInfoAsync()的空值。

但是有一些神秘的情况…当我打开提琴手。我使用这种方法得到正确的数据。

我不知道原因

var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync();

提前感谢!!

GetExternalLoginInfoAsync总是返回空,当我尝试登录使用Facebook或谷歌

我已经通过添加以下代码解决了我的问题

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。