授权码模式

最近更新时间:2022-03-23 18:05:22

我的收藏

接口描述

使用授权码(code)换取授权令牌(access_token)。

请求方法

POST

请求地址

/auth/oauth2/token

请求参数

参数
参数位置
类型
是否必填
描述
client_id
Query
String
客户端 ID,可参考 应用管理页面 > 选定指定应用 > 单击应用配置 > 对应的“Client Id”
grant_type
Query
String
固定值“authorization_code”
redirect_uri
Query
String
授权成功后的重定向地址。如果“用户授权/authorize”请求带有 redirect_uri 参数,则本步骤请求必须上送 redirect_uri 参数,EIAM 会校验该请求参数值与“用户授权/authorize”上送的 redirect_uri 参数值是否一致。含特殊字符,需要做 URLEncode
code
Query
String
授权码
client_secret
Query
String
客户端 Secret, 应用管理页面 > 选定指定应用 > 单击应用配置 > 对应的“Client Secret”。含有特殊字符,需要做 URLEncode。如 code_verifier 为空,则 client_secret 必须上送。
code_verifier
Query
String
PKCE 模式必要参数,code_verifier 校验码原文。可能含有特殊字符,需要做 URLEncode

返回参数

参数
参数位置
类型
描述
access_token
Body
String
access_token
expires_in
Body
Long
access_token 有效时间,与创建应用时设置的“access_token有效期”一致
refresh_token
Body
String
refresh_token

返回方式

重定向

接口示例

输入示例

https://<auth_domain>/auth/oauth2/token?client_id=ODQyNGJlYmFjY****WE4YjkwNjU4MzMxOThkMGU&grant_type=authorization_code&redirect_uri=http%3A%2F%2Flocalhost%3A9080%2Fauth%2Fredirect%2Fget&code=b9eb0dc2****4993e0aca6180&client_secret=oG412Uk6EdbfXtgU****UdJht1j%2bq&code_verifier=s9hw2n

返回示例

{
"access_token": "c6a40b1****058eaed0f59509b541",
"expires_in": 7200,
"refresh_token": "6865e92a****01df8081e4562e26c82"
}