存储 OAuth 用户配置文件

当有人向你的应用程序注册时,新的 ApplicationUser 对象将存储在数据库中。默认情况下,该类非常准确,但可以自定义 - 你可以在 Models> IdentityModels.cs 中找到它。这是我的:

public class ApplicationUser : IdentityUser
{
      public string ImageUrl { get; set; }
      public DateTime DateCreated { get; set; }
      public string FirstName { get; set; }
      public string AuthProvider { get; set; }
      public string Surname { get; set; }

      public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager, string authenticationType)
      {
            // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
            var userIdentity = await manager.CreateIdentityAsync(this, authenticationType);
            // Add custom user claims here
            return userIdentity;
      }
}

作为参考,从启用了 Google+ API 的 Google 返回的用户个人资料采用以下 JSON 结构:

{{
    "id": "1****************6",
    email": "dan********@gmail.com",
    "verified_email": true,
    "name": "Dan Richardson",
    "given_name": "Dan",
    "family_name": "Richardson",
    "link": "https://plus.google.com/+DanRichardson",
    "picture": "https://lh4.googleusercontent.com/photo.jpg",
    "gender": "male",
    "locale": "en"
}}