Aspnet Core Identity 有關的數據庫表、配置及擴展


1、表 AspNetUserTokens  有四個字段  UserId(關聯用戶表) 、LoginProvider 、Name、Value

     用於外部驗證的 token 存儲,被方法  SignInManager.UpdateExternalAuthenticationTokensAsync 填寫。

     內部驗證的 token 默認存儲在內存(memory)中  , 如果想存儲在數據庫中, 你必須創建自己的表及相關存儲的邏輯。

      參考《https://stackoverflow.com/questions/51200884/populating-aspnetuserlogins-and-aspnetusertokens

2、表 AspNetUserLogins  有四個字段  LoginProvider、 ProviderKey、ProviderDisplayName,  UserId(關聯用戶表)

      保留 第3方/外部 login 的信息,如 Google, Facebook, Twitter 等。此表被外部 authentication provider 所用。

      通用在一個 user 經 external provider登錄(login )后,此 provider 返回一個 ClaimsIdentity,  其中包括了用戶 claims,含有有一個 唯一用戶id 在 external provider 中, 並自動更新此表,不用自己寫代碼。

      如果你一定要手動增加表中數據,你可這樣做:參考:《https://stackoverflow.com/questions/35155447/the-aspnetuserlogins-table-identity

         userManager.AddLoginAsync(user.Id, new Microsoft.AspNet.Identity.UserLoginInfo("Facebook", id))

         上述是通過:Facebook login,必須將  Facebook 用戶 id 與 ASPNet Identity 的 user.Id 關聯起來。

 --¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥

3、AspNetUserClaims 表 有四個字段:   Id,UserId(關聯用戶表)ClaimType, ClaimValue,  

     此表對應 類 IdentityRoleClaim可以通過 本方法增加 表中 Claim 記錄:  wait UserManager.AddClaimAsync(user, customClaim);

 

   在用戶登錄驗證通過后,是否 自動獲取 本表中 Claim ? 等驗證!  =====  好像是登錄后,自動獲取表中的 Claim,放入 ClaimsIdentity中。

   問題: 是擴展  AspNetUser 的字段,或者 通過 AspNetUserClaims 擴展用戶信息,取決於你的需要!

   public class AspNetUserTokens : IdentityUserToken<Guid>{ /*your code here*/ }

public class AspNetRoleClaims : IdentityRoleClaim<Guid>{ /*your code here*/ } public class AspNetUserLogins : IdentityUserLogin<Guid>{ /*your code here*/ } public class AspNetUserRoles : IdentityUserRole<Guid>{ /*your code here*/ } public class AspNetUserClaims : IdentityUserClaim<Guid>{ /*your code here*/ }

 

4、IdentityDbContextIdentityUserContext 源代碼

   IdentityEntityFrameworkBuilderExtensions 有 IdentityBuilder AddEntityFrameworkStores<TContext>()擴展方法。

5、ASPNET Core Identity 主要通過三個比較核心的類 UserManager、RoleManager、SigninManager進行管理(在Microsoft.AspNetCore.Identity程序集) 參考:《NET Core中的認證授權管理解析http://blog.baibaota.com/918.html》 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM