Archived
1
0
Fork 0

app/library/OAuth/Adapter/League.php: add support for non-standard providers.

This commit is contained in:
Henrik Hautakoski 2018-04-09 00:06:57 +02:00
parent 158cacdb8a
commit 4042b36422

View file

@ -7,6 +7,16 @@ use League\OAuth2\Client\Provider\AbstractProvider,
class League implements AdapterInterface
{
/**
* List of all supported providers and their class name.
*
* @var array
*/
protected $_providerClasses = array(
'github' => '\League\OAuth2\Client\Provider\Github',
'gitlab' => '\Omines\OAuth2\Client\Provider\Gitlab',
);
/**
* @var AbstractProvider
*/
@ -17,15 +27,19 @@ class League implements AdapterInterface
*/
protected $_accessToken;
protected $_options;
/**
* {@inheritDoc}
* @throws Exception
*/
public function __construct($provider_name, $options)
{
$provider_name = ucfirst($provider_name);
if (!array_key_exists($provider_name, $this->_providerClasses)) {
throw new Exception("Provider '{$provider_name}' is not supported.");
}
$className = 'League\OAuth2\Client\Provider\\' . $provider_name;
$className = $this->_providerClasses[$provider_name];
$provider = new $className($options);
if (!($provider instanceof AbstractProvider)) {
@ -34,6 +48,7 @@ class League implements AdapterInterface
}
$this->_provider = $provider;
$this->_options = $options;
}
/**
@ -49,7 +64,7 @@ class League implements AdapterInterface
*/
public function getAuthorizationUrl()
{
return $this->_provider->getAuthorizationUrl();
return $this->_provider->getAuthorizationUrl($this->_options);
}
/**