Original source https://github.com/uzyn/cakephp-opauth
CakePHP 2.x plugin for Opauth.
Opauth is a multi-provider authentication framework.
CakePHP v2.x
Opauth >= v0.2 (submoduled with this package)
-
Install this plugin for your CakePHP app. Assuming
APP
is the directory where your CakePHP app resides, it's usuallyapp/
from the base of CakePHP.cd APP/Plugin git clone git://github.com/jmillerdesign/cakephp-opauth.git Opauth
-
Download Opauth library as a submodule.
git submodule init git submodule update
-
Add this line to the bottom of your app's
Config/bootstrap.php
:<?php CakePlugin::load('Opauth', array('routes' => true, 'bootstrap' => true));
Overwrite any Opauth configurations you want after the above line.
-
Load strategies onto
Strategy/
directory.Append configuration for strategies at your app's
Config/bootstrap.php
as follows:<?php CakePlugin::load('Opauth', array('routes' => true, 'bootstrap' => true)); // Using Facebook strategy as an example Configure::write('Opauth.Strategy.Facebook', array( 'app_id' => 'YOUR FACEBOOK APP ID', 'app_secret' => 'YOUR FACEBOOK APP SECRET', 'redirect' => '/' ));
-
Go to
http://path_to_your_cake_app/auth/facebook
to authenticate with Facebook, and similarly for other strategies that you have loaded. -
After you return from the strategy's site, you will be redirected to the Opauth.Strategy.Facebook.redirect URL that you set in the configuration. The response will be POSTed to this url and is accessible in $this->data. If validated, the response data will be set in the session, with the strategy being the session key. The CakeEvents
Opauth.validated
andOpauth.complete
are also dispatched.
If your CakePHP app does not reside at DocumentRoot (eg. http://localhost
), but at a directory below DocumentRoot (eg. http://localhost/your-cake-app
),
add this line to your app's APP/Config/bootstrap.php
, replacing your-cake-app
with your actual path :
<?php // APP/Config/bootstrap.php
Configure::write('Opauth.path', '/your-cake-app/auth/');