Skip to content

Connected apps

A connected app is a frontend your organization runs on its own origin — an operations console, an internal admin tool, a page that joins Tessule data with your other systems — whose people sign in through your organization’s identity provider. The app calls the workspace API as the person using it. It sends that person’s id_token from your identity provider to Tessule and gets back a short-lived Tessule token for the same person. There is no proxy to run and no shared key: every call is made by a named member, with that member’s own permissions, capped by a ceiling you set.

If you only remember one thing: a connected app never does more than the person using it may do. Its token holds the actions that both the app’s ceiling and the person’s own role allow, in one workspace, for no longer than the identity provider’s token lives.

Choose the door that fits the frontend:

You are building Use
A frontend for one workspace, hosted by Tessule A custom app. Tessule handles the sign-in and the hosting.
A frontend on your own origin, for people who sign in through your identity provider A connected app (this guide).
A script, a server or a scheduled job with no person behind it A personal API token or an agent.
A third-party tool a person connects to their own account An OAuth client.

A connected app works for members of your organization only. The person must already be a member of the workspace, or become one when they first arrive (see Who the token is for).


A connected app is bound to one of your organization’s SSO connections, and it trusts the same identity provider. You need:

  • An OIDC SSO connection for the identity provider your app signs people in with. Its issuer is the issuer of your app’s tokens.
  • A verified email domain when you want people linked or created by email (see Who the token is for).
  • Your app’s own registration at the identity provider. It is a separate app from the one your SSO connection uses, with its own client id. That client id is the aud of the id_tokens your app receives.

Organization Settings → Connected apps lists your apps (GET /organizations/{organizationId}/connected-apps). Managing them needs org:sso:manage, which organization owners and admins hold. Add connected app asks for:

Field Notes
Name Shown in the list, and in the audit trail beside each request the app makes.
SSO connection The connection whose identity provider signs the app’s id_tokens. A token from any other issuer is refused.
Token audiences Your app’s own client id at the identity provider, not the one your SSO connection uses. One to ten values. A token whose aud is not listed is refused.
Subject claim Which claim names the person: Subject (sub, for every provider) or Object id (oid, for Microsoft Entra).
Allowed origins Exactly the origins your app’s pages load from, such as https://ops.example.com. One to ten. Each is a scheme, host and optional port with no path. Use https; plain http is accepted for localhost only, with its port, for development.
Workspaces The workspaces the app may act in. Leave it empty for any workspace of the organization.
Ceiling The most the app’s tokens may do. See The ceiling.
Token lifetime (seconds) The longest a token lives, from 60 to 1800. Defaults to 1800.
Enabled A disabled app keeps its registration and refuses every exchange.

The list shows each app’s Client ID, app_ followed by 24 hexadecimal characters, with a copy button. Your app sends it with every exchange. The client ID is not a secret: an exchange also needs a valid id_token for one of the listed audiences.

Registering an app is consent on behalf of every member who signs in to it. Members are not asked. The app acts as whichever member uses it, up to the ceiling.

Apps are created with POST /organizations/{organizationId}/connected-apps, read with GET /organizations/{organizationId}/connected-apps/{appId}, changed with PATCH /organizations/{organizationId}/connected-apps/{appId} (partial; only provided fields change) and deleted with DELETE /organizations/{organizationId}/connected-apps/{appId}. Your organization’s limits set how many connected apps it can register; a disabled app counts.

The ceiling is a list of workspace actions, picked by category in the same words the role editor uses (Data, Analytics, Processes, Schema, Administration). A person’s token through the app holds an action only when both the ceiling and the person’s own role allow it. A reader using an app whose ceiling includes records:create still cannot create records: their role never had that action.

  • The default is every action outside the Administration category.
  • You may add Administration actions, such as workspace:members:read for an app that shows the member list.
  • Nine actions are never available to a connected app, because each can mint further credentials or rewire who may do what: tokens:manage, agents:manage, integrationAccounts:manage, secrets:manage, permissions:manage, hostedSites:manage, integrations:manage, mirrors:manage and webhooks:manage.

Record visibility and field permissions apply as they do in the app: the token sees the records and fields the person sees, and no more. A connected app’s token reaches the workspace API only. Organization settings refuse it, and so do changes to the person’s password and sign-in methods, whatever the ceiling.

