描述
通过密码模式授权流程,获取到Access token以及Refresh token。Access token有一定的时效,在Access token的有效内可以通过Refresh token来延长Access token的时效。
请求
URL
HTTP请求方式
POST
Header参数
{ "Content-Type":"application/x-www-form-urlencoded" }
- HTTP请求参数
名称 | 是否必需 | 类型 | 描述 |
---|---|---|---|
client_id | 是 | String | 申请应用时分配的AppKey。 |
client_secret | 是 | String | 申请应用时分配的AppSecret。 |
grant_type | 是 | String | 授权类型,此处的值固定为refresh_token 。 |
refresh_token | 是 | String | 早前收到的更新令牌。 |
scope | 是 | String | 申请scope权限所需参数,可一次申请多个scope权限,用空格分隔。此处的值固定为openapi offline_access |
响应
- 返回参数
名称 | 类型 | 描述 |
---|---|---|
access_token | String | 授权后访问api的令牌。 |
expires_in | String | access_token的生命周期,单位是秒。 |
token_type | String | token类型。 |
refresh_token | String | 用于刷新获取最新的access_token。 |
示例
请求示例
POST /connect/token HTTP/1.1
Host: api.dadayun.cn
Content-Type: application/x-www-form-urlencoded
Date: Tue, 28 Aug 2018 06:33:44 GMT
client_id=xxx&client_secret=xxx&grant_type=refresh_token&refresh_token=REFRESH_TOKEN&scope=openapi%20offline_access
正常返回示例
HTTP/1.1 200 OK
Date: Tue, 28 Aug 2018 06:33:44 GMT
Content-Type: application/json
{
"access_token": "ACCESS_TOKEN",
"expires_in": 3600,
"token_type": "Bearer",
"refresh_token": "REFRESH_TOKEN"
}
异常返回示例
HTTP/1.1 400 Bad Request
Date: Tue, 28 Aug 2018 06:33:44 GMT
Content-Type: application/json
{
"error": "invalid_request",
"error_description": "请求不合法。"
}
错误码
以下为本接口特有的错误码。
错误代码(error) | 错误信息(error_description) | HTTP 状态码(StatusCode) | 说明 |
---|---|---|---|
invalid_request | 请求不合法。 | 400 | 请求不合法。 |
invalid_client | client_id或client_secret参数无效。 | 400 | client_id或client_secret参数无效。 |
unauthorized_client | 客户端没有权限。 | 400 | 客户端没有权限(客户端不允许此模式验证)。 |
unsupported_grant_type | 不支持的 GrantType。 | 400 | 不支持的 GrantType。 |
invalid_scope | Scope验证失败。 | 400 | Scope验证失败。 |
temporarily_unavailable | 服务暂时无法访问。 | 500 | 服务暂时无法访问。 |
server_error | 服务器内部错误,请联系管理员。 | 500 | 服务器内部错误,请联系管理员。 |