TokenManager#

class TokenManager(token=None, tokens_file=None, auth_header_callback=None, *, use_env_vars=True)#

Bases: object

TokenManager manages the access token required for user authentication.

Parameters:
  • token (str | None) – Long-lived IQM token in plain text format.

  • tokens_file (str | None) – Path to a tokens file used for authentication.

  • auth_header_callback (Callable[[], str] | None) – Callback function that returns an Authorization header containing a bearer token.

  • use_env_vars (bool) – Iff True, the first two parameters can also be read from the environment variables IQM_TOKEN and IQM_TOKENS_FILE, respectively. Environment variables can not be mixed with initialisation arguments.

At most one auth parameter should be given.

Module: iqm.station_control.client.authentication

Methods

close

Close the configured token provider.

get_auth_header_callback

Return a callback providing an Authorization header, or None if we cannot provide it.

time_left_seconds

Check how much time is left until the token expires.

static time_left_seconds(token)#

Check how much time is left until the token expires.

Returns:

Time left on token in seconds.

Parameters:

token (Any)

Return type:

int

get_auth_header_callback()#

Return a callback providing an Authorization header, or None if we cannot provide it.

Return type:

Callable[[], str] | None

_get_bearer_token(retries=1)#

Return a valid bearer token.

Raises:
Parameters:

retries (int)

Return type:

str

close()#

Close the configured token provider.

Returns:

True if closing was successful

Raises:

ClientAuthenticationError – closing failed

Return type:

bool