@@ -135,6 +135,32 @@ def test_includes_client_secret_when_api_key_present(self, workos, httpx_mock):
135135 body = json .loads (request .content )
136136 assert "client_secret" in body
137137
138+ def test_forwards_radar_context (self , workos , httpx_mock ):
139+ httpx_mock .add_response (json = load_fixture ("authenticate_response.json" ))
140+ workos .user_management .authenticate_with_code_pkce (
141+ code = "auth_code_123" ,
142+ code_verifier = "test_verifier_abc" ,
143+ ip_address = "203.0.113.42" ,
144+ device_id = "device_01HXYZ" ,
145+ user_agent = "Mozilla/5.0" ,
146+ )
147+ request = httpx_mock .get_request ()
148+ body = json .loads (request .content )
149+ assert body ["ip_address" ] == "203.0.113.42"
150+ assert body ["device_id" ] == "device_01HXYZ"
151+ assert body ["user_agent" ] == "Mozilla/5.0"
152+
153+ def test_omits_radar_context_when_not_provided (self , workos , httpx_mock ):
154+ httpx_mock .add_response (json = load_fixture ("authenticate_response.json" ))
155+ workos .user_management .authenticate_with_code_pkce (
156+ code = "auth_code_123" , code_verifier = "test_verifier_abc"
157+ )
158+ request = httpx_mock .get_request ()
159+ body = json .loads (request .content )
160+ assert "ip_address" not in body
161+ assert "device_id" not in body
162+ assert "user_agent" not in body
163+
138164
139165@pytest .mark .asyncio
140166class TestAsyncAuthKitPKCECodeExchange :
@@ -148,6 +174,34 @@ async def test_sends_code_verifier(self, async_workos, httpx_mock):
148174 body = json .loads (request .content )
149175 assert body ["code_verifier" ] == "test_verifier_abc"
150176
177+ async def test_forwards_radar_context (self , async_workos , httpx_mock ):
178+ httpx_mock .add_response (json = load_fixture ("authenticate_response.json" ))
179+ await async_workos .user_management .authenticate_with_code_pkce (
180+ code = "auth_code_123" ,
181+ code_verifier = "test_verifier_abc" ,
182+ ip_address = "203.0.113.42" ,
183+ device_id = "device_01HXYZ" ,
184+ user_agent = "Mozilla/5.0" ,
185+ )
186+ request = httpx_mock .get_request ()
187+ body = json .loads (request .content )
188+ assert body ["ip_address" ] == "203.0.113.42"
189+ assert body ["device_id" ] == "device_01HXYZ"
190+ assert body ["user_agent" ] == "Mozilla/5.0"
191+
192+ async def test_omits_radar_context_when_not_provided (
193+ self , async_workos , httpx_mock
194+ ):
195+ httpx_mock .add_response (json = load_fixture ("authenticate_response.json" ))
196+ await async_workos .user_management .authenticate_with_code_pkce (
197+ code = "auth_code_123" , code_verifier = "test_verifier_abc"
198+ )
199+ request = httpx_mock .get_request ()
200+ body = json .loads (request .content )
201+ assert "ip_address" not in body
202+ assert "device_id" not in body
203+ assert "user_agent" not in body
204+
151205
152206class TestSSOPKCEAuthorizationUrl :
153207 def test_returns_required_keys (self , workos ):
0 commit comments