设为首页 加入收藏

TOP

使用 OAuth2-Server-php 在 Yii 框架上搭建 OAuth2 Server(八)
2017-10-10 11:49:46 】 浏览:10212
Tags:使用 OAuth2-Server-php Yii 架上 搭建 OAuth2 Server
p; |         |         Password Credentials     | Authorization |
     | Client  |                                  |     Server    |
     |         |<--(C)---- Access Token ---------<|               |
     |         |    (w/ Optional Refresh Token)   |               |
     +---------+                                  +---------------+

     图3:资源所有者密码凭据流程

     图3中的所示流程包含以下步骤:

    (A)资源所有者提供给客户端它的用户名和密码。
    (B)通过包含从资源所有者处接收到的凭据,客户端从授权服务器的令牌端点请求访问令牌。当发起请求时,客户端与授权服务器进行身份验证。

    (C)授权服务器对客户端进行身份验证,验证资源所有者的凭证,如果有效,颁发访问令牌。


    Tips: 客户端一旦获得访问令牌必须丢弃凭据。

oauth2-server-php 对 Resource Owner Password Credentials 的实现如下:

    1. 首先在 Oauth2Controller 的构造函数中添加对于 Resource Owner Password Credentials 授权方式的支持,加入以下代码:

    $server->addGrantType(new OAuth2\GrantType\UserCredentials($storage));

    2. 获取 access_token :

    curl -u testclient:testpass www.yii.com/oauth2/index.php?r=oauth2/token -d 'grant_type=password&username=rereadyou&password=rereadyou'

    返回:
        {"access_token":"66decd1b10891db5f8f63efe7cc352ce326895c6",
         "expires_in":3600,
         "token_type":"bearer",
         "scope":null,
         "refresh_token":"b5fa0c24e786e37e7ce7d6e2f911805dc65a0d7c"}

    Tips:    Github 上 oauth2-server-php 提供的 sql schema user 表里面没有 user_id 字段[12],需要自行添加该字段(主键, auto_increment)。
        user 表设计使用 sha1 摘要方式,没有添加 salt。
        
        在 Pdo.php 中有:
        // plaintext passwords are bad!  Override this for your application
        protected function checkPassword($user, $password)
        {
            return $user['password'] == sha1($password);
        }
       
首页 上一页 5 6 7 8 9 10 11 下一页 尾页 8/11/11
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇PHP多台服务器跨域SESSION共享 下一篇微信浏览器判断

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目