# OIDC

OIDC (OpenID Connect) is an identity layer built on OAuth 2.0. After users sign in at their company identity provider, ECP uses the identity information returned by the provider to authenticate them and complete single sign-on.

This page uses Okta to show how to configure OIDC single sign-on and how users sign in to ECP with a company account.

## About Okta

Okta is an enterprise identity and access management platform. Administrators use it to manage employee accounts, application access, and multi-factor authentication. With this integration, Okta verifies the user’s company identity and returns them to ECP. Learn more on the [Okta website](https://www.okta.com/) and the [Okta Single Sign-On product page](https://www.okta.com/products/single-sign-on-workforce-identity/).

## Administrator Configuration

### Prerequisites

- Have an ECP system administrator account and an Okta administrator account with permission to manage applications and assign users.
- In ECP, configure the [Root Address](../system_admin/general_config.md#configure-root-address) under **System Settings** -> **General Settings**. Use the HTTPS address that users open to log in to ECP. The scheme, hostname, and port must match.

  ![ECP 通用配置中的访问地址](./_assets/oidc-root-addr.png)

- Make sure the ECP server can reach your organization’s Okta domain over HTTPS. For production, confirm that API Access Management is enabled before using a custom authorization server. This guide uses `default` as an example. You can use a custom authorization server designated by your organization for ECP. See [Okta authorization server configuration](https://developer.okta.com/docs/guides/customize-authz-server/).

### Prepare Your Okta Organization

If your company already has an Okta organization, sign in with an administrator account for that organization. If you are setting up Okta for the first time, follow these steps to open an organization.

#### Set Up Your First Organization

1. Have your company name and the email address of the administrator responsible for setup ready. Use the [Okta contact page](https://www.okta.com/contact/) to work with sales on provisioning a production organization for enterprise SSO. To explore the Admin Console, you can [sign up for an Okta Integrator Free Plan](https://developer.okta.com/signup/) for non-production use. See [Okta organizations](https://developer.okta.com/docs/concepts/okta-organizations/) for the organization types.
2. After provisioning, note the organization’s sign-in address, such as `https://your-company.okta.com`. Follow the instructions you receive to activate the administrator account and set up the required authentication methods.
3. Open the organization’s sign-in address, sign in as an administrator, and click **Admin** in the upper-right corner to open the **Admin Console**.

#### Prepare Users and Groups

- In **Directory** -> **People**, check that the employees who need ECP access have active accounts and valid primary email addresses. For anyone who has yet to join the organization, click **Add Person** and have them complete activation according to your organization’s policy. See [Add users manually in Okta](https://help.okta.com/oie/en-us/content/topics/users-groups-profiles/usgp-add-users.htm).
- If you plan to assign the ECP app to a group, check membership in **Directory** -> **Groups**. After creating the app, grant access on its **Assignments** tab.

![Okta 用户目录中的添加用户入口和账号状态](./_assets/oidc-okta-directory.png)

### 1. Get the ECP Sign-in Redirect URI

1. Log in as an ECP system administrator and open **System Settings** -> **General Settings** -> **SSO**.
2. Click **Add Identity Provider** and select **OpenID Connect** for **Protocol**.
3. Click the copy button beside **Sign-in redirect URI**. The address looks like `https://ecp.example.com/api/sso/oidc/callback`. Leave this page open while you obtain the Okta client credentials.

![在 ECP 复制 OIDC 登录重定向 URI](./_assets/oidc-ecp-redirect-uri.png)

### 2. Create the Okta App and Assign Users

1. In the Okta Admin Console, go to **Applications and Resources** -> **Applications** and click **Create App Integration**. Some organizations must select **Classic experience** first.
2. Select **OIDC - OpenID Connect** as the sign-in method and **Web Application** as the application type, then click **Next**.

   ![在 Okta 选择 OIDC 和 Web Application](./_assets/oidc-okta-app-type.png)

3. Enter a name, such as `ECP`. Configure the following options, then click **Save**.

   - **Client definition**: Select **Use Okta-generated client ID**. The creation wizard may label this option **Configure in Okta**. Use the **Client ID** generated by Okta when configuring ECP.
   - **Grant type**: Select **Authorization Code**.

     ![Okta Web 应用的客户端定义和授权码设置](./_assets/oidc-okta-web-app.png)

   - **Sign-in redirect URIs**: Enter the full sign-in redirect URI copied from your ECP deployment.

     ![Okta 应用的登录重定向 URI](./_assets/oidc-okta-redirect-uri.png)

   - **Controlled access**: Select **Skip group assignment for now**. Save the app first, then grant access to the ECP users or groups on the **Assignments** tab.

     ![创建 Okta 应用时暂不分配用户组](./_assets/oidc-okta-controlled-access.png)

   See [Create an OIDC app integration in Okta](https://help.okta.com/oie/en-us/content/topics/apps/apps_app_integration_wizard_oidc.htm).
4. In the app's **General** tab, record the **Client ID** and **Client Secret**. Use **Client secret** for client authentication.
5. In the app's **Assignments** tab, click **Assign** and assign the users or groups that can sign in to ECP. See [Okta web app setup](https://developer.okta.com/docs/guides/sign-into-web-app-redirect/main/).

![Okta 应用的 Assignments 标签页，显示已分配的示例用户或组](./_assets/oidc-okta-assignments.png)

### 3. Get the Okta Issuer URL

1. In the Okta Admin Console, go to **Security** -> **API** -> **Authorization Servers** and open the custom authorization server selected for ECP, such as **default**.
2. Copy the **Issuer URI** from **Settings**. For example, `https://example.okta.com/oauth2/default`.

   ![Okta 授权服务器列表中的 Issuer URI](./_assets/oidc-okta-issuer.png)

3. In **Access Policies**, verify that a policy and rule apply to the ECP app. The rule must allow assigned users to use **Authorization Code** and let ECP request `openid`, `profile`, and `email`. If there is no matching policy, use **Add Policy** to create one for the ECP app. Then use **Add Rule** to add an authorization code rule for assigned users. See [Okta access policy configuration](https://developer.okta.com/docs/guides/customize-authz-server/).

![Okta 授权服务器的访问策略和授权码规则](./_assets/oidc-okta-access-policy.png)

### 4. Save and Enable the Provider in ECP

1. Return to the **Add Identity Provider** dialog and complete the following fields.

   | Field | Setting |
   | --- | --- |
   | **Name** | The name shown on the ECP login page, for example `Okta sign-in`. |
   | **Issuer URL** | The **Issuer URI** you copied from the Okta authorization server. |
   | **Client ID** | The **Client ID** from the Okta app. |
   | **Client Secret** | The **Client Secret** from the Okta app. |
   | **Auto Bind IdP User** | Off by default. New users activate their accounts on first sign-in. When enabled, ECP uses the email from Okta to find an existing SSO account or creates one if there is no match. |

2. Turn on **Enabled** and click **Confirm**. The provider appears on the ECP login page.
3. Sign in at your deployed ECP login address with a company account authorized to use the app. Confirm that the account can access its assigned organizations and projects, then share the ECP login address and provider name with users.

![ECP 的 OIDC 认证服务配置](./_assets/oidc-ecp-provider.png)

:::tip
Users with an existing ECP password or invitation account should keep using their original sign-in method. If SSO reports that an email is already in use, contact an ECP administrator. An ECP administrator grants project access separately.
:::

### Manage a Configured Provider

- In the **SSO** list, click the edit icon to update the configuration. After rotating the Okta secret, enter the new value in **Client Secret** and save.
- To stop sign-ins through this provider, turn off **Enabled**. Existing ECP sessions continue until they expire.
- If **Bound Users** shows a user count, disable the provider to stop sign-ins. You can delete a provider only after it has no bound users.

### Check SSO Users and Grant Project Access

In ECP, go to **Administration** -> **Users** and find the user by email. The **SSO User** column shows the account type, and the **Status** column shows whether the account is active.

- **SSO users** sign in with their company identity provider. **Reset Password** is unavailable in ECP for these accounts. Reset Okta passwords through Okta.
- **Non-SSO users** sign in with their ECP email and password. An Okta account with the same email cannot sign in to that ECP account through SSO.

![ECP 用户管理列表中的状态和 SSO 用户列](./_assets/oidc-ecp-user-management.png)

When ECP creates an account on first SSO sign-in, it starts with no organization or project memberships and cannot access those resources. An administrator can grant access as follows.

1. In **Organizations**, edit the organization that owns the target project and add the user. See [Manage Organizations](../system_admin/org_management.md).
2. In **Projects**, find the target project and click the edit icon in the **Action** column.
3. Select the user in **Candidates**, assign the appropriate role in **Members**, and save. See [Edit Projects and Members](../system_admin/project_management.md#edit-projects-and-members).

## Sign in to ECP with Okta

1. Open the ECP login page and select the provider your administrator set up, for example **Okta sign-in**.

   ![ECP 登录页的 Okta 单点登录入口](./_assets/oidc-ecp-login.png)

2. Sign in with your company account on the Okta page. If Okta prompts you for multi-factor authentication, follow the on-screen instructions.

   ![Okta 要求设置安全验证方式时的页面](./_assets/oidc-okta-mfa.png)

3. The browser returns to ECP. If you see an activation page on your first sign-in, enter your username and any other required fields, then click **Confirm**. ECP fills in your email from Okta.

   ![ECP 首次单点登录的账号激活表单](./_assets/oidc-ecp-activate.png)

If you see no organizations or projects after signing in for the first time, ask your ECP administrator to grant project access.

After you log out of ECP, your Okta session may still be active. The next sign-in in the same browser may return you directly to ECP. To switch company accounts, sign out of Okta first or use a private browser window.

## Troubleshooting

| Symptom | What to do |
| --- | --- |
| The Okta option is missing from the login page | Ask your ECP administrator to confirm that the identity provider is enabled. |
| Okta reports a redirect URI mismatch | Copy the **Sign-in redirect URI** again from ECP and compare it with **Sign-in redirect URIs** in Okta. Check the scheme, hostname, port, and path. |
| Okta reports that you cannot access the app | Ask your Okta administrator to check application assignments and the authorization server's access policy. |
| ECP reports that the sign-in has expired | Start again from the ECP login page and complete sign-in in the same browser. |
