fix: honor UseOauthSpecScope when marshaling OAuth2 connection scope - #837
Open
Asarew wants to merge 1 commit into
Open
fix: honor UseOauthSpecScope when marshaling OAuth2 connection scope#837Asarew wants to merge 1 commit into
Asarew wants to merge 1 commit into
Conversation
ConnectionOptionsOAuth2.MarshalJSON was always emitting scope as a JSON array, regardless of UseOauthSpecScope. Auth0's backend then persists that array as a comma-joined string and forwards it verbatim to the upstream IdP, so RFC 6749-compliant IdPs (Keycloak, Ory, ...) reject the scope as "a,b,c" — a single invalid literal. When UseOauthSpecScope is true, marshal scope as a raw space-delimited string per the OAuth 2.0 spec. When false or nil, keep the historical array form for back-compat. UnmarshalJSON already handled both wire shapes; no change needed there. Related: auth0/terraform-provider-auth0#1656
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.
🔧 Changes
Fixes
ConnectionOptionsOAuth2.MarshalJSONto honorUseOauthSpecScope.Before this change,
MarshalJSONunconditionally emittedscopeas a JSON array (["a","b","c"]), regardless ofUseOauthSpecScope. Auth0's backend then persists that array as a comma-joined string and forwards it verbatim to the upstream IdP on/authorize, so RFC 6749-compliant IdPs (Keycloak, Ory, ...) reject the entire value as one invalid scope literal (invalid_scope: a,b,c). TheUseOauthSpecScopefield added in #699 was accepted by Auth0 and reflected in the dashboard checkbox, but never changed the wire format — it only affects per-authorizeconnection_scopeextras server-side.With this change, when
UseOauthSpecScope == true,scopeis marshaled as a raw space-delimited string ("a b c") — the form spec-compliant IdPs expect, and the same form the Auth0 dashboard produces when the "Separate scopes using a space" checkbox is on. Whenfalseornil, the existing array behavior is preserved for back-compat.Types and methods changed:
ConnectionOptionsOAuth2.MarshalJSON— split thescopewrite into two branches keyed onGetUseOauthSpecScope(). No new API, no removals.UnmarshalJSONalready accepts both the array and the string forms, so no change was needed on the read path — round-tripping is preserved.📚 References
UseOauthSpecScopefield but did not wire it into serialization) and Add useOauthSpecScope option to OAuth2 connection terraform-provider-auth0#1480 (which exposed the field through Terraform schema).["scope1 scope2 scope3"]), but this resolves back to a comma-separated list." — that observation is exactly what this PR fixes.🔬 Testing
Automated: extended
TestOAuth2Connection_MarshalJSONwith two new cases (UseOauthSpecScope=true→ string,UseOauthSpecScope=false→ array) and added a{"scope":"foo bar baz"}row toTestOAuth2Connection_UnmarshalJSONto make the round-trip through the newly-emitted string form explicit.Full connection marshal/unmarshal suite also passes (
TestConnection.*Marshal|Unmarshal|TestGoogleOauth2Connection.*).Manual end-to-end (against a real Auth0 tenant, on a custom social oauth2 connection to a Keycloak-backed IdP):
UseOauthSpecScope = trueand scopes["openid","profile","email"].openid profile email(space-delimited) instead ofopenid,profile,email. The "Separate scopes using a space" checkbox is on.scope=openid profile emailand login completes. Previously it receivedscope=openid,profile,emailand failed withinvalid_scope.📝 Checklist