1 | <?php |
||
12 | abstract class AbstractTokenService implements AuthorizesRequests |
||
13 | { |
||
14 | /** @string Refresh Token grant */ |
||
15 | const GRANT_REFRESH_TOKEN = 'refresh_token'; |
||
16 | |||
17 | /** @string */ |
||
18 | const GRANT_CLIENT_CREDENTIALS = 'client_credentials'; |
||
19 | |||
20 | /** @var AbstractProvider */ |
||
21 | private $provider; |
||
22 | |||
23 | /** @var AccessToken */ |
||
24 | private $accessToken; |
||
25 | |||
26 | /** @var callable */ |
||
27 | private $refreshTokenCallback; |
||
28 | |||
29 | /** |
||
30 | * @param AbstractProvider $provider A League OAuth2 Client Provider. |
||
31 | * @param null|AccessToken $accessToken Provide an initial (e.g. cached/persisted) access token. |
||
32 | * @param null|callable $refreshTokenCallback Will be called with a new AccessToken as a parameter if the Access |
||
33 | * Token ever needs to be renewed. |
||
34 | */ |
||
35 | 8 | public function __construct( |
|
52 | |||
53 | /** |
||
54 | * @inheritdoc |
||
55 | */ |
||
56 | 6 | final public function authorize(RequestInterface $request): RequestInterface |
|
74 | |||
75 | /** |
||
76 | * @return AccessToken |
||
77 | */ |
||
78 | 7 | final protected function getAccessToken(): AccessToken |
|
82 | |||
83 | /** |
||
84 | * Refreshes an existing Access Token. Or requests a new one (using the client_credentials grant) if no token |
||
85 | * is available to the service yet. |
||
86 | * |
||
87 | * @return void |
||
88 | */ |
||
89 | 3 | final protected function refreshToken() |
|
106 | |||
107 | /** |
||
108 | * Request a new Access Token from the provider |
||
109 | * |
||
110 | * @return AccessToken |
||
111 | */ |
||
112 | abstract protected function requestAccessToken(): AccessToken; |
||
113 | |||
114 | /** |
||
115 | * Returns an authorized copy of the request. Only gets called when necessary (i.e. not if the request is already |
||
116 | * authorized), and always with a valid (fresh) Access Token. However, it SHOULD be idempotent. |
||
117 | * |
||
118 | * @param RequestInterface $request An unauthorized request |
||
119 | * |
||
120 | * @return RequestInterface An authorized copy of the request |
||
121 | */ |
||
122 | abstract protected function getAuthorizedRequest(RequestInterface $request): RequestInterface; |
||
123 | |||
124 | /** |
||
125 | * @return AbstractProvider |
||
126 | */ |
||
127 | 2 | final protected function getProvider(): AbstractProvider |
|
131 | } |
||
132 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: