授权码流程第 2 步:用户在授权页点击允许/拒绝后调用。允许时生成授权码(有效期 10 分钟,一次性),返回拼好 code 与 state 的 redirect_url,前端据此跳转;拒绝时返回 HTTP 200、msg「用户拒绝授权」,data.redirect_url 带 error=access_denied&error_description=User+denied+access&state=... 的 redirect_url。client_id / redirect_uri 校验规则同 authorize;scope 与 PKCE 参数应原样传入 authorize 返回的值。PKCE:code_challenge_method 支持 plain / S256(仅传 code_challenge 不传 method 时视为 plain);plain 时 code_challenge 须匹配 ^[A-Za-z0-9-._~]{43,128}$,S256 时须为 43 位 base64url。public 客户端必须携带 code_challenge。
鉴权:需要用户 JWT(Authorization: Bearer )
OAuth2:不允许使用 OAuth2 Access Token 调用
错误响应:
| code | msg |
|---|---|
| 401 | authorization header is missing |
| 401 | authorization header format must be Bearer {token} |
| 401 | invalid token |
| 401 | token has been revoked |
| 503 | token validation temporarily unavailable |
| 403 | 此接口不支持OAuth2访问 |
| 400 | 请求参数错误: <校验错误详情> |
| 400 | 无效的客户端ID |
| 400 | 应用已停用 |
| 400 | 无效的重定向URI |
| 400 | 无效的权限范围 |
| 400 | 缺少 code_challenge 参数 |
| 400 | public 客户端必须使用 PKCE |
| 400 | 不支持的 code_challenge_method,仅支持 plain 或 S256 |
| 400 | code_challenge 格式不正确 |
| 500 | 内部错误 |
| 500 | 生成授权码失败 |
| 500 | 创建授权码失败 |