You are here

public function Auth0::renewTokens in Auth0 Single Sign On 8.2

Renews the access token and ID token using an existing refresh token. Scope "offline_access" must be declared in order to obtain refresh token for later token renewal.

@link https://auth0.com/docs/tokens/refresh-token/current

Parameters

array $options Options for the token endpoint request.:

  • options.scope Access token scope requested; optional.

Throws

CoreException If the Auth0 object does not have access token and refresh token

ApiException If the Auth0 API did not renew access and ID token properly

File

vendor/auth0/auth0-php/src/Auth0.php, line 605

Class

Auth0
Class Auth0 Provides access to Auth0 authentication functionality.

Namespace

Auth0\SDK

Code

public function renewTokens(array $options = []) {
  if (!$this->accessToken) {
    throw new CoreException('Can\'t renew the access token if there isn\'t one valid');
  }
  if (!$this->refreshToken) {
    throw new CoreException('Can\'t renew the access token if there isn\'t a refresh token available');
  }
  $response = $this->authentication
    ->refresh_token($this->refreshToken, $options);
  if (empty($response['access_token']) || empty($response['id_token'])) {
    throw new ApiException('Token did not refresh correctly. Access or ID token not provided.');
  }
  $this
    ->setAccessToken($response['access_token']);
  $this
    ->setIdToken($response['id_token']);
}