authentication_flow
Authentication flow and session management.
Classes
AuthEnvironmentError
class AuthEnvironmentError(*args, **kwargs):
Exception related to the authorization and authentication environment.
Ancestors
- BitfountError
- builtins.Exception
- builtins.BaseException
BitfountSession
class BitfountSession( auth_domain: str = 'auth.bitfount.com', client_id: str = '8iCJ33Kp6hc9ofrXTzr5GLxMRHWrlzZO', username: str = '_default', scopes: str = 'profile openid offline_access', audience: str = 'https://hub.bitfount.com/api',):
Manages session-based interactions with Bitfount.
Extends requests.Session, appending an access token to the authorization of any requests made if an access token is present
When the token expires it will request a new token prior to sending the web request.
Attributes
access_token_expires_at
: The time at which the access token expires.device_code
: The device code returned by the Bitfount API.device_code_arrival_time
: The time at which the device code was issued.device_code_expires_at
: The time at which the device code expires.id_token
: The ID token returned by the Bitfount API.refresh_token
: The refresh token returned by the Bitfount API.token_file
: The path to the file where the token is stored.token_request_interval
: The time between token requests.user_storage_path
: The path to the file where the user is stored.
Ancestors
- requests.sessions.Session
- requests.sessions.SessionRedirectMixin
Methods
def authenticate(self) ‑> None:
Authenticates user to allow protected requests.
Prompts the user to login/authenticate and stores the tokens to use them in future requests.
Raises
AssertionError
: If user storage path corresponds to a different username from the BitfountSession.ConnectionError
: If a token cannot be retrieved.
def request( self, method, url, params=None, data=None, headers=None, **kwargs,) ‑> Response:
Performs an HTTP request.
Overrides requests.session.request, appending our access token to the request headers or API keys if present.
Variables
access_token : Optional[str]
- Returns the access token. Tries to refresh it if needed.
api_keys
- Returns API keys to be used for the current session if they exist.These are cached so they don't need to be retrieved every time.
authenticated : bool
- Returns true if we have an unexpired access token or API Keys.
expired : bool
- Whether or not the access token has expired.Returns: True if the token has expired
username : str
- Returns the username of the authenticated user.