密码模式认证
用户在客户端输入用户名和密码进行登录,客户端应用后台调用统一认证平台获取Access Token接口。
请求说明
http
POST https://{your_domain}/api/v1/oauth2/token请求头
| 参数名 | 中文名称 | 必填 | 示例值 | 描述 |
|---|---|---|---|---|
| Authorization | 认证信息 | 必须 | Basic UnFCMOWk9xWA== | 使用client_id和client_secret进行basic64认证, 格式为: base64(client_id:client_secret) |
| Content-Type | 数据类型 | 必须 | application/x-www-form-urlencoded | 使用表单方式提交参数 |
请求示例
http
POST https://{your_domain}/api/v1/oauth2/tokenAuthorization: Basic UnFCMkhKdGt6bFU...aT0NObkk4NlNOWk9xWA==
Content-Type: application/x-www-form-urlencoded
username=test&password=123456&grant_type=password
请求参数
| 参数名 | 中文名称 | 必填 | 示例值 | 描述 |
|---|---|---|---|---|
| grant_type | 授权类型 | 是 | password | password |
| username | 登录名 | 是 | test | 登录名/手机号/邮箱 |
| password | 密码 | 是 | 123456 |
返回示例
正确返回示例
json
HTTP Status: 200 OK
{
"access_token": "Z43T3KWH9lecmy3H1IaCI...XRmsXaA",
"token_type": "Bearer",
"refresh_token": "WEAFOmOJ-A4LOhF_I39DvJuqxP0...XkFlFA",
"expires_in": 7199,
"scope": "get_user_info"
}用户名密码不正确
json
HTTP Status: 400 Bad Request
{
"error": "invalid_request",
"error_description": "An authorization username must be supplied."
}用户名密码不正确
json
HTTP Status: 400 Bad Request
{
"error": "invalid_grant",
"error_description": "Bad credentials"
}用户已被锁定
json
HTTP Status: 400 Bad Request
{
"error": "invalid_grant",
"error_description": "User is locked"
}用户已被禁用
json
HTTP Status: 400 Bad Request
{
"error": "invalid_grant",
"error_description": "User is disabled"
}用户密码已过期
json
HTTP Status: 400 Bad Request
{
"error": "invalid_grant",
"error_description": "Password has expired"
}应用凭据错误
json
HTTP Status: 401 UNAUTHORIZED
{
"error": "invalid_client",
"error_description": "Bad client credentials"
}返回参数
如果用户成功登录并授权,会返回系统的授权令牌access token。
| 参数名 | 中文名称 | 必填 | 描述 |
|---|---|---|---|
| access_token | 授权令牌 | 8ab9812c-1076-47f0-9e4a-6d48280ec524 | 授权服务器返回给第三方应用的授权令牌,后续所有接口访问均需提供此参数。 |
| expires_in | 授权令牌的有效期 | 1500 | 授权服务器返回给应用的访问票据的有效期。注意:有效期以秒为单位。 |
| refresh_token | 刷新令牌 | 92fe3c7a-f8ad-4dc3-b0c4-c0281c1fa560 | |
| token_type | 令牌类型 | bearer | |
| scope | 授权范围 | get_user_info |