CakePHP 2.x plugin for Opauth.
Opauth is a multi-provider authentication framework.
CakePHP v2.x
Opauth >= v0.2 (submoduled with this package)
Check out CakePHP bakery for tutorial and the sample branch for a quick sample app.
-
Install this plugin for your CakePHP app.
AssumingAPPis the directory where your CakePHP app resides, it's usuallyapp/from the base of CakePHP.cd APP/Plugin git clone git://github.com/uzyn/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.phpas 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' ));
-
Go to
http://path_to_your_cake_app/auth/facebookto authenticate with Facebook, and similarly for other strategies that you have loaded. -
After validation, user will be redirected to
Router::url('/opauth-complete')with validated auth response data retrievable available at$this->data.To route a controller to handle the response, at your app's
Config/routes.php, add a connector, for example:<?php Router::connect( '/opauth-complete/*', array('controller' => 'users', 'action' => 'opauth_complete') );
You can then work with the authentication data at, say
APP/Controller/UsersController.phpas follows:<?php // APP/Controller/UsersController.php: class UsersController extends AppController { public function opauth_complete() { debug($this->data); } }
Note that this CakePHP Opauth plugin already does auth response validation for you with its results available as a boolean value at
$this->data['validated']. -
(optional) The submoduled Opauth core library may not be of the latest build, to update to the latest:
git submodule foreach git pull origin master
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/');Opauth is a multi-provider authentication framework for PHP, inspired by OmniAuth for Ruby.
Opauth enables PHP applications to do user authentication with ease.
Try out Opauth for yourself at http://opauth.org
Opauth provides a standardized method for PHP applications to interface with authentication providers.
Opauth as a framework provides a set of API that allows developers to create strategies that work in a predictable manner across PHP frameworks and applications.
Opauth works well with other PHP applications & frameworks. It is currently supported on:
- vanilla (plain) PHP applications (of course)
- CakePHP (maintained by uzyn)
- CodeIgniter (maintained by destinomultimedia)
- CodeIgniter (maintained by mcatm)
- FuelPHP (maintained by andreoav)
- Yii Framework (maintained by kahwee)
- and more to come.
If your PHP framework of choice is not yet listed, you can still use Opauth like you would a normal PHP component (class).
Guide on how to run the bundled example.
-
Set
DocumentRootof your web server toexample/.
(Opauth can be instantiated in your own PHP app, but we will leave that out of this quick start guide) -
Configure Opauth.
First, make a copy of opauth config's file by copying or renaming
opauth.conf.php.defaulttoopauth.conf.php.Open up
opauth.conf.phpand make the necessary changes. -
Install some Opauth strategies.
Place the strategy files inlib/Opauth/Strategy/.For this example, we recommend that you start with Opauth-Facebook:
i. Download the strategy files and place them at
lib/Opauth/Strategy/Facebook/.ii. Follow the steps at Opauth-Facebook's README to set up your Faceobok app.
iii. Add the following at
opauth.conf.phpunderStrategyas such:
<?php
'Strategy' => array(
// Define strategies here.
'Facebook' => array(
'app_id' => 'YOUR APP ID',
'app_secret' => 'YOUR APP SECRET'
),
);Finally, send user to http://localhost/facebook to authenticate.
Check out the wiki for more in-depth details, especially on how to use Opauth with your own PHP application.
A strategy is a set of instructions that interfaces with respective authentication providers and relays it back to Opauth.
Provider-specific:
| Strategy | Maintained by |
|---|---|
| uzyn | |
| uzyn | |
| muhdazrain | |
| uzyn | |
| ritou | |
| uzyn | |
| uzyn |
Generic strategy: OAuth
See wiki's list of strategies for an updated list of Opauth strategies or to make requests. Also, refer to strategy contribution guide if you would like to contribute a strategy.
PHP 5 (>= 5.2)
Opauth needs your contributions, especially the following:
-
More strategies
Refer to wiki for contribution guide and inform us when your work is ready. -
Plugins for more PHP frameworks and CMSes
eg. Symfony, Laravel, WordPress, Drupal, etc. -
Guides & tutorials
On how to implement Opauth on CakePHP app, etc. -
Unit testing
Coverage is only average at the moment.
- Discussion group: Google Groups
This is the primary channel for support, especially for user questions. - Issues: Github Issues
- Twitter: @uzyn
- Email me: [email protected]
- IRC: #opauth on Freenode
Used this plugin in your CakePHP project? Let us know!
###v0.4.0 (10 June 2012)
mapProfile()andclientGet()for OpauthStrategy class.
###v0.3.0 (30 May 2012)
- Some unit testing
- More consistent naming of Strategy's internal properties
- Smarter loading of strategy, able to make a few guesses on where the class file might be at.
###v0.2.0 (23 May 2012)
- Opauth is now Composer compatible and listed on Packagist
- Opauth now supports autoloaders
- If a strategy is not autoloaded, Opauth falls back and searches for it at
strategy_dirdefined in config.
- Class name for strategy Foo should now be FooStrategy instead of Foo.
- This is to reduce the likelihood of class name collision due to Opauth not requiring the use of namespace.
- v0.1.0-type class name, ie. Foo, still works, but is now deprecated.
###v0.1.0 (22 May 2012)
- Initial release
The MIT License
Copyright © 2012 U-Zyn Chua (http://uzyn.com)
U-Zyn Chua is a Principal Consultant at gladlyCode, a premier PHP web development firm.
If you need consultation in web technologies and services, feel free to talk to us.

