auth0/go-auth0

SDK is expecting different JSON schema for ListAuthenticationMethods API endpoint

mparz111 opened this issue · 7 comments

Checklist

  • I have looked into the README and have not found a suitable solution or answer.
  • I have looked into the documentation and have not found a suitable solution or answer.
  • I have searched the issues and have not found a suitable solution or answer.
  • I have upgraded to the latest version of this SDK and the issue still persists.
  • I have searched the Auth0 Community forums and have not found a suitable solution or answer.
  • I agree to the terms within the Auth0 Code of Conduct.

Description

The Auth0 Go SDK is expecting a different JSON schema than what is returned from the API for the ListAuthenticationMethods API endpoint.

Response sample from Management API V2 endpoint:

[
    {
        "id": "phone|dev_sampleid",
        "type": "phone",
        "confirmed": true,
        "phone_number": "XXXXXXXX1234",
        "created_at": "2023-07-13T20:24:42.388Z",
        "last_auth_at": "2023-07-13T20:28:49.095Z",
        "preferred_authentication_method": "sms",
        "authentication_methods": [
            {
                "id": "sms|dev_sampleid",
                "type": "sms"
            }
        ]
    }
]

Error message from Auth0 Management GO SDK Call:

failed to unmarshal response payload: json: cannot unmarshal array into Go value of type management.AuthenticationMethodList

Expectation

The SDK is expecting a wrapping authenticators parent object wrapping around the array of authentication methods, for example:


{
    "authenticators": [
      {
          "id": "phone|dev_sampleid",
          "type": "phone",
          "confirmed": true,
          "phone_number": "XXXXXXXX1234",
          "created_at": "2023-07-13T20:24:42.388Z",
          "last_auth_at": "2023-07-13T20:28:49.095Z",
          "preferred_authentication_method": "sms",
          "authentication_methods": [
              {
                  "id": "sms|dev_sampleid",
                  "type": "sms"
              }
          ]
      }
   ]
}

I would expect the SDK to be able to handle the latest version of the Auth0 Management API.

Reproduction

  1. Given a user who is enrolled with one or more Authentication factors in an Auth0 Tenant.
  2. When you call the ListAuthenticationMethods function, providing the user ID from step 1, then ....
  3. You receive the error "failed to unmarshal response payload: json: cannot unmarshal array into Go value of type management.AuthenticationMethodList"

Auth0 Go SDK version

0.17.2

Hey @mparz111, thank you for raising this issue.

We've investigated this and it appears that the root cause is the API no longer returning the expected structure when include_totals is set. This has been escalated to the relevant team and we're waiting on a fix.

I'll leave this issue open until I can provide some further feedback.

MFFoX commented

@ewanharris Thanks for the response. Can you provide a sample curl request to Management API endpoint that responds with the json structure that the SDK is expecting? I am wanting to make sure I understand this functionality.

@MFFoX, unfortunately because of the issue mentioned it's not possible to currently get the data in the expected response format. However, an example curl that would correspond to this normally is https://<auth0-domain>/api/v2/users/<user-id>/authentication-methods?include_totals=true&per_page=50, it's the addition of the include_totals (that the Go SDK expects) that changes the response format.

It is similar to the format mentioned in the issue body, with the addition of pagination data, you can find all potential properties for the different authentication methods in the API docs

{
    "authenticators": [
        {
            "id": "email|dev_test",
            "type": "email",
            "confirmed": true,
            "name": "Test",
            "email": "chuc****@exam*******",
            "created_at": "2023-03-10T16:25:51.113Z"
        }
    ],
    "total": 1,
    "start": 0,
    "limit": 50
}

@mparz111 @MFFoX, just a heads up that the fix for the change in response should be rolling out to all environments so I believe this issue should now be resolved.

Thanks @ewanharris!

Was the fix made with the API or the SDK?

This was an API side fix to restore the pagination headers in the response

Closing this issue out now as it's resolved.