Skip to content

Commit 06a35cc

Browse files
Merge branch 'main' into carl/doc-improvements
2 parents 67bc325 + de77851 commit 06a35cc

File tree

135 files changed

+947
-608
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

135 files changed

+947
-608
lines changed
Lines changed: 6 additions & 0 deletions

docs/examples/cli/embed-plauth-click.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313

1414
@click.group(help="my cli main help message")
1515
@planet_auth_utils.opt_profile
16-
@planet_auth_utils.opt_client_id
17-
@planet_auth_utils.opt_client_secret
16+
@planet_auth_utils.opt_client_id()
17+
@planet_auth_utils.opt_client_secret()
1818
@click.pass_context
1919
def my_cli_main(ctx, auth_profile, auth_client_id, auth_client_secret):
2020
ctx.ensure_object(dict)

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ nav:
8080
- API Reference:
8181
- Planet Auth: 'api-planet-auth.md'
8282
- Planet Auth Utils: 'api-planet-auth-utils.md'
83+
- Planet Auth Config Injection: 'api-planet-auth-config-injection.md'
8384
- Examples:
8485
- Installation: 'examples-installation.md'
8586
- CLI: 'examples-cli.md'

src/planet_auth/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2024 Planet Labs PBC.
1+
# Copyright 2024-2025 Planet Labs PBC.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

src/planet_auth/auth.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2024 Planet Labs PBC.
1+
# Copyright 2024-2025 Planet Labs PBC.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

src/planet_auth/auth_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2024 Planet Labs PBC.
1+
# Copyright 2024-2025 Planet Labs PBC.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

src/planet_auth/auth_exception.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2024 Planet Labs PBC.
1+
# Copyright 2024-2025 Planet Labs PBC.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

src/planet_auth/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2024 Planet Labs PBC.
1+
# Copyright 2024-2025 Planet Labs PBC.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

src/planet_auth/credential.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2024 Planet Labs PBC.
1+
# Copyright 2024-2025 Planet Labs PBC.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

src/planet_auth/internal/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2024 Planet Labs PBC.
1+
# Copyright 2024-2025 Planet Labs PBC.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

src/planet_auth/logging/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2024 Planet Labs PBC.
1+
# Copyright 2024-2025 Planet Labs PBC.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

src/planet_auth/logging/auth_logger.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2024 Planet Labs PBC.
1+
# Copyright 2024-2025 Planet Labs PBC.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

src/planet_auth/logging/events.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2024 Planet Labs PBC.
1+
# Copyright 2024-2025 Planet Labs PBC.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

src/planet_auth/none/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2024 Planet Labs PBC.
1+
# Copyright 2024-2025 Planet Labs PBC.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

src/planet_auth/none/noop_auth.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2024 Planet Labs PBC.
1+
# Copyright 2024-2025 Planet Labs PBC.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

src/planet_auth/oidc/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2024 Planet Labs PBC.
1+
# Copyright 2024-2025 Planet Labs PBC.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

src/planet_auth/oidc/api_clients/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2024 Planet Labs PBC.
1+
# Copyright 2024-2025 Planet Labs PBC.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

src/planet_auth/oidc/api_clients/api_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2024 Planet Labs PBC.
1+
# Copyright 2024-2025 Planet Labs PBC.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

src/planet_auth/oidc/api_clients/authorization_api_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2024 Planet Labs PBC.
1+
# Copyright 2024-2025 Planet Labs PBC.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

src/planet_auth/oidc/api_clients/device_authorization_api_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2024 Planet Labs PBC.
1+
# Copyright 2024-2025 Planet Labs PBC.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

src/planet_auth/oidc/api_clients/discovery_api_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2024 Planet Labs PBC.
1+
# Copyright 2024-2025 Planet Labs PBC.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

src/planet_auth/oidc/api_clients/introspect_api_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2024 Planet Labs PBC.
1+
# Copyright 2024-2025 Planet Labs PBC.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

src/planet_auth/oidc/api_clients/jwks_api_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2024 Planet Labs PBC.
1+
# Copyright 2024-2025 Planet Labs PBC.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

src/planet_auth/oidc/api_clients/oidc_request_auth.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2024 Planet Labs PBC.
1+
# Copyright 2024-2025 Planet Labs PBC.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

