Skip to content
This repository was archived by the owner on Apr 26, 2025. It is now read-only.

Commit 4f6ced5

Browse files
committed
Do not pass code_verifier in request payload if None
1 parent 969ec00 commit 4f6ced5

2 files changed

Lines changed: 32 additions & 1 deletion

File tree

fief_client/client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,8 +395,9 @@ def _get_auth_exchange_token_request(
395395
"grant_type": "authorization_code",
396396
"code": code,
397397
"redirect_uri": redirect_uri,
398-
"code_verifier": code_verifier,
399398
}
399+
if code_verifier is not None:
400+
data["code_verifier"] = code_verifier
400401
if self.client_secret is not None:
401402
data["client_secret"] = self.client_secret
402403
return client.build_request("POST", endpoint, data=data)

tests/test_client.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,36 @@ def test_valid_response_tenant(
397397
assert isinstance(userinfo, dict)
398398
assert userinfo["sub"] == user_id
399399

400+
def test_no_code_verifier(
401+
self,
402+
fief_client: Fief,
403+
mock_api_requests: respx.MockRouter,
404+
access_token: str,
405+
signed_id_token: str,
406+
user_id: str,
407+
):
408+
token_route = mock_api_requests.post("/token")
409+
token_route.return_value = Response(
410+
200,
411+
json={
412+
"access_token": access_token,
413+
"id_token": signed_id_token,
414+
"token_type": "bearer",
415+
},
416+
)
417+
418+
token_response, userinfo = fief_client.auth_callback(
419+
"CODE", "https://www.bretagne.duchy/callback"
420+
)
421+
422+
token_route_call = token_route.calls.last
423+
assert token_route_call is not None
424+
425+
request_data = token_route_call.request.content.decode("utf-8")
426+
assert "client_id" in request_data
427+
assert "client_secret" in request_data
428+
assert "code_verifier" not in request_data
429+
400430

401431
class TestAuthRefreshToken:
402432
def test_error_response(

0 commit comments

Comments
 (0)