# How do i get userinfo endpoint to return username?

**URL:** <https://community.auth0.com/t/how-do-i-get-userinfo-endpoint-to-return-username/109636>\
**Category:** Get Help\
**Tags:** user-profile, users, user-management, management-api\
**Created:** [June 21, 2023, 3:43am UTC](https://community.auth0.com/t/how-do-i-get-userinfo-endpoint-to-return-username/109636 "2023-06-21T03:43:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![j.sach](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/j.sach/32/46565_2.png) [@j.sach](https://community.auth0.com/u/j.sach)\
**Post date:** [June 21, 2023, 3:43am UTC](https://community.auth0.com/t/how-do-i-get-userinfo-endpoint-to-return-username/109636/1 "2023-06-21T03:43:30Z")

</div>

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](https://auth0.com/docs/api/authentication#get-user-info) this is the documentation that I read

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [June 30, 2023, 12:44am UTC](https://community.auth0.com/t/how-do-i-get-userinfo-endpoint-to-return-username/109636/3 "2023-06-30T00:44:10Z")

</div>

Hey there @j.sach welcome to the community!

> [@j.sach](#):
>
> 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.

Thanks for pointing this out - `preferred_username` doesn’t exist as an attribute on the [Auth0 profile](https://auth0.com/docs/manage-users/user-accounts/user-profiles/user-profile-structure). 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`:

```auto
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](https://auth0.com/docs/authenticate/database-connections/require-username#require-username) in the first place.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [July 14, 2023, 12:45am UTC](https://community.auth0.com/t/how-do-i-get-userinfo-endpoint-to-return-username/109636/4 "2023-07-14T00:45:08Z")

</div>

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