Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug when decoding Social Google Connection #14

Closed
sergiught opened this issue Feb 16, 2022 · 4 comments · Fixed by #174
Closed

Bug when decoding Social Google Connection #14

sergiught opened this issue Feb 16, 2022 · 4 comments · Fixed by #174
Labels
bug Something isn't working

Comments

@sergiught
Copy link
Contributor

From auth0 created by juniocezar: go-auth0/auth0#117

The allowed audiences field for the Google OAuth2 Social connection has the []interface{} type.

https://github.com/go-auth0/auth0/blob/1c72b20f2cab2ec7b754b93169a19d773af8d444/management/connection.go#L195

The Social Google account usually comes enabled by default in Auth0, but if you disable it:

image

and run a ConnectionManager.List() to get the list of all connections, this Social Google connection is still being listed.

{
    "total":1,
    "start":0,
    "limit":50,
    "connections":[
       {
          "id":"con_jBya21zJU4o*****",
          "options":{
             "email":true,
             "gmail":false,
             "orkut":false,
             "scope":[
                "email",
                "profile"
             ],
             "sites":false,
             "tasks":false,
             "blogger":false,
             "profile":true,
             "youtube":false,
             "calendar":false,
             "contacts":false,
             "analytics":false,
             "client_id":"",
             "moderator":false,
             "coordinate":false,
             "picasa_web":false,
             "google_plus":false,
             "google_books":false,
             "google_drive":false,
             "spreadsheets":false,
             "client_secret":"",
             "document_list":false,
             "latitude_best":false,
             "latitude_city":false,
             "url_shortener":false,
             "webmaster_tools":false,
             "chrome_web_store":false,
             "allowed_audiences":"",
             "adsense_management":false,
             "google_drive_files":false,
             "coordinate_readonly":false,
             "google_cloud_storage":false,
             "content_api_for_shopping":false,
             "google_affiliate_network":false
          },
          "strategy":"google-oauth2",
          "name":"google-oauth2",
          "is_domain_connection":false,
          "realms":[
             "google-oauth2"
          ],
          "enabled_clients":[
 
          ]
       }
    ]
 }

The problem here is that the allowed_audiences option comes as an empty string, leading to an Unmarshall error.

json: cannot unmarshal string into Go struct field ConnectionOptionsGoogleOAuth2.allowed_audiences of type []interface {}

I may try to work on a fix for it when I get some spare time

@nickzelei
Copy link

nickzelei commented Jan 9, 2023

This issue still persists today, just got bit by it again as I was creating a new tenant and forgot that I originally hit this months ago.

The extra frustrating thing is that if you add a fake value here, and then remove it - the allowed_audiences appears to correctly come through as an empty list. I'm going to keep a fake-value listed in there for now as I know that works, and don't want it to magically rollback to being an empty string and start failing again.

An extra frustrating thing is in the Go SDK it doesn't tell you which field it is that is having troubles.
I had to bypass the SDK and make an HTTP request directly to the endpoint, but then try to marshal the same type. Then I was able to actually view the real issue.

Example:

	url := fmt.Sprintf("%s/api/v2/connections", c.domain)

	req, err := http.NewRequest("GET", url, nil)
	if err != nil {
		return nil, err
	}
	req.Header.Add("authorization", fmt.Sprintf("Bearer %s", accessToken))

	res, err := http.DefaultClient.Do(req)
	if err != nil {
		return nil, err
	}

	defer res.Body.Close()
	body, err := ioutil.ReadAll(res.Body)
	if err != nil {
		return nil, err
	}

	var connectionList []*management.Connection
	err = json.Unmarshal(body, &connectionList)
	if err != nil {
		panic(err)
	}
	return connectionList, nil

Prints the real error:

panic: json: cannot unmarshal string into Go struct field ConnectionOptionsGoogleOAuth2.allowed_audiences of type []string

Where as the SDK prints out a pretty cryptic:

failed to unmarshal response payload: json: cannot unmarshal string into Go struct field ConnectionList.connections of type []string

I'm guessing because it uses a wrapper ConnectionList type to get the pagination data.

@alex-restless
Copy link

This hit me again today, any chance of a bump? Appreciate there's a workaround so low priority.

The workaround for me was hinted in the linked issue - I went to the connection, edited the Allowed Mobile Client IDs with a value, then cleared it and hey-presto it works.

go-auth0/auth0#117 (comment)

ewanharris added a commit that referenced this issue Mar 8, 2023
allowed_audiences can be null, an empty string, or an array of strings. In order to handle this we
have to implement a custom marshaller that will map to the expected value to avoid errors.

Fixes #14
@ewanharris
Copy link
Contributor

Hey @alex-restless, we have a fix up for this at #174. I think we might (tentatively) cut a release next week as we'd like to also include some other changes alongside it

@mswezey23
Copy link

Thank you for fixing this! Upgraded from 0.37.1 to 0.45. Worked like a charm! 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants