Cairn Developers

DEVELOPERS · PREVIEW

Sign in with Cairn (OIDC)

OpenID Connect for apps with their own screens outside Cairn (web apps, PWAs, and so on) to identify users as Cairn users. Your app receives only an ID token with the information the user allowed. It cannot be used to read or write Cairn data.

This specification is a preview. External developers cannot register apps or issue bot tokens yet (only first-party apps run today). Details may change before registration opens.

What it can and cannot do

The ID token's sub is the user's Cairn user ID. ID tokens are signed with a key dedicated to Cairn's OIDC, and cannot be used with the Cairn API, data, files, or Realtime.

GoalMechanism
Know who the user is (sign-in)OIDC on this page (ID token)
Post to channels, send cards, receive interactionsBot token with the Web API and interactions
The ID token contains no workspace membership or role. To admit only members of a specific workspace, check that sub is an active member with the Bot Web API (for example users.info).

Registering a client

The Cairn operators register clients. Dynamic registration is not supported. Send your app name, a redirect URI for each environment (https, exact match; http://localhost / http://127.0.0.1 are also accepted for local development), and whether your app has a server. Apps with a server are registered as confidential clients and receive a client ID and a client secret. Keep the client secret on your server only. Apps that run only in the browser (such as a PWA without a server) cannot keep a secret safe, so they are registered as public clients and receive only a client ID. PKCE (S256) is required for both.

Sign-in flow

  1. Send an authorization request to https://oss-cairn.com/oidc/authorize with the authorization code flow and PKCE. Request openid, plus only the scopes you need (profile / email).
  2. Always use state. Generate an unguessable value, store it in the session that starts sign-in, and check it on the callback. If it does not match, do not exchange the code. We also recommend nonce.
  3. The user allows or denies the request on Cairn's consent screen. If they already allowed the same scopes, the consent screen is skipped.
  4. Exchange the code from the callback at the token endpoint to receive the ID token. No refresh token is issued. Send a new authorization request whenever you need the user to sign in with Cairn again (the consent screen is skipped if already allowed).

Read the endpoints from https://oss-cairn.com/oidc/.well-known/openid-configuration. Do not hard-code them.

ScopeClaims in the ID token
openidsub (the Cairn user ID)
profilename (the Cairn account display name, which may differ from the display name in each workspace)
emailemail / email_verified

Verifying the ID token

Verify the ES256 signature with the JWKS, check iss, aud (your client ID), and nonce, then use sub as the Cairn user ID. ID tokens expire after 5 minutes.

import { createRemoteJWKSet, jwtVerify } from 'jose'

// The issuer is https://oss-cairn.com/oidc
const issuer = 'https://oss-cairn.com/oidc'
const jwks = createRemoteJWKSet(new URL(`${issuer}/jwks.json`))

const { payload } = await jwtVerify(idToken, jwks, {
  issuer,
  audience: process.env.CAIRN_OIDC_CLIENT_ID,
  algorithms: ['ES256'],
})
// Reject the sign-in unless nonce matches the one you stored with the authorization request
if (payload.nonce !== savedNonce) throw new Error('nonce mismatch')
const cairnUserId = payload.sub
The token endpoint also returns an access token, but it only works for UserInfo (it expires after 5 minutes). It cannot be used with any other Cairn API.

Revoking access

Users can revoke an app's access anytime from Settings, Integrations in Cairn. After revoking, they must allow access again to sign in.