FastAPI · Function
Security
Use OAuth2PasswordBearer as a dependency to read a bearer token from the Authorization header. FastAPI also adds the scheme to OpenAPI and returns 401 when the header is missing or lacks a bearer token.
Last updated
Syntax
OAuth2PasswordBearer(tokenUrl="token")
Annotated[str, Depends(oauth2_scheme)]In-depth API docs are only for subscribers: parameters, examples, common mistakes and interview practice.
SubscribeRelated
OAuth2OAuth2PasswordRequestFormSecurityBaseDependsOpenAPIHTTPBearer