@@ -433,9 +433,11 @@ def _select_scopes(self, init_response: httpx.Response) -> None:
433433
434434 # Discovery and registration helpers provided by BaseOAuthProvider
435435
436- async def _perform_authorization (self ) -> tuple [str , str ]:
437- """Perform the authorization flow and return authorization code data."""
438- return await self ._perform_authorization_code_grant ()
436+ async def _perform_authorization (self ) -> httpx .Request :
437+ """Perform the authorization flow."""
438+ auth_code , code_verifier = await self ._perform_authorization_code_grant ()
439+ token_request = await self ._exchange_token_authorization_code (auth_code , code_verifier )
440+ return token_request
439441
440442 async def _perform_authorization_code_grant (self ) -> tuple [str , str ]:
441443 """Perform the authorization redirect and get auth code."""
@@ -685,18 +687,14 @@ async def async_auth_flow(self, request: httpx.Request) -> AsyncGenerator[httpx.
685687 break # Non-4XX error, stop trying
686688
687689 # Step 4: Register client if needed
688- if self .context .client_info and not self ._client_info :
689- self ._client_info = self .context .client_info
690690 registration_request = self ._create_registration_request (self ._metadata )
691691 if registration_request :
692692 registration_response = yield registration_request
693693 await self ._handle_registration_response (registration_response )
694694 self .context .client_info = self ._client_info
695695
696696 # Step 5: Perform authorization and complete token exchange
697- auth_code , code_verifier = await self ._perform_authorization ()
698- token_request = await self ._exchange_token_authorization_code (auth_code , code_verifier )
699- token_response = yield token_request
697+ token_response = yield await self ._perform_authorization ()
700698 await self ._handle_token_response (token_response )
701699 except Exception : # pragma: no cover
702700 logger .exception ("OAuth flow error" )
@@ -717,9 +715,7 @@ async def async_auth_flow(self, request: httpx.Request) -> AsyncGenerator[httpx.
717715 self ._select_scopes (response )
718716
719717 # Step 2b: Perform (re-)authorization and token exchange
720- auth_code , code_verifier = await self ._perform_authorization ()
721- token_request = await self ._exchange_token_authorization_code (auth_code , code_verifier )
722- token_response = yield token_request
718+ token_response = yield await self ._perform_authorization ()
723719 await self ._handle_token_response (token_response )
724720 except Exception : # pragma: no cover
725721 logger .exception ("OAuth flow error" )
0 commit comments