Sto cercando di recuperare le proprietà degli utenti che vengono restituiti come contesto OnAuthenticated e aggiunto come affermazioni che seguono questo esempio: How to access Facebook private information by using ASP.NET Identity (OWIN)?Come accedere a Microsoft.Owin.Security.xyz ContestoAutenticato Valori AddClaims?
posso vedere che i dati mi aspetto che viene restituita al login e viene aggiunto come Rivendica all'interno di Starup.Auth.cs. Tuttavia, quando sono all'interno del controller account, le sole affermazioni che appaiono all'interno di UserManager o UserStore sono emesse dall'autorità locale. Nessun reclamo può essere trovato per Facebook (o altri fornitori esterni). Dove finiscono le affermazioni aggiunte al contesto? (Sto usando VS2013 RTM.)
sorgente completo e il sito in diretta su Azure legata qui: https://github.com/johndpalm/IdentityUserPropertiesSample/tree/VS2013rtm
Ecco quello che ho in 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);
Un modo alternativo per catturare le proprietà d'accesso esterne sarebbe quella di aggiungere un singolo reclamo per il token di accesso e popolarlo con le proprietà:
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);
}
}
};
NOTA - Questo esempio non funziona: tu Sarebbe bello passare un singolo reclamo con proprietà. Il cookie esterno sembra sottolineare le proprietà dei crediti. Le proprietà sono vuote quando le recuperano in seguito dall'identità.
Ricevo un codice di errore 404 di Google quando utilizzo il codice. Da quello che posso dire a Google non supporta più questo, oauth2. –