OAuth facebook login not working normally

668 views Asked by At

I use asp.net MVC webapi, and have been using facebook login for a long time. But suddenly there is an error as below:

Not Logged In: You are not logged in. Please login and try again.

bellow my code: Startup.Auth.cs

FacebookAuthenticationOptions options = new FacebookAuthenticationOptions();
options.AppId = ConfigurationManager.AppSettings["FBappId"];
options.AppSecret = ConfigurationManager.AppSettings["FBappSecret"];
string[] FBScopes = ConfigurationManager.AppSettings["FBScope"].ToString().Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);

foreach (string s in FBScopes)
{
    options.Scope.Add(s);
}

Microsoft.Owin.Security.Twitter.Messages.RequestToken request = new Microsoft.Owin.Security.Twitter.Messages.RequestToken();

options.Provider = new FacebookAuthenticationProvider()
{
    OnAuthenticated = async context =>
    {
        //Get the access token from FB and store it in the database and
        //use FacebookC# SDK to get more information about the user
        context.Identity.AddClaim(
            new System.Security.Claims.Claim("FacebookAccessToken", context.AccessToken));
    }
};
options.SignInAsAuthenticationType = DefaultAuthenticationTypes.ExternalCookie;
//options.SignInAsAuthenticationType = Microsoft.Owin.Security.AppBuilderSecurityExtensions.GetDefaultSignInAsAuthenticationType(app);
app.UseFacebookAuthentication(options);

So far it's working fine and no such error ever appeared. Anyone know why this happens?

Have there been any security changes by facebook?

Advice me please.

2

There are 2 answers

0
Oussama Dinia On

In my case, it was the "Valid OAuth redirect URIs" property which was set to an old redirect URI I had set before.

Once I changed it to the current port, it worked correctly.

This setting is in the "Products=>Facebook Login" section.

0
sarnosos On

I had the same problem, in my case, the solution was to remove android aplication in the facebook.

enter image description here