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是 “證件單元
檢視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 //與下面的意思相同 34 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 }