docs_src/security/tutorial006_an_py310.py
raw| 1 | from typing import Annotated |
| 2 | |
| 3 | from fastapi import Depends, FastAPI |
| 4 | from fastapi.security import HTTPBasic, HTTPBasicCredentials |
| 5 | |
| 6 | app = FastAPI() |
| 7 | |
| 8 | security = HTTPBasic() |
| 9 | |
| 10 | |
| 11 | @app.get("/users/me") |
| 12 | def read_current_user(credentials: Annotated[HTTPBasicCredentials, Depends(security)]): |
| 13 | return {"username": credentials.username, "password": credentials.password} |