# Setting up OpenID Connect integration with OpenSearch is resulting in a 401 Unauthorized error when using Azure AD as the identity provider

**URL:** <https://forum.opensearch.org/t/setting-up-openid-connect-integration-with-opensearch-is-resulting-in-a-401-unauthorized-error-when-using-azure-ad-as-the-identity-provider/22105>\
**Category:** Security\
**Tags:** troubleshoot, configure\
**Created:** [October 25, 2024, 3:31pm UTC](https://forum.opensearch.org/t/setting-up-openid-connect-integration-with-opensearch-is-resulting-in-a-401-unauthorized-error-when-using-azure-ad-as-the-identity-provider/22105 "2024-10-25T15:31:15Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vidhu](https://avatars.discourse-cdn.com/v4/letter/v/f0a364/32.png) [@Vidhu](https://forum.opensearch.org/u/Vidhu)\
**Post date:** [October 25, 2024, 3:31pm UTC](https://forum.opensearch.org/t/setting-up-openid-connect-integration-with-opensearch-is-resulting-in-a-401-unauthorized-error-when-using-azure-ad-as-the-identity-provider/22105/1 "2024-10-25T15:31:15Z")

</div>

**Versions** (relevant - OpenSearch/Dashboard/Server OS/Browser):  
opensearch version : “2.17.1”  
opensearch dasboard : 2.17.1  
Browser : Chrome

**Describe the issue** :  
After configuring OpenID Connect in OpenSearch with Azure as the identity provider, I’m encountering a 401 Unauthorized error. I can see the Microsoft login screen, but after entering credentials, it returns a 401 error.

**Configuration** :  
config.yml

```auto
---
_meta:
  type: "config"
  config_version: 2

config:
  dynamic:
    http:
      anonymous_auth_enabled: false
    authc:
      basic_internal_auth_domain:
        description: "Authenticate via HTTP Basic against internal users database"
        http_enabled: true
        transport_enabled: true
        order: 0 # Must set to 1 to prevent logs flooding with warnings
        http_authenticator:
          type: basic
          challenge: false
        authentication_backend:
          type: internal
      openid_auth_domain:
        http_enabled: true
        transport_enabled: true
        order: 1
        http_authenticator:
          type: openid
          challenge: false
          config:
            enable_ssl: true
            verify_hostnames: false
            subject_key: preferred_username
            roles_key: groups
            openid_connect_url: https://login.microsoftonline.com/f98dce6e-1a76-47b2-b1fa-21ab2df162c7/v2.0/.well-known/openid-configuration
        authentication_backend:
          type: noop

```

opensearch\_dashboard.yml

```auto
opensearch.hosts: [https://localhost:9200]
opensearch.ssl.verificationMode: none
opensearch.username: admin
opensearch.password: <password>
opensearch.requestHeadersWhitelist: [authorization, securitytenant]

opensearch_security.multitenancy.enabled: true
opensearch_security.multitenancy.tenants.preferred: [Private, Global]
opensearch_security.readonly_mode.roles: [kibana_read_only]

opensearch_security.auth.multiple_auth_enabled: true
opensearch_security.auth.type: ["openid", "basicauth"]
# opensearch_security.auth.type: "openid"
# The IdP metadata endpoint
opensearch_security.openid.connect_url: "https://login.microsoftonline.com/<tenant-id>/v2.0/.well-known/openid-configuration"
opensearch_security.openid.base_redirect_url: "http://localhost:5601"
opensearch_security.openid.trust_dynamic_headers: true
# The ID of the OpenID Connect client in your IdP
opensearch_security.openid.client_id: <client-id>

# The client secret of the OpenID Connect client
opensearch_security.openid.client_secret: <client-sec>
opensearch_security.openid.scope: "openid"
opensearch_security.openid.header: "Authorization"
# Use this setting if you are running opensearch-dashboards without https
opensearch_security.cookie.secure: false
server.host: "0.0.0.0"

```

**Relevant Logs or Screenshots** :

 ![Screenshot 2024-10-25 at 11.28.09 AM](https://us1.discourse-cdn.com/flex019/uploads/mauve_hedgehog/original/2X/3/3c5e3dd652245f2a2ddd9df612003b593509e162.png)

---

<div class="post-metadata">

**Author:** ![Mantas](https://avatars.discourse-cdn.com/v4/letter/m/7bcc69/32.png) [@Mantas](https://forum.opensearch.org/u/Mantas)\
**Post date:** [October 30, 2024, 10:46am UTC](https://forum.opensearch.org/t/setting-up-openid-connect-integration-with-opensearch-is-resulting-in-a-401-unauthorized-error-when-using-azure-ad-as-the-identity-provider/22105/2 "2024-10-30T10:46:42Z")

</div>

Hi @Vidhu,

How are you mapping OpenSearch permission to your users authenticated via OpenID (individual users, back-end roles, etc.)?

best,  
mj

---

<div class="post-metadata">

**Author:** ![Vidhu](https://avatars.discourse-cdn.com/v4/letter/v/f0a364/32.png) [@Vidhu](https://forum.opensearch.org/u/Vidhu)\
**Post date:** [October 30, 2024, 1:25pm UTC](https://forum.opensearch.org/t/setting-up-openid-connect-integration-with-opensearch-is-resulting-in-a-401-unauthorized-error-when-using-azure-ad-as-the-identity-provider/22105/3 "2024-10-30T13:25:01Z")

</div>

Hi @Mantas ,

I’ve uploaded my latest `config.yml` file. I’m trying to retrieve the groups that a user belongs to. I have a user in Entra ID who is a member of over 200 groups, and I’d like to pull those groups. Could you guide me on how to map them?

Now I am able to login not getting 401, but I cant retrieve the groups

Additionally, is there a way to retrieve the access token upon login?

---

<div class="post-metadata">

**Author:** ![Mantas](https://avatars.discourse-cdn.com/v4/letter/m/7bcc69/32.png) [@Mantas](https://forum.opensearch.org/u/Mantas)\
**Post date:** [October 30, 2024, 1:41pm UTC](https://forum.opensearch.org/t/setting-up-openid-connect-integration-with-opensearch-is-resulting-in-a-401-unauthorized-error-when-using-azure-ad-as-the-identity-provider/22105/4 "2024-10-30T13:41:22Z")

</div>

@Vidhu, the JWT passed from your IDp (to OS) will have groups for the user, you will need to use `roles_key` to assign them as backend role(s) and use the backend roles to map OS roles to a user:

sample of config (I see you already added `roles_key: groups`):

```auto
      openid_auth_domain:
        http_enabled: true
        transport_enabled: true
        order: 1
        http_authenticator:
          type: openid
          challenge: false
          config:
            enable_ssl: true
            verify_hostnames: false
            subject_key: preferred_username
            roles_key: groups
            openid_connect_url: https://login.microsoftonline.com/f98dce6e-1a76-47b2-b1fa-21ab2df162c7/v2.0/.well-known/openid-configuration
        authentication_backend:
          type: noop

```

roles: [Modifying the YAML files - OpenSearch Documentation](https://opensearch.org/docs/latest/security/configuration/yaml/#rolesyml)

```auto
role-x:
  cluster_permissions:
    - "cluster_composite_ops_ro" 
  index_permissions:
    - index_patterns:
        - "index-*"
      allowed_actions:
        - "read"

```

roles mapping: [Modifying the YAML files - OpenSearch Documentation](https://opensearch.org/docs/latest/security/configuration/yaml/#roles_mappingyml)

```auto
role-x:
  reserved: true
  hidden: false
  backend_roles:
  - "role-from-groups"
  hosts: []
  users: []
  and_backend_roles: []
kibana_user:
  reserved: false
  hidden: false
  backend_roles:
  - "kibanauser"
  - "role-from-groups"
  hosts: []
  users: []
  and_backend_roles: []
  description: "Maps kibanauser to kibana_user"

```

best,  
mj

---

<div class="post-metadata">

**Author:** ![Mantas](https://avatars.discourse-cdn.com/v4/letter/m/7bcc69/32.png) [@Mantas](https://forum.opensearch.org/u/Mantas)\
**Post date:** [October 30, 2024, 1:42pm UTC](https://forum.opensearch.org/t/setting-up-openid-connect-integration-with-opensearch-is-resulting-in-a-401-unauthorized-error-when-using-azure-ad-as-the-identity-provider/22105/5 "2024-10-30T13:42:03Z")

</div>

@Vidhu, Do you have a sample JWT that is sent to OS?

---

<div class="post-metadata">

**Author:** ![Vidhu](https://avatars.discourse-cdn.com/v4/letter/v/f0a364/32.png) [@Vidhu](https://forum.opensearch.org/u/Vidhu)\
**Post date:** [October 30, 2024, 2:02pm UTC](https://forum.opensearch.org/t/setting-up-openid-connect-integration-with-opensearch-is-resulting-in-a-401-unauthorized-error-when-using-azure-ad-as-the-identity-provider/22105/6 "2024-10-30T14:02:32Z")

</div>

Hey @Mantas I am not able to figure out how to get JWT , where it be stored. Is there a way to retrieve it

---

<div class="post-metadata">

**Author:** ![Mantas](https://avatars.discourse-cdn.com/v4/letter/m/7bcc69/32.png) [@Mantas](https://forum.opensearch.org/u/Mantas)\
**Post date:** [November 4, 2024, 1:34pm UTC](https://forum.opensearch.org/t/setting-up-openid-connect-integration-with-opensearch-is-resulting-in-a-401-unauthorized-error-when-using-azure-ad-as-the-identity-provider/22105/7 "2024-11-04T13:34:22Z")

</div>

@Vidhu,

You could try something like:

```auto

	1. RESULT=$( curl -k --noproxy '*' -d 'client_id=<CLIENT ID>' -d 'username=<USERNAME>' -d 'grant_type=password' -d 'client_secret=<SECRET>' -d 'scope=openid' 'https://login.microsoftonline.com/<DOMAIN>/oauth2/v2.0/token' -d 'password=<password>')

	2. TOKEN=$(echo $RESULT | sed 's/.*access_token":"\([^"]*\).*/\1/')
	3. curl --insecure -H "Authorization: Bearer $TOKEN" https://login.microsoftonline.com/<DOMAIN>/oauth2/v2.0/authorize

```

More info here (check the workflow): [OpenID Connect (OIDC) on the Microsoft identity platform - Microsoft identity platform | Microsoft Learn](https://learn.microsoft.com/en-us/entra/identity-platform/v2-protocols-oidc)

Best,  
mj

---

<div class="post-metadata">

**Author:** ![ar.shashikumar](https://avatars.discourse-cdn.com/v4/letter/a/6a8cbe/32.png) [@ar.shashikumar](https://forum.opensearch.org/u/ar.shashikumar)\
**Post date:** [November 14, 2024, 5:33am UTC](https://forum.opensearch.org/t/setting-up-openid-connect-integration-with-opensearch-is-resulting-in-a-401-unauthorized-error-when-using-azure-ad-as-the-identity-provider/22105/8 "2024-11-14T05:33:14Z")

</div>

any progress on this? I am getting 401 error too with OIDC

---

<div class="post-metadata">

**Author:** ![taltsafrir](https://avatars.discourse-cdn.com/v4/letter/t/a698b9/32.png) [@taltsafrir](https://forum.opensearch.org/u/taltsafrir)\
**Post date:** [December 9, 2024, 9:26am UTC](https://forum.opensearch.org/t/setting-up-openid-connect-integration-with-opensearch-is-resulting-in-a-401-unauthorized-error-when-using-azure-ad-as-the-identity-provider/22105/9 "2024-12-09T09:26:02Z")

</div>

same here, getting 401 with saml
