Sign-in and users
Let your app's users sign in, find out who they are, and control what they can reach.
The Shell signs your users in, so your app never handles passwords or sign-in screens. Your app asks the Shell for the signed-in user's token and uses it to call Groundfloor, and gets a separate app token for its own backend.
These are your app's users, not your team: they sign in to your Shell site, not the Client Portal.
Choose how users sign in
In the Client Portal, go to Administer → App authentication and choose a mode. The Shell picks it up automatically:
| Mode | Users sign in with | Users are managed in |
|---|---|---|
| None | Nothing: the app is open, or handles access itself | — |
| Groundfloor | A sign-in page Groundfloor hosts for your workspace | The Users tab of App authentication |
| External | Your own identity provider, such as Okta, Microsoft Entra ID or Auth0 | Your identity provider |
See App authentication for setting each one up.
Get the user's token
The Shell makes a function available to your app:
const token = await window.__GF_GET_ACCESS_TOKEN__?.(); // null when nobody is signed inSend it as Authorization: Bearer <token> to Groundfloor's API. The starter kit's helpers, for data and feature flags, already do this. The function returns a fresh token each time, so call it before each request rather than storing the result.
This is the Shell site token. Groundfloor's APIs accept only it, not an app token.
Get a token for your own backend
Rolling out, with Groundfloor sign-in. When your app calls its own backend, send an app token instead: a token for your app only, which your backend can tell apart from tokens meant for other apps.
import { getAppToken } from "@groundfloorcloud/app-auth/browser";
const res = await fetch("https://api.example.com/api/orders", {
headers: { Authorization: `Bearer ${await getAppToken()}` },
});getAppToken() is in @groundfloorcloud/app-auth 0.2.0 and later. Inside the Shell it needs no arguments: it takes your workspace, your app and the user's Shell site token from the Shell. It asks Groundfloor to swap the Shell site token for an app token, and caches the result.
- The token has
audandazpequal toapp-<app-id>, and the user'ssub,email,rolesand, with Multi-tenant on,organization. - It lasts at most 5 minutes, and never longer than the user's Shell sign-in. Call
getAppToken()before every request; it returns the cached token until shortly before it expires. - Only signed-in users who can open the app get one.
- Send it only to your own backend. Keep sending the Shell site token to Groundfloor's APIs.
Your backend checks it as in Check an app token. Backends that check the Shell site token keep working until Groundfloor announces a date to retire it, so you can move over at your own pace.
With External sign-in there are no app tokens (getAppToken() throws app_token_requires_groundfloor_login): your backend checks your identity provider's tokens instead.
Know who the user is
The Shell site token is a JWT. These claims identify the user and where the token came from:
| Claim | What it is |
|---|---|
sub | The user's ID. Store this to tie records to the user |
external_user_id | With Groundfloor sign-in, the same value as sub. Don't store it; use sub |
external_tenant_id | Your workspace's ID — the same for every user |
organization | The customer company the user belongs to, when Multi-tenant is on in App authentication |
realm_access.roles | The user's roles, with Groundfloor sign-in. See What users can reach |
iss | The issuer: who signed the token. With Groundfloor sign-in it's unique to your workspace |
azp | The client the token was issued to: shell with Groundfloor sign-in, or your client ID with External sign-in |
Use sub as the user's ID
Your backend should store and match records by sub, read from a token it has verified, in both sign-in modes. Don't take a user ID from the request body, a header or a token you haven't checked.
What sub holds depends on the sign-in mode:
- Groundfloor: the user's ID in your workspace's sign-in, the same
idthe Users API returns. It doesn't change while the user exists. Users who sign in through single sign-on get a Groundfloor ID too, not the ID their company's provider uses. Each workspace has its own users, so the same person has a differentsubin another workspace. - External: the ID your identity provider puts in
sub. Groundfloor doesn't change it. External tokens carryexternal_user_idonly if your provider adds it.
A user's sub changes only when their account is replaced. A user you remove and invite again gets a new ID; Delete Groundfloor login removes every user, so users get new IDs if you turn Groundfloor sign-in on again; and moving to External sign-in means the IDs come from your provider instead. Records stored under the old IDs then no longer match, so plan how to move them, for example by email address, before you make one of these changes.
external_user_id is an older claim that Groundfloor sign-in tokens still carry. It holds the same value as sub and isn't a separate ID, so don't build on it: store sub.
A backend must check the signature, iss, exp and which client the token was issued to before trusting any of these, and refuse a token with an x-client-key or x-userid claim: those are Groundfloor's own management tokens, not a user's. See Who can reach your Service.
If your app serves several customer companies, turn on Multi-tenant and keep each company's data apart by the organization claim. Don't use external_tenant_id for that: it identifies your workspace, not the user's company.
Pages anyone can open
By default every page of your app needs a signed-in user. To make a page public, set "visibility": "public" on its route in the manifest.
What users can reach
Signed-in users get a role in your workspace's site, such as viewer, user or admin, set on the Users tab of App authentication. Roles decide which apps they can open and which data they can read or change:
- Apps: each app is open to everyone, or restricted to chosen roles. See What is an app.
- Data: each collection grants read, write and delete per role. New collections are open only to admins until you grant access. See Data.
Manage both on the Site access page.
A user's roles are in their token's realm_access.roles claim, as a list such as ["user", "offline_access", "default-roles-…"]. Look for the roles you use and ignore the rest. Your own backend reads them there to decide what the user may do; in an app token they're also in the roles claim. With External sign-in, roles come from your identity provider, in whatever claim it uses.
Next steps
- Data — read and write records as the signed-in user.
- Secrets and backends — call your own backend with an app token.
- App authentication — set up a sign-in mode.