]> git.ipfire.org Git - pbs.git/commitdiff
API: Add functions to verify authentication
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 16 Jun 2025 17:24:04 +0000 (17:24 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 16 Jun 2025 17:24:04 +0000 (17:24 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/api/auth.py

index db960a0318783293017d3f653501570fde0e0416..7bf41388ae5d9dc9352ea83fb3181737c92cef4e 100644 (file)
@@ -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"