Microsoft.Owin.Security.xyz OnAuthenticated doesn't store in database
-
21-12-2019 - |
문제
I'm using ASP.NET Identity 2.0. I see many ASP.NET Identity samples like this:
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);
}
}
};
The AddClaim looks like just add these claim into memory only. Not store in the database. Is that normal? I mean what can I do if I want to store these claims into database and read it after. I few see any code sample about this.
해결책
It's usually in the callback where you map the claims from the external provider to your DB, and then you issue a new cookie to model the main authentication cookie for your app. This might help explain more:
제휴하지 않습니다 StackOverflow