From fcbed1c91c8ce747d76e8c9d280a8607ad000a0c Mon Sep 17 00:00:00 2001 From: Luckaskl Date: Thu, 28 May 2026 14:05:17 -0500 Subject: [PATCH] =?UTF-8?q?exibi=C3=A7=C3=A3o=20completa=20do=20motivo=20d?= =?UTF-8?q?o=20erro=20de=20unauthorized?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/core/security.py | 6 ++++-- test_jwt.py | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 test_jwt.py diff --git a/app/core/security.py b/app/core/security.py index 4200c8a..b730aaa 100644 --- a/app/core/security.py +++ b/app/core/security.py @@ -46,9 +46,11 @@ def get_current_user(credentials: HTTPAuthorizationCredentials = Depends(securit detail="Invalid access token", headers={"WWW-Authenticate": "Bearer"}, ) - except Exception: + except Exception as e: + import traceback + traceback.print_exc() # Imprime no log do docker para ajudar a debugar raise HTTPException( status_code=status.HTTP_401_UNAUTHORIZED, - detail="Could not validate credentials", + detail=f"Could not validate credentials: {str(e)}", headers={"WWW-Authenticate": "Bearer"}, ) diff --git a/test_jwt.py b/test_jwt.py new file mode 100644 index 0000000..bb01a58 --- /dev/null +++ b/test_jwt.py @@ -0,0 +1,14 @@ +from app.core.config import settings +import jwt +print(repr(settings.JWT_PUBLIC_KEY_PEM)) +try: + public_key = settings.JWT_PUBLIC_KEY_PEM.replace('\\n', '\n') + print("Public key repr:", repr(public_key)) + # We don't have a valid token, but we can see if loading the key fails. + # PyJWT lazy loads the key when verifying signature. + # Let's force it to load the key by importing cryptography + from cryptography.hazmat.primitives.serialization import load_pem_public_key + load_pem_public_key(public_key.encode('utf-8')) + print("Key loaded successfully!") +except Exception as e: + print(f"Exception: {type(e).__name__}: {e}")