From aee09a3b9c37e9ecf810403436975697e34054a3 Mon Sep 17 00:00:00 2001 From: Bruce Schultz Date: Thu, 17 Oct 2024 11:14:14 +0200 Subject: [PATCH] feat(auth): add defensive code for missing token build_image --- hub_adapter/auth.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/hub_adapter/auth.py b/hub_adapter/auth.py index 543a63e..a3b2d09 100644 --- a/hub_adapter/auth.py +++ b/hub_adapter/auth.py @@ -69,6 +69,13 @@ async def get_hub_public_key() -> dict: async def verify_idp_token(token: str = Security(idp_oauth2_scheme)) -> dict: """Decode the auth token using keycloak's public key.""" + if not token: + raise HTTPException( + status_code=status.HTTP_400_BAD_REQUEST, + detail=str("Missing or invalid token"), + headers={"WWW-Authenticate": "Bearer"}, + ) + try: return jwt.decode( token,