# Auth0 password grant with organization

**URL:** <https://community.auth0.com/t/auth0-password-grant-with-organization/80278>\
**Category:** Get Help\
**Tags:** organizations, password, testing\
**Created:** [March 21, 2022, 10:17pm UTC](https://community.auth0.com/t/auth0-password-grant-with-organization/80278 "2022-03-21T22:17:42Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![billyf](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/billyf/32/33224_2.png) [@billyf](https://community.auth0.com/u/billyf)\
**Post date:** [March 21, 2022, 10:17pm UTC](https://community.auth0.com/t/auth0-password-grant-with-organization/80278/1 "2022-03-21T22:17:42Z")

</div>

We would like to adopt Cypress for testing a SPA with organization enabled.

Based on my research, the recommended approach is to enable password grant and use it to get the tokens. I’m able to get it working for the path that doesn’t involve organization. But I’m not able to get an access token when an organization is involved.

> **[End-to-End Testing with Cypress and Auth0](https://auth0.com/blog/end-to-end-testing-with-cypress-and-auth0/)**
>
> Learn how to programmatically authenticate against Auth0 in your Cypress tests in a manner that adheres to both Cypress and Auth0 best pr...

I wonder if password grant type is currently supported for SPA with organization enabled. If it is supported, how to exchange an access token for an organization with password grant type via the `oauth/token` endpoint?

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [March 23, 2022, 5:00pm UTC](https://community.auth0.com/t/auth0-password-grant-with-organization/80278/3 "2022-03-23T17:00:41Z")

</div>

Hi @billyf,

Thanks for reaching out to the Auth0 Community!

I am currently looking into your observations and will follow up once I have new information.

Thank you.

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [March 23, 2022, 8:15pm UTC](https://community.auth0.com/t/auth0-password-grant-with-organization/80278/4 "2022-03-23T20:15:31Z")

</div>

Hi @billyf,

First, when using Organizations, I suggest using the Authorization Code Grant to get tokens.

In this case, you will need to [Call the Authorization Code Flow](https://auth0.com/docs/get-started/authentication-and-authorization-flow/add-login-auth-code-flow) with the `organization` query parameter. To begin the login transaction, start by calling the `/authorize` request:

```auto
https://YOUR_DOMAIN/authorize?
    response_type=code&
    client_id=YOUR_CLIENT_ID&
    redirect_uri=https://YOUR_APP/callback&
    scope=SCOPE&
    state=STATE&
    organization=ORG_ID

```

Then exchange the code for a token by calling the `/oauth/token` endpoint:

```auto
curl --request POST \
  --url 'https://YOUR_DOMAIN/oauth/token' \
  --header 'content-type: application/x-www-form-urlencoded' \
  --data grant_type=authorization_code \
  --data 'client_id=YOUR_CLIENT_ID' \
  --data client_secret=YOUR_CLIENT_SECRET \
  --data code=YOUR_AUTHORIZATION_CODE \
  --data 'redirect_uri=https://YOUR_APP/callback'

```

Once that is complete, you will have a valid access token.

Lastly, you may find our [Work with Tokens and Organizations](https://auth0.com/docs/manage-users/organizations/using-tokens) documentation useful.

Please let me know if you have any additional questions. I’d be happy to help.

Thank you.

---

<div class="post-metadata">

**Author:** ![billyf](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/billyf/32/33224_2.png) [@billyf](https://community.auth0.com/u/billyf)\
**Post date:** [March 23, 2022, 8:28pm UTC](https://community.auth0.com/t/auth0-password-grant-with-organization/80278/5 "2022-03-23T20:28:49Z")

</div>

Hi @rueben.tiow

Thanks for your answer. The authorization code flow works but it requires user interaction. The reason we need to use password grant flow is to be able to do it programmatically which is needed for the e2e test. Is there a way to get the organization access tokens programmatically with the flow and `/oauth/token` endpoint?

Thanks,

---

<div class="post-metadata">

**Author:** ![Hawxy](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/hawxy/32/21395_2.png) [@Hawxy](https://community.auth0.com/u/Hawxy)\
**Post date:** [March 24, 2022, 1:48am UTC](https://community.auth0.com/t/auth0-password-grant-with-organization/80278/6 "2022-03-24T01:48:46Z")

</div>

There isn’t at this point in time. AFAIK it’s on the Auth0 Roadmap for the end of this year.

To get over this, I combined Cypress’s new Session API with a custom Puppeteer integration to handle the login flow and then copy/store the cookies. This works fairly well.

The other option is to wait for Cypress’s Multi-domain support which should be hitting an experimental release in an upcoming update:  
[Multi-domain Support · Issue #17336 · cypress-io/cypress (github.com)](https://github.com/cypress-io/cypress/issues/17336)  
You’d be able to login to the application like a normal user once this is released.

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [December 21, 2022, 5:13pm UTC](https://community.auth0.com/t/auth0-password-grant-with-organization/80278/7 "2022-12-21T17:13:49Z")

</div>



---

<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, 5:58pm UTC](https://community.auth0.com/t/auth0-password-grant-with-organization/80278/8 "2026-02-25T17:58:37Z")

</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
