@@ -222,8 +222,17 @@ async def _handle_oauth_metadata_response(self, response: httpx.Response) -> Non
222222 self .client_metadata .scope = " " .join (metadata .scopes_supported )
223223
224224 def _create_registration_request (self , metadata : OAuthMetadata | None = None ) -> httpx .Request | None :
225- if self ._client_info :
226- return None
225+ context = getattr (self , "context" , None )
226+
227+ if metadata is not None :
228+ if self ._client_info :
229+ return None
230+ if context and context .client_info :
231+ self ._client_info = context .client_info
232+ return None
233+ elif context and context .client_info and not self ._client_info :
234+ self ._client_info = context .client_info
235+
227236 if metadata and metadata .registration_endpoint :
228237 registration_url = str (metadata .registration_endpoint )
229238 else :
@@ -537,12 +546,12 @@ async def _exchange_token_authorization_code(
537546 async def _handle_token_response (self , response : httpx .Response ) -> None :
538547 """Handle token exchange response."""
539548 if response .status_code != 200 : # pragma: no cover
540- body = await response .aread ()
549+ body = response . content or await response .aread ()
541550 body = body .decode ("utf-8" )
542551 raise OAuthTokenError (f"Token exchange failed ({ response .status_code } ): { body } " )
543552
544553 try :
545- content = await response .aread ()
554+ content = response . content or await response .aread ()
546555 token_response = OAuthToken .model_validate_json (content )
547556
548557 # Validate scopes
0 commit comments