Skip to content

密码模式认证

用户在客户端输入用户名和密码进行登录,客户端应用后台调用统一认证平台获取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/token

Authorization: Basic UnFCMkhKdGt6bFU...aT0NObkk4NlNOWk9xWA==

Content-Type: application/x-www-form-urlencoded

username=test&password=123456&grant_type=password

请求参数

参数名中文名称必填示例值描述
grant_type授权类型passwordpassword
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

竹云IDaaS开放平台