/oauth/token-exchange
实现 RFC 8693 令牌交换标准,支持 subject_token 和 actor_token 的委托链,将原始 JWT 交换为下游服务的受限访问令牌。用于 NHI Workload 身份委托场景。参考:RFC 8693 (OAuth 2.0 Token Exchange)。
请求参数
| 名称 | 位置 | 类型 | 必填 | 默认值 | 示例 | 约束 | 描述 |
|---|---|---|---|---|---|---|---|
grant_type |
formData |
string |
是 | enum: `urn:ietf:params:oauth:grant-type:token-exchange` | 授权类型 | ||
subject_token |
formData |
string |
是 | 主体令牌(JWT) | |||
actor_token |
formData |
string |
否 | 委托方令牌(JWT) | |||
scope |
formData |
string |
否 | 请求的权限范围 | |||
client_id |
formData |
string |
否 | 客户端ID |
响应
| 状态 | 描述 | Schema |
|---|---|---|
| 200 | 交换后的访问令牌(含 access_token, token_type, expires_in, scope) | service-oauth/internal/handler/dto.OAuthTokenResponse |
| 400 | invalid_scope:请求的 scope 无效或超出范围。参考:RFC 8693。 | service-oauth/internal/handler/dto.OAuthErrorResponse |
| 401 | invalid_token:subject_token 无效或过期 | service-oauth/internal/handler/dto.OAuthErrorResponse |
| 500 | server_error:令牌交换服务内部错误 | service-oauth/internal/handler/dto.OAuthErrorResponse |
引用的 Schema
service-oauth/internal/handler/dto.AuthorizationDetailDTO
| 字段 | 类型 | 必填 | 示例 | 约束 | 描述 |
|---|---|---|---|---|---|
actions |
array of string |
否 | ['["list_accounts"', '"read_balances"]'] |
操作 | |
constraints |
object |
否 | 扩展约束 | ||
data_types |
array of string |
否 | ['["account_details"', '"balances"]'] |
数据类型 | |
identifier |
string |
否 | account-12345 |
标识符 | |
locations |
array of string |
否 | ['["https://example.com/accounts"]'] |
位置 | |
type |
string |
否 | account_information |
授权类型 |
service-oauth/internal/handler/dto.OAuthErrorResponse
OAuth标准错误响应
| 字段 | 类型 | 必填 | 示例 | 约束 | 描述 |
|---|---|---|---|---|---|
error |
string |
否 | invalid_request |
错误码 | |
error_description |
string |
否 | Missing required parameter |
错误描述 | |
error_uri |
string |
否 | https://docs.example.com/errors |
错误URI | |
i18n_key |
string |
否 | error.oauth_invalid_request |
I18nKey 本地化键(AUTH-46①/U416):协议字段 error/error_description 保持 RFC 6749 §5.2 原样, 本字段是**附加**信息(omitempty;未知错误码不填),供前端/AI 客户端按键确定性渲染文案, 无需解析英文原文。仅出现在 JSON 错误体,不写入 302 错误重定向的查询串。 | |
state |
string |
否 | state-123 |
状态 |
service-oauth/internal/handler/dto.OAuthTokenResponse
OAuth令牌响应
| 字段 | 类型 | 必填 | 示例 | 约束 | 描述 |
|---|---|---|---|---|---|
access_token |
string |
否 | eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9... |
访问令牌 | |
authorization_details |
array of 参见 |
否 | RAR授权详情 | ||
dpop_access_token_bound |
boolean |
否 | 访问令牌DPoP绑定确认(RFC 9449) | ||
dpop_signing_alg |
string |
否 | DPoP签名算法(RFC 9449) | ||
expires_in |
integer |
否 | 3600 |
过期秒数 | |
id_token |
string |
否 | eyJhbGci... |
OIDC ID令牌 | |
refresh_token |
string |
否 | rt_abc123 |
刷新令牌 | |
scope |
string |
否 | openid profile email |
范围 | |
token_type |
string |
否 | Bearer |
令牌类型 |