libsimba.client_credentials#

class libsimba.auth.client_credentials.BlocksAuthProvider#

Bases: ClientCredentials

async login(client_id: str, client_secret: str, headers: Dict[str, Any], config: ConnectionConfig | None = None) AuthToken | None#

Login by adding headers and return a token

login_sync(client_id: str, client_secret: str, headers: Dict[str, Any], config: ConnectionConfig | None = None) AuthToken | None#

Login by adding headers and return a token

provider() AuthProviderName#
class libsimba.auth.client_credentials.ClientCredentials(do_init: bool = True)#

Bases: AuthProvider

add_header(token: AuthToken, headers: Dict[str, Any]) None#
cache_token(client_id: str, token: AuthToken) None#

Saves the token data to a file if configured, and also memory..

Checks the TOKEN_DIR environment variable for alternative token storage locations, otherwise uses the current working path

Creates the token directory if it doesn’t already exist.

Adds an “expires” key to the auth token data, set to time “now” added to the expires_in time This is used later to discover if the token has expired

Token files are named <client_id>_token.json

Parameters:
  • client_id – The ID for the client, token files are named <client_id>_token.json

  • token – The token object to save

Returns:

do_login(client_id: str) Tuple[AuthToken | None, AuthProvider]#
get_cached_token(client_id: str) AuthToken | None#
header = 'Authorization'#
async login(client_id: str, client_secret: str, headers: Dict[str, Any], config: ConnectionConfig | None = None) AuthToken | None#

Login by adding headers and return a token

login_sync(client_id: str, client_secret: str, headers: Dict[str, Any], config: ConnectionConfig | None = None) AuthToken | None#

Login by adding headers and return a token

test_token_valid(token: AuthToken) bool#
async test_token_valid_async(token: AuthToken) bool#
token_expired(token: AuthToken, offset: int = 60) bool#

Checks to see if a token has expired, by checking the ‘expires’ key Adds an offset to allow for delays when performing auth processes

Parameters:
  • token – the token to check for expiry. Should contain an ‘expires’ key

  • offset – To allow for delays in auth processes, this number of seconds is added to the expiry time

Returns:

class libsimba.auth.client_credentials.KcAuthProvider#

Bases: ClientCredentials

access_tokens: Dict[str, AuthToken]#
async login(client_id: str, client_secret: str, headers: Dict[str, Any], config: ConnectionConfig | None = None) AuthToken | None#

Login by adding headers and return a token

async login_sync(client_id: str, client_secret: str, headers: Dict[str, Any], config: ConnectionConfig | None = None) AuthToken | None#

Login by adding headers and return a token

provider() AuthProviderName#
registry: Dict[AuthProviderName, AuthProvider]#