Expand description
Common functionality related to authorization
StructsΒ§
- Action
OnResource - Auth
User - Extractor for an authenticated user.
- Authorization
Token - Validates that user has right to function
- Authorized
Response - Responder for AuthorizationToken
- GraphQL
Request π - Moocfi
User π - Moocfi
User πResponse - Moocfi
User πResponse Data
EnumsΒ§
ConstantsΒ§
- MOOCFI_
GRAPHQL_ πURL - SESSION_
KEY π
FunctionsΒ§
- async_
http_ πclient_ with_ headers - HTTP Client used only for authenticating with TMC server. This function:
- authenticate_
moocfi_ user - Authenticates the user with mooc.fi, returning the authenticated user and their oauth token.
- authenticate_
test_ token - authenticate_
test_ user - Authenticates a test user with predefined credentials. Returns Ok(true) if authentication succeeds, Ok(false) if credentials are incorrect, and Err for other errors.
- authorize
- The authorization token is the only way to return a controller result, and should only be used in controller functions that return a response to the user.
- authorize_
access_ to_ course_ material - Can be used to check whether user is allowed to view some course material
- authorize_
access_ to_ tmc_ server - Can be used to check whether user is allowed to view some course material
- authorize_
with_ fetched_ list_ of_ roles - Same as
authorize
, but takes as an argumentVec<Role>
so that we avoid fetching the roles from the database for optimization reasons. This is useful when weβre checking multiple authorizations at once. - can_
user_ view_ chapter - Can be used to check whether user is allowed to view some course material. Chapters can be closed and and limited to certain people only.
- check_
course_ πinstance_ permission - Also checks organization and course roles which are valid for course instances.
- check_
course_ πor_ exam_ permission - check_
course_ πpermission - Also checks organization role which is valid for courses.
- check_
exam_ πpermission - Also checks organization role which is valid for exams.
- check_
organization_ πpermission - check_
study_ πregistry_ permission - create_
authorization_ πerror - Creates a ControllerError for authorization failures with more information in the source error
- exchange_
password_ with_ tmc - Exchanges user credentials with TMC server to obtain an OAuth token.
- forget
- Forgets authentication from the current session, if any.
- get_
or_ πcreate_ user_ from_ moocfi_ response - get_
ratelimit_ πapi_ key - Gets the rate limit protection API key from environment variables and converts it to a header value. This key is used to bypass rate limiting when making requests to TMC server.
- get_
user_ from_ moocfi_ by_ login_ token - get_
user_ from_ moocfi_ by_ tmc_ access_ token_ and_ upstream_ id - has_
auth_ user_ session - Checks if the user is authenticated in the given session.
- has_
permission π - parse_
secret_ key_ from_ header - remember
- Stores the user as authenticated in the given session.
- skip_
authorize - Skips the authorize() and returns AuthorizationToken, needed in functions with anonymous and test users
- verify_
auth_ πuser_ exists - For making sure the user saved in the session still exists in the database. Check the userβs existance when the session is at least 3 hours old, updates the session automatically, and returns an up-to-date AuthUser.