github-actions[bot] commited on
Commit
6a25d7a
·
1 Parent(s): b0ec2bd

Automated deployment from GitHub Actions: 202a810ed74aa5ffe0f432415aac4bcf352f7332

Browse files
Files changed (1) hide show
  1. src/dependencies.py +12 -5
src/dependencies.py CHANGED
@@ -81,7 +81,7 @@ def get_keycloak_jwks() -> dict:
81
 
82
 
83
  # ── JWT Bearer scheme ─────────────────────────────────────────────────────────
84
- bearer_scheme = HTTPBearer(auto_error=True)
85
 
86
 
87
  class CurrentUser:
@@ -121,15 +121,13 @@ class CurrentUser:
121
 
122
 
123
  async def get_current_user(
124
- credentials: Annotated[HTTPAuthorizationCredentials, Depends(bearer_scheme)],
125
  supabase: Annotated[AsyncClient, Depends(get_supabase)],
126
  ) -> CurrentUser:
127
  """
128
  Validate Keycloak RS256 JWT and return enriched user.
129
  PRD §4 Decision 2: verify against Keycloak JWKS endpoint.
130
  """
131
- token = credentials.credentials
132
-
133
  if settings.DISABLE_AUTH:
134
  return CurrentUser(
135
  sub="demo-bypass-user",
@@ -138,7 +136,7 @@ async def get_current_user(
138
  roles=["admin", "operator", "supervisor", "sme"],
139
  tier="enterprise",
140
  company_id="demo-bypass-user",
141
- raw_token=token,
142
  )
143
 
144
  credentials_exception = HTTPException(
@@ -147,6 +145,15 @@ async def get_current_user(
147
  headers={"WWW-Authenticate": "Bearer"},
148
  )
149
 
 
 
 
 
 
 
 
 
 
150
  try:
151
  jwks = get_keycloak_jwks()
152
  payload = jwt.decode(
 
81
 
82
 
83
  # ── JWT Bearer scheme ─────────────────────────────────────────────────────────
84
+ bearer_scheme = HTTPBearer(auto_error=False)
85
 
86
 
87
  class CurrentUser:
 
121
 
122
 
123
  async def get_current_user(
124
+ credentials: Annotated[HTTPAuthorizationCredentials | None, Depends(bearer_scheme)],
125
  supabase: Annotated[AsyncClient, Depends(get_supabase)],
126
  ) -> CurrentUser:
127
  """
128
  Validate Keycloak RS256 JWT and return enriched user.
129
  PRD §4 Decision 2: verify against Keycloak JWKS endpoint.
130
  """
 
 
131
  if settings.DISABLE_AUTH:
132
  return CurrentUser(
133
  sub="demo-bypass-user",
 
136
  roles=["admin", "operator", "supervisor", "sme"],
137
  tier="enterprise",
138
  company_id="demo-bypass-user",
139
+ raw_token="demo-token",
140
  )
141
 
142
  credentials_exception = HTTPException(
 
145
  headers={"WWW-Authenticate": "Bearer"},
146
  )
147
 
148
+ if not credentials:
149
+ raise HTTPException(
150
+ status_code=status.HTTP_401_UNAUTHORIZED,
151
+ detail="Not authenticated",
152
+ headers={"WWW-Authenticate": "Bearer"},
153
+ )
154
+
155
+ token = credentials.credentials
156
+
157
  try:
158
  jwks = get_keycloak_jwks()
159
  payload = jwt.decode(