Security Dependencies
noun
say it: “sih-KYOOR-ih-tee dih-PEN-den-seez” /sɪˈkjʊrəti dɪˈpɛndənsiz/
FastAPI dependencies that read and check a request's credentials, such as a bearer token, and return the current user or refuse with 401.
What is Security Dependencies?
Security dependencies are dependencies that read and check credentials (like a bearer token) and return the current user, or reject the request with 401.
def current_user(token: Annotated[str, Depends(oauth2_scheme)]) -> User:
user = user_from_token(token)
if not user:
raise HTTPException(401, 'Not logged in')
return user
In a sentence
- “Every task route takes current_user, one of the API's security dependencies.”
- “Security dependencies keep the token checks out of the routes.”
Level: Freelancer · More FastAPI terms at this level
Updated