> ## Documentation Index
> Fetch the complete documentation index at: https://docs.openhands.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Map Identity Provider Groups to Organizations

> Add users to OpenHands Enterprise organizations automatically, based on their Okta or other identity provider groups, when they sign in with SSO.

Map groups in your identity provider (IdP), such as Okta, to OpenHands organizations. When a user signs in through the
provider, OpenHands adds them as a `Member` of each organization that is mapped to one of their groups. You then manage
organization membership in your IdP instead of adding each user by hand.

## Prerequisites

* You run OpenHands Enterprise 0.113.0 or later.
* [Auth V2](https://docs.openhands.dev/enterprise/auth-v2/overview.md) is enabled, and you added your IdP directly on the `Auth Providers` page with
  the `Okta OIDC`, `Generic OAuth / OIDC`, or `Generic SAML` preset. See
  [Configure Auth Providers](https://docs.openhands.dev/enterprise/auth-v2/configure-providers.md).
* You are a Super Admin.
* The organizations you want to map to exist. See
  [Manage Organizations](https://docs.openhands.dev/enterprise/super-admin.md#manage-organizations).
* Administrator access to your IdP, so you can add a groups claim or attribute to the application.

## How Group Mapping Works

Each mapping pairs one IdP group with one organization. OpenHands checks the mappings each time a user signs in:

* **Groups come from the `groups` claim or attribute**: The IdP must send the user's groups in an OIDC claim or a SAML
  attribute named `groups`. OpenHands reads the claim from the provider's userinfo response, or from the ID token when
  the provider has no `Userinfo URL`.
* **Groups match exactly**: The group in the mapping must match the value your IdP sends, including case. Okta sends
  group names. Microsoft Entra ID sends group object IDs, so use the object ID as the group.
* **Users join as members**: A user in a mapped group joins that organization with the `Member` role. A user in several
  groups that map to the same organization joins it once.
* **Existing memberships don't change**: If the user already belongs to the organization, OpenHands keeps their role
  and status.
* **Users on their personal workspace switch to the organization**: A user whose current workspace is their personal
  workspace switches to the first organization they are added to, in the order the mappings are listed. A user who is
  already working in another organization stays there.
* **Access is only added**: Removing a user from a group in your IdP doesn't remove them from the organization. To
  remove access, see [Remove Access](#remove-access).
* **Changes apply at the next sign-in**: A user who is already signed in picks up a new group the next time they sign
  in, which can be up to 30 days later. To apply it right away, ask them to sign out and sign in again.

OpenHands skips a mapping whose organization was deleted or suspended.

Group mapping has no effect on providers that don't send a `groups` claim:

* **Git providers used for sign-in**: GitHub, GitLab, Bitbucket, and other Git providers with
  `Use as OpenHands Authentication Provider` turned on.
* **Keycloak providers**: The `Log in with` providers and the Enterprise SSO provider (titled `Company SSO` by default)
  that were created when you [migrated from V1](https://docs.openhands.dev/enterprise/auth-v2/migrate-from-v1.md). These sign in through Keycloak,
  which doesn't send groups. This includes the V1 [SAML SSO](https://docs.openhands.dev/enterprise/integrations/saml-sso.md) setup.

To use group mapping with one of these setups, add your IdP directly with the `Okta OIDC`, `Generic OAuth / OIDC`, or
`Generic SAML` preset.

## Send Groups From Your Identity Provider

> [tab] Okta OIDC
>
> 1. In the Okta Admin Console, open your OpenHands OIDC app and go to the `Sign On` tab.
> 2. In `OpenID Connect ID Token`, select `Edit`.
> 3. Set `Groups claim type` to `Filter`, and set the claim name to `groups`.
> 4. Choose a filter that matches only the groups you want to map, for example `Starts with` `OpenHands-`, then save.
>    The filter must match no more than 100 of a user's groups.
> 5. In OpenHands, open the Okta provider on the `Auth Providers` page and add `groups` to `Scopes`. For example:
>    `openid email offline_access groups`.
> 6. Select `Save Changes`.
>
> The `Okta OIDC` preset doesn't request the `groups` scope, so you must add it.
>
> If you use an Okta custom authorization server instead, follow these steps in place of the steps above:
>
> 1. In OpenHands, change `Authorization URL`, `Token URL`, and `Userinfo URL` to your authorization server's
>    endpoints, for example `https://YOUR_DOMAIN.okta.com/oauth2/default/v1/authorize`. Use your authorization server
>    ID in place of `default` if you don't use the default server.
> 2. In the Okta Admin Console, open your authorization server and add a claim named `groups`. Set the token type to
>    `ID Token`, the value type to `Groups`, and a filter that matches no more than 100 of a user's groups, for example
>    `Starts with` `OpenHands-`.
> 3. Add `groups` to `Scopes` in OpenHands only if your authorization server defines a `groups` scope.

> [tab] Okta SAML
>
> 1. In the Okta Admin Console, open your OpenHands SAML app and edit its SAML settings.
> 2. Add a group attribute statement with the name `groups`.
> 3. Choose a filter that matches the groups you want to map, for example `Starts with` `OpenHands-`, then save.
>
> OpenHands reads the `groups` attribute as it is sent. The provider's `Attribute Mapping` setting doesn't apply to
> groups.

> [tab] Other Providers
>
> Configure your IdP to send the user's groups in a claim (OIDC) or attribute (SAML) named `groups`. The value can be a
> list of groups or a single group.
>
> For an OIDC provider, add the scope that releases the groups claim, if your IdP requires one, to the provider's
> `Scopes` in OpenHands.

## Add Group Mappings

> [!WARNING]
>
> Map groups only on providers that you control and that serve only your own organization. OpenHands trusts the groups
> that the provider sends, so anyone who can set group names in a shared or multi-tenant IdP could add themselves to a
> mapped organization.

1. Open the Super Admin dashboard and choose `Auth Providers`.
2. Open your login provider from the row menu.
3. In `Group to Organization Mapping`, select `Add Mapping`.
4. In `Identity Provider Group`, enter the group exactly as your IdP sends it, for example `OpenHands-Platform`.
5. In `Organization`, choose the organization that members of the group join.
6. Repeat for each group, then select `Save Changes`.

`Save Changes` stays disabled while a mapping has a group but no organization, or an organization but no group. To
delete a mapping, select `Remove` on its row and save.

The `Group to Organization Mapping` section appears on SAML providers and on OAuth providers that have
`Use as OpenHands Authentication Provider` turned on. It has no effect on Git login providers or on providers that sign
in through Keycloak. See [How Group Mapping Works](#how-group-mapping-works).

## Check the Result

1. Open OpenHands in a private browser window and sign in as a user who is in a mapped group.
2. Open the organization selector. The user should be a member of the mapped organization.

If the user wasn't added, check that the IdP sends the `groups` claim or attribute and that the group matches exactly.
For OIDC providers, also check that `Scopes` includes the scope that releases groups.

## Remove Access

Group mappings never remove a membership. To keep a user out of a mapped organization while they are still in the
group, go to `Users` in the Super Admin dashboard and suspend their membership in that organization. OpenHands keeps a
suspended membership as it is when the user signs in again. See [Manage Users](https://docs.openhands.dev/enterprise/super-admin.md#manage-users).

If you remove the membership instead, OpenHands adds the user again at their next sign-in while they are still in the
group.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.