@@ -228,18 +228,13 @@ async def handle_registration_response(response: Response) -> OAuthClientInforma
228228
229229async def handle_token_response_scopes (
230230 response : Response ,
231- client_metadata : OAuthClientMetadata ,
232- validate_scope : bool = True ,
233231) -> OAuthToken :
234232 """Parse and validate token response with optional scope validation.
235233
236- Parses token response JSON and validates scopes to prevent scope escalation
237- if requested. Callers should check response.status_code before calling.
234+ Parses token response JSON. Callers should check response.status_code before calling.
238235
239236 Args:
240237 response: HTTP response from token endpoint (status already checked by caller)
241- client_metadata: Client metadata containing requested scopes (if any)
242- validate_scope: Whether to validate scopes (default True). Set False for refresh.
243238
244239 Returns:
245240 Validated OAuthToken model
@@ -250,16 +245,6 @@ async def handle_token_response_scopes(
250245 try :
251246 content = await response .aread ()
252247 token_response = OAuthToken .model_validate_json (content )
253-
254- # Validate scopes to prevent scope escalation
255- # Only validate during initial token exchange, not during refresh
256- if validate_scope and token_response .scope and client_metadata .scope :
257- requested_scopes = set (client_metadata .scope .split ())
258- returned_scopes = set (token_response .scope .split ())
259- unauthorized_scopes = returned_scopes - requested_scopes
260- if unauthorized_scopes :
261- raise OAuthTokenError (f"Server granted unauthorized scopes: { unauthorized_scopes } " )
262-
263248 return token_response
264249 except ValidationError as e :
265250 raise OAuthTokenError (f"Invalid token response: { e } " )
0 commit comments