说明: 本文档用于描述spring-oauth-server对外开发的接口(API)使用, 所有标记 public 的API都是公开的, 其他的API则需要获取 access_token 后可调用

获取access_token (grant_type=password) public

使用grant_type=password方式来获取access_token

  • 请求URI: /oauth/token POST

    请求参数说明:
    参数名 参数值 必须? 备注
    client_id {client_id}
    client_secret {client_secret}
    grant_type password 固定值
    scope {scope} read or write
    username {username} 用户名
    password {password} 用户密码
    请求示例:

    http://localhost:8080/spring-oauth-server/oauth/token?client_id=6361b08fdea6400f93b2eccda8936b32&client_secret=i4KXewMI0u6i8CFEZo10mB2rGzQRXrIv&grant_type=password&scope=read&username=mobile&password=mobile


    响应
    • 正常 [200]
      {"access_token":"1f60abaf-6c3f-45a8-a574-bbbe6f76083f","token_type":"bearer","expires_in":41769,"scope":"read"}

    • 异常 [401]
      <oauth><error_description>Bad client credentials</error_description><error>invalid_client</error></oauth>

获取access_token (grant_type=authorization_code) public

使用grant_type=authorization_code 方式来获取access_token, 需要先获取code

  • 请求URI: /oauth/token POST

    请求参数说明:
    参数名 参数值 必须? 备注
    client_id {client_id}
    client_secret {client_secret}
    grant_type authorization_code 固定值
    code {code}
    redirect_uri {redirect_uri}
    请求示例:

    http://localhost:8080/spring-oauth-server/oauth/token?client_id=unity-client&client_secret=unity&grant_type=authorization_code&code=[code]&redirect_uri=[redirect_uri]


    响应
    • 正常 [200]
      {"access_token":"2c612eb7-a22b-45f0-8b2e-cd6f9e366772","token_type":"bearer","refresh_token":"6c984bdc-01c7-486f-93bf-5637990d8a37","expires_in":43199,"scope":"read write"}

    • 异常 [401]
      {"error":"invalid_grant","error_description":"Invalid authorization code: vzmIh1"}


© 2013 - 2016 sz@monkeyk.com from spring-oauth-server