Skip to content

Commit b8c40d3

Browse files
Minor fixes to changes due to wx feedback (#27)
* detect 'refresh to login' failures earlier to throw a better error. * Remove the builtin provider interface from the main __init__. This very easily leads to circular dependencies in applications built on top of the library. * black formatting
1 parent c4be6d3 commit b8c40d3

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/planet_auth/oidc/request_authenticator.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from typing import Dict, Optional
1818

1919
import planet_auth.logging.auth_logger
20+
from planet_auth import AuthException
2021
from planet_auth.credential import Credential
2122
from planet_auth.request_authenticator import CredentialRequestAuthenticator
2223
from planet_auth.oidc.auth_client import OidcAuthClient
@@ -123,6 +124,11 @@ def _refresh_if_needed(self):
123124
msg="Error refreshing auth token. Continuing with old auth token. Refresh error: " + str(e)
124125
)
125126

127+
if not (self._credential and self._credential.is_loaded()):
128+
# "refresh" may also be called to initialize in some cases, as in client credentials flow.
129+
# Continuing with what we have is not an option when we have nothing.
130+
raise AuthException("Failed to load or obtain a valid access token.")
131+
126132
def pre_request_hook(self):
127133
self._refresh_if_needed()
128134
super().pre_request_hook()

src/planet_auth_utils/__init__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,11 @@
9999
from .commands.cli.util import recast_exceptions_to_click
100100
from planet_auth_utils.constants import EnvironmentVariables
101101
from planet_auth_utils.plauth_factory import PlanetAuthFactory
102-
from planet_auth_utils.builtins import Builtins, BuiltinConfigurationProviderInterface
102+
from planet_auth_utils.builtins import (
103+
Builtins,
104+
# Easily causes circular dependencies. Intentionally not part of the main package interface for now.
105+
# BuiltinConfigurationProviderInterface,
106+
)
103107
from planet_auth_utils.profile import Profile
104108
from planet_auth_utils.plauth_user_config import PlanetAuthUserConfig
105109

@@ -161,7 +165,7 @@
161165
"recast_exceptions_to_click",
162166
#
163167
"Builtins",
164-
"BuiltinConfigurationProviderInterface",
168+
# "BuiltinConfigurationProviderInterface",
165169
"EnvironmentVariables",
166170
"PlanetAuthFactory",
167171
"Profile",

0 commit comments

Comments
 (0)