Commit b00bc3ec authored by John Davis's avatar John Davis
Browse files

Check if refresh token is decodable before decoding it

parent f28450cb
Loading
Loading
Loading
Loading
+11 −5
Original line number Diff line number Diff line
@@ -123,11 +123,17 @@ class OIDCAuthnzBase(IdentityProvider):
            return False
        if not custos_authnz_token.refresh_token:
            return False

        # Try to extract expiration date from the refresh token. If expired, do not refresh token.
        try: 
            refresh_token_decoded = self._decode_token_no_signature(custos_authnz_token.refresh_token)
            # do not attempt to use refresh token that is already expired
            if int(refresh_token_decoded["exp"]) <= int(time.time()):
                # in the future we might want to log out the user here
                return False
        except jwt.exceptions.DecodeError:
            log.error("Refresh token is non-decodable")

        oauth2_session = self._create_oauth2_session()
        token_endpoint = self.config.token_endpoint
        if self.config.iam_client_secret: