Add remote authorization server indication to OAuth2 error messages#4101
Open
Add remote authorization server indication to OAuth2 error messages#4101
Conversation
When the local Nuts node acts as a client and the remote OAuth2 server returns an error, the error is now wrapped in RemoteOAuthError which prefixes the message with "remote authorization server: ". This allows developers and administrators to clearly distinguish whether an error originated locally or from a remote server. Fixes #4096 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Coverage Impact ⬆️ Merging this pull request will increase total coverage on Modified Files with Diff Coverage (2)
🛟 Help
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.

Summary
Closes #4096
When the local Nuts node acts as a client and the remote OAuth2 authorization server returns an error, the error was propagated as-is to the caller (e.g. EHR), making it impossible to tell whether the error originated locally or remotely.
RemoteOAuthErrorwrapper type inauth/oauth/error.gothat prefixes error messages with"remote authorization server: "HTTPClient.AccessToken()andHTTPClient.doRequest()to wrap parsed remote OAuth2 errors withRemoteOAuthErrorPresentationDefinition()to useerrors.Asinstead of a direct type assertion (needed after wrapping)RemoteOAuthErrorimplementsHTTPStatusCodeError(delegates to inner error) andUnwrap()soerrors.Asstill finds the underlyingOAuth2ErrorBefore:
{"detail": "invalid_request - unable to get subject DID from VC: credential subjects have no ID", "status": 400, "title": "RequestServiceAccessToken failed"}After:
{"detail": "remote authorization server: invalid_request - unable to get subject DID from VC: credential subjects have no ID", "status": 400, "title": "RequestServiceAccessToken failed"}Test plan
RemoteOAuthErrorinauth/oauth/error_test.goauth/client/iam/client_test.goandopenid4vp_test.goupdated to assertRemoteOAuthErrorwrappinggo test ./...)🤖 Generated with Claude Code