fastapi-master/docs_src/bigger_applications/app_an/dependencies.py

13 lines
419 B
Python
Raw Permalink Normal View History

2024-08-24 12:41:47 +08:00
from fastapi import Header, HTTPException
from typing_extensions import Annotated
async def get_token_header(x_token: Annotated[str, Header()]):
if x_token != "fake-super-secret-token":
raise HTTPException(status_code=400, detail="X-Token header invalid")
async def get_query_token(token: str):
if token != "jessica":
raise HTTPException(status_code=400, detail="No Jessica token provided")