OIDC authentication works, remove debug.
This commit is contained in:
+3
-44
@@ -401,78 +401,37 @@ async def userinfo(
|
|||||||
Returns claims about the authenticated user.
|
Returns claims about the authenticated user.
|
||||||
Requires Bearer token from /token endpoint.
|
Requires Bearer token from /token endpoint.
|
||||||
"""
|
"""
|
||||||
print(f"DEBUG UserInfo: Received request from {request.client.host}")
|
|
||||||
print(f"DEBUG UserInfo: Authorization header present: {bool(credentials)}")
|
|
||||||
|
|
||||||
if not credentials:
|
if not credentials:
|
||||||
print("DEBUG UserInfo: No credentials provided")
|
|
||||||
raise HTTPException(401, "Bearer token required")
|
raise HTTPException(401, "Bearer token required")
|
||||||
|
|
||||||
print(f"DEBUG UserInfo: Token length: {len(credentials.credentials)}")
|
|
||||||
print(f"DEBUG UserInfo: Token prefix: {credentials.credentials[:50]}...")
|
|
||||||
|
|
||||||
issuer = _get_issuer(request)
|
issuer = _get_issuer(request)
|
||||||
print(f"DEBUG UserInfo: Computed issuer: {issuer}")
|
|
||||||
|
|
||||||
# Try to decode without verification to see token contents
|
|
||||||
try:
|
|
||||||
import jwt
|
|
||||||
unverified_payload = jwt.decode(credentials.credentials, options={"verify_signature": False})
|
|
||||||
print(f"DEBUG UserInfo: Unverified payload: {unverified_payload}")
|
|
||||||
print(f"DEBUG UserInfo: Token issuer claim: {unverified_payload.get('iss')}")
|
|
||||||
print(f"DEBUG UserInfo: Token audience claim: {unverified_payload.get('aud')}")
|
|
||||||
except Exception as e:
|
|
||||||
print(f"DEBUG UserInfo: Failed to decode unverified: {e}")
|
|
||||||
|
|
||||||
payload = oidjwt.decode_access_token(credentials.credentials, issuer)
|
payload = oidjwt.decode_access_token(credentials.credentials, issuer)
|
||||||
print(f"DEBUG UserInfo: JWT decode result: {payload is not None}")
|
|
||||||
|
|
||||||
if not payload:
|
if not payload:
|
||||||
print("DEBUG UserInfo: JWT decode failed")
|
|
||||||
raise HTTPException(401, "Invalid or expired token")
|
raise HTTPException(401, "Invalid or expired token")
|
||||||
|
|
||||||
print(f"DEBUG UserInfo: Decoded payload: {payload}")
|
|
||||||
|
|
||||||
# Verify audience is a valid client
|
# Verify audience is a valid client
|
||||||
aud = payload.get("aud")
|
aud = payload.get("aud")
|
||||||
print(f"DEBUG UserInfo: Audience claim: {aud}")
|
|
||||||
|
|
||||||
if not aud:
|
if not aud:
|
||||||
print("DEBUG UserInfo: Missing aud claim")
|
|
||||||
raise HTTPException(401, "Invalid token (missing aud claim)")
|
raise HTTPException(401, "Invalid token (missing aud claim)")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
client_uuid = UUID(aud)
|
client_uuid = UUID(aud)
|
||||||
print(f"DEBUG UserInfo: Client UUID: {client_uuid}")
|
|
||||||
except ValueError:
|
except ValueError:
|
||||||
print(f"DEBUG UserInfo: Invalid UUID format: {aud}")
|
|
||||||
raise HTTPException(401, "Invalid token (invalid aud format)")
|
raise HTTPException(401, "Invalid token (invalid aud format)")
|
||||||
|
|
||||||
client = db.data().oid_clients.get(client_uuid)
|
if not db.data().oid_clients.get(client_uuid):
|
||||||
print(f"DEBUG UserInfo: Client found: {client is not None}")
|
|
||||||
if not client:
|
|
||||||
print(f"DEBUG UserInfo: Unknown client UUID: {client_uuid}")
|
|
||||||
raise HTTPException(401, "Invalid token (unknown client)")
|
raise HTTPException(401, "Invalid token (unknown client)")
|
||||||
|
|
||||||
# Get user
|
# Get user
|
||||||
sub = payload.get("sub")
|
|
||||||
print(f"DEBUG UserInfo: Subject claim: {sub}")
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
user_uuid = UUID(sub)
|
user_uuid = UUID(payload["sub"])
|
||||||
print(f"DEBUG UserInfo: User UUID: {user_uuid}")
|
except (KeyError, ValueError):
|
||||||
except (KeyError, ValueError) as e:
|
|
||||||
print(f"DEBUG UserInfo: Invalid sub claim: {e}")
|
|
||||||
raise HTTPException(401, "Invalid token")
|
raise HTTPException(401, "Invalid token")
|
||||||
|
|
||||||
user = db.data().users.get(user_uuid)
|
user = db.data().users.get(user_uuid)
|
||||||
print(f"DEBUG UserInfo: User found: {user is not None}")
|
|
||||||
if not user:
|
if not user:
|
||||||
print(f"DEBUG UserInfo: Unknown user UUID: {user_uuid}")
|
|
||||||
raise HTTPException(401, "User not found")
|
raise HTTPException(401, "User not found")
|
||||||
|
|
||||||
print("DEBUG UserInfo: All validations passed, proceeding with response")
|
|
||||||
|
|
||||||
# Get user's permissions scoped to this OIDC client (domain == client UUID)
|
# Get user's permissions scoped to this OIDC client (domain == client UUID)
|
||||||
role = user.role
|
role = user.role
|
||||||
org = role.org
|
org = role.org
|
||||||
|
|||||||
@@ -204,6 +204,5 @@ def decode_access_token(
|
|||||||
options=options,
|
options=options,
|
||||||
**decode_kwargs
|
**decode_kwargs
|
||||||
)
|
)
|
||||||
except jwt.PyJWTError as e:
|
except jwt.PyJWTError:
|
||||||
print(f"DEBUG JWT decode error: {e}")
|
|
||||||
return None
|
return None
|
||||||
|
|||||||
Reference in New Issue
Block a user