dev-1.8/develop
dev-1.8/develop
MIT
The Requires
by Shingo Yamada
FuelPHP 1.x package for Opauth., (*1)
Opauth is a multi-provider authentication framework., (*2)
FuelPHP v1.x
Opauth >= v0.2, (*3)
Install this package for your FuelPHP application. Go to your FuelPHP application package folder., (*4)
cd your_fuel_app/fuel/packages/ git clone git://github.com/andreoav/fuel-opauth.git opauth
Copy the opauth configuration file located at PKGPATH/opauth/config/opauth.php to your_fuel_app/fuel/app/config/, change the security salt and tweak as you need. eg., (*5)
<?php 'path' => '/auth/login/', 'callback_url' => '/auth/callback/', 'Strategy' => array( 'Facebook' => array( 'app_id' => 'APP_ID', 'app_secret' => 'APP_SECRET' ), ),
Enable fuel-opauth package., (*6)
<?php 'always_load' => array( 'packages' => array( 'opauth', ), ),
Create a controller called Controller_Auth and an action called login. eg., (*7)
<?php class Controller_Auth extends Controller { private $_config = null; public function before() { if(!isset($this->_config)) { $this->_config = Config::load('opauth', 'opauth'); } } /** * eg. http://www.exemple.org/auth/login/facebook/ will call the facebook opauth strategy. * Check if $provider is a supported strategy. */ public function action_login($_provider = null) { if(array_key_exists(Inflector::humanize($_provider), Arr::get($this->_config, 'Strategy'))) { $_oauth = new Opauth($this->_config, true); } else { return Response::forge('Strategy not supported'); } } // Print the user credentials after the authentication. Use this information as you need. (Log in, registrer, ...) public function action_callback() { $_opauth = new Opauth($this->_config, false); switch($_opauth->env['callback_transport']) { case 'session': session_start(); $response = $_SESSION['opauth']; unset($_SESSION['opauth']); break; } if (array_key_exists('error', $response)) { echo '<strong style="color: red;">Authentication error: </strong> Opauth returns error auth response.'."<br>\n"; } else { if (empty($response['auth']) || empty($response['timestamp']) || empty($response['signature']) || empty($response['auth']['provider']) || empty($response['auth']['uid'])) { echo '<strong style="color: red;">Invalid auth response: </strong>Missing key auth response components.'."<br>\n"; } elseif (!$_opauth->validate(sha1(print_r($response['auth'], true)), $response['timestamp'], $response['signature'], $reason)) { echo '<strong style="color: red;">Invalid auth response: </strong>'.$reason.".<br>\n"; } else { echo '<strong style="color: green;">OK: </strong>Auth response is validated.'."<br>\n"; /** * It's all good. Go ahead with your application-specific authentication logic */ } } return Response::forge(var_dump($response)); } }
A strategy is a set of instructions that interfaces with respective authentication providers and relays it back to Opauth. This package comes with strategies for Facebook and twitter. To install other strategies copy the files to PKGPATH/opauth/classes/Strategy/ folder., (*8)
Provider-specific:, (*9)
Strategy | Maintained by |
---|---|
uzyn | |
uzyn | |
muhdazrain | |
uzyn | |
mixi | ritou |
OpenID | uzyn |
uzyn |
Generic strategy: OAuth, (*10)
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., (*11)
MIT