承载协议 | HTTPS POST |
|---|---|
接口方向 | 服务商服务器 -> 华为服务器 |
接口URL | https://oauth-login.cloud.huawei.com/oauth2/agent/v1/access-token/refresh |
数据格式 | 请求:Content-Type: application/json 响应:Content-Type: application/json |
参数 | 必选(M)/可选(O) | 类型 | 说明 |
|---|---|---|---|
x-client-id | M | String | 商家的client_id。 |
x-agent-client-id | M | String | 服务商的client_id。 创建第三方平台时由服务商主动创建的服务账号ID,可在第三方管理平台“开发配置 > 开发资料设置”页面中创建/查询,详情请参见接口访问凭证(应用访问凭据)。 |
参数 | 必选(M)/可选(O) | 类型 | 说明 |
|---|---|---|---|
grant_type | M | String | 固定为refresh_token。 |
refresh_token | M | String | 填写获取用户级Token返回的refresh_token。 |
client_assertion_type | M | String | 固定为"urn:ietf:params:oauth:client-assertion-type:jwt-bearer"。 |
client_assertion | M | String | 服务商生成的JWT。 |
其中,client_assertion是一个JSON Web Token(JWT)。
JWT由Header、Payload和Signature三部分拼接组成,三部分中间以“.”号分隔,例如:xxxx.yyyy.zzzz。
服务商可以依据Header中指定算法以及使用创建凭据下载的json文件内密钥ID关联的私钥(即json凭据文件中private_key)进行签名生成JWT。
JWT Header
参数 | 必选(M)/可选(O) | 类型 | 说明 |
|---|---|---|---|
alg | M | String | 算法类型,固定为PS256。 |
typ | M | String | Token类型,固定为JWT。 |
kid | M | String | 密钥ID。即json凭据文件中key_id。 |
JWT Payload
参数 | 必选(M)/可选(O) | 类型 | 说明 |
|---|---|---|---|
iss | M | String | 服务商的client_id。 创建第三方平台时由服务商主动创建的服务账号ID,可在第三方管理平台“开发配置 > 开发资料设置”页面中创建/查询,详情请参见接口访问凭证(应用访问凭据)。 |
sub | M | String | 商家的client_id。 |
aud | M | String | 固定为"https://oauth-login.cloud.huawei.com/oauth2/agent/token"。 |
iat | M | Integer | 生成时间,linux时间戳。 |
exp | M | Integer | 过期时间,linux时间戳。 |
POST /oauth2/agent/v1/access-token/refresh HTTP/1.1
Host: oauth-login.cloud.huawei.com
x-client-id: 12345000
x-agent-client-id: 12345666
Content-Type: application/json
{
"grant_type": "refresh_token",
"refresh_token": "DAECABdcJTSlxxxxxHi81JkkE6zGT",
"client_assertion_type": "urn:ietf:params:oauth:client-assertion-type:jwt-bearer",
"client_assertion": "xxxx.yyyy.zzzz"
} 返回值为JSON格式的字符串,包含参数如下。
字段名 | 类型 | 说明 |
|---|---|---|
id_token | String | 如果scope中包含openid,则返回id_token,JWT格式。 如果要解析出用户的ID Token,需要先对ID Token的有效性进行验证,详情请参见ID Token验证签名。 |
access_token | String | ACCESS_TOKEN,后续用它来调用业务API接口。 |
token_type | String | 固定值Bearer。 |
expires_in | Integer | access_token的过期时间,以秒为单位。过期时间默认60分钟。 |
scope | String | 该access_token对应的scope列表,以空格分隔。 |
成功:
HTTP/1.1 200 OK
Content-Type: application/json;charset=UTF-8
Cache-Control: no-store
Pragma: no-cache
{
"access_token": "CFyJ4Jxxxxxxxxx7vs=",
"id_token": "eyJhbGciOiJSUzxxxxxxxxxx1GDLQ",
"expires_in": 3600,
"scope": "openid profile email",
"token_type": "Bearer"
} 失败:
失败返回的httpstatus=400,在body中返回错误码和描述,json格式。
例如:
HTTP/1.1 400 Bad Request
Content-Type: text/html;charset=UTF-8
{
"error":31204,
"error_description":"token revoked"
} 错误码 | 描述 | 解决方法 |
|---|---|---|
20181 | grant_type为空 |
|
20182 | grant_type值不正确 | |
20001 | 商家client_id为空 | |
20002 | 商家client_id格式不对 | |
20003 | 商家client_id在系统不存在 | |
20900 | 服务商client_id为空 | |
20901 | 服务商client_id格式不对 | |
20902 | 服务商client_id在系统不存在 | |
20903 | 服务商client_id和商家client_id无代理关系 | |
20910 | client_assertion_type的值不对 | |
20911 | client_assertion没有值 | |
20912 | client_assertion的值不满足基本格式校验 | |
20913 | client_assertion中iss和请求头x-agent-client-id不一致 | |
20914 | client_assertion中sub和请求头x-client-id不一致 | |
20915 | client_assertion过期 | |
20916 | client_assertion签名校验未通过 | |
20191 | refresh_token为空 | |
20192 | refresh_token初步格式校验不通过 | |
20154 | refresh_token对应的client_id和入参不一致 | |
31218 | refresh_token编码格式不对 | |
31202 | refresh_token不可解码 | |
11205 | refresh_token过期 | 需要提示用户重新授权 |
31204 | refresh_token失效(用户修改密码或者取消授权等操作,会使之前的refresh_token失效) | |
57301 | ip is overload blocked | 被流控,请排查是否有异常调用 |
57300 | ip is in blacklist | |
57304 | appid of usertoken is overload blocked | |
57305 | appid of usertoken is in blacklist | |
57306 | uid of usertoken is overload blocked | |
57307 | uid of usertoken is in blacklist | |
其他错误码 | 其他错误,服务器内部错误。 |
|