Debian Codegraph @

docs/examples/onboarding/django/authentication.py

raw
1 from typing import Dict
2
3 from litestar import Litestar, get
4 from litestar.connection import ASGIConnection
5 from litestar.exceptions import NotAuthorizedException
6 from litestar.handlers import BaseRouteHandler
7
8
9 async def require_token(connection: ASGIConnection, route_handler: BaseRouteHandler) -> None:
10 if connection.headers.get("authorization") != "Bearer secret":
11 raise NotAuthorizedException
12
13
14 @get("/", guards=[require_token])
15 async def index() -> Dict[str, str]:
16 return {"hello": "world"}
17
18
19 app = Litestar(route_handlers=[index])