GetExternalLoginInfoAsync always return null when i trying login using Facebook or Google

送分小仙女□ 提交于 2019-12-06 23:36:38

问题


I have a problem with OWIN Authentication. I always receive null value from GetExternalLoginInfoAsync() when I trying log in using Facebook or Google.

BUT there is some mystical case.. When I open Fiddler. I get correct data using this method.

I can't get the reason

var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync();

Thanks in advance!!


回答1:


I have solved my problem by adding this code

context.RequestContext.HttpContext.Response.SuppressFormsAuthenticationRedirect = true;

in the class:

    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);
        }
    }

It fixed my problem with returning NULL.

Notice: don't use fiddler when logging with twitter authorization. You will receive error.



来源:https://stackoverflow.com/questions/25402008/getexternallogininfoasync-always-return-null-when-i-trying-login-using-facebook

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!