# Progammatic login into organization

**URL:** <https://community.auth0.com/t/progammatic-login-into-organization/117344>\
**Category:** Get Help\
**Tags:** other, test\
**Created:** [September 28, 2023, 11:55am UTC](https://community.auth0.com/t/progammatic-login-into-organization/117344 "2023-09-28T11:55:10Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![felix4](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/felix4/32/61986_2.png) [@felix4](https://community.auth0.com/u/felix4)\
**Post date:** [September 28, 2023, 11:55am UTC](https://community.auth0.com/t/progammatic-login-into-organization/117344/1 "2023-09-28T11:55:10Z")

</div>

As this thread was closed: [Auth0 password grant with organization - #4 by rueben.tiow](https://community.auth0.com/t/auth0-password-grant-with-organization/80278/4)

@Hawxy you mentioned it’s on the Auth0 Roadmap for the end of 2022. Any update on this? Can’t find documentation about it. It was closed by @konrad.sopala so I assume it is solved?

---

<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:** [September 28, 2023, 2:07pm UTC](https://community.auth0.com/t/progammatic-login-into-organization/117344/2 "2023-09-28T14:07:57Z")

</div>

> [@felix4](#):
>
> you mentions it’s on the Auth0 Roadmap for the end of 2022. Any update on this?

M2M tokens w/ Organizations is actively being worked on, I’ve been involved with some user research aspects. If you’re on an enterprise plan you can reach out to TAM for more information.

---

<div class="post-metadata">

**Author:** ![felix4](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/felix4/32/61986_2.png) [@felix4](https://community.auth0.com/u/felix4)\
**Post date:** [September 29, 2023, 6:11am UTC](https://community.auth0.com/t/progammatic-login-into-organization/117344/3 "2023-09-29T06:11:59Z")

</div>

Thanks for the quick reply. Unfortunately we are not on an enterprise plan.

---

<div class="post-metadata">

**Author:** ![john22](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/john22/32/54605_2.png) [@john22](https://community.auth0.com/u/john22)\
**Post date:** [February 6, 2024, 8:29pm UTC](https://community.auth0.com/t/progammatic-login-into-organization/117344/4 "2024-02-06T20:29:10Z")

</div>

I’m also curious about updates - just ran into this same problem.

---

<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:59pm UTC](https://community.auth0.com/t/progammatic-login-into-organization/117344/5 "2026-02-25T17:59:53Z")

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

---

<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:** [March 11, 2026, 6:00pm UTC](https://community.auth0.com/t/progammatic-login-into-organization/117344/6 "2026-03-11T18:00:10Z")

</div>

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