OAuth2授权
http://pre.sovell.com/oauth/v2/authorize
http://pre.sovell.com/oauth/v2/token
http://pre.sovell.com/oauth/v2/check_token
http://pre.sovell.com/oauth/v2/userinfo
- 测试环境终端信息
client_id=B-8onb81TPCog2YBhSsQaA
client_secret=q1LQuI8C4CI
domain=pre.sovell.com
- 生产环境Oauth2地址
http://pass.sovell.com/oauth/v2/authorize
http://pass.sovell.com/oauth/v2/token
http://pass.sovell.com/oauth/v2/check_token
http://pass.sovell.com/oauth/v2/userinfo
- 生产环境终端信息根据实际情况配置
domain=pass.sovell.com
终端方式授权
- 这种方式只对client进行授权,没有用户信息
- 详见 rfc6749
-
接口调用示例
POST /oauth/v2/token HTTP/1.1 Host: pre.sovell.com Content-Type: application/x-www-form-urlencoded grant_type=client_credentials&client_id=B-8onb81TPCog2YBhSsQaA&client_secret=q1LQuI8C4CI- grant_type必须为client_credentials
短信授权
- 短信授权实际上扩展了code方式的授权过程
-
发送给某个手机
GET /oauth/v2/code?phone=${phone}&title=${title} HTTP/1.1 Host: ${domain} Authorization: Bearer ${token}参数名 类型 说明 phone string 手机号 title string 短信头 -
发送成功后不返回实际内容,HttpStatus=200即为成功
-
成功后调用/token接口
- 将手机号和收到的授权码共同作为code参数,使用.连接
- 可参考文档rfc6749
POST /oauth/v2/token HTTP/1.1 Host: ${domain} Content-Type: application/x-www-form-urlencoded client_id=${client_id}&client_secret=${client_secret}&grant_type=authorization_code&code=${phone}.${code}参数名 类型 说明 phone string 手机号 code string 收到的授权码 - grant_type必须为authorization_code
二维码授权
- 二维码授权实际上扩展了code方式的授权过程
-
取CODE
GET /oauth/v2/session/${session}/code HTTP/1.1 Host: ${domain} Authorization: Bearer ${token}参数名 类型 说明 session string 由生成端生成,此参数全局唯一,可能会与其他生成端冲突,需要做好重试机制,一个session五分钟内有效 -
调用成功后返回code
- 当调用失败时,请做好重试机制
HTTP/1.1 200 OK Content-Type: application/json;charset=UTF-8 { "code": "${code}" }状态码 说明 200 成功 409 session重复 参数名 类型 说明 code 一般用于生成二维码 -
调用/token接口
- 子系统通过二维码解码作为code参数
- 可参考文档rfc6749 4.1.3
-
调用扫码状态接口
- 一般由生产二维码端发起,用于展示二维码扫码结果
- 对于不需要知道二维码是否使用的场景可跳过本步骤
GET /oauth/v2/session/${session}/state HTTP/1.1 Host: ${domain} Authorization: Bearer ${token}参数名 类型 说明 session string 与生成时使用相同值 -
得到扫码状态结果
HTTP/1.1 200 OK Content-Type: application/json;charset=UTF-8 { "code": "${state}" }参数名 类型 说明 state 状态 used 已使用 unused 未使用
物理卡授权
-
读出物理卡号
-
调用/token接口
- 将
物理卡号以card/${物理卡号}的形式赋值code - grant_type=offline_cert
POST /oauth/v2/token HTTP/1.1 Host: ${domain} Content-Type: application/x-www-form-urlencoded code=card/001&client_id=fzU1cb7ESpuaVRThuBcYcQ&client_secret=abc&grant_type=offline_cert - 将
-
返回token
- 返回roles中会附加card角色
-
st卡状态,lost表示挂失,不输出表示正常
HTTP/1.1 200 OK Server: nginx/1.11.6 Date: Thu, 25 Oct 2018 02:09:13 GMT Content-Type: application/json;charset=utf-8 Content-Length: 254 Connection: keep-alive Cache-Control: no-store Pragma: no-cache { "access_token": "271952ee-a0b6-4360-9edd-e9052bb494d7", "token_type": "bearer", "refresh_token": "7abbd5ba-7704-4ba8-bc63-484997ce0659", "expires_in": 7199, "scope": "pass:payment openid", "sub": "6aeca60613e949f0a16e721faf9f1082", "roles": "root card", "card": "001", "st": "lost" }
获取用户信息
-
请求/userinfo
POST /oauth/v2/userinfo HTTP/1.1 Host: ${domain} Content-Length: 96 Authorization: Bearer ${token}使用授权的到的token
-
响应
HTTP/1.1 200 OK Content-Type: application/json;charset=utf-8 { "nickname": "Gaffi", "picture": "https://tfs.alipayobjects.com/images/partner/T1bNpdXh0xXXXXXXXX", "locale": "zh_CN", "phone_number": "18768424633", "sub": "6aeca60613e949f0a16e721faf9f1082" }参数说明参考