Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in
D documents
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 0
    • Issues 0
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
  • Merge requests 0
    • Merge requests 0
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Operations
    • Operations
    • Incidents
    • Environments
  • Analytics
    • Analytics
    • CI/CD
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • pass
  • documents
  • Wiki
  • Home

Last edited by 叶佳菲 Aug 01, 2019
Page history

Home

  • OAuth2授权
    • 终端方式授权
    • 授权码方式授权
    • 用户名密码方式授权
    • 短信授权
    • 二维码授权
    • 物理卡授权

OAuth2授权

  • 授权的具体过程详见 rfc6749

  • OpenID标准

  • 测试环境OAuth2地址

http://pre.sovell.com/oauth/v2/authorize
http://pre.sovell.com/oauth/v2/token
http://pre.sovell.com/oauth/v2/check_token
  • 测试环境终端信息
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
  • 生产环境终端信息根据实际情况配置
domain=pass.sovell.com

终端方式授权

  • 这种方式只对client进行授权,没有用户信息
  • 详见 rfc6749
  1. 接口调用示例

    POST /oauth/v2/token HTTP/1.1
    Host: ${domain}
    Content-Type: application/x-www-form-urlencoded
    
    grant_type=client_credentials&client_id=${client_id}&client_secret=${client_secret}
    • grant_type必须为client_credentials
  2. 返回

  • 返回参数参考

授权码方式授权

  • 适合大多数网页授权,不需要开发登录界面(使用公共登录界面)
  • 参考标准流程
  1. 跳转到authorize接口
  • 传入重定向地址redirect_rui
  1. 在重定向地址的参数位置取到code
  2. 调用token接口
  • 参数code

用户名密码方式授权

  • 需要开发登录界面
  • 参考标准流程

短信授权

  • 短信授权实际上扩展了code方式的授权过程
  1. 发送给某个手机

    GET /oauth/v2/code?phone=${phone}
                      &title=${title*}
                      &abort={abort*}
                      &phone_conflict={phone_conflict*} HTTP/1.1
    Host: ${domain}
    Authorization: Bearer ${token}
    参数名 类型 说明
    phone string 手机号
    title string 短信头
    abort 不允许发送条件
    if_exists 存在则不发送
    if_not_exists 不存在则不发送
    phone_conflict 当使用用户授权token时,如果手机号冲突
    replace 替换,如果原用户有手机号则会替换成新的
  2. 发送成功后不返回实际内容,HttpStatus=200即为成功

  3. 成功后调用/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方式的授权过程
  1. 取CODE

    GET /oauth/v2/session/${session}/code HTTP/1.1
    Host: ${domain}
    Authorization: Bearer ${token}
    参数名 类型 说明
    session string 由生成端生成,此参数全局唯一,可能会与其他生成端冲突,需要做好重试机制,一个session五分钟内有效
  2. 调用成功后返回code

    • 当调用失败时,请做好重试机制
    HTTP/1.1 200 OK
    Content-Type: application/json;charset=UTF-8
    
    {
        "code": "${code}"
    }
    状态码 说明
    200 成功
    409 session重复
    参数名 类型 说明
    code 一般用于生成二维码
  3. 调用/token接口

    • 子系统通过二维码解码作为code参数
    • 可参考文档rfc6749 4.1.3
  4. 调用扫码状态接口

    • 一般由生产二维码端发起,用于展示二维码扫码结果
    • 对于不需要知道二维码是否使用的场景可跳过本步骤
    GET /oauth/v2/session/${session}/state HTTP/1.1
    Host: ${domain}
    Authorization: Bearer ${token}
    参数名 类型 说明
    session string 与生成时使用相同值
  5. 得到扫码状态结果

    HTTP/1.1 200 OK
    Content-Type: application/json;charset=UTF-8
    
    {
        "code": "${state}"
    }
    参数名 类型 说明
    state 状态
    used 已使用
    unused 未使用

物理卡授权

  1. 读出物理卡号

  2. 调用/token接口

    • 单卡调用限制30次/60s
    • 将物理卡号以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
  3. 返回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"
    }
Clone repository
  • Home
  • 接口
    • 交易
    • 消息
    • 用户
    • 通用券
  • 渠道
    • 微信 1基本参数
    • 微信 2商户平台配置
    • 微信 3公众号参数
    • 微信 4公众平台配置
    • 微信(服务商方式)
    • 支付宝 1基本参数
    • 支付宝 2公钥上传
    • 支付宝(服务商方式)