hrevert/ht-league-oauth-client-module

There is no license information available for the latest version (0.4.0) of this package.

0.4.0 2017-06-17 14:40 UTC

This package is auto-updated.

Last update: 2024-11-13 03:26:16 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');