2017 © Pedro Peláez
 

library li3_socialauth

Lithium social oAuth adapters

image

scharrier/li3_socialauth

Lithium social oAuth adapters

  • Wednesday, December 17, 2014
  • by scharrier
  • Repository
  • 7 Watchers
  • 23 Stars
  • 203 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 15 Forks
  • 5 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

li3_socialauth

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)

Installation

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') ;

Using li3_socialauth

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)

Universal Auth class

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' ;
}

Supported services

Actually these services are supported. More to come soon: - Twitter - Facebook - Google+ - Microsoft Live - Github - Foursquare, (*11)

Help and support

Fork it, play with it, commit and pull ! Email at scharrier@gmail.com if some help needed., (*12)

The Versions

17/12 2014

dev-master

9999999-dev http://github.com/scharrier/li3_socialauth/

Lithium social oAuth adapters

  Sources   Download

The Requires

 

by Sebastien Charrier

authentication oauth