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