Skip to content

Commit

Permalink
Authentication: Make load optional for authentication.yaml, hosting_l…
Browse files Browse the repository at this point in the history
…imits.yaml and plugin.yaml files #5991
  • Loading branch information
AngelFQC committed Feb 17, 2025
1 parent 205c677 commit 60c67fa
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 19 deletions.
6 changes: 3 additions & 3 deletions config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,6 @@ cocur_slugify:
imports:
- { resource: ../src/CoreBundle/Resources/config/services.yml }
- { resource: ../src/LtiBundle/Resources/config/services.yml }
- { resource: ./authentication.yaml }
- { resource: ./hosting_limits.yaml }
- { resource: ./plugin.yaml }
- { resource: ./authentication.yaml, ignore_errors: not_found }
- { resource: ./hosting_limits.yaml, ignore_errors: not_found }
- { resource: ./plugin.yaml, ignore_errors: not_found }
50 changes: 36 additions & 14 deletions src/CoreBundle/Decorator/OAuth2ProviderFactoryDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,45 @@ public function createProvider(
Azure::class => $this->authenticationConfigHelper->getProviderConfig('azure'),
default => throw new InvalidArgumentException("Unsupported provider class: $class"),
};
$customConfig['client_id'] ??= '';
$customConfig['client_secret'] ??= '';

$redirectParams = $customConfig['redirect_params'] ?? [];

$customOptions = match ($class) {
GenericProvider::class => $this->authenticationConfigHelper->getProviderOptions(
'generic',
[
'client_id' => $customConfig['client_id'],
'client_secret' => $customConfig['client_secret'],
...$customConfig['provider_options'],
],
),
Facebook::class => $this->authenticationConfigHelper->getProviderOptions('facebook', $customConfig),
Keycloak::class => $this->authenticationConfigHelper->getProviderOptions('keycloak', $customConfig),
Azure::class => $this->authenticationConfigHelper->getProviderOptions('azure', $customConfig),
default => throw new InvalidArgumentException("Unsupported provider class: $class"),
};
switch ($class) {
case GenericProvider::class:
$customConfig['provider_options'] ??= [
'urlAuthorize' => '',
'urlAccessToken' => '',
'urlResourceOwnerDetails' => '',
'responseResourceOwnerId' => 'sub',
];

$customOptions = $this->authenticationConfigHelper->getProviderOptions(
'generic',
[
'client_id' => $customConfig['client_id'],
'client_secret' => $customConfig['client_secret'],
...$customConfig['provider_options'],
],
);
break;
case Facebook::class:
$customOptions = $this->authenticationConfigHelper->getProviderOptions('facebook', $customConfig);
break;
case Keycloak::class:
$customConfig['auth_server_url'] ??= '';
$customConfig['realm'] ??= '';

$customOptions = $this->authenticationConfigHelper->getProviderOptions('keycloak', $customConfig);
break;
case Azure::class:
$customOptions = $this->authenticationConfigHelper->getProviderOptions('azure', $customConfig);
break;
default:
$customOptions = throw new InvalidArgumentException("Unsupported provider class: $class");
break;
}

$options = $customOptions + $options;

Expand Down
10 changes: 8 additions & 2 deletions src/CoreBundle/ServiceHelper/AuthenticationConfigHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ public function getProviderConfig(string $providerName, ?AccessUrl $url = null):
{
$providers = $this->getProvidersForUrl($url);

if ([] === $providers) {
return [];
}

if (!isset($providers[$providerName])) {
throw new InvalidArgumentException('Invalid authentication provider for access URL');
}
Expand Down Expand Up @@ -62,7 +66,9 @@ private function getProvidersForUrl(?AccessUrl $url): array
{
$urlId = $url ? $url->getId() : $this->urlHelper->getCurrent()->getId();

$authentication = $this->parameterBag->get('authentication');
$authentication = $this->parameterBag->has('authentication')
? $this->parameterBag->get('authentication')
: [];

if (isset($authentication[$urlId])) {
return $authentication[$urlId];
Expand All @@ -72,7 +78,7 @@ private function getProvidersForUrl(?AccessUrl $url): array
return $authentication['default'];
}

throw new InvalidArgumentException('Invalid access URL configuration');
return [];
}

public function getProviderOptions(string $providerType, array $config): array
Expand Down

0 comments on commit 60c67fa

Please sign in to comment.