@@ -621,6 +621,28 @@ def test_authorization_url_has_expected_query_params_with_state(self):
621621 "response_type" : RESPONSE_TYPE_CODE ,
622622 }
623623
624+ def test_authorization_url_has_expected_query_params_with_code_challenge (self ):
625+ connection_id = "connection_123"
626+ redirect_uri = "https://localhost/auth/callback"
627+ code_challenge = json .dumps ({"code_challenge" : "code_challenge_for_pkce" })
628+
629+ authorization_url = self .user_management .get_authorization_url (
630+ connection_id = connection_id ,
631+ code_challenge = code_challenge ,
632+ redirect_uri = redirect_uri ,
633+ )
634+
635+ parsed_url = urlparse (authorization_url )
636+
637+ assert dict (parse_qsl (parsed_url .query )) == {
638+ "code_challenge" : code_challenge ,
639+ "code_challenge_method" : "S256" ,
640+ "client_id" : workos .client_id ,
641+ "redirect_uri" : redirect_uri ,
642+ "connection_id" : connection_id ,
643+ "response_type" : RESPONSE_TYPE_CODE ,
644+ }
645+
624646 def test_authenticate_with_password (
625647 self , capture_and_mock_request , mock_auth_response
626648 ):
@@ -653,13 +675,15 @@ def test_authenticate_with_password(
653675
654676 def test_authenticate_with_code (self , capture_and_mock_request , mock_auth_response ):
655677 code = "test_code"
678+ code_verifier = "test_code_verifier"
656679 user_agent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36"
657680 ip_address = "192.0.0.1"
658681
659682 url , request = capture_and_mock_request ("post" , mock_auth_response , 200 )
660683
661684 response = self .user_management .authenticate_with_code (
662685 code = code ,
686+ code_verifier = code_verifier ,
663687 user_agent = user_agent ,
664688 ip_address = ip_address ,
665689 )
@@ -670,6 +694,7 @@ def test_authenticate_with_code(self, capture_and_mock_request, mock_auth_respon
670694 assert response ["access_token" ] == "access_token_12345"
671695 assert response ["refresh_token" ] == "refresh_token_12345"
672696 assert request ["json" ]["code" ] == code
697+ assert request ["json" ]["code_verifier" ] == code_verifier
673698 assert request ["json" ]["user_agent" ] == user_agent
674699 assert request ["json" ]["ip_address" ] == ip_address
675700 assert request ["json" ]["client_id" ] == "client_b27needthisforssotemxo"
0 commit comments