dapla-auth-client 0.0.2__tar.gz → 0.0.4__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,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: dapla-auth-client
3
- Version: 0.0.2
3
+ Version: 0.0.4
4
4
  Summary: Dapla Auth Client
5
5
  License: MIT
6
6
  Author: Dapla Developers
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "dapla-auth-client"
3
- version = "0.0.2"
3
+ version = "0.0.4"
4
4
  description = "Dapla Auth Client"
5
5
  authors = ["Dapla Developers <dapla-platform-developers@ssb.no>"]
6
6
  license = "MIT"
@@ -95,7 +95,7 @@ class AuthClient:
95
95
  @staticmethod
96
96
  def _exchange_kubernetes_token_for_keycloak_token(
97
97
  audience: list[str] | None = None,
98
- scope: list[str] | None = None,
98
+ scopes: list[str] | None = None,
99
99
  ) -> tuple[str, datetime]:
100
100
  """Fetches a Keycloak token for the current user in Dapla Lab.
101
101
 
@@ -105,7 +105,7 @@ class AuthClient:
105
105
 
106
106
  Args:
107
107
  audience: Optional list of audiences to include in the token exchange request.
108
- scope: Optional list of scopes to include in the token exchange request.
108
+ scopes: Optional list of scopes to include in the token exchange request.
109
109
 
110
110
  Raises:
111
111
  RuntimeError: If the region is not DAPLA_LAB, or if the HTTP request fails.
@@ -134,7 +134,7 @@ class AuthClient:
134
134
  "grant_type": "urn:ietf:params:oauth:grant-type:token-exchange",
135
135
  "subject_token_type": "urn:ietf:params:oauth:grant-type:id_token",
136
136
  "subject_token": kubernetes_token,
137
- **({"scope": ",".join(scope)} if scope else {}),
137
+ **({"scope": ",".join(scopes)} if scopes else {}),
138
138
  **({"audience": ",".join(audience)} if audience else {}),
139
139
  },
140
140
  )
@@ -291,14 +291,30 @@ class AuthClient:
291
291
  return credentials
292
292
 
293
293
  @staticmethod
294
- def fetch_personal_token() -> str:
295
- """If Dapla Region is Dapla Lab, retrieve the Keycloak token."""
294
+ def fetch_personal_token(scopes: list[str] | None = None) -> str:
295
+ """If Dapla Region is Dapla Lab, retrieve the Keycloak token.
296
+
297
+ This method checks if the current Dapla Region is Dapla Lab and retrieves
298
+ the Keycloak token for the current user. If the region is not Dapla Lab,
299
+ it raises a RuntimeError.
300
+
301
+ Args:
302
+ scopes (list[str] | None): Optional list of scopes to include in the token request (ex. current_group, all_groups).
303
+
304
+ Raises:
305
+ RuntimeError: If the region is not DAPLA_LAB.
306
+
307
+ Returns:
308
+ str: The Keycloak token for the current user.
309
+ """
296
310
  _, _, region = AuthClient._get_current_dapla_metadata()
297
311
  if region != DaplaRegion.DAPLA_LAB:
298
312
  raise RuntimeError("Dapla Lab region not detected.")
299
313
 
300
314
  logger.debug("Auth - Dapla Lab detected, returning Keycloak token")
301
- keycloak_token, _ = AuthClient._exchange_kubernetes_token_for_keycloak_token()
315
+ keycloak_token, _ = AuthClient._exchange_kubernetes_token_for_keycloak_token(
316
+ scopes=scopes
317
+ )
302
318
  return keycloak_token
303
319
 
304
320
  @staticmethod