Skip to content
A Zend Framework module to integrate oauth2-client and oauth1-client library from the thephpleague.
PHP
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
config
src
tests
.gitignore
.scrutinizer.yml
.travis.yml
LICENSE
README.md
composer.json
phpunit.xml

README.md

HtLeagueOauthClientModule

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');
You can’t perform that action at this time.