dapla-auth-client 1.2.0__tar.gz → 1.2.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,24 +1,22 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: dapla-auth-client
3
- Version: 1.2.0
3
+ Version: 1.2.2
4
4
  Summary: Dapla Auth Client
5
5
  License: MIT
6
6
  Author: Dapla Developers
7
7
  Author-email: dapla-platform-developers@ssb.no
8
- Requires-Python: >=3.10,<4.0
8
+ Requires-Python: >=3.11
9
9
  Classifier: Development Status :: 5 - Production/Stable
10
10
  Classifier: License :: OSI Approved :: MIT License
11
11
  Classifier: Programming Language :: Python :: 3
12
- Classifier: Programming Language :: Python :: 3.10
13
12
  Classifier: Programming Language :: Python :: 3.11
14
13
  Classifier: Programming Language :: Python :: 3.12
15
14
  Classifier: Programming Language :: Python :: 3.13
16
- Requires-Dist: deprecated (>=1.2.18,<2.0.0)
15
+ Requires-Dist: deprecated (>=1.2.18)
17
16
  Requires-Dist: google-auth (>=2.40.2)
18
- Requires-Dist: pytest (>=8.4.0,<9.0.0)
19
17
  Requires-Dist: requests (>=2.27.1)
20
18
  Requires-Dist: responses (>=0.24.0)
21
- Requires-Dist: types-deprecated (>=1.2.15.20250304,<2.0.0.0)
19
+ Requires-Dist: types-deprecated (>=1.2.15.20250304)
22
20
  Requires-Dist: types-requests (>=2.28.11)
23
21
  Project-URL: Changelog, https://github.com/statisticsnorway/dapla-auth-client/releases
24
22
  Project-URL: Documentation, https://statisticsnorway.github.io/dapla-auth-client
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "dapla-auth-client"
3
- version = "1.2.0"
3
+ version = "1.2.2"
4
4
  description = "Dapla Auth Client"
5
5
  authors = ["Dapla Developers <dapla-platform-developers@ssb.no>"]
6
6
  license = "MIT"
@@ -15,20 +15,19 @@ packages = [{include = "dapla_auth_client", from = "src"}]
15
15
  Changelog = "https://github.com/statisticsnorway/dapla-auth-client/releases"
16
16
 
17
17
  [tool.poetry.dependencies]
18
- python = ">=3.10,<4.0"
18
+ python = ">=3.11"
19
19
  requests = ">=2.27.1"
20
20
  google-auth = ">=2.40.2"
21
- pytest = "^8.4.0"
22
- deprecated = "^1.2.18"
21
+ deprecated = ">=1.2.18"
23
22
  types-requests = ">=2.28.11"
24
23
  responses = ">=0.24.0"
25
- types-deprecated = "^1.2.15.20250304"
24
+ types-deprecated = ">=1.2.15.20250304"
26
25
 
27
26
  [tool.poetry.group.dev.dependencies]
28
27
  pygments = ">=2.10.0"
29
28
  black = { extras = ["jupyter"], version = ">=23.1.0" }
30
29
  coverage = { extras = ["toml"], version = ">=6.2" }
31
- darglint = ">=1.8.1"
30
+ darglint = {version = ">=1.8.1", python = ">=3.11,<4.0"}
32
31
  furo = ">=2021.11.12"
33
32
  mypy = ">=0.930"
34
33
  pre-commit = ">=2.16.0"
@@ -1,6 +1,7 @@
1
1
  import json
2
2
  import logging
3
3
  import os
4
+ from datetime import UTC
4
5
  from datetime import datetime
5
6
  from datetime import timedelta
6
7
  from functools import lru_cache
@@ -141,7 +142,7 @@ class AuthClient:
141
142
  )
142
143
  response.raise_for_status()
143
144
  auth_data = response.json()
144
- expiry = datetime.utcnow() + timedelta(seconds=auth_data["expires_in"])
145
+ expiry = datetime.now(UTC) + timedelta(seconds=auth_data["expires_in"])
145
146
  access_token = auth_data["access_token"]
146
147
 
147
148
  return access_token, expiry
@@ -194,7 +195,7 @@ class AuthClient:
194
195
 
195
196
  if response.status == 200:
196
197
  auth_data = json.loads(response.data)
197
- expiry = datetime.utcnow() + timedelta(seconds=auth_data["expires_in"])
198
+ expiry = datetime.now(UTC) + timedelta(seconds=auth_data["expires_in"])
198
199
  return auth_data["access_token"], expiry
199
200
  error = json.loads(response.data)
200
201
  print("Error: ", error.get("error_description", "Unknown error"))
@@ -247,12 +248,9 @@ class AuthClient:
247
248
  "Read more at: https://manual.dapla.ssb.no/blog/posts/2025-06-12-dapla-auth-client"
248
249
  ),
249
250
  )
250
- def fetch_google_credentials(force_token_exchange: bool = False) -> Credentials:
251
+ def fetch_google_credentials() -> Credentials:
251
252
  """Fetches the Google credentials for the current user.
252
253
 
253
- Args:
254
- force_token_exchange: Forces authentication by token exchange.
255
-
256
254
  Raises:
257
255
  RuntimeError: If fails to fetch credentials.
258
256
 
@@ -260,23 +258,9 @@ class AuthClient:
260
258
  The Google "Credentials" object.
261
259
  """
262
260
  env, service, region = AuthClient.get_current_dapla_metadata()
263
- force_token_exchange = (
264
- os.getenv("DAPLA_TOOLBELT_FORCE_TOKEN_EXCHANGE") == "1"
265
- or force_token_exchange
266
- )
267
-
261
+ credentials: Credentials
268
262
  try:
269
263
  match (env, service, region):
270
- case (_, _, _) if force_token_exchange is True:
271
- logger.debug("Auth - Forced token exchange")
272
- token, expiry = AuthClient.fetch_google_token()
273
- credentials = Credentials(
274
- token=token,
275
- expiry=expiry,
276
- token_uri="https://oauth2.googleapis.com/token",
277
- refresh_handler=AuthClient._refresh_handler,
278
- ) # type: ignore[no-untyped-call]
279
-
280
264
  case (_, DaplaService.CLOUD_RUN, _):
281
265
  logger.debug("Auth - Cloud Run detected, using ADC")
282
266
  credentials, _ = google.auth.default() # type: ignore[no-untyped-call]