Adding Rule to add user_metadata when user logs in, don't want to use a domain as namespace

Hey, I have read the documentation but I don’t understand the purpose in the namespace within the rules. So this is my rule:

function addAttributes(user, context, callback) {
  const namespace = 'http://www.test.co.uk/';
  context.idToken[namespace + 'user_metadata'] = user.user_metadata;
  callback(null, user, context);
}

Which of course displays this when I login:

[
  "http://www.test.co.uk/user_metadata" => [...],
  "nickname" => "mlb",
  "name" => "Martyn Lee Ball",
  "picture" => "...",
  "updated_at" => "2021-01-25T17:13:50.873Z"
]

As you can see http://www.test.co.uk/user_metadata has been added and it contains the data, however all I want is user_metadata, not any crap at the start, so it would be:

[
  "user_metadata" => [...],
  "nickname" => "mlb",
  "name" => "Martyn Lee Ball",
  "picture" => "...",
  "updated_at" => "2021-01-25T17:13:50.873Z"
]

Hi @martynleeball,

Unfortunately, namespaces are required so that claims do not collide with any reserved claims or claims from other resources. You can read more about this here: Create Custom Claims

1 Like

And the namespace MUST be a URI?

It’s recommended to use a URI because 1) it follows the conventional namespace established by XML namespaces and 2) because URIs are unique, you will prevent any accidental collision. However, the namespaces can be something else other than a URI.

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