fix: OAuth DCR scope field compliance and error handling #1003
+25
−7
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
fix: OAuth DCR scope field compliance and error handling
Problem
OAuth Dynamic Client Registration (DCR) was sending
scope: ""(empty string) when no scopes were discovered, violating OAuth 2.0 RFC 7591. This caused some OAuth servers (like Keycloak) to reject the registration request. Additionally, OAuth errors were not being caught or displayed to users.Root Cause
When scope discovery failed (e.g., due to CORS), the
clientMetadatagetter inInspectorOAuthClientProviderwas settingscope: this.scope ?? "", which sent an empty string instead of omitting the field entirely as required by the OAuth 2.0 specification.Changes
1. Fix OAuth Client Metadata Scope Field
File:
client/src/lib/auth.ts(line 155)Modified
clientMetadatato conditionally include thescopefield only when it's defined and non-empty, per OAuth 2.0 RFC 7591 specification.2. Improve OAuth Error Handling
File:
client/src/lib/hooks/useConnection.ts(line 396)Added try-catch block around
auth()call inhandleAuthErrorto catch OAuth failures and display user-friendly error messages via toast notifications.Testing
Impact
Related Issue
Fixes (follow-up to PR #999)
Note
This PR builds on top of PR #999 which fixed the initial OAuth flow trigger issue. This PR addresses the remaining OAuth spec compliance and error handling improvements.