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 }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· 展开说说关于C#中ORM框架的用法!
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?