commercetools-sdk-php-v2
The commercetools platform, import-api and PHP sdks generated from our api reference.
OAuth2Handler.php
1 <?php
2 
3 declare(strict_types=1);
9 namespace Commercetools\Client;
10 
11 use Psr\Cache\CacheItemInterface;
12 use Psr\Cache\CacheItemPoolInterface;
13 use Psr\Http\Message\RequestInterface;
14 
16 {
18  private $provider;
19 
24  public function __construct(TokenProvider $provider)
25  {
26  $this->provider = $provider;
27  }
28 
29  public function __invoke(RequestInterface $request, array $options = []): RequestInterface
30  {
31  return $request->withHeader('Authorization', $this->getAuthorizationHeader());
32  }
33 
34  public function getAuthorizationHeader(): string
35  {
36  return 'Bearer ' . $this->provider->getToken()->getValue();
37  }
38 
39  public function refreshToken(): Token
40  {
41  return $this->provider->refreshToken();
42  }
43 }
__invoke(RequestInterface $request, array $options=[])
__construct(TokenProvider $provider)