How to get org_id as part of access token?

  • 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 and I have decoded it and I couldn’t find any org_id in json

Hi @selvi,

Thanks for reaching out to the Auth0 Community!

I understand you want to add the org_id as a custom claim to your access token.

To do so, please make sure your Rule looks something like the following:

function (user, context, callback) {
  const namespace = '';
  context.accessToken[`${namespace}/org`] =;

  callback(null, user, context);

Once that is complete, you will get the org_id in the Access Token. I have tested this and can confirm that it works.

Please let me know if there’s anything else I can do to help.

Thank you.

Tried your solution. Refer the curl command and the error Which I got while trying to get org_id. I tried to print context (console.log(context):wink: Refer the context response below, but I don’t find organization information under the context.

// context response

tenant: 'dev-dsadsaf',
clientID: 'fsadSFA',
clientName: 'spring-with-auth0',
clientMetadata: {},
connection: 'Username-Password-Authentication',
connectionStrategy: 'auth0',
connectionID: 'con_5ivApE7L1v3Ef9UD',
connectionOptions: {},
connectionMetadata: {},
samlConfiguration: {},
jwtConfiguration: {},
protocol: 'oauth2-password',
stats: { loginsCount: 89 },
accessToken: {},
idToken: {},
locale: 'en',
request: {
userAgent: 'curl/7.58.0',
ip: '2409:4072:109:1233:5c80:2758:7910:4672',
hostname: '',
body: {
grant_type: 'password',
username: 'USERNAME',
audience: '',
client_id: '743r24twrt',
scope: 'openid',
client_secret: '56Euiegongdndni',
connection: 'Username-Password-Authentication'
geoip: {
country_code: 'IN',
country_code3: 'IND',
country_name: 'India',
city_name: 'Chennai',
latitude: 12.8996,
longitude: 80.2209,
time_zone: 'Asia/Kolkata',
continent_code: 'AS'
authorization: { roles: [ 'role-a' ] }
hobby: 'surfing',
preferred_contact: 'email',
favorite_color: 'blue',
tenant_name: 'dev-dsadsaf'
{ plan: 'full' }

// code
context.accessToken[${namespace}/org] =;

 curl --request POST   --url ''   --header 'content-type: application/x-www-form-urlencoded'   --data grant_type=password   --data username=username   --data password=pwd   --data audience=   --data 'client_id=savdhsvfdvf'   --data   scope=openid profile user_metadata app_metadata   --data client_secret=5rerheu

{"error":"access_denied","error_description":"Cannot read property 'id' of undefined"}

Hi @selvi,

Thank you for your response.

The reason why the context object does not contain the property is because the users did not authenticate through an organization.

To address this, you will need to authenticate users through an organization, and then the can be appended as a custom claim in the Access Token.

For example:


You can read our Work with Tokens and Organizations doc to learn more.

Please do not hesitate to reach out if you have any additional questions.

Thank you.


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