[Yandex Cloud documentation](../../../index.md) > [Tutorials](../../index.md) > [Security](../index.md) > Setting up single sign-on (SSO) for apps > Selectel > OpenID Connect

# Creating an OIDC application in Yandex Identity Hub for integration with Selectel


To enable your [organization](../../../organization/concepts/organization.md) users to authenticate in Selectel through OpenID Connect (OIDC), create an [OIDC application](../../../organization/concepts/applications/oidc.md) in Yandex Identity Hub and set up Selectel integration.

OIDC apps can be managed by users with the `organization-manager.oauthApplications.admin` [role](../../../organization/security/index.md#organization-manager-oauthApplications-admin) or higher.

To enable single sign-on in Selectel:

1. [Create an app](#create-app).
1. [Set up the integration](#setup-integration).
1. [Test SSO](#validate).

## Create an app {#create-app}

{% list tabs group=instructions %}

- Cloud Center UI {#cloud-center}

  1. Log in to [Yandex Identity Hub](https://center.yandex.cloud/organization).
  1. In the left-hand panel, select ![shapes-4](../../../_assets/console-icons/shapes-4.svg) **Apps**.
  1. Click ![circles-3-plus](../../../_assets/console-icons/circles-3-plus.svg) **Create application** and do the following in the window that opens:
      1. Select the **OIDC (OpenID Connect)** single sign-on method.
      1. In the **Application type** field, select [Web Application](*web_app_type).
         
         [*web_app_type]: OIDC apps of the `Web Application` type are optimized for user authentication to external web apps with a server end (backend), where the application secret can be safely stored. For more information about OIDC application types, see [Types of OIDC apps in Yandex Identity Hub](../../../organization/concepts/applications/oidc.md#oidc-application-types).
      1. In the **Name** field, enter the application name: `selectel-oidc`.
      1. In the **Folder** field, select the folder where you want to create an OAuth client for your app.
      1. Optionally, in the **Description** field, enter a description for the new app.
      1. Click **Create application**.

{% endlist %}

## Set up the integration {#setup-integration}

### Get the application’s credentials {#get-credentials}

{% list tabs group=instructions %}

- Cloud Center UI {#cloud-center}

  1. Open the OIDC app you created.
  1. Under **Overview** on the **Identity provider (IdP) configuration** tab, expand the **Additional attributes** section and copy the **ClientID** value.
  1. Create an app secret (only available for applications of the `Web Application` [type](../../../organization/concepts/applications/oidc.md#oidc-application-types)).
     
     To do this, under **App secrets**, click **Add secret**, and in the window that opens:
     
     1. Optionally, add a description for the new secret.
     1. Click **Create**.
     
         The window will display the generated [application secret](../../../organization/concepts/applications/oidc.md#oidc-secret). Save this value.
     
         {% note warning %}
     
         If you refresh or close the application information page, you will not be able to view the secret again.
     
         {% endnote %}
     
     If you closed or refreshed the page before saving the secret, click **Add secret** to create a new one.
     
     To delete a secret, in the list of secrets on the OIDC app page, click ![ellipsis](../../../_assets/console-icons/ellipsis.svg) in the secret row and select ![trash-bin](../../../_assets/console-icons/trash-bin.svg) **Delete**.

{% endlist %}

### Create a federation in Selectel {#setup-sp}

{% note info %}

To create a federation in Selectel, you must be an [account owner](https://docs.selectel.ru/access-control/user-types/#account-owner) or have the [`iam.admin`](https://docs.selectel.ru/access-control/role-reference/#iam-admin) role.

{% endnote %}

To set up a federation:

1. Log in to the [Selectel control panel](https://my.selectel.ru/iam/federations).
1. In the top menu, select **IAM** and go to **Federations**.
1. Click **Add federation** and select **OpenID Connect (OIDC)**.
1. Under **Federation settings**:
    1. In the **Name** field, enter a name for the federation, such as `identity-hub-oidc`.
    1. Optionally, in the **Description** field, specify the federation description.
    1. Under **Session lifetime**, specify how long an authentication session will last or leave the default value (24 hours).
1. Under **IDP settings**, specify the integration settings:

    * **IdP Issuer**: `https://auth.yandex.cloud`.
    * **Client ID**: **ClientID** field value you copied at the previous step.
    * **Client Secret**: App secret you saved at the previous step.
    * **Auth URL**: `https://auth.yandex.cloud/oauth/authorize`.
    * **Token URL**: `https://auth.yandex.cloud/oauth/token`.
    * **JWKS URI**: `https://auth.yandex.cloud/oauth/jwks/keys`.

1. Disable **Autocreate users**, if enabled.
1. Click **Create federation**.
1. On the federation page, copy its **ID**.

### Set up your application in Yandex Identity Hub {#setup-idp}

{% list tabs group=instructions %}

- Cloud Center UI {#cloud-center}

  1. Go back to [Yandex Identity Hub](https://center.yandex.cloud/organization), select **Apps**, and open `selectel-oidc`.
  1. At the top right, click ![pencil](../../../_assets/console-icons/pencil.svg) **Edit** and in the window that opens:
      1. In the **Redirect URI** field, enter this address:

          ```text
          https://api.selectel.ru/v1/auth/federations/oidc/<federation_ID>/callback
          ```

          Where `<federation_ID>` is the ID of the federation you created in Selectel at the previous step.
      1. Under **OAuth/OIDC security** in **Authentication methods**, leave both secret transmission methods active: `Client secret basic` and `Client secret post`.
      1. Under **OAuth/OIDC security**, disable **Require PKCE**.

          {% note alert %}

          For integration with Selectel, Yandex Identity Hub must not require the [PKCE](../../../organization/concepts/applications/oidc.md#pkce) security extension during data exchange.

          {% endnote %}

      1. Under **Scopes**, select `openid`, `email`, and `profile`.
      1. Click **Save**.

{% endlist %}

### Add users {#add-users}

Add users to the Yandex Identity Hub OIDC app and the Selectel federation.

{% note info %}

To manage users and groups added to an OIDC application, you need to have the `organization-manager.oauthApplications.userAdmin` [role](../../../organization/security/index.md#organization-manager-oauthApplications-userAdmin) or higher.

{% endnote %}

#### Add users to the OIDC application {#add-users-idp}

{% note tip %}

If you want to fine-tune user authentication in your applications, including authentication only from specific IP addresses, use [authentication policies](*authentication_policies).

{% endnote %}

[*authentication_policies]: Authentication policies are a Yandex Identity Hub tool that allows you to flexibly configure access to applications by denying or allowing authentication for specific users in specific applications and/or from specific IP addresses. For more information, see [Authentication policies in Yandex Identity Hub](../../../organization/concepts/authentication-policy.md).

To add users:

{% list tabs group=instructions %}

- Cloud Center UI {#cloud-center}

  1. Open `selectel-oidc` in [Yandex Identity Hub](https://center.yandex.cloud/organization).
  1. Navigate to the **Users and groups** tab.
  1. Click ![person-plus](../../../_assets/console-icons/person-plus.svg) **Add users**.
  1. In the window that opens, select the user or [user group](../../../organization/concepts/groups.md).
  1. Click **Add**.

{% endlist %}

#### Add users to Selectel {#add-users-sp}

To add a user to a Selectel federation:

1. Get the [user ID](../../../organization/operations/users-get.md) in Yandex Identity Hub.
1. Navigate to the [Selectel control panel](https://my.selectel.ru/iam/users), select **IAM** in the top menu and go to **Control panel users**.
1. Click **Add new control panel user**.
1. Under **User data**:
    1. In the **Login method** field, select **Federation (<federation_name>)**.
    1. Under **External ID**, specify the user ID you got at step 1.
    1. Under **Email**, specify the user email.
1. Under **Access settings**, select the access scope and assign the required [permissions](https://docs.selectel.ru/access-control/permissions/) to the user.
1. Click **Add user**.

## Test SSO {#validate}

To verify the integration, log in to Selectel as a user assigned to the OIDC application:

1. Open the [Selectel login page](https://my.selectel.ru/login/).
1. If already logged in to Selectel, sign out of your account.
1. Click **Sign in with SSO**.
1. Enter the ID of the Selectel federation you created and click **Sign in with SSO**.
1. On the Yandex Cloud authentication page, login to your user account. The user must be directly assigned to the OIDC application or belong to a group assigned to the application.
1. If Selectel prompts you for your full name on first login, enter it and click **Sign in with SSO**.
1. Make sure you are logged in to Selectel.