commercetools-sdk-php-v2
The commercetools platform, import-api and PHP sdks generated from our api reference.
Loading...
Searching...
No Matches
OAuth2Handler.php
1<?php
2
3declare(strict_types=1);
10
11use Psr\Cache\CacheItemInterface;
12use Psr\Cache\CacheItemPoolInterface;
13use 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)