---
metadata:
  - name: generator
    content: Diplodoc Platform v5.63.0
alternate:
  - en/concepts/auth-providers/oidc-examples
  - en/datalens/concepts/auth-providers/oidc-examples.md
  - ru/concepts/auth-providers/oidc-examples
  - href: en/concepts/auth-providers/oidc-examples.md
    type: text/markdown
    title: Markdown version
csp:
  - script-src:
      - https://mc.yandex.ru
    img-src:
      - https://mc.yandex.ru
    connect-src:
      - https://mc.yandex.ru
      - wss://mc.yandex.ru
    child-src:
      - 'blob:'
      - https://mc.yandex.ru
    frame-src:
      - 'blob:'
      - https://mc.yandex.ru
    frame-ancestors:
      - 'blob:'
      - https://mc.yandex.ru
canonical: en/concepts/auth-providers/oidc-examples.html
title: Examples of an OIDC configuration in DataLens On-premises
description: This section provides configuration examples for OIDC in DataLens On-premises.
vcsPath: en/concepts/auth-providers/oidc-examples.md
---

# Examples of an OIDC configuration in DataLens On-premises

## Keycloak {#keycloak}

### Example of a Keycloak configuration {#keycloak-config-example}

```javascript
const keycloakConfig = {
    slug: 'keycloak',
    title: 'Keycloak',
    type: 'oidc',
    defaultRole: 'datalens.visitor',
    config: {
        issuer: 'https://keycloak.example.org/realms/datalens-enterprise/.well-known/openid-configuration',
        clientId: 'datalens',
        clientSecret: 'password',
        codeChallengeMethod: 'S256',
        scope: ['openid', 'profile', 'email', 'roles', 'groups'],
        
        roles: {
            path: 'resource_access.datalens.roles',
            targetType: 'array-of-strings',
            mapping: {
                'datalens.admin': 'client.datalens.admin',
                'datalens.creator': 'client.datalens.creator',
            },
        },
        syncUserRoles: true,
        
        groups: {
            path: 'groups',
            targetType: 'array-of-strings', // We recommend that you configure Script Mapper and use 'array-of-objects' to specify the group ID and name
        },
        syncUserGroups: true,
    },
};
```

### Keycloak client settings {#keycloak-settings-example}

Set up a Keycloak client configuration for [this example](#keycloak-config-example):

1. Specify the client settings by clicking `Clients` → your client (`datalens`) → `Settings`:

   * **Valid redirect URIs**: `{UI_APP_ENDPOINT}/auth/callback/oidc`. Replace `UI_APP_ENDPOINT` with your app URL, such as `http://example.com:8080/auth/callback/oidc`.
   * **Client authentication**: `on`.
   * **Authentication flow**: `Standard flow`.

1. To create roles, click `Clients` → your client (`datalens`) → `Roles`:

   * `client.datalens.admin`
   * `client.datalens.creator`

1. To create a group, click `Groups` → `Create group`.
1. To assign a group and roles to a user, click `Users` → `user`.

   * Assign the roles on the `Role mapping` tab.
   * Assign the roles on the `Groups` tab.

1. To set the client scope, click `Client scopes` → `Create client scope`.

   * Create the `groups` scope and `Group Membership` mapper type. Enable `Add to userinfo` in the Keycloak settings.
   * Create the `roles` scope or `client roles` predefined mapper. Enable `Add to userinfo` in the Keycloak settings.


### Example of userinfo for Keycloak {#keycloak-userinfo-example}

```json
{
  "sub": "4d2b6d80-49cf-44fb-94c6-946393dea8c7",
  "resource_access": {
    "datalens": {
      "roles": [
        "client.datalens.creator"
      ]
    },
  },
  "email_verified": true,
  "name": "Bob Smith",
  "groups": [
    "datalens-admin"
  ],
  "preferred_username": "bob",
  "given_name": "Bob",
  "family_name": "Smith",
  "email": "bob@example.org"
}
```


## Example of configuration via the AUTH_PROVIDERS_CONFIG environment variable {#auth-providers-config}

To configure authentication providers, the application uses the `AUTH_PROVIDERS_CONFIG` environment variable. This variable contains a JSON string with an array of configurations of all authentication providers.

Example of the `AUTH_PROVIDERS_CONFIG` environment variable:

```json
[
  {
    "slug": "keycloak",
    "title": "Keycloak",
    "type": "oidc",
    "defaultRole": "datalens.visitor",
    "config": {
      "issuer": "https://keycloak.example.org/realms/datalens-enterprise/.well-known/openid-configuration",
      "clientId": "datalens",
      "clientSecret": "password",
      "codeChallengeMethod": "S256",
      "scope": ["openid", "profile", "email", "roles", "groups"],
      "roles": {
        "path": "resource_access.datalens.roles",
        "targetType": "array-of-strings",
        "mapping": {
          "datalens.admin": "client.datalens.admin",
          "datalens.creator": "client.datalens.creator"
        }
      },
      "syncUserRoles": true,
      "groups": {
        "path": "groups",
        "targetType": "array-of-strings"
      },
      "syncUserGroups": true
    }
  }
]
```
