]> BookStack Code Mirror - bookstack/commitdiff
Increase robustness of the refresh method
authorJasper Weyne <redacted>
Tue, 4 Aug 2020 19:29:11 +0000 (21:29 +0200)
committerJasper Weyne <redacted>
Tue, 4 Aug 2020 19:29:11 +0000 (21:29 +0200)
app/Auth/Access/OpenIdService.php

index 3d8818fa5d519f4ff890a2cf4cd563665c517c1c..2b536d492ffe659043c72e96c17c9a821aa6c1e9 100644 (file)
@@ -8,7 +8,6 @@ use Exception;
 use Lcobucci\JWT\Token;
 use League\OAuth2\Client\Provider\Exception\IdentityProviderException;
 use OpenIDConnectClient\AccessToken;
-use OpenIDConnectClient\Exception\InvalidTokenException;
 use OpenIDConnectClient\OpenIDConnectProvider;
 
 /**
@@ -63,11 +62,20 @@ class OpenIdService extends ExternalAuthService
     {
         // Retrieve access token for current session
         $json = session()->get('openid_token');
+
+        // If no access token was found, reject the refresh
+        if (!$json) {
+            $this->actionLogout();
+            return false;
+        }
+
         $accessToken = new AccessToken(json_decode($json, true) ?? []);
 
         // Check if both the access token and the ID token (if present) are unexpired
         $idToken = $accessToken->getIdToken();
-        if (!$accessToken->hasExpired() && (!$idToken || !$idToken->isExpired())) {
+        $accessTokenUnexpired = $accessToken->getExpires() && !$accessToken->hasExpired();
+        $idTokenUnexpired = !$idToken || !$idToken->isExpired(); 
+        if ($accessTokenUnexpired && $idTokenUnexpired) {
             return true;
         }