授权机制说明
Oauth 2.0概述
大部分API的访问都需要用户身份,目前奕奕开放平台用户身份鉴权有OAuth2.0(仅用于应用所属开发者调试接口)。
OAuth2.0授权验证流程更简单更安全,也是未来最主要的用户身份验证和授权方式。
关于OAuth2.0协议授权流程查看OAuth2.0授权流程 ,其中Client指第三方应用,Resource Owner指用户,Authorization Server是我们的授权服务器,Resource Server是API服务器。
接口文档
1. 9211登陆接口
http://passport.9211.com/oauth
1) HTTP请求方式
GET
2) 请求参数
参数 | 必选 | 类型 | 说明 |
---|---|---|---|
appId | True | long | 申请应用时分配的AppId |
redirectUrl | True | String | 授权回调的地址 |
responseType | True | String | 授权类型,固定为code |
3) 返回数据
返回值字段 | 字段类型 | 字段说明 |
---|---|---|
code | String | 用于调用access_token,接口获取授权后的access token。 |
通过回调地址把参数传递过去,例如: http://www.xxxx.com?code={code} ,回调地址通过code用于获取token
2. 获取授权过的Access Token
1) OAuth2的access_token接口
OAuth2的access_token接口
2) URL
http://openapi.5211game.com:8080/oauth/access_token
3) HTTP请求方式
POST
4) 请求参数
参数 | 必选 | 类型 | 说明 |
---|---|---|---|
app_id | True | long | 申请应用时分配的AppId。 |
app_secret | True | String | 申请应用时分配的appsecret。 |
grant_type | True | String | 请求的类型,固定填写"authorization_code"。 |
code | True | String | 调用authorize获得的code值。 |
redirect_uri | True | String | 回调地址,需与注册应用里的回调地址一致。 |
5) 返回数据
返回值字段 | 字段类型 | 字段说明 |
---|---|---|
access_token | String | 用于调用access_token,接口获取授权后的access token。 |
expires_in | long | access_token的生命周期,单位是秒数。 |
uid | int | 当前授权用户的uid。 |
{
"access_token": "ACCESS_TOKEN",
"expires_in": 1234,
"uid":"12341234",
"scope":"users"
}
"access_token": "ACCESS_TOKEN",
"expires_in": 1234,
"uid":"12341234",
"scope":"users"
}
3. 查询用户基本信息
1) OAuth2的users接口
根据用户ID获取用户信息
2) URL
http://openapi.5211game.com:8080/oauth/user_basic_info
3) 支持格式
JSON
4) HTTP请求方式
GET
5) 是否需要登录
是
6) 请求参数
参数 | 必选 | 类型 | 说明 |
---|---|---|---|
access_token | True | String | 采用OAuth授权方式为必填参数,其他授权方式不需要此参数,OAuth授权后获得。 |
uid | True | int | 需要查询的用户ID。 |
7) 返回结果
返回值字段 | 字段类型 | 字段说明 |
---|---|---|
uid | int | 用户ID。 |
screen_name | String | 用户名。 |
idcard_verified | String | 是否身份证验证过。0:未通过,1:通过。 |
idcard_birthday | String | 用户出生年月。如果idcard_verified为1,才会返回该字段。 |
UserAntiAddiction | int | 防沉迷设置(0:不作防沉迷判断 1:成年 2:未成年) |
{
"uid": 1234567890,
"screen_name": "5211game",
"idcard_verified": "1",
"idcard_birthday": "2000-01-01";
"UserAntiAddiction": 1
}
"uid": 1234567890,
"screen_name": "5211game",
"idcard_verified": "1",
"idcard_birthday": "2000-01-01";
"UserAntiAddiction": 1
}
4. 错误信息
1) 返回结果
返回值字段 | 字段类型 | 字段说明 |
---|---|---|
error | int | 错误码。 |
error_info | String | 错误说明。 |
{
"error":"10001",
"error_info": "参数错误"
}
"error":"10001",
"error_info": "参数错误"
}
2) 错误代码
错误码 | 错误码说明 |
---|---|
10001 | 系统错误 |
20001 | 错误的参数 |
20002 | 无效的Code |
20003 | 未授权的地址访问 |
20004 | 应用密码不正确 |
20005 | 应用不存在 |
30001 | 应用未上线,请使用测试账户 |