TokenManager#
- class TokenManager(token=None, tokens_file=None, auth_header_callback=None, *, use_env_vars=True)#
Bases:
objectTokenManager 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_TOKENandIQM_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.authenticationMethods
Close the configured token provider.
Return a callback providing an Authorization header, or None if we cannot provide it.
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.
- get_auth_header_callback()#
Return a callback providing an Authorization header, or None if we cannot provide it.
- _get_bearer_token(retries=1)#
Return a valid bearer token.
- Raises:
ClientAuthenticationError – getting the token failed
RuntimeError – There is no token provider (authentication disabled)
- Parameters:
retries (int)
- Return type:
- close()#
Close the configured token provider.
- Returns:
True if closing was successful
- Raises:
ClientAuthenticationError – closing failed
- Return type: