简体   繁体   中英

Using OAuth 2 with CakePHP3

I want to use an external Login (OAuth 2) with my CakePHP3 App. (The external Login need a Password and a Email). I never use an external Auth for my Applications (Everytime I use only my own Database with the Basic Auth of CakePHP3, so I have no clue what I should do)

In my AppController I write this :

 $this->loadComponent('Auth', [

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

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

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

And in my OAuth2Authenticate.php

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

But I cannot get access to the User?

Is there any helpful Tutorial out there or Examples where I can learn, to build up a external Login to CakePHP3?

You can use UseMuffin/OAuth2 plugin for this purpose.
See https://github.com/UseMuffin/OAuth2 for documentation.

The Cookbook also explains how to create custom authentication objects http://book.cakephp.org/3.0/en/controllers/components/authentication.html#creating-custom-authentication-objects

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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