Skip to content
Snippets Groups Projects
Commit 6768c03b authored by Reiter, Christoph's avatar Reiter, Christoph :snake:
Browse files

Add a health check for local validation

Checks that the OID config can be fetched and the public key
for token validation.
parent a6171465
No related branches found
No related tags found
No related merge requests found
......@@ -28,5 +28,9 @@ services:
autowire: true
autoconfigure: true
Dbp\Relay\AuthBundle\Service\HealthCheck:
autowire: true
autoconfigure: true
Dbp\Relay\AuthBundle\API\UserRolesInterface:
'@Dbp\Relay\AuthBundle\Service\DefaultUserRoles'
\ No newline at end of file
<?php
declare(strict_types=1);
namespace Dbp\Relay\AuthBundle\Service;
use Dbp\Relay\AuthBundle\OIDC\OIDProvider;
use Dbp\Relay\CoreBundle\HealthCheck\CheckInterface;
use Dbp\Relay\CoreBundle\HealthCheck\CheckOptions;
use Dbp\Relay\CoreBundle\HealthCheck\CheckResult;
class HealthCheck implements CheckInterface
{
private $provider;
public function __construct(OIDProvider $provider)
{
$this->provider = $provider;
}
public function getName(): string
{
return 'auth';
}
private function checkMethod(string $description, callable $func): CheckResult
{
$result = new CheckResult($description);
try {
$func();
} catch (\Throwable $e) {
$result->set(CheckResult::STATUS_FAILURE, $e->getMessage(), ['exception' => $e]);
return $result;
}
$result->set(CheckResult::STATUS_SUCCESS);
return $result;
}
public function checkConfig()
{
$this->provider->getProviderConfig();
}
public function checkPublicKey()
{
$this->provider->getJWKs();
}
public function check(CheckOptions $options): array
{
$results = [];
$results[] = $this->checkMethod('Check if the OIDC config can be fetched', [$this, 'checkConfig']);
$results[] = $this->checkMethod('Check if the OIDC public key can be fetched', [$this, 'checkPublicKey']);
return $results;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment