Skip to main content

Module authentication

Module authentication 

Source
Expand description

Common functionality related to authenticating users.

Structsยง

AuthUser
Extractor for an authenticated user.
GraphQLRequest ๐Ÿ”’
MoocfiUserData ๐Ÿ”’
MoocfiUserResponse ๐Ÿ”’
MoocfiUserResponseData ๐Ÿ”’

Constantsยง

MOOCFI_GRAPHQL_URL ๐Ÿ”’
SESSION_KEY ๐Ÿ”’

Functionsยง

async_http_client_with_headers ๐Ÿ”’
oauth2โ€™s HTTP transport, adapted to reqwest and tagged with the header that keeps TMC from rate-limiting the backendโ€™s own auth requests.
authenticate_test_token
authenticate_test_user
Authenticates a test user against predefined credentials.
authenticate_tmc_mooc_fi_user
Authenticates the user with mooc.fi, returning the authenticated user and their oauth token.
authenticate_tmc_server
Checks the Authorization header against a secret from environment variables to verify the request originates from the TMC server.
constant_time_eq_str ๐Ÿ”’
exchange_password_with_tmc
Exchanges user credentials with TMC for an OAuth token.
fetch_moocfi_id_by_upstream_id ๐Ÿ”’
Fetches the mooc.fi UUID for a user by their upstream ID using the TMC access token.
forget
Forgets authentication from the current session, if any.
get_or_create_user_from_tmc_mooc_fi_response
get_ratelimit_api_key ๐Ÿ”’
The rate-limit-bypass header value for requests to the TMC server.
handle_anonymous_token
Returns the bearer token only when there is no authenticated user, for the anonymous chatbot-embed path; a logged-in requestโ€™s token is never surfaced here.
has_auth_user_session
Checks if the user is authenticated in the given session.
parse_secret_key_from_header
remember
Stores the user as authenticated in the given session.
verify_auth_user_exists ๐Ÿ”’
Re-fetches the user from the database and refreshes the session once it is more than 3 hours old; otherwise returns the sessionโ€™s cached AuthUser unchanged.

Type Aliasesยง

LoginToken