ssb_guardian_client package

ssb_guardian_client.client module

class GuardianClient

Bases: object

Client 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 API

  • maskinporten_client_id (str) – The Maskinporten client ID

  • scopes (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 ID

  • scopes (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: Enum

Represents the ‘DAPLA_ENVIRONMENT’ environment variable.

DEV = 'DEV'
PROD = 'PROD'
TEST = 'TEST'
class DaplaRegion(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: Enum

Represents the ‘DAPLA_REGION’ environment variable.

CLOUD_RUN = 'CLOUD_RUN'
DAPLA_LAB = 'DAPLA_LAB'
ON_PREM = 'ON_PREM'
class DaplaService(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: Enum

Represents the ‘DAPLA_SERVICE’ environment variable.

CLOUD_RUN = 'CLOUD_RUN'
JUPYTERLAB = 'JUPYTERLAB'
R_STUDIO = 'R_STUDIO'
VS_CODE = 'VS_CODE'