How to get org_id as part of access token using Auth0?

Viewed 91
  • I am try to get get org_id While generating using UserNamePassword authentication?
  • I have added rule as below
context.accessToken[namespace + 'org'] = context.organization;
  • After generating access token I have decoded it and I couldn't find org_id in json response
1 Answers

Does namespace have a valid value e.g. http://www.myexample.com/org_id? If not it might be getting silently excluded

By default, Auth0 always enforces namespacing; any custom claims with non-namespaced identifiers will be silently excluded from tokens and silently ignored in Actions and Rules.

https://auth0.com/docs/secure/tokens/json-web-tokens/create-namespaced-custom-claims

You can debug these rules quite easily by adding some debug statements to your rule e.g. console.log(namespace + 'org') and installing and running the Real-time Webtask Logs extension

Finally, here's a full Rule example for adding a custom claim to access token:

function addAttributes(user, context, callback) {
  const namespace = configuration.Namespace;
  context.accessToken[`${namespace}org_id`] = 'test';
  callback(null, user, context);
}

note: configuration.Namespace is a rule setting with a value of something like http://www.myexample.com/

Related