Skip to main content

See It in a Sample App

Cloud has the newest features. Some may not be in a release yet; the newest release is Identity & Access Management 7.3.0.

Wayfinder Enterprise is the reference implementation for B2B SaaS applications: a corporate travel app that runs the journeys of this section against Choreo Identity & Access Management. Companies register themselves, their admins set travel policies and manage their team, and employees sign in with a password or through their company's own identity provider to book flights.

Get the complete sample

The Companies​

The walkthroughs use two companies, each an organization unit (OU) beneath the platform organization, Wayfinder Enterprise:

Wayfinder Enterprise the platform organization: the app, its roles, flows and user type
├── Northstar Labs a company whose employees sign in with passwords
└── Initech a company whose employees sign in through Initech's own identity provider

The application, its two roles (Wayfinder Admin and Wayfinder Member), and its sign-in flow are defined once in Wayfinder Enterprise and shared with every company, so a company works the moment it signs up.

Architecture​

The sample is one Next.js app. Its pages sign people in through Choreo Identity & Access Management with @thunderid/nextjs, and its API routes serve bookings and travel policies keyed by the company in the access token. The admin pages manage Choreo Identity & Access Management resources through the app's own /api/admin route, which pins every call to the admin's company and forwards it with a backend client's token for that company.

A user's token carries only the app's own permissions, never a Choreo Identity & Access Management management permission. See Let Organization Admins Manage Teams for why the admin calls go through a backend route.

Get the Sample​

Download the sample above, or copy its source:

npx degit thunder-id/samples/b2b/wayfinder-enterprise wayfinder-enterprise
cd wayfinder-enterprise

Import the Bundle​

The fastest way to create the resources the walkthroughs need. Import two files through the Console, in this order:

  1. Generate a client secret for each of the two applications, for example with openssl rand -base64 32, and set them as WAYFINDER_ENTERPRISE_CLIENT_SECRET and WAYFINDER_ENTERPRISE_BACKEND_CLIENT_SECRET in thunderid-config/thunderid.env. The file ships without them, and the Console does not import it until both are set. Keep the values for the app's .env.local.

  2. Point the resources at the Data Plane resource server. The backend's role names that resource server by ID, and in Choreo Identity & Access Management its ID is 01a1864b-ef42-7c41-b0a2-97f53fd3b1e4. Replace the ID the file ships with:

    perl -pi -e 's/01900000-0000-7000-8000-000000000020/01a1864b-ef42-7c41-b0a2-97f53fd3b1e4/g' thunderid-config/thunderid-config.yaml
  3. Sign in to the Console at https://console.cloud.choreolabs.com/iam/. Select the Default project in the project switcher in the header.

  4. Choose Import / Export, then Import. Upload thunderid-config/organization-unit.yaml as the configuration file. It needs no environment file. Choose Continue, and once the import test passes, choose Import configuration.

  5. Choose Import / Export, then Import again. Upload thunderid-config/thunderid-config.yaml as the configuration file and thunderid-config/thunderid.env as the environment variables file, to provide the variables the YAML references. Choose Continue, then Import configuration. A secret you left empty can be entered in the Environment variables editor before you import.

The Console tests each import before it runs it, and that test only finds an organization unit that already exists. The second file places every resource in the organization unit the first one creates, so import the first one on its own.

What the Import Creates​

ResourceNameWhat it does
Organization unitWayfinder Enterprise (wayfinder-enterprise)The platform organization, a root organization unit in the Default project. Every company that signs up becomes its child.
User typeWayfinder User (wayfinder-user)The account schema, with self-registration on. Owned by the platform organization, so every company can use it.
Resource serverWayfinder Enterprise API (urn:wayfinder-enterprise:api)The app's own permissions, for bookings, travel policies, and the admin pages
Server configdefaultResourceServerMakes the Wayfinder Enterprise API the default resource server
RolesWayfinder Admin, Wayfinder MemberShared with every company. An admin manages the company; a member books within its travel policy.
FlowWayfinder Enterprise Company Sign-upCreates the company, creates its first admin inside it, and assigns Wayfinder Admin
FlowWayfinder Enterprise Sign-inPassword, enterprise single sign-on (SSO), or company registration. Shared with every company, and each company sets its own enterpriseIdp.
Theme and layoutWayfinder, Wayfinder CenteredThe look of the sign-in and sign-up screens
ApplicationWayfinder EnterpriseThe app's confidential client, with the organization and role claims in its tokens. Shared with every company.
Application and roleWayfinder Enterprise BackendA client_credentials client for the app's admin route, shared with every company

The other defaults in thunderid.env work as they are.

Deploy your changes

Saving a change does not make it live. You author in the control plane, and your users sign in on a separate data plane, so a change takes effect in an environment only after you deploy it. Go to Deploy, deploy the latest version to your first environment, then promote it to the next environment when you are ready.

Auto-sync deploys saved changes to your first environment within seconds. Turning it on is your choice, per project. See Deploy a Version, or learn why you deploy and how auto-sync works.

Configure the Sample​

Copy the environment template:

cp .env.example .env.local

The other defaults match the import. In .env.local, set NEXT_PUBLIC_THUNDERID_BASE_URL to https://<DATA_PLANE_URL> and THUNDERID_SYSTEM_RESOURCE to https://<DATA_PLANE_URL>, the identifier of the Data Plane resource server. Set THUNDERID_CLIENT_SECRET and WAYFINDER_BACKEND_CLIENT_SECRET to the client secrets you set in thunderid.env, and THUNDERID_SECRET to a long random string; the SDK encrypts the session cookie with it. Generate one with:

openssl rand -base64 32
Data plane URL

https://<DATA_PLANE_URL> stands for your environment's data plane URL, where users sign in and tokens are issued. Replace it with the URL on the environment's Endpoints page. To open it, select your project, go to Deployment pipeline, and click Open environment on the environment's card. See Control Plane and Data Plane URLs.

Run the Sample​

From the sample directory, install dependencies and start the app:

npm install
npm run dev

The sample opens at http://localhost:3000.

Walkthroughs​

After the sample is running, follow a journey through it:

Next Steps​

  • Build a smaller B2B app from scratch with the React or Next.js B2B quickstart, including switching between organizations.
  • Review the Design Decisions behind the pattern.

Was this page helpful?