Social authentication library for PHP 5.3+

1.0.0-alpha3 2013-09-03 12:53 UTC


Social authentication library for PHP 5.3+


Social should be installed using composer.

Basic usage

  1. Create a AuthClient and register the providers:
// client_config.php
require_once __DIR__ . '/vendor/autoload.php'; //requires the autoloader

use Lcobucci\Social\Providers\Github;
use Lcobucci\Social\AuthClient;
use Lcobucci\Social\Providers\Facebook;

$client = new AuthClient();

    'github', // The provider identifier (anything you may want) 
        'blablabla', // The client ID
        'blablabla', // The client secret
        ''// The callback URI  (if you want...)
        ['user:email'] // The default scopes (if you want...)

return $client
  1. Redirect to provider
// init.php
$client = require __DIR__ . '/client_config.php'; // Get your configuration
$uri = $client->getAuthorizationUri(
    'github', // The provider identifier you want to use (that you configured before)
    [], // Additional scopes (if you want...)
    uniqid() // State to be validated (if you want...)

header('Location: ' . $uri);
  1. Get authenticated user information
// callback.php
use Symfony\Component\HttpFoundation\Request;

$client = require __DIR__ . '/client_config.php'; // Get your configuration
$request = Request::createFromGlobals();

$user = $client->getAuthenticatedUser('github', $request->query);

var_dump($user->getToken()); // Get the access token that should be used on API requests
var_dump($user->getId()); // Get the user ID
var_dump($user->getUsername()); // Get the user login
var_dump($user->getName()); // Get the user name
var_dump($user->getEmail()); // Get the user email
var_dump($user->getAvatar()); // Get the user avatar