FacebookAuthenticatedContext returns a null email address

I have this problem with Facebook authentication, here are the following steps that we will take to meet this problem:

  • User A uses device A to register with our application through Facebook authentication.
  • User A successfully goes to the registration page with his first name, surname and email address taken from Facebook authentication.
  • User Registers A.
  • User A logs out of our application, as well as on Facebook.
  • User B uses the same device as user A (device A) to register on our application via Facebook.
  • User B is redirected to the login page every time he tries to use Facebook Authentication.

Basically the problem is that the following Facebook authentication using the same device has problems. In the ExternalLoginCallback method, AuthenticationManager.GetExternalLoginInfoAsync returns null each time for user B.

I tried changing FacebookAuthenticationProviderOptions based on the solutions I found on the Internet, but none of them worked. Here is the current code I'm using:

string XmlSchemaString = "www.w3.org/.../XMLSchema";
        FacebookAuthenticationOptions options = new FacebookAuthenticationOptions();
        options.Scope.Add("email");
        options.AppId = "...";
        options.AppSecret = "...";
        options.Provider = new FacebookAuthenticationProvider()
        {
            OnAuthenticated = (context) =>
            {
                context.Identity.AddClaim(new System.Security.Claims.Claim("urn:facebook:access_token", context.AccessToken, XmlSchemaString, "Facebook"));
                context.Identity.AddClaim(new System.Security.Claims.Claim("urn:facebook:email", context.Email, XmlSchemaString, "Facebook"));
                foreach (var x in context.User)
                {
                    string claimType = string.Format("urn:facebook:{0}", x.Key);
                    string claimValue = x.Value.ToString();
                    if (!context.Identity.HasClaim(claimType, claimValue))
                    {
                        context.Identity.AddClaim(new Claim(claimType, claimValue, XmlSchemaString, "Facebook"));
                    }
                }
                return Task.FromResult(0);
            }
        };
        options.SignInAsAuthenticationType = DefaultAuthenticationTypes.ExternalCookie;
        app.UseFacebookAuthentication(options);

asnyc, AuthenticationManager.GetExternalLoginInfoAsync null B , B, async context.Email null.

, Facebook A, . - , . 3 , , , .

----- EDIT ----

, facebook . , .

,

+4

All Articles