iqm.iqm_client.authentication.TokenManager#

class iqm.iqm_client.authentication.TokenManager(token: str | None = None, tokens_file: str | None = None)#

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

The parameters can also be read from the environment variables IQM_TOKEN or IQM_TOKENS_FILE. Environment variables can not be mixed with initialisation arguments. All parameters must come from the same source.

Methods

close()

Close the configured token provider.

get_bearer_token([retries])

Returns a valid bearer token, or None if no user authentication has been configured.

time_left_seconds(token)

Check how much time is left until the token expires.

static time_left_seconds(token: Any) int#

Check how much time is left until the token expires.

Returns:

Time left on token in seconds.

Parameters:

token (Any)

Return type:

int

get_bearer_token(retries: int = 1) str | None#

Returns a valid bearer token, or None if no user authentication has been configured.

Raises:

ClientAuthenticationError – getting the token failed

Parameters:

retries (int)

Return type:

str | None

close() bool#

Close the configured token provider.

Returns:

True if closing was successful

Raises:

ClientAuthenticationError – closing failed

Return type:

bool