Changing anything but the name raises the app’s policy version. Tokens issued under an earlier version stop working within a minute; the client in Calling the API from your app exchanges again under the new settings without the person noticing.

  • Disable the app to stop every exchange at once and every outstanding token within a minute.
  • Delete the app to do the same and forget each member’s link to it.
  • Disabling the SSO connection stops new exchanges. Tokens already issued run to their expiry. To cut them off, disable the app.
  • Switching off Trust this provider’s email addresses on the connection stops linking and creating people by email. People already linked keep using the app.

The organization’s Require multi-factor authentication policy treats a connected app’s token like an SSO sign-in: your identity provider is responsible for the second factor.


Tessule resolves the person in the id_token to a member, in this order:

  1. The app’s own link. A person who has used this app before is recognised by their subject claim.
  2. The SSO connection’s link. A person who has signed in to Tessule through the same SSO connection, with the same sub, is linked to the app.
  3. A trusted email, to an existing member. The token’s email is trusted (below), its domain is a verified domain of your organization (and the connection’s Email domain, when it has one), and an active member of the organization has that email, verified in Tessule. That member is linked to the app.
  4. A trusted email nobody holds. Tessule creates the account, exactly as a first SSO sign-in does, and applies the connection’s role mapping using the token’s claims. The person can use the app once that mapping gives them the workspace.

Otherwise the exchange is refused. Each link is recorded once, so later exchanges take step 1.

When is the token’s email trusted? Only when one of these holds:

  • email_verified is the boolean true. A missing claim or the string "true" does not count.
  • The issuer is a Microsoft Entra host and the token carries xms_edov as the boolean true.
  • The SSO connection has Trust this provider’s email addresses switched on, and its issuer is tenant-specific: an issuer for your directory alone, never a shared one such as Entra’s common, organizations or consumers endpoints or Google’s consumer issuer. Only an organization owner can turn the switch on.

An explicit email_verified: false or xms_edov: false is never trusted, whatever the switch says.

A person whose email is not trusted and who has no link signs in to Tessule through the SSO connection once (its sign-in URL is GET /auth/sso/{connectionId}/start, copied from the SSO tab). That sign-in records the link that step 2 finds.


The app trades the person’s id_token for a Tessule token with POST /oauth/token, using the OAuth 2.0 token-exchange grant (RFC 8693). The browser calls it directly from an allowed origin. The client library below does this for you; this section is the wire contract.

POST https://api.tessule.com/api/oauth/token
Content-Type: application/x-www-form-urlencoded
grant_type=urn:ietf:params:oauth:grant-type:token-exchange
&client_id=<connected app client ID>
&subject_token=<the id_token>
&subject_token_type=urn:ietf:params:oauth:token-type:id_token
&resource=https://api.tessule.com/workspaces/ws_0123abcd
&scope=records:read query:execute
Field Notes
grant_type Always urn:ietf:params:oauth:grant-type:token-exchange.
client_id The connected app’s client ID.
subject_token The identity provider’s id_token for the signed-in person. Access tokens are refused.
subject_token_type Always urn:ietf:params:oauth:token-type:id_token.
resource The workspace the token is for: the API origin, then /workspaces/ and the workspace id. Required; a token is always for one workspace.
scope Optional. Space-separated actions that narrow the token below the ceiling. It can only remove actions; naming one outside the ceiling is invalid_scope. Omitted, the token carries the whole ceiling.

The body may also be JSON. A successful answer:

{
"access_token": "<Tessule token>",
"issued_token_type": "urn:ietf:params:oauth:token-type:access_token",
"token_type": "Bearer",
"expires_in": 1800,
"scope": "records:read query:execute"
}

Send access_token as Authorization: Bearer <token> on workspace API calls. GET /me/permissions tells the app what the token holds, so it can hide what the person cannot do.

A token lives for the app’s token lifetime or the id_token’s remaining life, whichever is shorter. It never outlives the id_token it came from. An id_token with under 60 seconds left, or one that expired less than 60 seconds ago, is refused with subject_token_expired. One that expired longer ago fails verification and is refused with subject_token_invalid.

There is no refresh token. Your identity provider’s session is the session of record: when the Tessule token expires, the app exchanges a fresh id_token, which identity provider SDKs produce without asking the person anything.

A refusal has the OAuth error shape, { error, error_description, reason }. reason says what the app should do:

