Can't retrieve user metadata using any Swift API

I am logged in using openid profile email offline_access read:users scope.
When signing in, I add given_name and family_name fields to user_metadata.

When retrieving user data using userinfo endpoint I don’t get any of above values in response, even though they are available in the code, but they are empty (nil), only basic values like id, email and pic URL are coming in response. So authentication header, basically, works, but some fields remain nil even though I filled them on sign up.

At the same time - when trying to retrieve user data using Users.get() API that uses users endpoint I am getting this error: {"statusCode":400,"error":"Bad Request","message":"Bad HTTP authentication header format","errorCode":"Bearer"} for no obvious reason since I am logging in with read:users scope included in the token.

This is basically the code I am using:

private let usernamePasswordConnection = "Username-Password-Authentication"

private let scope = "openid profile email offline_access read:users"

let credentials = try await Auth0
      .authentication
      .login(usernameOrEmail: email, password: password, realmOrConnection: usernamePasswordConnection, scope: scope)
      .start()

// accessToken is now in credentials, all good

credentialsManager.store(credentials: credentials)

// Now retrieving the user info:

let request = Auth0
     .users(token: credentials.accessToken)
     .get(user.id, fields: ["user_metadata"], include: true)

let meta = try await request.start()

// getting the {"statusCode":400,"error":"Bad Request","message":"Bad HTTP authentication header format","errorCode":"Bearer"} error

Hey @oleh.naumenko !

Currently, you are able to get data from /userinfo endpoint successfully, it just doesn’t include the metadata?

yes, /userinfo endpoint is responding successfully returning basic user info and leaving fields like givenName and familyName blank (nil), even though I filled them in user meta data during registration.

1 Like

Thanks for clarifying!

Have you added the metadata to the ID token similar to what’s outlined here:

Yes, it worked, but point of this post is that /users endpoint doesn’t work, I mentioned /usermetadata example to indicate that my setup generally works and that it’s not a basic authentication problem.

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.