src/planet_auth/oidc/api_clients/revocation_api_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2024 Planet Labs PBC.
1+
# Copyright 2024-2025 Planet Labs PBC.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

src/planet_auth/oidc/api_clients/token_api_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2024 Planet Labs PBC.
1+
# Copyright 2024-2025 Planet Labs PBC.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

src/planet_auth/oidc/api_clients/userinfo_api_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2024 Planet Labs PBC.
1+
# Copyright 2024-2025 Planet Labs PBC.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

src/planet_auth/oidc/auth_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2024 Planet Labs PBC.
1+
# Copyright 2024-2025 Planet Labs PBC.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

src/planet_auth/oidc/auth_client_default_authenticators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2024 Planet Labs PBC.
1+
# Copyright 2024-2025 Planet Labs PBC.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

src/planet_auth/oidc/auth_client_with_client_pubkey.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2024 Planet Labs PBC.
1+
# Copyright 2024-2025 Planet Labs PBC.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

src/planet_auth/oidc/auth_client_with_client_secret.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2024 Planet Labs PBC.
1+
# Copyright 2024-2025 Planet Labs PBC.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

src/planet_auth/oidc/auth_clients/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2024 Planet Labs PBC.
1+
# Copyright 2024-2025 Planet Labs PBC.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

src/planet_auth/oidc/auth_clients/auth_code_flow.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2024 Planet Labs PBC.
1+
# Copyright 2024-2025 Planet Labs PBC.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

src/planet_auth/oidc/auth_clients/client_credentials_flow.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2024 Planet Labs PBC.
1+
# Copyright 2024-2025 Planet Labs PBC.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

src/planet_auth/oidc/auth_clients/client_validator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2024 Planet Labs PBC.
1+
# Copyright 2024-2025 Planet Labs PBC.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

src/planet_auth/oidc/auth_clients/device_code_flow.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2024 Planet Labs PBC.
1+
# Copyright 2024-2025 Planet Labs PBC.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

src/planet_auth/oidc/auth_clients/resource_owner_flow.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2024 Planet Labs PBC.
1+
# Copyright 2024-2025 Planet Labs PBC.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

src/planet_auth/oidc/multi_validator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2024 Planet Labs PBC.
1+
# Copyright 2024-2025 Planet Labs PBC.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

src/planet_auth/oidc/oidc_credential.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2024 Planet Labs PBC.
1+
# Copyright 2024-2025 Planet Labs PBC.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

src/planet_auth/oidc/request_authenticator.py

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2024 Planet Labs PBC.
1+
# Copyright 2024-2025 Planet Labs PBC.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -14,7 +14,7 @@
1414

1515
import jwt
1616
import time
17-
from typing import Dict
17+
from typing import Dict, Optional
1818

1919
import planet_auth.logging.auth_logger
2020
from planet_auth.credential import Credential
@@ -79,45 +79,68 @@ def _load(self):
7979

8080
def _refresh(self):
8181
if self._auth_client:
82+
# TODO: cleanup? We did this before we wrote "update_credential_data()"
83+
# We maybe should just be using that now. Taking that clean-up slow
84+
# since it may have interactions with derived code.
85+
# It seems to me we should be able to collapse the credential.save()
86+
# calls in this file with the superclass.
8287
new_credentials = self._auth_client.refresh(self._credential.refresh_token())
8388
new_credentials.set_path(self._credential.path())
8489
new_credentials.set_storage_provider(self._credential.storage_provider())
8590
new_credentials.save()
8691

92+
# self.update_credential(new_credential=new_credentials)
8793
self._credential = new_credentials
8894
self._load()
8995