error reason Meaning, and what to do
invalid_client (401) client_unknown No connected app has this client_id. Check the ID you copied.
invalid_client (401) client_disabled The app or its SSO connection is switched off, or the connection cannot be verified. Ask an organization admin.
invalid_client (401) grant_not_allowed The app is not enabled for the token-exchange grant.
invalid_grant (400) subject_token_invalid The signature, issuer, audience, algorithm or lifetime failed, or the token lacks the app’s subject claim. error_description says which.
invalid_grant (400) subject_token_expired The id_token has under 60 seconds left, or expired less than 60 seconds ago. Fetch a fresh one from the identity provider and try once more.
invalid_grant (400) subject_not_linked The person has no link and their email cannot be trusted. Send them through the SSO connection’s sign-in once.
invalid_grant (400) subject_not_a_member The email is trusted, but no active member of the organization matches.
invalid_grant (400) workspace_not_allowed The workspace is not one the app may address, or the person is not a member of it.
invalid_scope (400) — scope named an action outside the ceiling, or kept nothing.
invalid_request (400) — A required field is missing or malformed, such as a resource that names no workspace.
temporarily_unavailable (503) — The service or the identity provider’s signing keys could not be reached. Retry after Retry-After seconds.

Token issuance per app is rate limited, as a brake on runaway clients rather than a budget to plan against. Past it, the exchange answers 429 with Retry-After: wait that long before exchanging again, and avoid exchanging more often than tokens expire. Refused exchanges do not count.

The API answers cross-origin requests from each allowed origin of an enabled app, without credentials: the app sends its token in the Authorization header and no cookie. A page on any other origin cannot read the answers; the browser blocks them. A new origin is answered within a minute of saving it. A browser may cache a preflight answer for ten minutes, so a removed origin can keep working in an open tab for up to that long.


@henrycpainter/client, the typed client a custom app uses, also runs a connected app. Pass connectedAppAuth as auth and the client does the exchange:

  • it exchanges on the first call and reuses the token until 30 seconds before it expires;
  • concurrent calls share one exchange;
  • it sends the token as a bearer and sends no cookies;
  • on subject_token_expired it asks for a fresh id_token once, with forceRefresh: true, and exchanges again;
  • on a 401 from the API it exchanges once more and resends the request; a second 401 is returned to your code.

Install it from GitHub Packages as described in Starting from the starter kit. For your workspace’s types, run tessule pull --audience api, or ask an AI assistant for the SDK archive with audience: "api" (Building with an AI assistant). That document’s paths start with /api, and its bearerAuth scheme names the exchange under x-token-exchange, for a client generated in another language.

import { createClient, connectedAppAuth } from '@henrycpainter/client';
import type { paths } from './tessule-api';
const api = createClient<paths>({
baseUrl: 'https://api.tessule.com',
auth: connectedAppAuth({
clientId: '<connected app client ID>',
workspaceId: 'ws_0123abcd',
scope: ['records:read', 'query:execute'], // optional: narrow below the ceiling
subjectToken: async ({ forceRefresh }) => getIdToken(forceRefresh),
}),
});
const { data, error } = await api.GET('/api/me/permissions');

baseUrl is the API host with no path; a base URL with a path, such as https://api.tessule.com/api, is refused when the client is created. subjectToken returns the identity provider’s id_token for the signed-in person, or null when nobody is signed in. When forceRefresh is true, return a newly issued token rather than a cached one.

AWS Amplify (Cognito):

import { fetchAuthSession } from 'aws-amplify/auth';
const subjectToken = async ({ forceRefresh }: { forceRefresh: boolean }) =>
(await fetchAuthSession({ forceRefresh })).tokens?.idToken?.toString() ?? null;

MSAL (Microsoft Entra):

import { PublicClientApplication } from '@azure/msal-browser';
const msal = new PublicClientApplication({
auth: { clientId: '<application (client) id>', authority: 'https://login.microsoftonline.com/<tenant id>' },
});
await msal.initialize();
const subjectToken = async ({ forceRefresh }: { forceRefresh: boolean }) => {
const account = msal.getActiveAccount();
if (!account) return null;
const result = await msal.acquireTokenSilent({ account, scopes: ['openid', 'profile', 'email'], forceRefresh });
return result.idToken;
};

Register the app with subject claim Object id (oid). Entra’s sub differs between your app’s registration and the one your SSO connection uses.

Google Identity Services (Google Workspace):

let credential: string | null = null;
google.accounts.id.initialize({
client_id: '<client id>.apps.googleusercontent.com',
callback: (response) => { credential = response.credential; },
});
// Seconds until the id_token's `exp`, read from its base64url JSON payload.
const secondsLeft = (idToken: string): number => {
const [, payload = ''] = idToken.split('.');
const { exp } = JSON.parse(atob(payload.replace(/-/g, '+').replace(/_/g, '/')));
return typeof exp === 'number' ? exp - Date.now() / 1000 : 0;
};
const subjectToken = async ({ forceRefresh }: { forceRefresh: boolean }) => {
if (forceRefresh || (credential !== null && secondsLeft(credential) < 60)) credential = null;
return credential;
};

