Skip to content

Commit

Permalink
Merge pull request #174 from statisticsnorway/fix-default-argument
Browse files Browse the repository at this point in the history
Fix auth refresh argument
  • Loading branch information
mallport authored Aug 26, 2024
2 parents e47661c + b20c020 commit 040c224
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "dapla-toolbelt"
version = "3.0.0"
version = "3.0.1"
description = "Dapla Toolbelt"
authors = ["Dapla Developers <dapla-platform-developers@ssb.no>"]
license = "MIT"
Expand Down
11 changes: 8 additions & 3 deletions src/dapla/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from datetime import timedelta
from enum import Enum
from functools import lru_cache
from functools import partial
from typing import Any
from typing import Optional

Expand Down Expand Up @@ -81,12 +82,14 @@ def _get_current_dapla_metadata() -> (

@staticmethod
def _refresh_handler(
request: google.auth.transport.Request, scopes: Sequence[str]
request: google.auth.transport.Request,
scopes: Sequence[str],
from_jupyterhub: bool = False,
) -> tuple[str, datetime]:
# We manually override the refresh_handler method with our custom logic for fetching tokens.
# Previously, we directly overrode the `refresh` method. However, this
# approach led to deadlock issues in gcsfs/credentials.py's maybe_refresh method.
return AuthClient.fetch_google_token()
return AuthClient.fetch_google_token(from_jupyterhub=from_jupyterhub)

@staticmethod
def fetch_google_token_from_oidc_exchange(
Expand Down Expand Up @@ -269,7 +272,9 @@ def fetch_google_credentials(force_token_exchange: bool = False) -> Credentials:
token=token,
expiry=expiry,
token_uri="https://oauth2.googleapis.com/token",
refresh_handler=AuthClient._refresh_handler,
refresh_handler=partial(
AuthClient._refresh_handler, from_jupyterhub=True
),
)
case (_, _, DaplaRegion.DAPLA_LAB):
logger.debug("Auth - Dapla Lab detected, attempting to use ADC")
Expand Down

0 comments on commit 040c224

Please sign in to comment.