Authenticate#
- class gafaelfawr.dependencies.auth.Authenticate(require_session=False, require_scope=None, redirect_if_unauthenticated=False, allow_bootstrap_token=False, auth_type=AuthType.Bearer, ajax_forbidden=False)#
Bases:
objectDependency to verify user authentication.
This is a class so that multiple authentication policies can be constructed while easily sharing the same code. It is used as a base class for
AuthenticateReadandAuthenticateWrite, which provide__call__implementations that do the work.- Parameters:
require_session (
bool, default:False) – Require that the credentials come from a cookie, not anAuthorizationheader.require_scope (
Optional[str], default:None) – If set, access will be denied if the authentication token does not have this scope.redirect_if_unauthenticated (
bool, default:False) – If the request is unauthenticated, redirect it to the/loginroute rather than returning a challenge.allow_bootstrap_token (
bool, default:False) – Allow use of the bootstrap token to authenticate to this route.auth_type (
AuthType, default:<AuthType.Bearer: 'bearer'>) – The type of the challenge if the user is not authenticated.ajax_forbidden (
bool, default:False) – If set toTrue, check to see if the request was sent via AJAX (see Notes) and, if so, convert it to a 403 error.
Methods Summary
authenticate(context[, x_csrf_token])Authenticate the request.
Methods Documentation
- async authenticate(context, x_csrf_token=None)#
Authenticate the request.
Always check the user’s cookie-based session first before checking the
Authorizationheader because some applications (JupyterHub, for instance) may use theAuthorizationheader for their own purposes.If the request was authenticated via a browser cookie rather than a provided
Authorizationheader, and the method was something other thanGETorOPTIONS, require and verify the CSRF header as well.- Parameters:
context (
RequestContext) – The request context.x_csrf_token (
Optional[str], default:None) – The value of theX-CSRF-Tokenheader, if provided.
- Returns:
The data associated with the verified token.
- Return type:
- Raises:
fastapi.HTTPException – Raised if authentication is not provided or is not valid.