identityServer4 中的概念(Scope,claim)


在IdentityServer中好多地方出現這幾個詞,這單詞的解釋也有好多大神解釋過:

chaim:

 

ASP.NET Core 之 Identity 入門(一),這個是asp.net identity中chaim的解釋,雖然不是identityServer,但解釋相當精准。

IdentityServer4實戰 - 基於角色的權限控制及Claim詳解 ,這是是Claim 在identityServer中的解釋。

首先查看identityServer中chaim出現的地方:

Clientclaims、Identityclaims、apiclaims和APIScopeclaims,說明claim與這些東東都有關系,按照上面第一篇博客的說明,這個claim是 “證件單元”,這個apiclaims就解釋為api的需要的證件單元,也不是太合適;按照第二篇博客說的claim是“用戶信息單元”,只有解釋用戶的時候可以這么說。

查看identityServer源碼,claim包含type和value兩個property,在identity、apiresource和apiscope中都有(UserClaims)這個屬性,官方解釋:List of associated user claim types that should be included in the access token.就是需要在access token中應該包含的一系列相關claim 類型,如果access token中含有這個claim可以訪問這個resource,另外APIScopeclaims中的claim也會附加到這個api資源上。

Scopes:

英文翻譯:范圍

Scope出現在兩個地方:clientScope和apiscope。

Scope 在ids3中的解釋:IdentityServer.Core.Models.Scope 類是對 OpenID Connect 或 OAuth2 scope 的建模。這個解釋很合理;

在token中scope是一個claim,這個很重要:scope也是一個claim;

apiscope,一個api至少有一個scope,下面的兩個定義是一個意思:

 1 new ApiResource("api1", "Some API 1")
 2 //與下面的意思相同 3 
 4 new ApiResource
 5 {
 6     Name = "api1",
 7     DisplayName = "Some API 1", 8 
 9     Scopes =
10     {
11         new Scope()
12         {
13             Name = "api1",
14             DisplayName = "Some API 1"
15         }
16     }
17 }

一個api也可以有多個scope,例如:

 1 new ApiResource
 2 {
 3     Name = "api2",
 4 
 5     Scopes =
 6     {
 7         new Scope()
 8         {
 9             Name = "api2.full_access",
10             DisplayName = "Full access to API 2"
11         },
12         new Scope
13         {
14             Name = "api2.read_only",
15             DisplayName = "Read only access to API 2"
16         }
17     }
18 }

 

 

 

 

 

 

 

 

 

 

 

 


免責聲明!

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



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