This code was working fine for a year or so, this problem is related to facebook changing their API response to JSON (instead of regular query string)
It's a MVC5 project, I updated to https://www.nuget.org/packages/Microsoft.Owin.Security.Facebook/3.1.0-rc1 as suggested here: ASP.NET MVC5 OWIN Facebook authentication suddenly not working and also try to simplify my call as suggested here: https://github.com/aspnet/AspNetKatana/issues/38
In addition I tried adding the BackchannelHttpHandler class (but removed it as it was not working for me), Also, I deleted my facebook web app (it was API 2.4) and created a new one (2.8) that is not approved yet, but I think test app should be working regardless.
I keep getting 302 error=access_denied
This is the code I'm using:
var facebookAuthOptions = new FacebookAuthenticationOptions();
facebookAuthOptions.AppId = "xxx";
facebookAuthOptions.AppSecret = "yyy";
facebookAuthOptions.SendAppSecretProof = true;
facebookAuthOptions.CallbackPath = new PathString("/signin-facebook");
facebookAuthOptions.Scope.Add("public_profile");
facebookAuthOptions.Scope.Add("email");
facebookAuthOptions.Scope.Add("user_birthday");
// added for Microsoft.Owin.Security.Facebook/3.1.0-rc1
facebookAuthOptions.Fields.Add("email");
facebookAuthOptions.Fields.Add("birthday");
facebookAuthOptions.Fields.Add("gender");
facebookAuthOptions.Fields.Add("locale");
facebookAuthOptions.Fields.Add("location");
facebookAuthOptions.Fields.Add("timezone");
facebookAuthOptions.Provider = new FacebookAuthenticationProvider()
{
OnAuthenticated = (context) =>
{
context.Identity.AddClaim(new Claim("FacebookAccessToken", context.AccessToken));
var expiryDuration = context.ExpiresIn ?? new TimeSpan();
context.Identity.AddClaim(new Claim("urn:facebook:expires_in", DateTime.UtcNow.Add(expiryDuration).ToString(CultureInfo.InvariantCulture)));
// Add all other available claims
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 Claim(claimType, claimValue, "XmlSchemaString", "Facebook"));
}
return Task.FromResult(0);
}
};
app.UseFacebookAuthentication(facebookAuthOptions);
The net traffic looks like this:
https://localhost:44300/external-providers (302)
https://localhost:44300/signup-connect?error=access_denied (302)