thunderbird_accounts.authentication.middleware
Functions
|
Store OIDC tokens. |
Classes
|
User authentication middleware for OIDC |
|
A middleware that will refresh the access token following proper OIDC protocol: https://auth0.com/docs/tokens/refresh-token/current |
|
- thunderbird_accounts.authentication.middleware.store_tokens(request, access_token, id_token, refresh_token)[source]
Store OIDC tokens. Mostly copy and paste from base package, but adjusted to live outside of OIDCAuthenticationBackend, and take in refresh_token
- class thunderbird_accounts.authentication.middleware.AccountsOIDCBackend(*args, **kwargs)[source]
Bases:
OIDCAuthenticationBackendUser authentication middleware for OIDC
This is our slightly customized mozilla-django-oidc middleware used to create/update/authenticate users against oidc flows.
- get_user(user_id)[source]
Retrieve the user from OIDC get_user and additionally check if they’re active. Fixes https://github.com/mozilla/mozilla-django-oidc/issues/520
- update_user(user, claims)[source]
Update existing user with new claims, if necessary save, and return user
- authenticate(request, **kwargs)[source]
Authenticates a user based on the OIDC code flow. Note: This is mostly a copy & paste from the middleware to accomondate refresh tokens. See https://github.com/thunderbird/thunderbird-accounts/issues/498 for more information
- class thunderbird_accounts.authentication.middleware.OIDCRefreshSession(get_response)[source]
Bases:
SessionRefreshA middleware that will refresh the access token following proper OIDC protocol: https://auth0.com/docs/tokens/refresh-token/current
Code is based on https://github.com/mozilla/mozilla-django-oidc/pull/377
- process_request(request)[source]
Handle a refresh session request. If it’s not refreshable or the token is not expired then we skip this and deal with the consequences elsewhere
- finish(request, prompt_reauth=True)[source]
Finish request handling and handle sending downstream responses for XHR.
This function should only be run if the session is determind to be expired.
Almost all XHR request handling in client-side code struggles with redirects since redirecting to a page where the user is supposed to do something is extremely unlikely to work in an XHR request. Make a special response for these kinds of requests.
The use of 403 Forbidden is to match the fact that this middleware doesn’t really want the user in if they don’t refresh their session.