FIX: Authorization en FastCGI
This commit is contained in:
@ -8,7 +8,7 @@ use Incoviba\Exception\Client\FastCGI as FastCGIException;
|
||||
|
||||
class FastCGI implements LoggerAwareInterface
|
||||
{
|
||||
public function __construct(protected string $hostname, protected int $port,
|
||||
public function __construct(protected Login $loginService, protected string $hostname, protected int $port,
|
||||
protected string $documentRoot,
|
||||
protected int $connectionTimeout = 5000, protected int $readTimeout = 5000)
|
||||
{
|
||||
@ -43,6 +43,7 @@ class FastCGI implements LoggerAwareInterface
|
||||
if (!isset($this->socket)) {
|
||||
$this->connect();
|
||||
}
|
||||
$request = $this->setHeaders($request);
|
||||
try {
|
||||
$this->socketIds []= $this->client->sendAsyncRequest($this->socket, $request);
|
||||
} catch (FCGI\Exceptions\FastCGIClientException $exception) {
|
||||
@ -97,4 +98,11 @@ class FastCGI implements LoggerAwareInterface
|
||||
$request->setRequestUri($uri);
|
||||
return $this->sendRequest($request);
|
||||
}
|
||||
|
||||
protected function setHeaders(FCGI\Interfaces\ProvidesRequestData $request): FCGI\Interfaces\ProvidesRequestData
|
||||
{
|
||||
$apiKey = $this->loginService->getKey();
|
||||
$request->setCustomVar('HTTP_AUTHORIZATION', "Bearer {$apiKey}");
|
||||
return $request;
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ class Login
|
||||
{
|
||||
public function __construct(protected ClientInterface $client, protected LoggerInterface $logger,
|
||||
protected string $tokenFilename,
|
||||
protected string $username, protected string $password) {}
|
||||
protected string $username, protected string $password, protected string $apiKey) {}
|
||||
|
||||
public function login(): string
|
||||
{
|
||||
@ -84,8 +84,11 @@ class Login
|
||||
}
|
||||
return $response->getStatusCode() === 200;
|
||||
}
|
||||
public function getKey(string $apiKey, string $separator = 'g'): string
|
||||
public function getKey(?string $apiKey = null, string $separator = 'g'): string
|
||||
{
|
||||
if ($apiKey === null) {
|
||||
$apiKey = $this->apiKey;
|
||||
}
|
||||
try {
|
||||
$savedToken = $this->retrieveToken();
|
||||
$token = implode('', [md5($apiKey), $separator, $savedToken]);
|
||||
|
Reference in New Issue
Block a user