mirror of
https://github.com/maelgangloff/domain-watchdog.git
synced 2025-12-29 16:15:04 +00:00
refactor: provider authentication flow
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user