Skip to main content

authentication_flow

Authentication flow and session management.

Classes

AuthEnvironmentError

class AuthEnvironmentError(*args, **kwargs):

Exception related to the authorization and authentication environment.

Ancestors

BitfountSession

class BitfountSession(authentication_handler: Optional[AuthenticationHandler] = None):

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.

Variables

  • am_request_headers : dict[typing.Anytyping.Any] - Returns metadata for authenticating with message service.
  • authenticated : bool - Returns true if we have an unexpired access token or API Keys.
  • hub_request_headers : dict[typing.Anytyping.Any] - Returns metadata for authenticating with message service.
  • message_service_metadata : list[tuple[str, str]] - Returns metadata for authenticating with message service.
  • username : str - Returns the username of the authenticated user.

Methods


authenticate

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.

request

def request(    self,    method: str | bytes,    url: str,    params: Optional[MutableMapping[str, Any]] = None,    data: Any = None,    headers: Optional[MutableMapping[str, str]] = None,    **kwargs: Any,)> Response:

Performs an HTTP request.

Overrides requests.session.request, appending our access token to the request headers or API keys if present.