设为首页 加入收藏

TOP

使用 OAuth2-Server-php 在 Yii 框架上搭建 OAuth2 Server(十一)
2017-10-10 11:49:46 】 浏览:10198
Tags:使用 OAuth2-Server-php Yii 架上 搭建 OAuth2 Server
ss_token 传输时的安全性。


第四部分: 使用 Bearer access_token 的调用 api

    1. 使用 refresh_token 换取 access_token:
     curl -u testclient:testpass www.yii.com/oauth2/index.php?r=oauth2/token -d "grant_type=refresh_token&refresh_token=1ce1a52dff3b5ab836ae25714c714cb86bf31b6f"

    返回: 
        {"access_token":"50540a7ead3a27cdb458b6cdc38df25f64da18f1",
         "expires_in":3600,
         "token_type":"bearer",
         "scope":null}
        这里没有新的 refresh_token,需要进行配置以重新获取 refresh_token,可修改 OAuth2/GrantType/RefreshToken.php 中的 RefreshToken class __construct 方法中的 'always_issue_new_refresh_token' => true 来开启颁发新的 refresh_token。
    Tips: IETF rfc2649 中对于 refresh_token section 的部分说明,
        POST /token HTTP/1.1
        Host: server.example.com
        Authorization: Basic czZCaGRSa3F0MzpnWDFmQmF0M2JW
        Content-Type: application/x-www-form-urlencoded

        grant_type=refresh_token&refresh_token=tGzv3JOkF0XG5Qx2TlKWIA

    需要提供客户端的 client_id 和 client_secret, grant_type 值必须是 refresh_token。
    access_token 有效期内不能使用 refresh_token 换取新的 access_token。

    2. 使用 access_token:
    a. client app 使用 access_token 获取 resource 信息。
    oauth2-server 验证 access_token:
        curl www.yii.com/oauth2/index.php?r=oauth2/verifytoken -d 'access_token=aea4a1059d3194a3dd5e4117bedd6e07ccc3f402'

    返回:
        {"result":"success",
         "message":"your access token is valid."
        }    这个部分只是为了验证 access token 的有效性,client app 并不应该直接调用该方法,而是在请求资源时有server自行调用,根据判断结果进行不同处理。
    可以在 Oauth2 extension 的 Server.php 中来修改 access_token 的有效期。

    3. scope
    scope 需要服务端确定具体的可行操作。
    scope 用来确定 client 所能进行的操作权限。项目中操作权限由 srbac 进行控制, Oauth2 中暂不做处理。

    4. state
    state 为 client app 在第一步骤中获取 authorization code 时向 OAuth2 Server 传递并由 OAuth2 Server 返回的随机哈希参数。state 参数主要用来防止跨站点请求伪造(Cross Site Request Forgery, CSRF),相关讨论可参见本文最后的参考【7】和【8】。

    
References:

首页 上一页 8 9 10 11 下一页 尾页 11/11/11
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇PHP多台服务器跨域SESSION共享 下一篇微信浏览器判断

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目