Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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!!

like image 224
Oleksandr Fentsyk Avatar asked Aug 20 '14 10:08

Oleksandr Fentsyk


1 Answers

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.

like image 136
Oleksandr Fentsyk Avatar answered Oct 15 '22 02:10

Oleksandr Fentsyk