fastapi-master/docs_src/security/tutorial006_an_py39.py

14 lines
361 B
Python
Raw Permalink Normal View History

2024-08-24 12:41:47 +08:00
from typing import Annotated
from fastapi import Depends, FastAPI
from fastapi.security import HTTPBasic, HTTPBasicCredentials
app = FastAPI()
security = HTTPBasic()
@app.get("/users/me")
def read_current_user(credentials: Annotated[HTTPBasicCredentials, Depends(security)]):
return {"username": credentials.username, "password": credentials.password}