|
16 | 16 | from cachetools import TTLCache |
17 | 17 | from fastapi import HTTPException, Request |
18 | 18 |
|
19 | | -from authentication.interface import NO_AUTH_TUPLE, AuthInterface, AuthTuple |
| 19 | +from authentication.interface import AuthInterface, AuthTuple |
20 | 20 | from authentication.utils import extract_user_token |
21 | 21 | from constants import ( |
22 | 22 | DEFAULT_VIRTUAL_PATH, |
@@ -163,24 +163,27 @@ def __init__( |
163 | 163 | async def __call__(self, request: Request) -> AuthTuple: |
164 | 164 | """Authenticate the JWT in the headers against the keys from the JWK url. |
165 | 165 |
|
166 | | - If the Authorization header is missing, returns NO_AUTH_TUPLE. On token |
167 | | - verification or validation failures this function raises HTTPException |
168 | | - with appropriate HTTP status codes: |
169 | | - - 401 for unknown signing key/algorithm, bad signature, expired token, |
170 | | - or missing required claims; |
| 166 | + When the Authorization header is missing, this method raises |
| 167 | + HTTPException with status 401 (Unauthorized). On token verification or |
| 168 | + validation failures it also raises HTTPException with appropriate |
| 169 | + status codes: |
171 | 170 | - 400 for token decode or other JOSE-related decode/validation errors; |
| 171 | + - 401 for missing Authorization header, unknown signing key/algorithm, |
| 172 | + bad signature, expired token, or missing required claims; |
172 | 173 | - 500 for unexpected internal errors. |
173 | 174 |
|
174 | 175 | Parameters: |
175 | | - request (Request): The incoming FastAPI request containing the Authorization header. |
| 176 | + request (Request): The incoming FastAPI request; must include the |
| 177 | + Authorization header (Bearer token) or 401 is raised. |
176 | 178 |
|
177 | 179 | Returns: |
178 | 180 | AuthTuple: A tuple (user_id, username, skip_userid_check, token) |
179 | | - extracted from the validated token, or NO_AUTH_TUPLE when no |
180 | | - Authorization header is present. |
| 181 | + extracted from the validated JWT. Only returned on successful |
| 182 | + authentication; all error paths raise HTTPException. |
181 | 183 | """ |
182 | 184 | if not request.headers.get("Authorization"): |
183 | | - return NO_AUTH_TUPLE |
| 185 | + response = UnauthorizedResponse(cause="No Authorization header found") |
| 186 | + raise HTTPException(**response.model_dump()) |
184 | 187 |
|
185 | 188 | user_token = extract_user_token(request.headers) |
186 | 189 |
|
|
0 commit comments