繁体   English   中英

将OAuth 2与CakePHP3结合使用

[英]Using OAuth 2 with CakePHP3

我想在CakePHP3应用程序中使用外部登录名(OAuth 2)。 (外部登录名需要密码和电子邮件)。 我从不对应用程序使用外部Auth(每次我只使用自己的数据库以及CakePHP3的Basic Auth,所以我不知道应该怎么做)

在我的AppController中,我这样写:

 $this->loadComponent('Auth', [

 'authenticate' => [
   'Basic' => [
       'fields' => ['username' => 'email', 'password' =>'password'],
   ], ],

     'loginAction' => [
                'controller' => 'Users',
                'action' => 'login'
            ]
        ]);

$this->Auth->config('authenticate', 'OAuth2');

在我的OAuth2Authenticate.php中

public function authenticate(Request $request, Response $response)
{
    $http = new Client();
    $response = $http->get('http:xxx/login', [], [
        'auth' => ['username' => 'email', 'password' => 'password']
    ]);
}

但是我无法访问该用户吗?

有没有什么有用的教程或可以从中学习的示例,可以用来建立CakePHP3的外部登录名?

您可以为此使用UseMuffin / OAuth2插件。
有关文档,请参阅https://github.com/UseMuffin/OAuth2

该食谱还说明了如何创建自定义身份验证对象http://book.cakephp.org/3.0/en/controllers/components/authentication.html#creating-custom-authentication-objects

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM