Migrating from Hybridauth 2 to Hybridauth 3

This is a pretty big release with lots of changes under the hood. Be sure to read the other pages in this guide for all the new features and API changes.

1. Upgrade to the latest hybridauth (see Installation):

composer require 'hybridauth/hybridauth:~3.0'

2. Migrate your configuration array (see Introduction):

Hybridauth 2.x:
$config = [
    // "base_url" the url that point to Hybridauth Endpoint (where index.php and config.php are found).
    'base_url' => 'https://mywebsite/path/to/hybridauth/',

    // Providers specifics.
    'providers' => [
        'Twitter' => [
            'enabled' => true,
            'keys' => [
                'key' => '...',
                'secret' => '...',
            ],
        ],
        'Google' => ['enabled' => true, 'keys' => ['id' => '...', 'secret' => '...']],
        'Facebook' => ['enabled' => true, 'keys' => ['id' => '...', 'secret' => '...']],
    ],
];
Hybridauth 3.x:
$config = [
    // Location where to redirect users once they authenticate,
    // For this example we choose to come back to this same script.
    'callback' => 'https://example.com/path/to/this/script.php',

    // Providers specifics.
    'providers' => [
        'Twitter' => [
            'enabled' => true,
            'keys' => [
                'key' => '...',
                'secret' => '...',
            ],
        ],
        'Google' => ['enabled' => true, 'keys' => ['id' => '...', 'secret' => '...']],
        'Facebook' => ['enabled' => true, 'keys' => ['id' => '...', 'secret' => '...']],
    ],
];

3. Migrate your OAuth 2.0 Redirect Urls:

Note, that Hybridauth 2.x uses hauth.done={providerId} in OAuth 2.0 Redirect Urls to determine which provider to authenticate.

In Hybridauth 3.x, it’s not required anymore. Check out examples.

4. Migrate your authentication (see User Authentication):

Hybridauth 2.x:
$hybridauth = new Hybrid_Auth($config);
$adapter = $hybridauth->authenticate('Twitter');
$userProfile = $adapter->getUserProfile();
Hybridauth 3.x:
$hybridauth = new Hybridauth\Hybridauth($config);
$adapter = $hybridauth->authenticate('Twitter');
$userProfile = $adapter->getUserProfile();

// or

$hybridauth = new Hybridauth\Provider\Twitter($config);
$adapter = $hybridauth->authenticate();
$userProfile = $adapter->getUserProfile();

5. Migrate custom API calls (see Providers APIs):

Hybridauth 2.x:
// Authenticate GitHub's adapter.
$hybridauth = new Hybrid_Auth($config);
$adapter = $hybridauth->authenticate('GitHub');

// Access GitHub API to retrieve the user's public gists.
// See: https://developer.github.com/v3/gists/
$apiResponse = $adapter->api()->get('gists'); // or absolute url: https://api.github.com/gists

// Inspect API's response.
var_dump($apiResponse);
Hybridauth 3.x:
// Authenticate GitHub's adapter.
$hybridauth = new Hybridauth\Hybridauth($config);
$adapter = $hybridauth->authenticate('GitHub');

// Access GitHub API to retrieve the user's public gists.
// See: https://developer.github.com/v3/gists/
$apiResponse = $adapter->apiRequest('gists'); // or absolute url: https://api.github.com/gists

// Inspect API's response.
var_dump($apiResponse);

6. Feeling like something is missing? Please let us know.