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
What is different from a staff login
Section titled “What is different from a staff login”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. Set up the portal on the platform
Section titled “1. Set up the portal on the platform”- 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. Thecodecannot change later. Creating the app also creates its portal OAuth client (authorization code with PKCE, your callback registered, linked to the app) and returnsoauthClientIdand, for the default confidential type, aclientSecretshown once. - A service account for the portal backend holding the built-in
platform:portal-administratorrole (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. - 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.
2. Wire the login
Section titled “2. Wire the login”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.
FLOWCATALYST_BASE_URL=https://platform.example.comFLOWCATALYST_OIDC_ENABLED=trueFLOWCATALYST_OIDC_PORTAL=true # /flowcatalyst/login goes to /portal/authorizeFLOWCATALYST_OIDC_CLIENT_ID=<portal OAuth client id>FLOWCATALYST_OIDC_CLIENT_SECRET=<secret># the backend's service account, for managing portal usersFLOWCATALYST_CLIENT_ID=<service account client id>FLOWCATALYST_CLIENT_SECRET=<service account secret>SESSION_COOKIE=portal_sessionPut your membership gate in your own OidcUserHandler; sub is the identity id:
final class PortalUserHandler implements OidcUserHandler{ public function handleAuthenticatedUser(FlowCatalystUser $user): mixed { if (! Membership::where('identity_id', $user->sub)->exists()) { abort(403, 'No portal access. Ask your administrator for an invitation.'); } session()->put('portal_user', ['id' => $user->sub, 'email' => $user->email]); return $user; } public function handleLogout(): void { session()->flush(); } public function getPostLoginRedirect(): string { return '/'; } public function getPostLogoutRedirect(): string { return '/'; }}Bind it in a service provider and leave FLOWCATALYST_NATIVE_LOGIN off: its local-user upsert is
meant for staff, not portal identities.
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.
3. Invite and manage portal users
Section titled “3. Invite and manage portal users”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 } }));use FlowCatalyst\Facades\FlowCatalyst;use FlowCatalyst\Generated\Model\PortalUserClientBody;use FlowCatalyst\Generated\Model\PortalUserRequest;
$api = FlowCatalyst::generated();
$result = $api->ensurePortalUser((new PortalUserRequest()) ->setClientId($clientId) ->setEmail('pat@customer.example') ->setName('Pat Jones') ->setReturnInviteLink(true) ->setRedirectUri('https://portal.example.com/auth/entry'));// $result->getIdentityId(), ->getCreated(), ->getInviteUrl()
$list = $api->listPortalUsers(['clientId' => $clientId]);$api->deactivatePortalUser($identityId, (new PortalUserClientBody())->setClientId($clientId));$api->deletePortalUser($identityId, ['clientId' => $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.
portalAppCodegrants 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: truenothing 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. redirectUriis 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: trueand the link (inreturnInviteLinkmode) 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.
Security notes
Section titled “Security notes”- 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.
Related
Section titled “Related”- Portal identity.
- Use FlowCatalyst as your app’s identity provider (staff logins).
- Portal users and portal apps HTTP reference.
- Decision: a separate portal identity plane.