forked from mallgroup/mpapi-client-php
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClientIdAuthenticator.php
More file actions
32 lines (23 loc) · 877 Bytes
/
Copy pathClientIdAuthenticator.php
File metadata and controls
32 lines (23 loc) · 877 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?php declare(strict_types=1);
namespace MpApiClient\Common\Authenticators;
use GuzzleHttp\Middleware;
use GuzzleHttp\Psr7\Uri;
use MpApiClient\Common\Interfaces\AuthMiddlewareInterface;
use Psr\Http\Message\RequestInterface;
final class ClientIdAuthenticator implements AuthMiddlewareInterface
{
private const CLIENT_ID_KEY = 'client_id';
private string $clientId;
public function __construct(string $clientId)
{
$this->clientId = $clientId;
}
public function getHandler(): callable
{
return Middleware::mapRequest(fn(RequestInterface $request): RequestInterface => $this->authenticateRequest($request));
}
public function authenticateRequest(RequestInterface $request): RequestInterface
{
return $request->withUri(Uri::withQueryValue($request->getUri(), self::CLIENT_ID_KEY, $this->clientId));
}
}