fastapi-master/docs_src/security/tutorial006_an.py

13 lines
371 B
Python
Raw Normal View History

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