diff --git a/CHANGELOG.md b/CHANGELOG.md index 03e9427..a77978b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# v2.1.1 +## 05/24/2021 + +1. [](#bugfix) + * Fixed Facebook login never showing up [#40](https://github.com/trilbymedia/grav-plugin-login-oauth2/issues/40) + # v2.1.0 ## 05/13/2021 diff --git a/blueprints.yaml b/blueprints.yaml index dbab6ed..ed1a206 100644 --- a/blueprints.yaml +++ b/blueprints.yaml @@ -1,7 +1,7 @@ name: Login OAuth2 type: login-oauth2 slug: form -version: 2.1.0 +version: 2.1.1 description: OAuth2 Client Plugin to integrate with Grav's Login icon: plug author: diff --git a/classes/OAuth2.php b/classes/OAuth2.php index e30490c..45120fd 100644 --- a/classes/OAuth2.php +++ b/classes/OAuth2.php @@ -42,9 +42,7 @@ public function addEnabledProviders(): void } foreach ($providers as $provider => $options) { - $enabled = $options['enabled'] ?? false; - $client_id = $options['client_id'] ?? false; - if ($enabled && $client_id) { + if (ProviderFactory::checkIfActive($provider, $options)) { $this->addProvider($provider, $options); } } diff --git a/classes/ProviderFactory.php b/classes/ProviderFactory.php index 1261d54..4081571 100644 --- a/classes/ProviderFactory.php +++ b/classes/ProviderFactory.php @@ -24,4 +24,15 @@ public static function create($provider, array $options = []): ProviderInterface return $class; } + + public static function checkIfActive($provider, array $options = []): bool + { + $provider_classname = 'Grav\\Plugin\\Login\\OAuth2\\Providers\\' . ucfirst($provider) . 'Provider'; + + if (!class_exists($provider_classname)) { + throw new \RuntimeException('Invalid OAuth2 provider'); + } + + return $provider_classname::checkIfActive($options); + } } \ No newline at end of file diff --git a/classes/Providers/BaseProvider.php b/classes/Providers/BaseProvider.php index a22b25d..c8970db 100644 --- a/classes/Providers/BaseProvider.php +++ b/classes/Providers/BaseProvider.php @@ -29,6 +29,15 @@ abstract class BaseProvider implements ProviderInterface /** @var Data */ protected $config; + /** + * @param array $options + * @return bool + */ + public static function checkIfActive(array $options): bool + { + return (bool)($options['enabled'] ?? false); + } + /** * BaseProvider constructor. */ diff --git a/classes/Providers/FacebookProvider.php b/classes/Providers/FacebookProvider.php index 7f12e4f..f9b17c0 100644 --- a/classes/Providers/FacebookProvider.php +++ b/classes/Providers/FacebookProvider.php @@ -13,6 +13,17 @@ class FacebookProvider extends BaseProvider /** @var string */ protected $classname = Facebook::class; + /** + * @param array $options + * @return bool + */ + public static function checkIfActive(array $options): bool + { + $client_id = $options['app_id'] ?? false; + + return $client_id && parent::checkIfActive($options); + } + /** * @param array $options */ diff --git a/classes/Providers/GithubProvider.php b/classes/Providers/GithubProvider.php index 023ca01..894f180 100644 --- a/classes/Providers/GithubProvider.php +++ b/classes/Providers/GithubProvider.php @@ -13,6 +13,17 @@ class GithubProvider extends BaseProvider /** @var string */ protected $classname = Github::class; + /** + * @param array $options + * @return bool + */ + public static function checkIfActive(array $options): bool + { + $client_id = $options['client_id'] ?? false; + + return $client_id && parent::checkIfActive($options); + } + /** * @param array $options */ diff --git a/classes/Providers/GoogleProvider.php b/classes/Providers/GoogleProvider.php index 38b2627..57b5925 100644 --- a/classes/Providers/GoogleProvider.php +++ b/classes/Providers/GoogleProvider.php @@ -13,6 +13,17 @@ class GoogleProvider extends BaseProvider /** @var string */ protected $classname = Google::class; + /** + * @param array $options + * @return bool + */ + public static function checkIfActive(array $options): bool + { + $client_id = $options['client_id'] ?? false; + + return $client_id && parent::checkIfActive($options); + } + /** * @param array $options */ diff --git a/classes/Providers/InstagramProvider.php b/classes/Providers/InstagramProvider.php index d875162..1350131 100644 --- a/classes/Providers/InstagramProvider.php +++ b/classes/Providers/InstagramProvider.php @@ -13,6 +13,17 @@ class InstagramProvider extends BaseProvider /** @var string */ protected $classname = Instagram::class; + /** + * @param array $options + * @return bool + */ + public static function checkIfActive(array $options): bool + { + $client_id = $options['client_id'] ?? false; + + return $client_id && parent::checkIfActive($options); + } + /** * @param array $options */ diff --git a/classes/Providers/LinkedinProvider.php b/classes/Providers/LinkedinProvider.php index ba40ce9..76009ac 100644 --- a/classes/Providers/LinkedinProvider.php +++ b/classes/Providers/LinkedinProvider.php @@ -13,6 +13,17 @@ class LinkedinProvider extends BaseProvider /** @var string */ protected $classname = LinkedIn::class; + /** + * @param array $options + * @return bool + */ + public static function checkIfActive(array $options): bool + { + $client_id = $options['client_id'] ?? false; + + return $client_id && parent::checkIfActive($options); + } + /** * @param array $options */ diff --git a/classes/Providers/ProviderInterface.php b/classes/Providers/ProviderInterface.php index ff8605b..a1e5c4d 100644 --- a/classes/Providers/ProviderInterface.php +++ b/classes/Providers/ProviderInterface.php @@ -8,6 +8,12 @@ interface ProviderInterface { + /** + * @param array $options + * @return bool + */ + public static function checkIfActive(array $options): bool; + public function __construct(); /**