Hussien Haider commited on
Commit
bedbcad
·
1 Parent(s): fbae3ab
Files changed (2) hide show
  1. app/core/auth.py +9 -4
  2. app/core/config.py +1 -0
app/core/auth.py CHANGED
@@ -10,22 +10,27 @@ from typing import Optional
10
 
11
  from fastapi import Request, HTTPException, status
12
 
13
- from app.core.config import SUPABASE_ANON_KEY
14
 
15
  log = logging.getLogger("auth")
16
 
17
 
18
  def _validate_jwt(token: str) -> Optional[dict]:
19
  """Validate JWT and return payload if valid."""
 
 
 
 
20
  try:
21
  payload = jwt.decode(
22
  token,
23
- options={"verify_signature": False},
24
- algorithms=["HS256", "HS384", "HS512", "RS256", "RS384", "RS512", "ES256", "ES384", "ES512", "EdDSA"],
 
25
  )
26
  return payload
27
  except jwt.ExpiredSignatureError:
28
- log.warning("JWT expired")
29
  return None
30
  except jwt.InvalidTokenError as exc:
31
  log.warning("JWT decode failed: %s", exc)
 
10
 
11
  from fastapi import Request, HTTPException, status
12
 
13
+ from app.core.config import SUPABASE_ANON_KEY, SUPABASE_JWT_SECRET
14
 
15
  log = logging.getLogger("auth")
16
 
17
 
18
  def _validate_jwt(token: str) -> Optional[dict]:
19
  """Validate JWT and return payload if valid."""
20
+ if not SUPABASE_JWT_SECRET:
21
+ log.warning("SUPABASE_JWT_SECRET is not configured - token verification will be insecure")
22
+ return None
23
+
24
  try:
25
  payload = jwt.decode(
26
  token,
27
+ SUPABASE_JWT_SECRET,
28
+ algorithms=["HS256"],
29
+ options={"verify_aud": False},
30
  )
31
  return payload
32
  except jwt.ExpiredSignatureError:
33
+ log.warning("JWT expired - user may need to refresh or re-authenticate")
34
  return None
35
  except jwt.InvalidTokenError as exc:
36
  log.warning("JWT decode failed: %s", exc)
app/core/config.py CHANGED
@@ -19,6 +19,7 @@ SUPABASE_URL = os.environ.get(
19
  "https://yevtnyokixocpihpdwqu.supabase.co",
20
  )
21
  SUPABASE_ANON_KEY = os.environ.get("SUPABASE_ANON_KEY", "")
 
22
 
23
 
24
  # --------------------------------------------------------------------------- #
 
19
  "https://yevtnyokixocpihpdwqu.supabase.co",
20
  )
21
  SUPABASE_ANON_KEY = os.environ.get("SUPABASE_ANON_KEY", "")
22
+ SUPABASE_JWT_SECRET = os.environ.get("SUPABASE_JWT_SECRET", "")
23
 
24
 
25
  # --------------------------------------------------------------------------- #