|
@@ 200-204 (lines=5) @@
|
| 197 |
|
} |
| 198 |
|
|
| 199 |
|
// make sure we have an access token |
| 200 |
|
if (false === $accessToken = $this->tokenStorage->getAccessToken($this->userId, $this->providerId, $requestScope)) { |
| 201 |
|
$this->logger->info(sprintf('no access_token available for user "%s" with scope "%s"', $this->userId, $requestScope)); |
| 202 |
|
|
| 203 |
|
return false; |
| 204 |
|
} |
| 205 |
|
|
| 206 |
|
if ($requestScope !== $accessToken->getScope()) { |
| 207 |
|
throw new OAuthException('access_token does not have the required scope'); |
|
@@ 214-221 (lines=8) @@
|
| 211 |
|
if ($accessToken->isExpired($this->dateTime)) { |
| 212 |
|
$this->logger->info(sprintf('access_token for user "%s" with scope "%s" expired', $this->userId, $requestScope)); |
| 213 |
|
// access_token is expired, try to refresh it |
| 214 |
|
if (is_null($accessToken->getRefreshToken())) { |
| 215 |
|
$this->logger->info(sprintf('no refresh_token available in this access_token for user "%s" with scope "%s", deleting it', $this->userId, $requestScope)); |
| 216 |
|
// we do not have a refresh_token, delete this access token, it |
| 217 |
|
// is useless now... |
| 218 |
|
$this->tokenStorage->deleteAccessToken($this->userId, $this->providerId, $accessToken); |
| 219 |
|
|
| 220 |
|
return false; |
| 221 |
|
} |
| 222 |
|
|
| 223 |
|
$this->logger->info(sprintf('using refresh_token to obtain new access_token for user "%s" with scope "%s"', $this->userId, $requestScope)); |
| 224 |
|
|
|
@@ 242-248 (lines=7) @@
|
| 239 |
|
$request->setHeader('Authorization', sprintf('Bearer %s', $accessToken->getToken())); |
| 240 |
|
|
| 241 |
|
$response = $this->httpClient->send($request); |
| 242 |
|
if (401 === $response->getStatusCode()) { |
| 243 |
|
$this->logger->info(sprintf('deleting access_token for user "%s" with scope "%s" that was supposed to work, but did not, possibly revoked by user', $this->userId, $requestScope)); |
| 244 |
|
// this indicates an invalid access_token |
| 245 |
|
$this->tokenStorage->deleteAccessToken($this->userId, $this->providerId, $accessToken); |
| 246 |
|
|
| 247 |
|
return false; |
| 248 |
|
} |
| 249 |
|
|
| 250 |
|
$this->logger->info(sprintf('access_token for use "%s" with scope "%s" successfully used', $this->userId, $requestScope)); |
| 251 |
|
|