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:

http://brockallen.com/2014/01/09/a-primer-on-external-login-providers-social-logins-with-owinkatana-authentication-middleware/

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top