diff --git a/app/library/OAuth/Adapter/League.php b/app/library/OAuth/Adapter/League.php index d1ebeb6..cf85b14 100644 --- a/app/library/OAuth/Adapter/League.php +++ b/app/library/OAuth/Adapter/League.php @@ -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); } /**