hrevert/ht-league-oauth-client-module

Installs: 195

Dependents: 1

Stars: 1

Watchers: 2

Forks: 1

Language: PHP

0.3.0 2015-08-01 04:24 UTC

README

Build Status Latest Stable Version

A Zend Framework 2 module to integrate oauth2-client and oauth1-client library from the thephpleague.

Usage

For Oauth2

// in config/module.config.php

use HtLeagueOauthClientModule\Module;

return [
    Module::CONFIG => [
        'oauth2_clients' => [
            'facebook' => [
                'clientId'      =>  'XXXXXXXX',
                'clientSecret'  =>  'XXXXXXXX',
                'redirectUri'   =>  'https://your-registered-redirect-uri/',          
            ],
        ],
    ],
];
$facebookProvider = $serviceLocator->get('HtLeagueOauthClientModule\Oauth2ClientManager')->get('facebook');
Creating custom oauth2 providers
  • Create a class implementing League\OAuth2\Client\Provider\ProviderInterface.
class MyProvider implements League\OAuth2\Client\Provider\ProviderInterface
{
    // .....
}
  • Inform Oauth2 client manager about the new provider
// in config/module.config.php

use HtLeagueOauthClientModule\Module;

return [
    Module::CONFIG => [
        'oauth2_client_manager' => [
            'factories' => [
                'my_provider' => 'MyProviderFactory',
            ], 
        ],
    ],
];
  • Use the provider
$myProvider = $serviceLocator->get('HtLeagueOauthClientModule\Oauth2ClientManager')->get('my_provider');

For Oauth1

// in config/module.config.php

use HtLeagueOauthClientModule\Module;

return [
    Module::CONFIG => [
        'oauth1_clients' => [
            'twitter' => [
                'identifier' => 'your-identifier',
                'secret' => 'your-secret',
                'callback_uri' => 'http://your-callback-uri/',        
            ],
        ],
    ],
];
$twitterProvider = $serviceLocator->get('HtLeagueOauthClientModule\Oauth1ClientManager')->get('twitter');
Creating custom oauth2 providers
  • Create a class extending League\OAuth1\Client\Server\Server.
class MyProvider extends League\OAuth1\Client\Server\Server
{
    // .....
}
  • Inform Oauth1 client manager about the new provider
// in config/module.config.php

use HtLeagueOauthClientModule\Module;

return [
    Module::CONFIG => [
        'oauth1_client_manager' => [
            'factories' => [
                'my_provider' => 'MyProviderFactory',
            ], 
        ],
    ],
];
  • Use the provider
$myProvider = $serviceLocator->get('HtLeagueOauthClientModule\Oauth1ClientManager')->get('my_provider');