簡體   English   中英

當我嘗試使用Facebook或Google登錄時,GetExternalLoginInfoAsync始終返回null

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

我有OWIN身份驗證的問題。 當我嘗試使用Facebook或Google登錄時,我總是從GetExternalLoginInfoAsync()收到空值。

但是有一些神秘的案例..當我打開提琴手。 我使用這種方法得到正確的數據。

我無法理解

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。 你會收到錯誤。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM