fix: handle legacy string format for customHeaders in ConnectionOptionsOAuth2 - #816
Open
alexmsenger wants to merge 1 commit into
Open
fix: handle legacy string format for customHeaders in ConnectionOptionsOAuth2#816alexmsenger wants to merge 1 commit into
customHeaders in ConnectionOptionsOAuth2#816alexmsenger wants to merge 1 commit into
Conversation
…nsOAuth2
Some older Auth0 tenants stored the customHeaders field as a JSON-encoded
string rather than a map[string]string object. When the SDK attempted to
unmarshal such a response directly into *map[string]string, it produced:
cannot unmarshal string into Go struct field ... of type map[string]string
This change extends ConnectionOptionsOAuth2.UnmarshalJSON to intercept the
raw customHeaders value as interface{} (alongside the existing scope handling)
before encoding/json attempts direct decoding. The two cases are then handled
explicitly:
- map[string]interface{}: decoded normally into *map[string]string
- string (legacy format): discarded gracefully; the operator can restore
custom header values in their Terraform config
Tests are added to TestOAuth2Connection_UnmarshalJSON covering the map,
legacy string, and null cases.
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
Extends
ConnectionOptionsOAuth2.UnmarshalJSONto gracefully handle thecustomHeadersfield when the Auth0 Management API returns it as a JSON-encoded string rather than amap[string]stringobject.Prior to this change, the decoder attempted to unmarshal the raw value directly into
*map[string]string, which produced:The fix intercepts
customHeadersasinterface{}(alongside the existingscopehandling) and normalizes the two possible forms:map[string]interface{}— decoded normally into*map[string]stringstring(legacy format) — discarded gracefully;CustomHeadersis left nil so the operator can restore the values through their configTypes/methods changed:
ConnectionOptionsOAuth2.UnmarshalJSONinmanagement/connection.go📚 References
Closes #815
🔬 Testing
The existing
make testsuite passes with HTTP recordings unchanged —the fix touches only unmarshal logic, not any API interaction.
Three new cases are added to
TestOAuth2Connection_UnmarshalJSONinmanagement/connection_test.go, covering:{"customHeaders":{"X-Foo":"bar"}}→ decoded into*map[string]string{"customHeaders":"{\"X-Foo\":\"bar\"}"}→ no error,CustomHeadersis nil{"customHeaders":null}→ no error,CustomHeadersis nilNo new HTTP recordings are required as the bug is fully exercisable without
a live tenant.
📝 Checklist