Skip to content

Commit

Permalink
[SDK-3081] Fix: Update session properties after a token is refreshed (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
evansims authored Jan 25, 2022
1 parent 5350fb9 commit 3797004
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/Auth0.php
Original file line number Diff line number Diff line change
Expand Up @@ -418,10 +418,23 @@ public function renew(

$this->setAccessToken($response['access_token']);

if (isset($response['expires_in']) && is_numeric($response['expires_in'])) {
$expiresIn = time() + (int) $response['expires_in'];
$this->setAccessTokenExpiration($expiresIn);
}

if (isset($response['id_token'])) {
$this->setIdToken($response['id_token']);
}

if (isset($response['refresh_token'])) {
$this->setRefreshToken($response['refresh_token']);
}

if (isset($response['scope'])) {
$this->setAccessTokenScope(explode(' ', $response['scope']));
}

$this->deferStateSaving(false);

return $this;
Expand Down
5 changes: 4 additions & 1 deletion tests/Unit/Auth0Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ public function defer(

$httpClient->mockResponses([
\Auth0\Tests\Utilities\HttpResponseGenerator::create('{"access_token":"1.2.3","refresh_token":"2.3.4","id_token":"' . $token . '"}'),
\Auth0\Tests\Utilities\HttpResponseGenerator::create('{"access_token":"__test_access_token__","id_token":"' . $token . '"}'),
\Auth0\Tests\Utilities\HttpResponseGenerator::create('{"access_token":"__test_access_token__","id_token":"' . $token . '","expires_in":"123","refresh_token":"5.6.7","scope":"test1 test2 test3"}'),
]);

$_GET['code'] = uniqid();
Expand All @@ -672,6 +672,9 @@ public function defer(

expect($auth0->getAccessToken())->toEqual('__test_access_token__');
expect($auth0->getIdToken())->toEqual($token);
expect($auth0->getAccessTokenExpiration())->toBeGreaterThanOrEqual(time() + 123);
expect($auth0->getRefreshToken())->toEqual('5.6.7');
expect($auth0->getAccessTokenScope())->toEqual(['test1', 'test2', 'test3']);

expect($requestBody['scope'])->toEqual('openid');
expect($requestBody['client_secret'])->toEqual('__test_client_secret__');
Expand Down

0 comments on commit 3797004

Please sign in to comment.