Skip to content

pull out new error. It causes downstream errors, and was only added in an attempt to give better errors, not change behavior. #29

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 8, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions src/planet_auth/oidc/request_authenticator.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from typing import Dict, Optional

import planet_auth.logging.auth_logger
from planet_auth import AuthException
from planet_auth.credential import Credential
from planet_auth.request_authenticator import CredentialRequestAuthenticator
from planet_auth.oidc.auth_client import OidcAuthClient
Expand Down Expand Up @@ -114,20 +113,28 @@ def _refresh_if_needed(self):
self._load()
except Exception as e: # pylint: disable=broad-exception-caught
auth_logger.warning(
msg="Error loading auth token. Continuing with old auth token. Load error: " + str(e)
msg=f"Error loading auth token. Continuing with old configuration and token data. Load error: {str(e)}"
)
if now > self._refresh_at:
try:
self._refresh()
except Exception as e: # pylint: disable=broad-exception-caught
auth_logger.warning(
msg="Error refreshing auth token. Continuing with old auth token. Refresh error: " + str(e)
msg=f"Error obtaining new or refreshed auth token. Continuing with old configuration and token data. Refresh error: {str(e)}"
)

if not (self._credential and self._credential.is_loaded()):
# "refresh" may also be called to initialize in some cases, as in client credentials flow.
# Continuing with what we have is not an option when we have nothing.
raise AuthException("Failed to load or obtain a valid access token.")
# This tries to give a client a better error when there is no old
# token to fall back to. But, it is known to cause problems when
# auth truly isn't needed, either because the service does not need
# it or because it has been mocked out (as in unit test cases).
# So, we rely on the warnings to keep the user informed. This might
# also result in the user seeing errors from the server - the quality
# of which we have no control over.
#
# if not (self._credential and self._credential.is_loaded()):
# # "refresh" may also be called to initialize in some cases, as in client credentials flow.
# # Continuing with what we have is not an option when we have nothing.
# raise AuthException("Failed to load or obtain a valid access token.")

def pre_request_hook(self):
self._refresh_if_needed()
Expand Down