Skip to content

Commit 58c864e

Browse files
committed
Delete existing access token if it is invalid
1 parent 1a94bc1 commit 58c864e

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

src/OAuth2Handler.php

+9
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,15 @@ public function setAccessToken($token)
147147
return $this;
148148
}
149149

150+
/**
151+
* Forcefully delete an access token, even if it's valid
152+
*/
153+
public function deleteAccessToken()
154+
{
155+
$this->rawToken = null;
156+
$this->tokenPersistence->deleteToken();
157+
}
158+
150159
/**
151160
* Get a valid access token.
152161
*

src/OAuth2Middleware.php

+3
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ private function onFulfilled(RequestInterface $request, array $options, $handler
6060
return $response;
6161
}
6262

63+
// Delete the previous access token, if any
64+
$this->deleteAccessToken();
65+
6366
// Acquire a new access token, and retry the request.
6467
$accessToken = $this->getAccessToken();
6568
if ($accessToken === null) {

src/OAuth2Subscriber.php

+3
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ public function onError(ErrorEvent $event)
6969
return;
7070
}
7171

72+
// Delete the previous access token, if any
73+
$this->deleteAccessToken();
74+
7275
// Acquire a new access token, and retry the request.
7376
$accessToken = $this->getAccessToken();
7477
if ($accessToken != null) {

0 commit comments

Comments
 (0)