Skip to content

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

License

Notifications You must be signed in to change notification settings

hrevert/HtLeagueOauthClientModule

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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');

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages