forked from square/square-php-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAccessTokenManager.php
51 lines (43 loc) · 1.16 KB
/
AccessTokenManager.php
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
declare(strict_types=1);
namespace Square;
use Square\Http\HttpRequest;
/**
* Utility class for authorization and token management.
*/
class AccessTokenManager implements AuthManagerInterface, AccessTokenCredentials
{
private $accessToken;
/**
* Returns an instance of this class.
*
* @param string|null $accessToken The OAuth 2.0 Access Token to use for API requests.
*/
public function __construct(?string $accessToken)
{
$this->accessToken = $accessToken;
}
/**
* String value for accessToken.
*/
public function getAccessToken(): ?string
{
return $this->accessToken;
}
/**
* Checks if provided credentials match with existing ones.
*
* @param string|null $accessToken The OAuth 2.0 Access Token to use for API requests.
*/
public function equals(?string $accessToken): bool
{
return $accessToken == $this->getAccessToken();
}
/**
* Adds authentication to the given HttpRequest.
*/
public function apply(HttpRequest $httpRequest)
{
$httpRequest->addHeader('Authorization', 'Bearer ' . $this->accessToken);
}
}