描述
此流程获取token适合开发者没有自己的web服务器,且应用为原生程序,即客户端应用(同时应用无法与浏览器交互,但是可以外调用浏览器)。搭搭云官方Android SDK、iOS SDK采用此认证。
请求
URL
HTTP请求方式
POST
Header参数
{ "Content-Type":"application/x-www-form-urlencoded" }
- HTTP请求参数
名称 | 是否必需 | 类型 | 描述 |
---|---|---|---|
client_id | 是 | String | 申请应用时分配的AppKey。 |
client_secret | 是 | String | 申请应用时分配的AppSecret。 |
grant_type | 是 | String | 授权类型,此处的值固定为password 。 |
username | 是 | String | 用户名 |
password | 是 | 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=password&username=xxx&password=xxx&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参数无效。 |
invalid_grant | 提供的凭证验证失败。 | 400 | 提供的凭证验证失败(用户名或密码为空,用户名或密码超过最大长度)。 |
unauthorized_client | 客户端没有权限。 | 400 | 客户端没有权限(客户端不允许此模式验证)。 |
unsupported_grant_type | 不支持的 GrantType。 | 400 | 不支持的 GrantType。 |
invalid_scope | Scope验证失败。 | 400 | Scope验证失败。 |
temporarily_unavailable | 服务暂时无法访问。 | 500 | 服务暂时无法访问。 |
server_error | 服务器内部错误,请联系管理员。 | 500 | 服务器内部错误,请联系管理员。 |