Skip to content

Build a customer portal

A portal is an application one of your clients runs for its own customers: a logistics company’s customer portal, a supplier portal. Those customers are not platform users. They sign in on the separate portal identity plane: their own credentials per client, no platform roles, no API access, and no single sign-on into the platform. The platform proves who they are; your portal decides what they may see. Portal identity explains the model and why it is separate.

sequenceDiagram
  participant B as Customer's browser
  participant P as Your portal
  participant FC as Platform (/portal)
  B->>P: GET / (no session)
  P-->>B: 302 to FC /portal/authorize (PKCE)
  B->>FC: email, then password or the org's SSO
  FC-->>B: 302 to portal callback with a code
  P->>FC: POST /oauth/token (code + verifier)
  FC-->>P: id_token (sub = ptu_...) + an authority-free access token
  P->>P: look up YOUR membership for ptu_..., start YOUR session
Staff login (/oauth/authorize) Portal login (/portal/authorize)
Who Platform users (prn_) Portal identities (ptu_), one per client and email
Roles in the id_token The user’s roles in your application Always empty: portal roles are your data
Refresh tokens With offline_access Never. When your session ends, send the user through /portal/authorize again.
Session reuse Platform session can make sign-in seamless None: every portal login is a fresh authentication
Credential pages Platform-hosted Platform-hosted too, including forgot password; you build none of it

The id_token carries sub (the ptu_ identity id: use it, not the email, as your join key), email, name, portal_client_id and, for an app-linked client, portal_app_code and portal_app_id.

  1. A portal app, for the client that runs the portal: console Portal, Portal Apps, or POST /api/portal-apps {clientId, code, name, redirectUris?, clientType?}. A client may run several portals (customer-portal, supplier-portal); its portal users are one population with one password each, granted per app. The code cannot change later. Creating the app also creates its portal OAuth client (authorization code with PKCE, your callback registered, linked to the app) and returns oauthClientId and, for the default confidential type, a clientSecret shown once.
  2. A service account for the portal backend holding the built-in platform:portal-administrator role (portal-user view and manage). It is client-delegable: the same role given to one of the client’s administrators lets them manage portal users in the console, confined to their client.
  3. Optional: SSO for customer organisations. An identity provider with the organisation’s email domains claimed. Domain ownership alone routes those users’ portal logins (and invitations) to their identity provider; the first SSO login creates the identity.
import { flowcatalystAuth } from "@flowcatalyst/sdk/fastify";
await app.register(flowcatalystAuth, {
baseUrl: process.env.FC_BASE_URL!,
clientId: process.env.FC_PORTAL_CLIENT_ID!, // the portal OAuth client
clientSecret: process.env.FC_PORTAL_CLIENT_SECRET!,
portal: true, // enter through /portal/authorize
expectedAudience: process.env.FC_PORTAL_CLIENT_ID!,
cookie: { secret: process.env.SESSION_SECRET! },
});
app.addHook("preHandler", async (req) => {
if (!req.principal) return;
const membership = await db.membership.findFirst({ where: { identityId: req.principal.id } });
if (!membership) throw app.httpErrors.forbidden("No portal access");
});

req.principal.id is the ptu_ identity. Callback, token exchange and session handling are the same as a staff login.

Any other stack runs the standard authorization-code flow with PKCE against {platform}/portal/authorize, exchanges the code at {platform}/oauth/token, and verifies the id_token against the platform’s JWKS (issuer = the platform URL, audience = the portal client id, plus the nonce).

Deploy the portal on its own hostname (a sibling subdomain of the platform is fine, the same hostname is not) with its own session cookie name.

Invitations are the portal’s job (the console deliberately has no invite button), so the portal can write its own membership row in the same step. Call as the portal backend’s service account.

import { ensurePortalUser, listPortalUsers, deactivatePortalUser, deletePortalUser } from "@flowcatalyst/sdk";
const ensured = await fc.request((client, headers) =>
ensurePortalUser({
client, headers,
body: {
clientId, email: "pat@customer.example", name: "Pat Jones",
portalAppCode: "customer-portal",
returnInviteLink: true, // you send the email
redirectUri: "https://portal.example.com/auth/entry",
},
}),
);
// ensured.value: identityId, created, invited, inviteUrl, state
const users = await fc.request((client, headers) =>
listPortalUsers({ client, headers, query: { clientId, portalAppCode: "customer-portal" } }));
await fc.request((client, headers) =>
deactivatePortalUser({ client, headers, path: { id }, body: { clientId } }));

POST /api/portal-users ensures an identity:

  • Idempotent. Calling again reactivates a suspended identity and re-sends the invitation while it has no password; an identity that can already sign in is left alone.
  • portalAppCode grants your portal app (other portals’ grants are untouched). A user without the app’s grant is refused at the portal login page.
  • Delivery. By default the platform emails its own set-password invitation (needs the platform’s SMTP). With returnInviteLink: true nothing is emailed and the answer carries a 72-hour set-password URL for your own email. It is a live credential: never log or store it.
  • redirectUri is where the user goes after setting a password. It must exactly match a redirect URI registered on one of the client’s portal OAuth clients; omitted, it defaults to the portal’s origin.
  • SSO domains. When the email’s domain belongs to an identity provider, there is no password step: the answer says ssoManaged: true and the link (in returnInviteLink mode) is simply the portal’s login.
Operation Route
List (prefix search q, portalAppCode, unassigned=true, page, size up to 1000) GET /api/portal-users?clientId=...
Suspend (blocks password and SSO login) and reactivate POST /api/portal-users/{id}/deactivate, /activate
Grant and revoke one portal app POST /api/portal-users/{id}/apps, DELETE /api/portal-users/{id}/apps/{portalAppCode}
Offboard from every portal of the client DELETE /api/portal-users/{id}?clientId=...
Grant an app to every user without one POST /api/portal-apps/{id}/assign-unassigned

A portal user’s state is INVITED, INVITE_EXPIRED (re-ensure to resend), ACTIVE or SUSPENDED. To offboard: remove your membership row, end your session, then delete the identity. Suspension takes effect at the next login or code redemption; ending your own session is your job.

  • Every portal login is a fresh authentication; there are no refresh tokens to steal.
  • Password logins are rate-limited per client and email (FC_RL_PORTAL_LOGIN_PER_15MIN, default 10) with uniform answers, so accounts cannot be enumerated.
  • Second factors for portal password users are not built yet; organisations that sign in through their own identity provider get that provider’s MFA. Prefer SSO for sensitive portals.
  • A login flow expires after 15 minutes; the stale page sends the user back to the portal to start again.