Base solution for your next web application
Open Closed

Facebook login stopped working #2823


User avatar
0
kythor created

Hi, since a couple of days it is impossible to login with facebook on our site. After some debugging, it seems that this line is the problem:

var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync();

The user is sucessfully redirected to facebook login first, after logging in, it returns to our site. But somehow "loginInfo" is null. When trying the same with Twitter, loginInfo is not null, and the login works.

tried adding this to ChallengeResult.cs: context.RequestContext.HttpContext.Response.SuppressFormsAuthenticationRedirect = true;

but doesn't help.

the big problem now is that a lot of our users have been registrered through Facebook in the past, but are now unable to login... What else can I do?

Installed version: Abp.Zero 0.10.1 Microsoft.Owin 3.0.1


4 Answer(s)
  • User Avatar
    0
    kythor created
    var options = new FacebookAuthenticationOptions
                {
                    AppId = ConfigurationManager.AppSettings["ExternalAuth.Facebook.AppId"],
                    AppSecret = ConfigurationManager.AppSettings["ExternalAuth.Facebook.AppSecret"],
                    SendAppSecretProof = true,
                    BackchannelHttpHandler = new FacebookBackChannelHandler(),
                    UserInformationEndpoint = "https://graph.facebook.com/v2.8/me?fields=id,name,email",
                    Scope = { "email" },
                    Provider = new FacebookAuthenticationProvider
                    {
                        OnAuthenticated = context =>
                        {
                            context.Identity.AddClaim(new System.Security.Claims.Claim("FacebookAccessToken", context.AccessToken));
                            foreach (var claim in context.User)
                            {
                                var claimType = string.Format("urn:facebook:{0}", claim.Key);
                                var claimValue = claim.Value.ToString();
                                if (!context.Identity.HasClaim(claimType, claimValue))
                                    context.Identity.AddClaim(new System.Security.Claims.Claim(claimType, claimValue, "XmlSchemaString", "Facebook"));
                            }
    
                            return Task.FromResult(0);
                        }
                    }
                };
    
                options.Scope.Add("public_profile");
    
  • User Avatar
    0
    kythor created

    Apparently, facebook changed it's API, causing these problems. but even after following this solution: <a class="postlink" href="http://stackoverflow.com/questions/22364442/asp-net-mvc5-owin-facebook-authentication-suddenly-not-working">http://stackoverflow.com/questions/2236 ... ot-working</a>

    is still get loginInfo = null

  • User Avatar
    0
    kythor created

    be advised, only solution that worked for me: updating Microsoft.Owin nuget package to version 3.1.0-rc1

    This has been fixed in Katana 3.1.0-RC1 which is now available on nuget.org.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Thank you very much for your solution. We will test and implement it here <a class="postlink" href="https://github.com/aspnetzero/aspnet-zero/issues/467">https://github.com/aspnetzero/aspnet-zero/issues/467</a>.