refactor: provider authentication flow

This commit is contained in:
Vincent
2024-09-30 13:48:15 +02:00
parent b162f2313e
commit 81512bebb4
7 changed files with 98 additions and 78 deletions

View File

@@ -5,8 +5,14 @@ namespace App\Service\Connector;
use App\Entity\Domain;
use Psr\Cache\CacheItemInterface;
use Psr\Cache\CacheItemPoolInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;
/**
* The typical flow of a provider will go as follows:
*
* MyProvider $provider; // gotten from DI
* $provider->authenticate($authData);
* $provider->orderDomain($domain, $dryRun);
*/
abstract class AbstractProvider
{
protected array $authData;
@@ -16,7 +22,17 @@ abstract class AbstractProvider
) {
}
abstract public static function verifyAuthData(array $authData, HttpClientInterface $client): array;
/**
* @param array $authData raw authentication data as supplied by the user
*
* @return array a cleaned up version of the authentication data
*/
abstract public function verifyAuthData(array $authData): array;
/**
* @throws \Exception when the registrar denies the authentication
*/
abstract public function assertAuthentication(): void; // TODO use dedicated exception type
abstract public function orderDomain(Domain $domain, bool $dryRun): void;
@@ -53,9 +69,13 @@ abstract class AbstractProvider
return true;
}
/**
* @throws \Exception
*/
public function authenticate(array $authData): void
{
$this->authData = $authData;
$this->authData = $this->verifyAuthData($authData);
$this->assertAuthentication();
}
abstract protected function getCachedTldList(): CacheItemInterface;