iqm.iqm_client.authentication.TokenManager#

class iqm.iqm_client.authentication.TokenManager(token=None, tokens_file=None, auth_server_url=None, username=None, password=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

  • auth_server_url (str | None) – Base URL of the authentication server

  • username (str | None) – Username to log in to authentication server

  • password (str | None) – Password to log in to authentication server

The parameters can also be read from the environment variables IQM_TOKEN, IQM_TOKENS_FILE, IQM_AUTH_SERVER, IQM_AUTH_USERNAME, IQM_AUTH_PASSWORD. 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)#

Check how much time is left until the token expires.

Returns:

Time left on token in seconds.

Parameters:

token (str) –

Return type:

int

get_bearer_token(retries=1)#

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()#

Close the configured token provider.

Returns:

True if closing was successful

Raises:

ClientAuthenticationError – closing failed

Return type:

bool