use Lcobucci\JWT\Token;
use League\OAuth2\Client\Provider\Exception\IdentityProviderException;
use OpenIDConnectClient\AccessToken;
+use OpenIDConnectClient\Exception\InvalidTokenException;
use OpenIDConnectClient\OpenIDConnectProvider;
/**
$json = session()->get('openid_token');
$accessToken = new AccessToken(json_decode($json, true));
- // Check whether the access token or ID token is expired
- if (!$accessToken->getIdToken()->isExpired() && !$accessToken->hasExpired()) {
+ // Check if both the access token and the ID token (if present) are unexpired
+ $idToken = $accessToken->getIdToken();
+ if (!$accessToken->hasExpired() && (!$idToken || !$idToken->isExpired())) {
return true;
}
// Refreshing failed, logout
$this->actionLogout();
return false;
+ } catch (InvalidTokenException $e) {
+ // A refresh token doesn't necessarily contain
+ // an ID token, ignore this exception
}
// A valid token was obtained, we update the access token