parse_authorization#
- gafaelfawr.auth.parse_authorization(context, *, only_bearer_token=False)#
Find a token in the Authorization header.
Supports either
BearerorBasicauthorization types (unlessonly_bearer_tokenis set). Rebinds the logging context to include the source of the token, if one is found.- Parameters:
context (
RequestContext) – The context of the incoming request.only_bearer_token (
bool, default:False) – If set toTrue, only accept bearer tokens.
- Returns:
Token if one was found, otherwise
None.- Return type:
str or None
- Raises:
InvalidRequestError – Raised if the
Authorizationheader is malformed, if the type of authentication is unknown, or ifonly_bearer_tokenisTrueand the header used some other type of authentication.
Notes
A Basic Auth authentication string is normally a username and a password separated by colon and then base64-encoded. This method accepts a token in either the username or the password field.