Skip to content

Commit

Permalink
Merge pull request #18 from PM-Connect/fix/cache-expiry
Browse files Browse the repository at this point in the history
Make the token data store cache expiry even when data says expires_in
  • Loading branch information
gregurco authored Jan 15, 2019
2 parents c82ccda + 9d3dc55 commit d2cbe6c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/Middleware/CachedOAuthMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,19 @@ protected function cacheToken(AccessToken $token)
{
$item = $this->cacheClient->getItem(sprintf('oauth.token.%s', $this->clientName));

$expires = $token->getExpires();

$item->set(
[
'token' => $token->getToken(),
'type' => $token->getType(),
'data' => $token->getData(),
'data' => array_merge($token->getData(), ['expires' => $expires->getTimestamp()]),
]
);
$item->tag('oauth');
$expires = $token->getExpires();

if ($expires) {
$item->expiresAt($expires->sub(\DateInterval::createFromDateString('1 minute')));
$item->expiresAt($expires->sub(\DateInterval::createFromDateString('10 seconds')));
}

$this->cacheClient->saveDeferred($item);
Expand Down
4 changes: 3 additions & 1 deletion src/Middleware/PersistentOAuthMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,13 @@ protected function acquireAccessToken()
*/
protected function storeTokenInSession(AccessToken $token)
{
$expires = $token->getExpires();

$this->session->start();
$this->session->set($this->clientName . '_token', [
'token' => $token->getToken(),
'type' => $token->getType(),
'data' => $token->getData(),
'data' => array_merge($token->getData(), ['expires' => $expires->getTimestamp()]),
]);
$this->session->save();
}
Expand Down

0 comments on commit d2cbe6c

Please sign in to comment.