# Setting up OpenID Connect

Copy as Markdown[View as Markdown](/docs/development/authentication/providers/setting-up-oidc.md)

***

**Added in** `eventcatalog@5.20.0`

info

This guide takes you through setting up a protected sign-in screen for your docs. Before going through this guide, make sure you've first gone through [Enabling authentication](/docs/development/authentication/enabling-authentication.md).

If your identity provider does not have its own entry in EventCatalog, you can connect it with the generic `oidc` provider. It works with any provider that supports [OpenID Connect](https://openid.net/connect/).

To set up your EventCatalog site with an OpenID Connect provider, the process looks as follows:

1. Create an OIDC app in your identity provider
2. Configure the provider in EventCatalog
3. Test the authentication

## Create an OIDC app[​](#create-an-oidc-app "Direct link to Create an OIDC app")

**Added in** `eventcatalog@5.20.0`

First, create a new OIDC application (sometimes called a client) in your identity provider's admin console. The exact steps depend on your provider, so check its documentation for creating a web application that uses the authorization code flow.

You will need the following:

* **Application type:** a web application using the **Authorization Code** flow

* **Redirect URI (callback URL):**

  * Production: `{YOUR_EVENTCATALOG_SITE_URL}/api/auth/callback/oidc`
  * Local development: `http://localhost:3000/api/auth/callback/oidc`

* **Scopes:** `openid`, `email` and `profile`

* **Assignments:** the users or groups who can access the application

The redirect URI always ends in `/api/auth/callback/oidc`. The provider id is fixed to `oidc` and cannot be changed.

Once the app is created, copy the **Client ID** and **Client Secret**, and find the **issuer** URL of your provider.

The issuer must match exactly

The `issuer` must match the `issuer` value in your provider's `/.well-known/openid-configuration` document exactly, including any trailing slash. For example, `https://auth.example.com/` and `https://auth.example.com` are different values.

## Configure the provider in EventCatalog[​](#configure-the-provider-in-eventcatalog "Direct link to Configure the provider in EventCatalog")

**Added in** `eventcatalog@5.20.0`

Add your Client ID and Client Secret to your `.env` file.

.env

```
AUTH_OIDC_ISSUER={YOUR_OIDC_ISSUER}
AUTH_OIDC_CLIENT_ID={YOUR_OIDC_CLIENT_ID}
AUTH_OIDC_CLIENT_SECRET={YOUR_OIDC_CLIENT_SECRET}
```

In your `eventcatalog.auth.js` file, add an `oidc` provider.

eventcatalog.auth.js

```
export default {
  providers: {
    oidc: {
      name: 'Company SSO',
      issuer: process.env.AUTH_OIDC_ISSUER,
      clientId: process.env.AUTH_OIDC_CLIENT_ID,
      clientSecret: process.env.AUTH_OIDC_CLIENT_SECRET,
    },
  },
};
```

### Options[​](#options "Direct link to Options")

| Option         | Required | Description                                                                                      |
| -------------- | -------- | ------------------------------------------------------------------------------------------------ |
| `name`         | No       | Name shown on the login button ("Continue with `name`") and in the user menu. Defaults to `SSO`. |
| `issuer`       | Yes      | Issuer URL of your provider. Must match its `/.well-known/openid-configuration` exactly.         |
| `clientId`     | Yes      | Client ID of the OIDC app.                                                                       |
| `clientSecret` | No       | Client secret of the OIDC app.                                                                   |
| `scope`        | No       | Scopes to request. Defaults to `openid email profile`.                                           |
| `groupsClaim`  | No       | Token claim that holds the user's groups. Defaults to `groups`.                                  |
| `rolesClaim`   | No       | Token claim that holds the user's roles. Defaults to `roles`.                                    |

Any other [Auth.js OIDC option](https://authjs.dev/reference/core/providers#oidcconfig) (for example `checks`, `authorization` or `client`) is passed through to Auth.js. If you set `authorization.params`, it is merged with `scope`, and a scope set there wins.

## Read groups and roles[​](#read-groups-and-roles "Direct link to Read groups and roles")

**Added in** `eventcatalog@5.20.0`

EventCatalog reads the user's groups and roles from claims in their tokens, and makes them available to your [RBAC middleware](/docs/development/authentication/rbac-middleware.md). Use `hasGroup()` and `hasRole()`, or read `locals.user.groups` and `locals.user.roles`. For these users, `locals.user.provider` is `oidc`.

Claims are read as follows:

* The ID token's claims are read first. If it has none, the access token's claims are used.
* An exact claim name is tried first, so namespaced claims such as `https://example.com/groups` work.
* Otherwise the name is read as a dotted path into nested claims, such as `realm_access.roles`.
* An array claim gives a list of values. A single string counts as one value and is not split.

eventcatalog.auth.js

```
export default {
  providers: {
    oidc: {
      name: 'Company SSO',
      issuer: process.env.AUTH_OIDC_ISSUER,
      clientId: process.env.AUTH_OIDC_CLIENT_ID,
      clientSecret: process.env.AUTH_OIDC_CLIENT_SECRET,
      groupsClaim: 'https://example.com/groups',
      rolesClaim: 'roles',
    },
  },
};
```

Your provider must include these claims in the tokens it issues. Check its documentation for how to add a groups or roles claim to an app.

## Test the authentication[​](#test-the-authentication "Direct link to Test the authentication")

Restart your EventCatalog server and test the authentication.

```
npm run dev
```

All pages should now be protected and require an account from your identity provider.

1. Navigate to your EventCatalog site
2. You should be redirected to the sign-in page
3. Click **Continue with** followed by the `name` you configured
4. Sign in with your identity provider
5. After successful authentication, you'll be redirected back to EventCatalog

## Found an issue?[​](#found-an-issue "Direct link to Found an issue?")

Remember to setup the prerequisites for this guide:

* [Enabling authentication](/docs/development/authentication/enabling-authentication.md)

If you still have problems, please [let us know](https://github.com/eventcatalog/eventcatalog/issues/new/choose).