90-
def pre_request_hook(self):
96+
def _refresh_if_needed(self):
9197
# Reload the file before refreshing. Another process might
9298
# have done it for us, and save us the network call.
9399
#
94100
# Also, if refresh tokens are configured to be one time use,
95-
# we want a fresh refresh token. Stale refresh tokens are
96-
# invalid in this case.
101+
# we want a fresh refresh token. Stale refresh tokens may be
102+
# invalid depending on server configuration.
97103
#
98104
# Also, it's possible that we have a valid refresh token,
99105
# but not an access token. When that's true, we should
100106
# try to cash in the refresh token.
101107
#
102108
# If everything fails, continue with what we have. Let the API
103109
# we are calling decide if it's good enough.
104-
if int(time.time()) > self._refresh_at:
110+
now = int(time.time())
111+
if now > self._refresh_at:
105112
try:
106113
self._load()
107114
except Exception as e: # pylint: disable=broad-exception-caught
108115
auth_logger.warning(
109-
msg="Error loading auth token. Continuing with old auth token. Load error: " + str(e)
116+
msg=f"Error loading auth token. Continuing with old configuration and token data. Load error: {str(e)}"
110117
)
111-
if int(time.time()) > self._refresh_at:
118+
if now > self._refresh_at:
112119
try:
113120
self._refresh()
114121
except Exception as e: # pylint: disable=broad-exception-caught
115122
auth_logger.warning(
116-
msg="Error refreshing auth token. Continuing with old auth token. Refresh error: " + str(e)
123+
msg=f"Error obtaining new or refreshed auth token. Continuing with old configuration and token data. Refresh error: {str(e)}"
117124
)
125+
126+
# This tries to give a client a better error when there is no old
127+
# token to fall back to. But, it is known to cause problems when
128+
# auth truly isn't needed, either because the service does not need
129+
# it or because it has been mocked out (as in unit test cases).
130+
# So, we rely on the warnings to keep the user informed. This might
131+
# also result in the user seeing errors from the server - the quality
132+
# of which we have no control over.
133+
#
134+
# if not (self._credential and self._credential.is_loaded()):
135+
# # "refresh" may also be called to initialize in some cases, as in client credentials flow.
136+
# # Continuing with what we have is not an option when we have nothing.
137+
# raise AuthException("Failed to load or obtain a valid access token.")
138+
139+
def pre_request_hook(self):
140+
self._refresh_if_needed()
118141
super().pre_request_hook()
119142

120-
def update_credential(self, new_credential: Credential):
143+
def update_credential(self, new_credential: Credential) -> None:
121144
if not isinstance(new_credential, FileBackedOidcCredential):
122145
raise TypeError(
123146
f"{type(self).__name__} does not support {type(new_credential)} credentials. Use FileBackedOidcCredential."
@@ -126,7 +149,7 @@ def update_credential(self, new_credential: Credential):
126149
self._refresh_at = 0
127150
# self._load() # Mimic __init__. Don't load, let that happen JIT.
128151

129-
def update_credential_data(self, new_credential_data: Dict):
152+
def update_credential_data(self, new_credential_data: Dict) -> None:
130153
# This is more different than update_credential() than it may
131154
# appear. Inherent in being passed a Credential in update_credential()
132155
# is that it may not yet be loaded from disk, and so deferring
@@ -137,6 +160,11 @@ def update_credential_data(self, new_credential_data: Dict):
137160
super().update_credential_data(new_credential_data=new_credential_data)
138161
self._load()
139162

163+
def credential(self, refresh_if_needed: bool = False) -> Optional[Credential]:
164+
if refresh_if_needed:
165+
self._refresh_if_needed()
166+
return super().credential()
167+
140168

141169
class RefreshOrReloginOidcTokenRequestAuthenticator(RefreshingOidcTokenRequestAuthenticator):
142170
"""
@@ -171,5 +199,6 @@ def _refresh(self):
171199
new_credentials.set_storage_provider(self._credential.storage_provider())
172200
new_credentials.save()
173201

202+
# self.update_credential(new_credential=new_credentials)
174203
self._credential = new_credentials
175204
self._load()

src/planet_auth/oidc/resources/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2024 Planet Labs PBC.
1+
# Copyright 2024-2025 Planet Labs PBC.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

src/planet_auth/oidc/token_validator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2024 Planet Labs PBC.
1+
# Copyright 2024-2025 Planet Labs PBC.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

src/planet_auth/oidc/util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2024 Planet Labs PBC.
1+
# Copyright 2024-2025 Planet Labs PBC.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

src/planet_auth/planet_legacy/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2024 Planet Labs PBC.
1+
# Copyright 2024-2025 Planet Labs PBC.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

src/planet_auth/planet_legacy/auth_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2024 Planet Labs PBC.
1+
# Copyright 2024-2025 Planet Labs PBC.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

src/planet_auth/planet_legacy/legacy_api_key.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2024 Planet Labs PBC.
1+
# Copyright 2024-2025 Planet Labs PBC.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

0 commit comments

Comments
 (0)