I need to get user metadata in a Go middleware function.
I followed the Go SDK quickstart and have the profile
in the request context.
Here are the steps I’m taking. And where it’s going wrong.
Create a new management API instance:
auth0Api, err := management.New(
auth0Domain,
management.WithClientCredentials(ctx, auth0ClientId, auth0ClientSecret),
)
Get the userID in the middleware:
id := profile["sub"]
Everything works up to now. This is how I’m trying to get the user metadata with the management API.
user, err := auth0Api.User.Read(
ctx,
id, // The id returned from profile["sub"]
management.IncludeFields("user_metadata", "app_metadata"),
)
This request fails to send. It appears to be sending a get request to https://auth0domain/api/v2/users/userId
and a post request to https://auth0domain/oauth/token
in the stack trace.
I got most of what I’ve done with the documentation at GitHub - auth0/go-auth0: Go SDK for the Auth0 Management API. and reading the definitions in the library.
But I’m struggling to find any examples on how to make this request.
What am I doing wrong?
What’s the correct way to get the user metadata?