ssb_guardian_client package¶
ssb_guardian_client.client module¶
- class GuardianClient¶
Bases:
objectClient for interacting with the SSB Guardian service.
This class provides methods to retrieve Maskinporten tokens via Guardian and make authenticated API calls to external services.
Example
>>> import os >>> os.environ["DAPLA_ENVIRONMENT"] = "TEST" >>> client = GuardianClient() >>> response = client.call_api( ... "https://api.example.com/data", ... "my-client-id", ... "scope1 scope2" ... )
- call_api(api_endpoint_url, maskinporten_client_id, scopes)¶
Call an external API using Maskinporten Guardian.
- Parameters:
api_endpoint_url (
str) – URL to the target APImaskinporten_client_id (
str) – The Maskinporten client IDscopes (
str) – The Maskinporten scopes as a space-separated string (e.g., “scope1 scope2”)
- Return type:
Any- Returns:
The endpoint json response
- Raises:
RuntimeError – If the API call fails
- get_maskinporten_token(maskinporten_client_id, scopes)¶
Retrieve access token from Maskinporten Guardian.
- Parameters:
maskinporten_client_id (
str) – The Maskinporten client IDscopes (
str|Sequence[str]) – The Maskinporten scopes. Can be either: - A space-separated string (e.g., “scope1 scope2”) - A list/sequence of scopes (e.g., [“scope1”, “scope2”])
- Return type:
str- Returns:
The maskinporten access token
- Raises:
RuntimeError – If the Guardian token request fails
- get_guardian_url()¶
Get the Guardian URL for the current environment.
- Return type:
str
ssb_guardian_client.const module¶
- class DaplaEnvironment(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)¶
Bases:
EnumRepresents the ‘DAPLA_ENVIRONMENT’ environment variable.
- DEV = 'DEV'¶
- PROD = 'PROD'¶
- TEST = 'TEST'¶