ds_stoa.authentication._rest¶
This module provides an interface for RESTful authentication with the Stoa API. It encapsulates the process of authenticating a user by their email and password, returning an access token for successful authentication.
The module abstracts away the details involved in constructing the HTTP request, handling the response, managing errors, and logging. It uses the requests library to make HTTP POST requests and handles JSON responses.
The rest function within this module is designed for applications needing to authenticate users against the Stoa API’s RESTful authentication endpoint. This function returns an access token that can be used to authorize subsequent API requests.
Usage of this module requires setting the BUILDING_MODE environment variable to switch between development and production environments. This facilitates easy testing and deployment without needing to alter the codebase.
Dependencies: - requests: For making HTTP requests to the authentication endpoint. - utils.exceptions: For enriching HTTP exceptions with additional context. - utils.logger: For logging the authentication process and any errors that occur.
Example usage:
from ds_stoa.authentication import rest
# Authenticate a user and obtain an access token
access_token = rest('user@example.com', 'password123')
print(access_token)
Attributes¶
Functions¶
|
Enriches an HTTP exception with additional context without re-raising it. |
|
Authenticates a user and retrieves an access token. |
Module Contents¶
- ds_stoa.authentication._rest.enrich_http_exception(exc: requests.exceptions.HTTPError) None[source]¶
Enriches an HTTP exception with additional context without re-raising it.
- Parameters:
exc – Exception
- Returns:
None
- ds_stoa.authentication._rest.LOGGER¶
- ds_stoa.authentication._rest.BUILDING_MODE¶
- ds_stoa.authentication._rest.rest(email: str, password: str) str[source]¶
Authenticates a user and retrieves an access token.
- Parameters:
email (str) – The email of the user.
password (str) – The password of the user.
- Returns:
An access token indicating successful authentication.
- Return type:
str
Example:
>>> rest('user@example.com', 'secret') 'access_token_value'