Checklist
Description
ConnectionOptionsOAuth2.UnmarshalJSON fails with a type assertion error when
the Auth0 Management API returns the customHeaders field as a JSON-encoded
string rather than a map object.
The error message is:
json: cannot unmarshal string into Go struct field of type map[string]string
This occurs on older Auth0 tenants where the customHeaders value was persisted
in a legacy string format. The SDK makes no attempt to handle this variant and
instead surfaces the raw JSON decode error to the caller, which causes the
terraform-provider-auth0 to crash when reading or refreshing an OAuth2
connection resource on such tenants.
Expectation
When the API returns "customHeaders": "<json-encoded-string>", the SDK should
not return an error. The legacy format cannot be reliably decoded without knowing
the original structure, so the field should be surfaced as nil/empty and the
operator can restore the values through their Terraform configuration.
When the API returns "customHeaders": {"key": "value"} (the current format),
the field should continue to be decoded into *map[string]string as normal.
Reproduction
package main
import (
"encoding/json"
"fmt"
"github.com/auth0/go-auth0/management"
)
func main() {
// Simulates what the Management API returns on an older tenant.
// customHeaders is a JSON-encoded string instead of a map object.
payload := `{
"authorizationURL": "https://example.com/oauth/authorize",
"tokenURL": "https://example.com/oauth/token",
"customHeaders": "{\"X-Custom-Header\":\"custom-value\"}"
}`
var opts management.ConnectionOptionsOAuth2
err := json.Unmarshal([]byte(payload), &opts)
if err != nil {
fmt.Printf("Error: %v\n", err)
// Prints: json: cannot unmarshal string into Go struct field of type map[string]string
}
}
Steps to reproduce in production:
- Have an Auth0 tenant where an OAuth2 connection was created and had
customHeaders set while the SDK persisted them in a legacy string format.
- Use
terraform-provider-auth0 to run terraform refresh or terraform plan against that connection.
- The provider crashes with the above unmarshal error.
Auth0 Go SDK version
v1.44.0
Checklist
Description
ConnectionOptionsOAuth2.UnmarshalJSONfails with a type assertion error whenthe Auth0 Management API returns the
customHeadersfield as a JSON-encodedstring rather than a map object.
The error message is:
This occurs on older Auth0 tenants where the
customHeadersvalue was persistedin a legacy string format. The SDK makes no attempt to handle this variant and
instead surfaces the raw JSON decode error to the caller, which causes the
terraform-provider-auth0to crash when reading or refreshing an OAuth2connection resource on such tenants.
Expectation
When the API returns
"customHeaders": "<json-encoded-string>", the SDK shouldnot return an error. The legacy format cannot be reliably decoded without knowing
the original structure, so the field should be surfaced as
nil/emptyand theoperator can restore the values through their Terraform configuration.
When the API returns
"customHeaders": {"key": "value"}(the current format),the field should continue to be decoded into
*map[string]stringas normal.Reproduction
Steps to reproduce in production:
customHeadersset while the SDK persisted them in a legacy string format.terraform-provider-auth0to run terraform refresh or terraform plan against that connection.Auth0 Go SDK version
v1.44.0