# Add org\_id to access token returned from Resource Owner Password Flow

**URL:** <https://community.auth0.com/t/add-org-id-to-access-token-returned-from-resource-owner-password-flow/102885>\
**Category:** Get Help\
**Tags:** new-universal-login-experience, login-experience\
**Created:** [March 19, 2023, 6:52pm UTC](https://community.auth0.com/t/add-org-id-to-access-token-returned-from-resource-owner-password-flow/102885 "2023-03-19T18:52:23Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![simon17](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/simon17/32/33814_2.png) [@simon17](https://community.auth0.com/u/simon17)\
**Post date:** [March 19, 2023, 6:52pm UTC](https://community.auth0.com/t/add-org-id-to-access-token-returned-from-resource-owner-password-flow/102885/1 "2023-03-19T18:52:23Z")

</div>

Hello, I’m using the Resource Owner Password Flow to obtain an access token which I then use to access my API in e2e tests with Cypress. The issue is that the access token I get back does not contain an org\_id since the Resource Owner Password Flow is not supported in the context of Organizations - however, our API requires the access token to contain an org\_id, otherwise, the user will not be allowed to access any endpoints. Is there a way to add an `org_id` to the access token returned from the Resource Owner Password Flow?

I understand that I can utilize the Authorization Code Flow which utilizes the `/authorize` endpoint in order to add an org\_id to the access token. However, this flow does not allow me to authenticate through a specific user. In this case, I need to receive an access token for a test user that I’m using in the e2e tests but I also need the token to contain an org\_id as well.

Any help/advice is greatly appreciated!

---

<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:** [March 21, 2023, 12:32am UTC](https://community.auth0.com/t/add-org-id-to-access-token-returned-from-resource-owner-password-flow/102885/3 "2023-03-21T00:32:31Z")

</div>

Hello @simon17 welcome to the community!

Unfortunately, as far I can tell this is not possible - Even if you temporarily disable organization for a specific application, and use the ROP flow + a rule to manually add a custom claim of `org_id`, you won’t be able to as `org_id` is subject to [restrictions](https://auth0.com/docs/secure/tokens/json-web-tokens/create-custom-claims#general-restrictions).

The only option I can think of while using the ROP flow is to add a custom claim with an `org_id` but naming it something else, like `org_id1` - Obviously not ideal, but an option if you can work around this in testing.

```auto
function (user, context, callback) {

    context.accessToken.org_id1 = "your_org_id";
  	context.idToken.org_id1 = "your_org_id";
  
  	return callback(null, user, context);

}

```

---

<div class="post-metadata">

**Author:** ![simon17](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/simon17/32/33814_2.png) [@simon17](https://community.auth0.com/u/simon17)\
**Post date:** [March 21, 2023, 2:52pm UTC](https://community.auth0.com/t/add-org-id-to-access-token-returned-from-resource-owner-password-flow/102885/4 "2023-03-21T14:52:59Z")

</div>

Thanks for the reply @ty.frith ! Do you know if the Auth0 team has any plans in the near future to enable the support of Organizations in the ROP flow? This would be a great feature to have when it comes to have.

---

<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:** [March 21, 2023, 4:22pm UTC](https://community.auth0.com/t/add-org-id-to-access-token-returned-from-resource-owner-password-flow/102885/5 "2023-03-21T16:22:07Z")

</div>

Hey @simon17 no problem, I’m happy to help where I can!

ROPG support for organizations is on the radar (primarily for testing purposes similar to your needs), but there are no plans to support in the near future. I do however recommend creating a [feedback request](https://community.auth0.com/c/feedback/95) for this as I don’t currently see anything related. It would be good to have it on record and the more votes it gets from community members the more likely it is to get attention.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [April 4, 2023, 4:23pm UTC](https://community.auth0.com/t/add-org-id-to-access-token-returned-from-resource-owner-password-flow/102885/7 "2023-04-04T16:23:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![nik.baleca](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/nik.baleca/32/68749_2.png) [@nik.baleca](https://community.auth0.com/u/nik.baleca)\
**Post date:** [February 25, 2026, 6:00pm UTC](https://community.auth0.com/t/add-org-id-to-access-token-returned-from-resource-owner-password-flow/102885/8 "2026-02-25T18:00:15Z")

</div>

Hi everyone!

In the context of performing automated tests in the context of organizations, it can be a difficult task since the usual [ROPG grant flow](https://auth0.com/docs/get-started/authentication-and-authorization-flow/resource-owner-password-flow) cannot be enabled.

However, this can be resolved by using a [Custom Token Exchange Trigger](https://auth0.com/docs/customize/actions/explore-triggers/signup-and-login-triggers/custom-token-exchange-trigger) in which you will be able to set the organization as seen in this [example](https://auth0.com/docs/customize/actions/explore-triggers/signup-and-login-triggers/custom-token-exchange-trigger/custom-token-exchange-api-object#api-authentication-setorganization-organization):

```auto
exports.onExecuteCustomTokenExchange = async (event, api) => {

  // 1. Validate subject_token
  const subject_token = await validateToken(event.transaction.subject_token, jwksUri);

  // 2. Apply your authorization policy on the user
  const isAuthorized = await authorizeAccess(subject_token.sub);
  if (!isAuthorized) {
    api.access.deny('Unauthorized_login', 'User cannot login due to reason: X');
  }

  // 3. Set the user for the transaction
  api.authentication.setOrginzation('org_xS525r979AS33MSf');

  // 4. Set the user for the transaction. You may also use setUserByConnection()
  api.authentication.setUserById(subject_token.sub);

  return;
};

```

Hope this helps anybody who stumbles across the same issue!

Kind Regards,  
Nik
