How do i get userinfo endpoint to return username?

So I’ve read in the authentication api docs that I can get user info from the /userinfo end-point, but the response that I get from said end-point does not match the sample given in the documentation, even though I’ve used openid, email, and profile scope. how do I get atleast the preferred_username as seen in the response sample in the documentation?

Authentication API Explorer this is the documentation that I read

Hey there @j.sach welcome to the community!

Thanks for pointing this out - preferred_username doesn’t exist as an attribute on the Auth0 profile. I think that might just be an example of a custom claim, where preferred_username is added to an ID token using the event.user.username:

exports.onExecutePostLogin = async (event, api) => {

  if (event.authorization) {
    api.idToken.setCustomClaim('preferred_username', event.user.username);

That should get the username in the ID token and subsequently in the /userinfo response. This assumes a connection has been configured to require a username in the first place.

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