Skip to content

Commit 3797004

Browse files
authored
[SDK-3081] Fix: Update session properties after a token is refreshed (#593)
1 parent 5350fb9 commit 3797004

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/Auth0.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,10 +418,23 @@ public function renew(
418418

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

421+
if (isset($response['expires_in']) && is_numeric($response['expires_in'])) {
422+
$expiresIn = time() + (int) $response['expires_in'];
423+
$this->setAccessTokenExpiration($expiresIn);
424+
}
425+
421426
if (isset($response['id_token'])) {
422427
$this->setIdToken($response['id_token']);
423428
}
424429

430+
if (isset($response['refresh_token'])) {
431+
$this->setRefreshToken($response['refresh_token']);
432+
}
433+
434+
if (isset($response['scope'])) {
435+
$this->setAccessTokenScope(explode(' ', $response['scope']));
436+
}
437+
425438
$this->deferStateSaving(false);
426439

427440
return $this;

tests/Unit/Auth0Test.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@ public function defer(
654654

655655
$httpClient->mockResponses([
656656
\Auth0\Tests\Utilities\HttpResponseGenerator::create('{"access_token":"1.2.3","refresh_token":"2.3.4","id_token":"' . $token . '"}'),
657-
\Auth0\Tests\Utilities\HttpResponseGenerator::create('{"access_token":"__test_access_token__","id_token":"' . $token . '"}'),
657+
\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"}'),
658658
]);
659659

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

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

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

0 commit comments

Comments
 (0)