Made PKCE and nonce optional, only when client wants them.
This commit is contained in:
+3
-3
@@ -23,15 +23,15 @@ AUTH_CODE_LIFETIME = timedelta(seconds=60)
|
||||
class OIDCCode(msgspec.Struct):
|
||||
"""An OIDC authorization code pending token exchange.
|
||||
|
||||
PKCE uses S256 only (verified at auth time).
|
||||
PKCE uses S256 only when provided (verified at token exchange).
|
||||
"""
|
||||
|
||||
session_key: str
|
||||
created: datetime
|
||||
redirect_uri: str
|
||||
scope: str
|
||||
nonce: str
|
||||
code_challenge: str
|
||||
nonce: str | None = None
|
||||
code_challenge: str | None = None
|
||||
|
||||
|
||||
class CookieCode(msgspec.Struct):
|
||||
|
||||
@@ -196,7 +196,8 @@ async def _handle_authorization_code(
|
||||
status_code=400,
|
||||
)
|
||||
|
||||
# Verify PKCE (S256 only, enforced at auth time)
|
||||
# Verify PKCE if code_challenge was provided at authorization time
|
||||
if oidc_code.code_challenge:
|
||||
if not code_verifier:
|
||||
return JSONResponse(
|
||||
{
|
||||
|
||||
+5
-11
@@ -158,12 +158,10 @@ async def websocket_authenticate(
|
||||
await ws.send_json({"status": 400, "detail": "Scope must include openid"})
|
||||
return
|
||||
|
||||
# PKCE is required with S256
|
||||
if not code_challenge:
|
||||
await ws.send_json(
|
||||
{"status": 400, "detail": "PKCE code_challenge is required"}
|
||||
)
|
||||
return
|
||||
# PKCE: when code_challenge is present, only S256 is supported
|
||||
# If method is omitted, default to S256 per best practice (not "plain" per RFC 7636)
|
||||
# When code_challenge is absent, ignore code_challenge_method entirely
|
||||
if code_challenge:
|
||||
if code_challenge_method and code_challenge_method != "S256":
|
||||
await ws.send_json(
|
||||
{
|
||||
@@ -172,11 +170,7 @@ async def websocket_authenticate(
|
||||
}
|
||||
)
|
||||
return
|
||||
|
||||
# Nonce is required for OIDC
|
||||
if not nonce:
|
||||
await ws.send_json({"status": 400, "detail": "nonce is required for OIDC"})
|
||||
return
|
||||
# Default to S256 when method not specified (implicit)
|
||||
|
||||
# Validate state parameter if provided (defensive against injection)
|
||||
if state:
|
||||
|
||||
Reference in New Issue
Block a user