4. JSON Web Token 声明和 Introspection 响应参数 (JSON Web Token Claims and Introspection Response Parameters)
定义一些机制来在 token 中表达 delegation, 以及表达对 delegation 或 impersonation 的授权, 是有用的. 虽然本文档描述的 token exchange protocol 可以与任意类型的 token 一起使用, 本节专门为 JWT 以及 OAuth 2.0 Token Introspection [RFC7662] 响应定义 claims, 用于表达这些语义. 为其他类型 token 给出类似定义是可能的, 但超出本规范范围.
请注意, 本文未建立但在示例和说明中使用的 claims, 例如 "iss", "sub", "exp" 等, 由 [JWT] 定义.
4.1. "act" (Actor) Claim
"act" (actor) claim 提供一种在 JWT 中表达已发生 delegation 的方式, 并标识被委派权限的 acting party. "act" claim 值是一个 JSON object, JSON object 中的成员是用于标识 actor 的 claims. 组成 "act" claim 的 claims 标识 actor, 并可能提供有关 actor 的附加信息. 例如, 可能需要组合 "iss" 和 "sub" 两个 claims 才能唯一标识 actor.
但是, "act" claim 内部的 claims 只与 actor 的身份有关, 不像顶层 claims 那样与包含它的 JWT 的有效性相关. 因此, 非身份 claims, 例如 "exp", "nbf" 和 "aud", 在 "act" claim 内部使用时没有意义, 因而不使用.
图 5 展示 JWT Claims Set 中的 "act" (actor) claim. token 本身的 claims 关于 [email protected], 而 "act" claim 指示 [email protected] 是当前 actor.
{
"aud":"https://consumer.example.com",
"iss":"https://issuer.example.com",
"exp":1443904177,
"nbf":1443904077,
"sub":"[email protected]",
"act":
{
"sub":"[email protected]"
}
}
图 5: Actor Claim
通过在一个 "act" claim 中嵌套另一个 "act" claim, 可以表达 delegation chain. 最外层的 "act" claim 表示当前 actor, 嵌套的 "act" claims 表示先前 actors. 时间上最早的 actor 位于最深层嵌套处. 嵌套的 "act" claims 作为 history trail, 将初始请求和 subject 与到达当前 actor 之前执行的各个 delegation steps 连接起来. 从这个意义上说, 当前 actor 被认为包含完整的 authorization/delegation history, 这自然导向本文描述的嵌套结构.
为了应用访问控制策略, token 的消费者MUST只考虑 token 的顶层 claims 以及由 "act" claim 标识为当前 actor 的一方. 由任何嵌套 "act" claims 标识的先前 actors 仅供参考, 不应在访问控制决策中考虑.
图 6 中的示例展示 JWT Claims Set 中嵌套的 "act" (actor) claims. token 本身的 claims 关于 [email protected], 而 "act" claim 指示系统 <https://service16.example.com> 是当前 actor, <https://service77.example.com> 是先前 actor. 这类 token 可能产生于如下情况: service16 在来自 service77 的调用中收到一个 token, 并将其交换为适合调用 service26 的 token, 同时 authorization server 在新签发的 token 中记录该情况.
{
"aud":"https://service26.example.com",
"iss":"https://issuer.example.com",
"exp":1443904100,
"nbf":1443904000,
"sub":"[email protected]",
"act":
{
"sub":"https://service16.example.com",
"act":
{
"sub":"https://service77.example.com"
}
}
}
图 6: 嵌套 Actor Claim
当 "act" 作为 OAuth token introspection 响应的顶层成员包含时, 它具有与同名 claim 相同的语义和格式.
4.2. "scope" (Scopes) Claim
"scope" claim 的值是一个 JSON string, 其中包含与 token 关联的 scopes 的空格分隔列表, 格式见 [RFC6749] 第 3.3 节.
图 7 展示 JWT Claims Set 中的 "scope" claim.
{
"aud":"https://consumer.example.com",
"iss":"https://issuer.example.com",
"exp":1443904177,
"nbf":1443904077,
"sub":"dgaf4mvfs75Fci_FL3heQA",
"scope":"email profile phone address"
}
图 7: Scopes Claim
OAuth 2.0 Token Introspection [RFC7662] 已经定义 "scope" parameter, 用于传达与 token 关联的 scopes.
4.3. "client_id" (Client Identifier) Claim
"client_id" claim 携带请求该 token 的 OAuth 2.0 [RFC6749] client 的 client identifier.
图 8 中的示例展示 JWT Claims Set 中的 "client_id" claim, 表示一个 identifier 为 "s6BhdRkqt3" 的 OAuth 2.0 client.
{
"aud":"https://consumer.example.com",
"iss":"https://issuer.example.com",
"exp":1443904177,
"sub":"[email protected]",
"client_id":"s6BhdRkqt3"
}
图 8: Client Identifier Claim
OAuth 2.0 Token Introspection [RFC7662] 已经将 "client_id" parameter 定义为请求该 token 的 OAuth 2.0 client 的 client identifier.
4.4. "may_act" (Authorized Actor) Claim
"may_act" claim 声明某一方被授权成为 actor 并代表另一方行事. 例如, 当 "subject_token" 在 token exchange request 中提交给 token endpoint 时, subject token 中的 "may_act" claim 可供 authorization server 用于判断 client, 或 "actor_token" 中标识的一方, 是否被授权参与所请求的 delegation 或 impersonation.
claim 值是一个 JSON object, JSON object 中的成员是用于标识某一方的 claims, 该方被断言为有资格代表包含该 claim 的 JWT 所标识的一方行事. 组成 "may_act" claim 的 claims 标识 authorized actor, 并可能提供有关它的附加信息. 例如, 有时需要组合 "iss" 和 "sub" 两个 claims 才能唯一标识 authorized actor, 而 "email" claim 可用于提供有关该方的其他有用信息.
但是, "may_act" claim 内部的 claims 只与该方身份有关, 不像顶层 claims 那样与包含它的 JWT 的有效性相关. 因此, "exp", "nbf" 和 "aud" 等 claims 在 "may_act" claim 内部使用时没有意义, 因而不使用.
图 9 展示 JWT Claims Set 中的 "may_act" claim. token 本身的 claims 关于 [email protected], 而 "may_act" claim 指示 [email protected] 被授权代表 [email protected] 行事.
{
"aud":"https://consumer.example.com",
"iss":"https://issuer.example.com",
"exp":1443904177,
"nbf":1443904077,
"sub":"[email protected]",
"may_act":
{
"sub":"[email protected]"
}
}
图 9: Authorized Actor Claim
当 "may_act" 作为 OAuth token introspection 响应的顶层成员包含时, 它具有与同名 claim 相同的语义和格式.