Get user_metadata in jwt

Hi @SaqibHussain

How can i obtain the user_metadata in the id token?
i’ve tried this:
context.idToken["mydomainnamespace/user_metadata"] = user.user_metadata;

but when i go to jwt.io to decode the token, the user_metadata doesn’t appear.

Please advise.

Regards,
Jerry

Hi @jerryforcode

You’re on the right lines there, you’ll need to specify the property/object you want to extract e.g. with user_metadata like this:

{
  "preferences": {
    "year": "1985",
    "genre": "family"
  }
}

You might have a rule like this to extract the preferences:

function (user, context, callback) {
	if((user.user_metadata || {} ).preferences){
		context.idToken['https://mynamespace/preferences'] = user.user_metadata.preferences;
	}
	callback(null, user, context);
}

I hope this helps.
Regards

1 Like

thank you for clarifying that!

2 Likes

We are here for you!

1 Like