Expand description
Common functionality related to authenticating users.
Structsยง
- Auth
User - Extractor for an authenticated user.
- GraphQL
Request ๐ - Moocfi
User ๐Data - Moocfi
User ๐Response - Moocfi
User ๐Response Data
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.