Skip to main content

Setting up OpenID Connect

View as Markdown

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.

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.

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​

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​

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​

OptionRequiredDescription
nameNoName shown on the login button ("Continue with name") and in the user menu. Defaults to SSO.
issuerYesIssuer URL of your provider. Must match its /.well-known/openid-configuration exactly.
clientIdYesClient ID of the OIDC app.
clientSecretNoClient secret of the OIDC app.
scopeNoScopes to request. Defaults to openid email profile.
groupsClaimNoToken claim that holds the user's groups. Defaults to groups.
rolesClaimNoToken claim that holds the user's roles. Defaults to roles.

Any other Auth.js OIDC option (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​

EventCatalog reads the user's groups and roles from claims in their tokens, and makes them available to your RBAC middleware. 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​

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?​

Remember to setup the prerequisites for this guide:

If you still have problems, please let us know.