Examples of an OIDC configuration in DataLens On-premises

Keycloak

Example of a Keycloak configuration

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

Set up a Keycloak client configuration for this 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.
  2. To create roles, click Clients → your client (datalens) → Roles:

    • client.datalens.admin
    • client.datalens.creator
  3. To create a group, click Groups → Create group.

  4. 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.
  5. 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

{
  "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

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:

[
  {
    "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
    }
  }
]