Customer portals
A portal is an application one of your clients runs for its own customers. Those customers are
portal identities (ptu_…): a separate population from platform users, per client and email, with
no roles, no client access and no platform API access. The platform owns proving who they are
(passwords, invitations, reset, or federation to the customer organisation’s own identity provider);
your application owns what they may do, keyed by the identity id. The model and the reasons are in
Portal identity; the step-by-step guide is
Build a customer portal. This page is the TypeScript API.
Sign-in: portal mode
Section titled “Sign-in: portal mode”In portal mode the Fastify plugin’s login route enters through {platform}/portal/authorize
instead of the standard authorize endpoint. The callback, token exchange, session cookie and ID-token
verification are unchanged, and the session principal’s id is the ptu_… identity.
import { flowcatalystAuth } from '@flowcatalyst/sdk/fastify';
await app.register(flowcatalystAuth, { baseUrl: process.env.FC_BASE_URL!, clientId: process.env.FC_OIDC_CLIENT_ID!, // the portal OAuth client clientSecret: process.env.FC_OIDC_CLIENT_SECRET!, portal: true, // portal identity plane expectedAudience: process.env.FC_OIDC_CLIENT_ID!, cookie: { name: 'portal_session', secret: process.env.SESSION_SECRET! },});Points that differ from a normal sign-in:
- The portal OAuth client must be flagged as a portal client for the operating client; creating a portal app in the console or API provisions one for you. Without that the portal plane refuses it.
- There are no refresh tokens. Your session is the session: when it ends, send the user through login again.
- The access token is useless for platform APIs (its
token_useisidentity). Platform calls from your backend use a service account. - The ID token has an empty
rolesclaim, so the plugin’s role and permission helpers have nothing to say about portal users. Resolve your own membership data fromrequest.principal.idand refuse anyone who has none. request.principal.portalholdsclientIdand, for an app-linked portal client,appCodeandappId(theportal_app_codeclaim).- The
clientoption (login branding) is ignored in portal mode. - Give the portal its own distinct
cookie.nameand its own hostname.
A membership gate is an ordinary preHandler:
app.addHook('preHandler', async (req, reply) => { const p = req.principal; if (!p) return; if (!p.id.startsWith('ptu_')) return reply.code(403).send({ error: 'no_portal_access' }); const membership = await db.memberships.findByIdentity(p.id); if (!membership) return reply.code(403).send({ error: 'no_portal_access' });});If one application serves both an administrative plane and a portal plane, register the plugin twice with distinct cookies and routes; the first plane to authenticate a request wins. See Fastify.
Without Fastify, run the standard authorization-code flow with PKCE against /portal/authorize, exchange
the code at /oauth/token, and verify the ID token against the platform’s JWKS with any OIDC library.
Managing portal users
Section titled “Managing portal users”The portal-user admin API is called with a service account that holds the
platform:portal-administrator role. The five lifecycle functions are re-exported from the package
root, and the rest of the generated surface is under the api namespace. Pass any of them through
client.request() for authentication, retries and error mapping:
import { FlowCatalystClient, ensurePortalUser, listPortalUsers, deactivatePortalUser } from '@flowcatalyst/sdk';
const client = new FlowCatalystClient({ baseUrl: process.env.FC_BASE_URL!, clientId: process.env.FC_CLIENT_ID!, // service account clientSecret: process.env.FC_CLIENT_SECRET!,});
// Invite. Idempotent: returns identityId, created, invited, state and (optionally) inviteUrl.const ensured = await client.request((c, headers) => ensurePortalUser({ client: c, headers, body: { clientId, email: 'pat@customer.example', name: 'Pat Jones', portalAppCode: 'customer-portal', returnInviteLink: true, redirectUri: 'https://portal.example.com/auth/entry', }, }),);
const users = await client.request((c, headers) => listPortalUsers({ client: c, headers, query: { clientId, q: 'pat', portalAppCode: 'customer-portal' } }));
await client.request((c, headers) => deactivatePortalUser({ client: c, headers, path: { id: identityId }, body: { clientId } }));| Function | Purpose |
|---|---|
ensurePortalUser |
Create or invite a portal user, and grant a portal app by portalAppCode. Re-calling reactivates a suspended identity and re-sends the invite while no password exists. |
listPortalUsers |
List with clientId, q (prefix on email and name), portalAppCode, unassigned, page (0-based) and size (default 100, maximum 1000). Page through total. |
activatePortalUser, deactivatePortalUser |
Suspend or restore sign-in; body { clientId }. |
deletePortalUser |
Offboard from every portal of the client; query: { clientId }. |
api.grantPortalUserApp, api.revokePortalUserApp |
Grant or revoke one portal app for an identity. |
api.listPortalApps, api.createPortalApp, api.updatePortalApp, api.deletePortalApp, api.assignUnassignedPortalUsers |
Portal apps. |
The ensure response carries identityId (your join key), created, invited, state (INVITED,
INVITE_EXPIRED, ACTIVE, SUSPENDED), hasPassword, portalAppCode, ssoManaged and inviteUrl.
- Invites. By default the platform emails its own set-password invite (it needs the platform’s SMTP
configured). With
returnInviteLink: truenothing is emailed: the response has the 72-hour set-password URL and you send your own email around it. The URL is a live credential: never log or store it.redirectUrimust match a registered redirect of one of the client’s portal OAuth clients. - Federated organisations. When the invitee’s email domain belongs to an identity provider bound
to the portal, there is no set-password step:
ssoManagedis true andinviteUrlis the portal login destination. - Offboarding order. Remove your membership row, end your session, then delete the platform identity. Suspension and deletion bite at the next login or code redemption; your own session survives until you end it.
Errors from these calls are the usual SDK errors.
Testing
Section titled “Testing”Test the membership gate by decorating request.principal with an object whose id starts with ptu_
in a test hook, without running the OIDC flow. To test sign-in itself, reuse the mock-issuer approach
described in Fastify with portal: true and assert that the
login redirect goes to /portal/authorize. For user management, run fcdev and a portal app created
in its console.