我正在尝试检索作为OnAuthenticated上下文返回的用户属性,并在此示例后添加为声明: 如何使用ASP.NET身份(OWIN)访问Facebook私人信息?
我可以看到我期望的数据是在登录时返回的,并且在Starup.Auth.cs中被添加为声明.但是,当我在帐户控制器内时,UserManager或UserStore中出现的唯一声明由LOCAL AUTHORITY颁发.Facebook(或其他外部提供商)无法找到任何索赔.在上下文中添加的声明到底在哪里?(我正在使用VS2013 RTM.)
Azure上的完整源代码和实时站点链接到这里:https://github.com/johndpalm/IdentityUserPropertiesSample/tree/VS2013rtm
这是我在Startup.Auth.cs中的内容:
var facebookOptions = new Microsoft.Owin.Security.Facebook.FacebookAuthenticationOptions()
{
AppId = ConfigurationManager.AppSettings.Get("FacebookAppId"),
AppSecret = ConfigurationManager.AppSettings.Get("FacebookAppSecret"),
Provider = new Microsoft.Owin.Security.Facebook.FacebookAuthenticationProvider()
{
OnAuthenticated = (context) =>
{
const string XmlSchemaString = "http://www.w3.org/2001/XMLSchema#string";
foreach (var x in context.User)
{
var claimType = string.Format("urn:facebook:{0}", x.Key);
string claimValue = x.Value.ToString();
if (!context.Identity.HasClaim(claimType, claimValue))
context.Identity.AddClaim(new System.Security.Claims.Claim(claimType, claimValue, XmlSchemaString, "Facebook"));
}
context.Identity.AddClaim(new System.Security.Claims.Claim("urn:facebook:access_token", context.AccessToken, XmlSchemaString, "Facebook"));
return Task.FromResult(0);
}
}
};
facebookOptions.Scope.Add("email");
app.UseFacebookAuthentication(facebookOptions);
Run Code Online (Sandbox Code Playgroud)
捕获外部登录属性的另一种方法是为访问令牌添加单个声明并使用属性填充它:
const string XmlSchemaString = "http://www.w3.org/2001/XMLSchema#string";
var …Run Code Online (Sandbox Code Playgroud)