>我创建了一个启用了独立身份验证的 MVC SPA 应用程序。并将所有 OWIN DLL 更新到 3.1.0 版本。更新了启动中注册的 AppID 和密钥.cs(从 DeConsole 获取(
登录页面中启用了"Facebook"按钮,单击它会将我带到FB登录页面以提供我的凭据。登录后,它不会要求任何确认,例如谷歌询问(应用程序尝试访问您的基本信息允许/拒绝(,然后重定向回应用程序。但是没有任何基本信息从FB获得。我在这里错过了什么吗返回网址始终为 localhost:33343/Account/Login#=_..
我想Microsoft提供了我们需要的一切,但实际上并非如此。
您必须从 OWIN 中间件获取acccess_denied。尝试将调试器放在帐户控制器操作"外部登录回调"中。
我假设您已经添加了 http://your_domain/signin-facebook 作为 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);