fix: OAuth DCR scope field compliance and error handling#1003
Conversation
|
@cliffhall PTAL |
5601411 to
5858ab3
Compare
5858ab3 to
87fff8b
Compare
|
@cliffhall Thanks for merging #999 - this PR is now a followup! I've rebased this PR on the latest main. This PR addresses outstanding OAuth spec compliance issue where the scope field was being sent as an empty string instead of being omitted entirely (per RFC 7591), which caused some OAuth servers like Keycloak to reject the DCR request. It also adds better error handling to display user-friendly messages when OAuth fails. |
olaservo
left a comment
There was a problem hiding this comment.
Tested and approved.
Testing performed:
Set up Keycloak (Docker) with DCR enabled and verified the behavior difference:
| DCR Request | Result |
|---|---|
"scope": "" |
Client registered with no scopes |
| No scope field | Client registered with default scopes |
This confirms the fix is correct - omitting the scope field when undefined (per RFC 7591) allows servers to assign default scopes, whereas sending an empty string explicitly requests no scopes.
Code review:
- Fix is minimal and focused
- Correctly implements RFC 7591 spec compliance
- Appropriate for V1 maintenance scope
This review was conducted with assistance from Claude (AI).
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.