Fix: HTTPBearer gibt 401 statt 403 bei fehlendem Token
HTTPBearer(auto_error=True) gab 403 zurueck wenn kein Authorization- Header gesendet wurde. Das Frontend erkennt nur 401 als Session-Ablauf und leitet zum Login weiter. 403 wurde als generischer Fehler behandelt, wodurch abgelaufene Sessions still fehlschlugen (kein Redirect zum Login). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Dieser Commit ist enthalten in:
@@ -6,7 +6,7 @@ from fastapi import Depends, HTTPException, status
|
|||||||
from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
|
from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
|
||||||
from config import get_jwt_secret, JWT_ALGORITHM, JWT_EXPIRE_HOURS, TIMEZONE
|
from config import get_jwt_secret, JWT_ALGORITHM, JWT_EXPIRE_HOURS, TIMEZONE
|
||||||
|
|
||||||
security = HTTPBearer()
|
security = HTTPBearer(auto_error=False)
|
||||||
|
|
||||||
|
|
||||||
JWT_ISSUER = "intelsight-osint"
|
JWT_ISSUER = "intelsight-osint"
|
||||||
@@ -63,6 +63,11 @@ async def get_current_user(
|
|||||||
credentials: HTTPAuthorizationCredentials = Depends(security),
|
credentials: HTTPAuthorizationCredentials = Depends(security),
|
||||||
) -> dict:
|
) -> dict:
|
||||||
"""FastAPI Dependency: Aktuellen Nutzer aus Token extrahieren."""
|
"""FastAPI Dependency: Aktuellen Nutzer aus Token extrahieren."""
|
||||||
|
if credentials is None:
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||||
|
detail="Nicht authentifiziert",
|
||||||
|
)
|
||||||
payload = decode_token(credentials.credentials)
|
payload = decode_token(credentials.credentials)
|
||||||
return {
|
return {
|
||||||
"id": int(payload["sub"]),
|
"id": int(payload["sub"]),
|
||||||
|
|||||||
In neuem Issue referenzieren
Einen Benutzer sperren