我试图检索返回作为OnAuthenticated背景和添加下面这个例子中的权利要求用户属性:How to access Facebook private information by using ASP.NET Identity (OWIN)?如何访问Microsoft.Owin.Security.xyz OnAuthenticated上下文AddClaims值?
我可以看到数据,我希望在登录时被返回,被添加为在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);
的另一种方式捕捉外部登录属性将添加一个要求的访问令牌和填充它与属性:
const string XmlSchemaString = "http://www.w3.org/2001/XMLSchema#string";
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) =>
{
var claim = new System.Security.Claims.Claim("urn:facebook:access_token", context.AccessToken, XmlSchemaString, "Facebook");
foreach (var x in context.User)
{
string key = string.Format("urn:facebook:{0}", x.Key);
string value = x.Value.ToString();
claim.Properties.Add(key, value);
}
context.Identity.AddClaim(claim);
return Task.FromResult(0);
}
}
};
注 - 此示例不起作用:你呃这将是很好的通过一个单一的索赔与属性。外部cookie似乎要注意声明属性。从身份中稍后检索它们时,属性为空。
当我使用你的代码时,我得到了一个Google 404的错误代码。我可以告诉Google不再支持这个,oauth2。 –