HTTPBasic
HTTP Basic authentication. Create an instance object and use that object as the dependency inDepends(). The dependency result will be an HTTPBasicCredentials object containing the username and the password.
Reference: RFC 7617
Parameters
str | None
default:"None"
Security scheme name. It will be included in the generated OpenAPI (e.g. visible at
/docs).str | None
default:"None"
HTTP Basic authentication realm.
str | None
default:"None"
Security scheme description. It will be included in the generated OpenAPI (e.g. visible at
/docs).bool
default:"True"
By default, if the HTTP Basic authentication is not provided (a header),
HTTPBasic will automatically cancel the request and send the client an error.If auto_error is set to False, when the HTTP Basic authentication is not available, instead of erroring out, the dependency result will be None.This is useful when you want to have optional authentication or when you want to have authentication that can be provided in one of multiple optional ways (for example, in HTTP Basic authentication or in an HTTP Bearer token).Example
HTTPBasicCredentials
The HTTP Basic credentials given as the result of usingHTTPBasic in a dependency.
Fields
str
The HTTP Basic username.
str
The HTTP Basic password.
HTTPBearer
HTTP Bearer token authentication. Create an instance object and use that object as the dependency inDepends(). The dependency result will be an HTTPAuthorizationCredentials object containing the scheme and the credentials.
Parameters
str | None
default:"None"
Bearer token format.
str | None
default:"None"
Security scheme name. It will be included in the generated OpenAPI (e.g. visible at
/docs).str | None
default:"None"
Security scheme description. It will be included in the generated OpenAPI (e.g. visible at
/docs).bool
default:"True"
By default, if the HTTP Bearer token is not provided (in an
Authorization header), HTTPBearer will automatically cancel the request and send the client an error.If auto_error is set to False, when the HTTP Bearer token is not available, instead of erroring out, the dependency result will be None.This is useful when you want to have optional authentication or when you want to have authentication that can be provided in one of multiple optional ways (for example, in an HTTP Bearer token or in a cookie).Example
HTTPDigest
HTTP Digest authentication. Warning: this is only a stub to connect the components with OpenAPI in FastAPI, but it doesn’t implement the full Digest scheme, you would need to to subclass it and implement it in your code. Reference: RFC 7616 Create an instance object and use that object as the dependency inDepends(). The dependency result will be an HTTPAuthorizationCredentials object containing the scheme and the credentials.
Parameters
str | None
default:"None"
Security scheme name. It will be included in the generated OpenAPI (e.g. visible at
/docs).str | None
default:"None"
Security scheme description. It will be included in the generated OpenAPI (e.g. visible at
/docs).bool
default:"True"
By default, if the HTTP Digest is not provided,
HTTPDigest will automatically cancel the request and send the client an error.If auto_error is set to False, when the HTTP Digest is not available, instead of erroring out, the dependency result will be None.This is useful when you want to have optional authentication or when you want to have authentication that can be provided in one of multiple optional ways (for example, in HTTP Digest or in a cookie).Example
HTTPAuthorizationCredentials
The HTTP authorization credentials in the result of usingHTTPBearer or HTTPDigest in a dependency.
The HTTP authorization header value is split by the first space. The first part is the scheme, the second part is the credentials.
For example, in an HTTP Bearer token scheme, the client will send a header like:
schemewill have the value"Bearer"credentialswill have the value"deadbeef12346"
Fields
str
The HTTP authorization scheme extracted from the header value.
str
The HTTP authorization credentials extracted from the header value.