Skip to content

Commit

Permalink
Merge branch 'release/2.1.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
rhukster committed May 24, 2021
2 parents 662e2b4 + 11a29ad commit b3f34ad
Show file tree
Hide file tree
Showing 11 changed files with 89 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion blueprints.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
4 changes: 1 addition & 3 deletions classes/OAuth2.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
11 changes: 11 additions & 0 deletions classes/ProviderFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
9 changes: 9 additions & 0 deletions classes/Providers/BaseProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
11 changes: 11 additions & 0 deletions classes/Providers/FacebookProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
11 changes: 11 additions & 0 deletions classes/Providers/GithubProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
11 changes: 11 additions & 0 deletions classes/Providers/GoogleProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
11 changes: 11 additions & 0 deletions classes/Providers/InstagramProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
11 changes: 11 additions & 0 deletions classes/Providers/LinkedinProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
6 changes: 6 additions & 0 deletions classes/Providers/ProviderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@

interface ProviderInterface
{
/**
* @param array $options
* @return bool
*/
public static function checkIfActive(array $options): bool;

public function __construct();

/**
Expand Down

0 comments on commit b3f34ad

Please sign in to comment.