# How to get user meta from /userinfo endpoint?

**URL:** <https://community.auth0.com/t/how-to-get-user-meta-from-userinfo-endpoint/106000>\
**Category:** Get Help\
**Tags:** login-experience, new-universal-login-experience\
**Created:** [May 2, 2023, 4:54pm UTC](https://community.auth0.com/t/how-to-get-user-meta-from-userinfo-endpoint/106000 "2023-05-02T16:54:06Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![kkrp1](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@kkrp1](https://community.auth0.com/u/kkrp1)\
**Post date:** [May 2, 2023, 4:54pm UTC](https://community.auth0.com/t/how-to-get-user-meta-from-userinfo-endpoint/106000/1 "2023-05-02T16:54:06Z")

</div>

Hey everyone,

I’m trying to work out how to get user meta data as part of the profile returned by `/userinfo`.

[This article](https://auth0.com/docs/manage-users/user-accounts/metadata) aludes to it being possible but IMO does a pretty poor job of explaining the steps.

It says:

> You can also use the [GET `/userinfo` endpoint](https://auth0.com/docs/api/authentication#get-user-info) to get a user’s `user_metadata`, however, you must first write a Rule to copy `user_metadata` properties to the ID token.

That last sentence could definitely do with some elaboration. In any case, I went to Rules, created a rule from the “Move user metadata attributes to profile root attributes” template. I saved it. But I still don’t get user meta returned in the profile.

The same article also says:

> Use the Auth0 Dashboard to configure application metadata which contains key/value pairs. To learn more, read [Configure Application Metadata](https://auth0.com/docs/get-started/applications/configure-application-metadata).

…suggesting (or at least I inferred) that it’s possible to instruct the application to pull in user meta via the Dashboard \> Applications area. But again there’s no elaboration here.

What’s the best way to pull in user meta to the profile response from `/userinfo`?

Many thanks in advance for any help.

---

<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:** [May 2, 2023, 10:35pm UTC](https://community.auth0.com/t/how-to-get-user-meta-from-userinfo-endpoint/106000/3 "2023-05-02T22:35:01Z")

</div>

Hey again @kkrp1 !

> [@kkrp1](#):
>
> That last sentence could definitely do with some elaboration. In any case, I went to Rules, created a rule from the “Move user metadata attributes to profile root attributes” template. I saved it. But I still don’t get user meta returned in the profile.

I would use a [post-login Action](https://auth0.com/docs/customize/actions/flows-and-triggers/login-flow) to add custom meta\_data claims to tokens instead - I just verified the following works:

```auto
exports.onExecutePostLogin = async (event, api) => {
  const namespace = 'https://my-app.example.com';
  if (event.authorization) {
    api.idToken.setCustomClaim(`${namespace}/user_metadata`, event.user.user_metadata);
    api.idToken.setCustomClaim(`${namespace}/app_metadata`, event.client.metadata);
  }
};

```

Some more on custom claims in general:

[https://community.auth0.com/t/adding-custom-claims-to-tokens/84590](https://community.auth0.com/t/adding-custom-claims-to-tokens/84590)

Hope this helps!

---

<div class="post-metadata">

**Author:** ![kkrp1](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@kkrp1](https://community.auth0.com/u/kkrp1)\
**Post date:** [May 4, 2023, 10:09am UTC](https://community.auth0.com/t/how-to-get-user-meta-from-userinfo-endpoint/106000/4 "2023-05-04T10:09:38Z")

</div>

Thanks for this! That works. Am I right that this should expose the meta data to the user info endpoint, rather than include the user meta directly within the JWT? That latter point would be great, as it would mean I don’t have to make an API call to Auth0 at all, but perhaps that’s not the done thing and again suggests my ignorance of JWT general practice!

---

<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:** [May 4, 2023, 9:55pm UTC](https://community.auth0.com/t/how-to-get-user-meta-from-userinfo-endpoint/106000/5 "2023-05-04T21:55:47Z")

</div>

No problem!

> [@kkrp1](#):
>
> Am I right that this should expose the meta data to the user info endpoint, rather than include the user meta directly within the JWT?

Yes, if you have the action code above configured to run on login then the metadata _should_ be available in both the token(s) as well as userinfo.

---

<div class="post-metadata">

**Author:** ![kkrp1](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@kkrp1](https://community.auth0.com/u/kkrp1)\
**Post date:** [May 9, 2023, 9:35am UTC](https://community.auth0.com/t/how-to-get-user-meta-from-userinfo-endpoint/106000/6 "2023-05-09T09:35:41Z")

</div>

Right, thanks. Is it possible (and this is probably my JWT noobness talking) to get the user meta added directly to the JWT, so I don’t even have to make the call to `/userinfo`?

---

<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:** [May 10, 2023, 12:28am UTC](https://community.auth0.com/t/how-to-get-user-meta-from-userinfo-endpoint/106000/7 "2023-05-10T00:28:07Z")

</div>

That’s exactly what the code referenced above does - It adds existing user/app metadata as custom claims to tokens. Therefore you can get this directly from the jwt itself:

> [@How to get user meta from /userinfo endpoint?](https://community.auth0.com/t/how-to-get-user-meta-from-userinfo-endpoint/106000/3):
>
> Hey again @kkrp1 ! I would use a [post-login Action](https://auth0.com/docs/customize/actions/flows-and-triggers/login-flow) to add custom meta\_data claims to tokens instead - I just verified the following works: exports.onExecutePostLogin = async (event, api) =\> { const namespace = 'https://my-app.example.com'; if (event.authorization) { api.idToken.setCustomClaim(`${namespace}/user_metadata`, event.user.user\_metadata); api.idToken.setCustomClaim(`${namespace}/app_metadata`, event.client.metadata); } }; Some more on custom claims in general: Hop…

---

<div class="post-metadata">

**Author:** ![kkrp1](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@kkrp1](https://community.auth0.com/u/kkrp1)\
**Post date:** [May 11, 2023, 12:00pm UTC](https://community.auth0.com/t/how-to-get-user-meta-from-userinfo-endpoint/106000/8 "2023-05-11T12:00:17Z")

</div>

Hmm, that’s not my experience currently. What the code you provided _did_ do was make the user meta suddenly available within the response to `/userinfo`. The JWT itself does not contain any meta data, so far as I can see.

To be clear, here’s what I’m doing.

```auto
	(async () => {

		//get client
		const auth0Client = await auth0.createAuth0Client({
			domain: ' ******',
			clientId: ' ******',
			cacheLocation: 'localstorage',
			authorizationParams: {
				redirect_uri: window.location.origin,
				audience: ' ******'
			}
		})

		//on login callback, strip out A0 QS params
		if (location.search.includes('state=') && (
			location.search.includes('code=') || 
			location.search.includes('error='))
		) {
			await auth0Client.handleRedirectCallback();
			window.history.replaceState({}, document.title, '/');
		}

		//logged in? Get auth token
		const isAuthenticated = await auth0Client.isAuthenticated();
		let token;
		if (isAuthenticated) token = await auth0Client.getTokenSilently({aud: ' ******'});

		//...

```

This produces a JWT which, when run through [jwt.io](http://jwt.io), contains the below. Notice it doesn’t have the user meta in the payload, which is what I’m asking and I believe your previous reply said should be there.

 ![image](https://global.discourse-cdn.com/auth0/original/3X/a/a/aa02a947e51fe4c01a76cca973569598cc5db0fc.png)

The user meta doesn’t show up until I then use that token to call `getUser()`, which of course involves an API request to Auth0.

---

<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:** [December 22, 2023, 11:53pm UTC](https://community.auth0.com/t/how-to-get-user-meta-from-userinfo-endpoint/106000/9 "2023-12-22T23:53:13Z")

</div>


