-
Install this plugin using Composer, add "wouter0100/cakephp-opauth": "*"
to your Composer file and execute composer update
., (*4)
-
Add this line to the bottom of your app's config/bootstrap.php
:, (*5)
Plugin::load('Wouter0100/Opauth', ['routes' => true, 'bootstrap' => true]);
-
Create a config/opauth.php
file with the URL you wish to use for handeling the authentication data after opauth has run:, (*6)
<?php
$config['Opauth']['CompleteURL'] = '/auth/complete';
You may want to add config/opauth.php
to your gitignore, as the file will contain sensitive information., (*7)
-
Load strategies using Composer for Opauth 1.0.0., (*8)
Append configuration for strategies at your config/opauth.php
file as follows:, (*9)
// Using Facebook strategy as an example
$config['Opauth']['Strategy']['Facebook'] = [
'app_id' => 'YOUR FACEBOOK APP ID',
'app_secret' => 'YOUR FACEBOOK APP SECRET'
];
-
Go to /auth/facebook
to authenticate with Facebook, and similarly for other strategies that you have loaded., (*10)
-
After validation, user will be redirected to '/auth/complete'
(or whatever you chose in the opauth.php
config file) with validated auth response data retrievable available at $this->response->data
., (*11)
To route a controller to handle the response, at your app's config/routes.php
, add a connector, for example:, (*12)
$routes->connect(
'/auth/complete',
['controller' => 'Users', 'action' => 'complete']
);
You can then work with the authentication data at, say src/Controller/UsersController.php
as follows:, (*13)
<?php
namespace App\Controller;
use App\Controller\AppController;
class UsersController extends AppController
{
public function complete()
{
debug($this->request->data);
}
}
Note that this CakePHP Opauth plugin already does auth response validation for you with its results available
as a boolean value at $this->request->data['validated']
., (*14)