dev-master
9999999-dev http://github.com/scharrier/li3_socialauth/Lithium social oAuth adapters
The Requires
by Sebastien Charrier
authentication oauth
Wallogit.com
2017 © Pedro Peláez
Lithium social oAuth adapters
I'm sorry, this li3 package isn't still maintained. If someone wants to take the lead, just ping me., (*1)
Lithium universal oAuth plugin: uses the excellent oAuth library by Lusitanian (https://github.com/Lusitanian/PHPoAuthLib) to provide Li3 auth adapters., (*2)
The easiest way to install li3_socialauth is to use composer, adding this lines in your composer.json file:, (*3)
{
"require": {
"scharrier/li3_socialauth": "dev-master"
}
}
Then update your project:, (*4)
composer update
And load the library:, (*5)
// config/bootstrap/libraries.php
Libraries::add('li3_socialauth') ;
// Add the composer autoloader if not already done
require_once(LITHIUM_LIBRARY_PATH . '/autoload.php') ;
Each social auth type has its own Lithium auth adapter. Just define your new auth like this:, (*6)
Auth::config(array(
'twitter' => array(
'adapter' => 'Twitter',
'key' => 'YOUR_KEY',
'secret' => 'YOUR_SECRET'
),
'facebook' => array(
'adapter' => 'Facebook',
'key' => 'YOUR_KEY',
'secret' => 'YOUR_SECRET',
'scope' => array('email','read_friendlists','user_online_presence') // Extend the auth scope
)
));
Then you can use this auth like any other auth mecanism in Lithium. Here is an example of an oauth login method:, (*7)
public function login() {
// The user choose an external auth : adapter name given as the first param
if (!empty($this->request->params['args'][0])) {
// Can we login in ?
if (Auth::check($this->request->params['args'][0], $this->request)) {
$this->redirect('/') ;
}
}
}
And you are done., (*8)
Using this method of authentication, you will quickly have a lot of adapters to check in order to get the authed user. So I have created an universal Auth class witch checks each adapter when calling check() or clear() methods., (*9)
Here is an example of usage:, (*10)
// Using li3_socialauth instead of Lithium auth
use li3_socialauth\extensions\security\Auth;
if (Auth::check()) {
echo 'Logout ?' ;
} else {
echo 'You should login first' ;
}
Actually these services are supported. More to come soon: - Twitter - Facebook - Google+ - Microsoft Live - Github - Foursquare, (*11)
Fork it, play with it, commit and pull ! Email at scharrier@gmail.com if some help needed., (*12)
Lithium social oAuth adapters
authentication oauth