fastapi.security provides dependencies that read credentials and document them in OpenAPI (the docs page gets an Authorize button). Scheme Class API key in header APIKeyHeader(name="X-API-Key") Bearer token HTTPBearer() OAuth2 password flow OAuth2PasswordBearer(tokenUrl="token") Basic auth HTTPBasic() Typical JWT flow POST /token with username/password → verify the hash → return a signed JWT (pyjwt / python-jose). Protected endpoints depend on getcurrentuser, which decodes the token and loads the user. Use Security(..., scopes=[...]) for fine-grained permissions. Compare secrets with secrets.comparedigest to avoid timing attacks, and hash passwords with bcrypt/argon2, never plain SHA.