From 37bad88fbd90a29e2b989d1e6d8f2447f7013687 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Mon, 16 Jun 2025 17:24:04 +0000 Subject: [PATCH] API: Add functions to verify authentication Signed-off-by: Michael Tremer --- src/api/auth.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/api/auth.py b/src/api/auth.py index db960a03..7bf41388 100644 --- a/src/api/auth.py +++ b/src/api/auth.py @@ -48,6 +48,19 @@ router = fastapi.APIRouter( tags=["Authentication"], ) +# Class to extract the Bearer token from the request headers +security = fastapi.security.HTTPBearer() + +def get_current_principal( + credentials: fastapi.security.HTTPAuthorizationCredentials = fastapi.Depends(security) +): + """ + This is the main function to check whether a client is authenticated. + It will fetch the Bearer token from the request header and return the + principal. + """ + return get_principal(credentials.credentials) + class AuthResponse(pydantic.BaseModel): # Token Type type: str = "Bearer" -- 2.47.2