The credential response’s credential is the id_token. Google Identity Services has no silent refresh: on forceRefresh, or once the credential is within a minute of its expiry, the snippet returns null, and the app shows the Google sign-in button again.

An exchange that cannot happen rejects the call with a TessuleClientError whose kind says why:

kind Meaning What the app does
not-signed-in subjectToken returned null. No request was sent. Sign the person in at the identity provider.
not-linked The exchange answered subject_not_linked. Send the person through the SSO connection’s sign-in once.
exchange-refused Any other refusal. reason and oauthError carry the answer’s reason and error. Show the reason; most need an organization admin.

An id_token that expired more than 60 seconds ago is refused with subject_token_invalid, which the client does not retry, so the call rejects with exchange-refused. When subjectToken returns null for a token it cannot refresh, as the Google snippet does, the call rejects with not-signed-in instead.

import { TessuleClientError } from '@henrycpainter/client';
try {
const { data } = await api.GET('/api/me/permissions');
} catch (err) {
if (err instanceof TessuleClientError && err.kind === 'not-signed-in') showSignIn();
else if (err instanceof TessuleClientError && err.kind === 'not-linked') location.assign(SSO_SIGN_IN_URL);
else throw err;
}

API errors after a successful exchange (403, 404, validation) come back as the API’s own answers, as for any client.


In each walkthrough, Tessule’s SSO connection and your app are two registrations at the same identity provider, under the same issuer.

  1. Your SSO connection’s issuer is the user pool’s issuer, https://cognito-idp.<region>.amazonaws.com/<user pool id>.
  2. In the same user pool, create an app client for your app with the openid and email scopes. Its client id is the id_token’s aud: enter it under Token audiences.
  3. Keep the subject claim Subject (sub). A Cognito sub is the same for every app client in the pool, so anyone who has signed in to Tessule through SSO is recognised on their first exchange.
  4. Cognito sets email_verified when the user pool has verified the person’s email, which lets Tessule link or create them by email.
  5. For role mapping by group, set the connection’s groups claim to cognito:groups.
  1. Your SSO connection’s issuer is your tenant’s, https://login.microsoftonline.com/<tenant id>/v2.0.
  2. Register your app as a single-page application in the same tenant, with your app’s origin as a redirect URI. Its Application (client) ID is the id_token’s aud: enter it under Token audiences.
  3. Set the subject claim to Object id (oid). Entra’s sub is different for each app registration; oid is the same person in both.
  4. Request the email scope so the id_token carries the person’s email. Entra does not send email_verified. To link and create people by email, either switch on Trust this provider’s email addresses on the SSO connection (an organization owner can; the tenant-specific issuer above qualifies) or add the optional claim xms_edov. Without either, each person signs in to Tessule through SSO once before using the app.
  5. For role mapping by group, add a groups claim to the app registration’s token configuration. Entra sends group object ids; map those in the connection’s role mapping.
  1. Your SSO connection’s issuer is https://accounts.google.com.
  2. In Google Cloud, create an OAuth client ID of type Web application for your app, with your app’s origin as an authorized JavaScript origin. Its client id (ending .apps.googleusercontent.com) is the id_token’s aud: enter it under Token audiences.
  3. Keep the subject claim Subject (sub). Google’s sub is the same for every client, so anyone who has signed in to Tessule through SSO is recognised on their first exchange.
  4. Google sets email_verified for Workspace accounts. The token’s hd claim names the Workspace domain; Tessule reads the email instead, and links or creates a person only when the email’s domain is one of your verified domains. Set the OAuth consent screen’s user type to Internal so only your Workspace accounts can sign in to the app.
  5. Google sends no groups claim, so a person created by the app gets the connection’s default roles.

Does a connected app work for people outside our organization? No. The token always acts as a member of your organization, in a workspace they belong to.

Can the app read the token’s permissions before calling? Yes: GET /me/permissions returns what the token holds, which is the person’s own permissions narrowed by the ceiling.

What do our members see? Nothing to approve. Requests the app makes appear in the audit trail under the person’s name, “via” the app’s name.

We narrowed the ceiling. When does it apply? Within a minute. Outstanding tokens stop working, and the client exchanges again under the new ceiling.

Can we test from a development server? Yes. Add http://localhost with your dev server’s port to Allowed origins.

Open the app