OAuth2 授权流程介绍
OAuth2登录授权
伙伴账号申请
申请数据 | 说明 |
---|---|
应用名称 | OAuth2登录授权页需要展示 |
Icon图标 | OAuth2登录授权页需要展示, 要求尺寸100*100 |
Scope授权作用域 | 支持多个, OAuth2登录授权页需要展示, 明确告知用户需要授权的功能 |
重定向地址 | 支持多个, 登录授权重定向时使用 |
client_id
: 合作伙伴唯一标识client_secret
: 合作伙伴的 client_secret, 请妥善保管,非常重要Scope授权作用域
授权作用域 | 说明 |
---|---|
simple_info | 授权用户基础信息,头像,用户昵称,以及 openId |
mobile | 授权绑定的手机号码 |
asset | 用户资产信息,获取余额 |
steam_info | 获取绑定 steam 账号数据信息 |
steam_inventory | 读取 steam 库存数据 |
order_record | 查询购买订单与出售订单信息 |
order_operate | 授权订单操作,发货 / 取消 |
product_query | 查询在售商品数据 |
product_operate | 授权商品操作,上架 / 改价 / 下架 |
开发指南
1.
2.
3.
4.
第一步:用户同意授权,获取code
https://h5.c5game.com/thirdauth?client_id=CLIENTID&response_type=code&scope=SCOPE&redirect_uri=REDIRECT_URI
https://h5.c5game.com/thirdauth?client_id=1861097523721883713&response_type=code&scope=simple_info&redirect_uri=https%3A%2F%2Fwww.c5game.com
参数 | 是否必须 | 说明 |
---|---|---|
client_id | 是 | 客户端的唯一标识, 由C5提供 |
redirect_uri | 是 | 授权后重定向的回调链接地址 |
response_type | 是 | 返回类型,请填写code |
scope | 是 | 应用授权作用域, 多个用","分隔simple_info 授权头像,用户昵称mobile 授权绑定的手机号码steam_info 授权绑定的Steam信息template_message 授权发送模板消息 |
用户同意授权后, 将跳转至 redirect_uri?code=CODE
code说明:
code作为换取access_token的票据,每次用户授权带上的code将不一样,code只能使用一次,5分钟未被使用自动过期。
返回码 | 说明 |
---|---|
30112 | 请求的Scope暂未签约 |
30113 | 无效redirect_url |
30114 | 非法redirect_url |
30125 | 无效response_type |
第二步:通过code换取授权access_token
请求方法
获取code后,请求以下链接获取access_token:
https://partner.c5game.com/api/oauth2/token?
client_id=CLIENTID&client_secret=CLIENT_SECRET&grant_type=authorization_code&code=CODE
参数 | 是否必须 | 说明 |
---|---|---|
client_id | 是 | 客户端的唯一标识 |
client_secret | 是 | 客户端的client_secret |
code | 是 | 填写第一步获取的code参数 |
grant_type | 是 | 填写为authorization_code |
正确时返回的JSON数据包如下:
{
"success": true,
"data": {
"access_token": "xAtRg2oega5YEyLMPHtbsD7hc7fhrIb11YxVs5Kw3crhXOqK8Hd6lVTSJVUw",
"refresh_token": "NHRuicFth9F9Fj0Oo46YZWQcWgqFi5DknFgq1SnqvzytRojslfwJfATXjQjw",
"expires_in": "7199",
"refresh_expires_in": "2591999",
"client_id": "1861097523721883713",
"scope": "simple_info",
"openid": "137627761146425bac2fb4d1ad45294c"
},
"errorCode": 0,
"errorMsg": null,
"errorData": null,
"errorCodeStr": null
}
参数 | 描述 |
---|---|
access_token | 授权接口调用凭证 |
refresh_token | 用户刷新access_token |
expires_in | access_token接口调用凭证超时时间,单位(秒) |
refresh_expires_in | refresh_token接口调用凭证超时时间,单位(秒) |
client_id | 客户端的唯一标识 |
scope | 用户授权的作用域,使用逗号(,)分隔 |
openid | 用户唯一标识,用户在该客户端下唯一的OpenID |
{
"success":false,
"errorCode":30117,
"errorMsg":"无效code",
"data":null
}
返回码 | 说明 |
---|---|
30110 | 无效code |
30117 | 无效code |
30118 | 无效client_id |
30119 | 非法client_secret |
第三步:刷新access_token(如果需要)
请求方法
获取第二步的refresh_token后,请求以下链接获取access_token:
https://partner.c5game.com/api/oauth2/refresh?client_id=CLIENTID&client_secret=CLIENT_SECRET&grant_type=refresh_token&refresh_token=REFRESH_TOKEN
参数 | 是否必须 | 说明 |
---|---|---|
client_id | 是 | 客户端的唯一标识 |
client_secret | 是 | 客户端的client_secret |
grant_type | 是 | 填写为refresh_token |
refresh_token | 是 | 填写通过access_token获取到的refresh_token参数 |
正确时返回的JSON数据包如下:
{
"success": true,
"data": {
"access_token": "xAtRg2oega5YEyLMPHtbsD7hc7fhrIb11YxVs5Kw3crhXOqK8Hd6lVTSJVUw",
"refresh_token": "NHRuicFth9F9Fj0Oo46YZWQcWgqFi5DknFgq1SnqvzytRojslfwJfATXjQjw",
"expires_in": "7199",
"refresh_expires_in": "2591999",
"client_id": "1861097523721883713",
"scope": "simple_info",
"openid": "137627761146425bac2fb4d1ad45294c"
},
"errorCode": 0,
"errorMsg": null,
"errorData": null,
"errorCodeStr": null
}
参数 | 描述 |
---|---|
access_token | 授权接口调用凭证 |
refresh_token | 用户刷新access_token |
expires_in | access_token接口调用凭证超时时间,单位(秒) |
refresh_expires_in | refresh_token接口调用凭证超时时间,单位(秒) |
client_id | 客户端的唯一标识 |
scope | 用户授权的作用域,使用逗号(,)分隔 |
openid | 用户唯一标识,用户在该客户端下唯一的OpenID |
返回码 | 说明 |
---|---|
30111 | 无效refresh_token |
修改于 2024-07-17 10:00:39