Getter
A “Getter” is an instance used by a backend to extract the authentication information from a falcon Request.
Getter
- class falcon_auth2.Getter[source]
Represents a class that extracts authentication information from a request.
Note
Subclasses that wish to only support the
load_async()method are also required to override theload()method since it is defined as abstract. In these cases the sync version may just raise an exception.- async_calls_sync_load: ClassVar[bool | None] = None
Indicates if this Getter has an async load implementation that is not just a fallback to sync
load()method, like the defaultload_async()method.This property is automatically set by the
Getterwhen a subclass is defined (using__init_subclass__) if not specified directly by a subclass (by setting it to a valued different thanNone).
- abstractmethod load(req: Request, *, challenges: Iterable[str] | None = None) str[source]
Loads the specified attribute from the provided request.
If a getter cannot be used with the current request, a
BackendNotApplicableis raised. Thechallenges, when provided, will be added toWWW-Authenticateheader in case of error.- Parameters:
req (Request) – The current request. This may be a wsgi or an asgi falcon request.
- Keyword Arguments:
challenges (Optional[Iterable[str]], optional) – One or more authentication challenges to use as the value of the
WWW-Authenticateheader in case of errors.- Returns:
str – The loaded data, in case of success.
HeaderGetter
- class falcon_auth2.HeaderGetter(header_key: str)[source]
Returns the specified header from a request.
- Parameters:
header_key (str) – the name of the header to load.
- async_calls_sync_load: ClassVar[bool | None] = True
Indicates if this Getter has an async load implementation that is not just a fallback to sync
load()method, like the defaultload_async()method.This property is automatically set by the
Getterwhen a subclass is defined (using__init_subclass__) if not specified directly by a subclass (by setting it to a valued different thanNone).
AuthHeaderGetter
- class falcon_auth2.AuthHeaderGetter(auth_header_type: str, *, header_key: str = 'Authorization')[source]
Returns the auth header from a request, checking that it in the form
<auth_header_type> value.- Parameters:
auth_header_type (str) – The type of the auth header. Common values are
"Basic","Bearer".- Keyword Arguments:
header_key (str, optional) – The name of the header to load. Defaults to
"Authorization".
- async_calls_sync_load: ClassVar[bool | None] = True
Indicates if this Getter has an async load implementation that is not just a fallback to sync
load()method, like the defaultload_async()method.This property is automatically set by the
Getterwhen a subclass is defined (using__init_subclass__) if not specified directly by a subclass (by setting it to a valued different thanNone).
ParamGetter
- class falcon_auth2.ParamGetter(param_name: str)[source]
Returns the specified parameter from the request.
If the parameter appears multiple times an error will be raised.
Note
When the falcon
RequestoptionRequestOptions.auto_parse_form_urlencodedis set toTrue, this getter can also retrieve parameter in the body of aform-urlencodedrequest.- Parameters:
param_name (str) – the name of the param to load.
- async_calls_sync_load: ClassVar[bool | None] = True
Indicates if this Getter has an async load implementation that is not just a fallback to sync
load()method, like the defaultload_async()method.This property is automatically set by the
Getterwhen a subclass is defined (using__init_subclass__) if not specified directly by a subclass (by setting it to a valued different thanNone).
MultiGetter
- class falcon_auth2.MultiGetter(getters: Iterable[Getter])[source]
Combines multiple getters. This is useful if a value can be passed in multiple ways to the server, like using an header or a query parameter.
Will use the first value successfully returned, ignoring all
BackendNotApplicableexceptions raised by the previously tried getters. If no getter can return a valid value an exception will only be raised.- Parameters:
getters (Iterable[Getter]) – The getters to use. They will be tried in order and the first value successfully returned is used.
- async_calls_sync_load: ClassVar[bool | None] = True
Indicates if this Getter has an async load implementation that is not just a fallback to sync
load()method, like the defaultload_async()method.This property is automatically set by the
Getterwhen a subclass is defined (using__init_subclass__) if not specified directly by a subclass (by setting it to a valued different thanNone).