您必須從OWIN中間件獲取acccess_denied。嘗試將調試器放入帳戶控制器操作「ExternalLoginCallback」中。
我假設你已經在facebook中添加了http://your_domain/signin-facebook作爲允許的redirect_uri。請注意,https在這裏不是強制性的,如果它是http,Facebook仍然提供憑據。
我還假設您已將您的nuget軟件包更新到Microsoft.Owin.Security.Facebook 3.1.0。 有用的鏈接:https://github.com/aspnet/AspNetKatana/issues/38
請參閱:https://developers.facebook.com/docs/facebook-login/permissions以查看允許的權限。詢問適當的範圍和領域,如下代碼:
var facebookAuthenticationOptions = new FacebookAuthenticationOptions()
{
AppId = "....",
AppSecret = "....",
AuthenticationType = "Facebook",
SignInAsAuthenticationType = DefaultAuthenticationTypes.ExternalCookie,
Provider = new FacebookAuthenticationProvider
{
OnAuthenticated = async ctx =>
{
ctx.Identity.AddClaim(new Claim("FacebookAccessToken", ctx.AccessToken));
foreach (var claim in ctx.User)
{
var claimType = string.Format("urn:facebook:{0}", claim.Key);
string claimValue = claim.Value.ToString();
if (!ctx.Identity.HasClaim(claimType, claimValue))
{
ctx.Identity.AddClaim(new Claim(claimType, claimValue, "XmlSchemaString", "Facebook"));
}
}
}
}
};
// Set requested scope
facebookAuthenticationOptions.Scope.Add("email");
facebookAuthenticationOptions.Scope.Add("public_profile");
// Set requested fields
facebookAuthenticationOptions.Fields.Add("email");
facebookAuthenticationOptions.Fields.Add("first_name");
facebookAuthenticationOptions.Fields.Add("last_name");
app.UseFacebookAuthentication(facebookAuthenticationOptions);
謝謝!有效 – DevExpress