Identity and sign-in
Every way a person gets into EduSpaze, who sets it up, and what a platform admin can see and change. Last updated 2026-09-18.
1. The ways in
| Who | Signs in with | Where | Set up by |
|---|---|---|---|
| School staff — admins, teachers, office | Email or username + password, always available | /school/login (or /login) | the school, or EduSpaze on their behalf |
| School staff | Google Workspace / Microsoft Entra ID / Sign in with Apple, where the school has switched SSO on | /school/login → provider | the school, or EduSpaze on their behalf |
| School staff | A one-time emailed link (passwordless) | /school/login | — |
| Pupils | Username + PIN | /school/login → Pupil | the school (roster import or batch issue) |
| Pupils | The school's own SSO, where the school has switched it on and the pupil's school email is on the roster | /school/login → Pupil → provider | the school (roster email column) |
| Staff and pupils | The school's LMS, launching EduSpaze over LTI 1.3 (docs/integration/lti.md) | the LMS | the school's LMS administrator |
| Vendors, EduSpaze staff, guardians | Password, plus optional two-factor | /login | EduSpaze (vendors, staff) or the school (guardians) |
Anyone with an email address can also request a one-time sign-in link (docs/email.md §3).
The school sign-in, /school/login. Every way a school's staff and pupils get in, on one page, with a Staff / Pupil switch (?as=pupil). *Changed 2026-09-30:* the school-account buttons go straight to the provider — nobody types an email first. The school is found afterwards from the address the provider verified, and every check runs then: the school's domains and directory (claimsRefusal), that it uses this provider, that SSO is switched on, and its EduSpaze subscription (afterVerification, lib/identity/sso-status.ts).
What a refusal says. Before the provider has verified anybody, every refusal reads the same — anybody can type any address. *After* verification the person has proved they hold an account on that domain, so they are told where their own school stands: no school on EduSpaze uses the domain, the school signs in with another provider, it has not switched single sign-on on, or its subscription ended on a date (school admins keep their password, §1). The message travels back signed, so the URL cannot put words on the page. Outside the school's own configuration the only proof is an address the provider itself verified; a Microsoft answer carries no such guarantee, so without the school's tenant to check it is refused without explanation.
A public email provider's domain never belongs to a school (lib/validation/personal-domains.ts: gmail.com, outlook.com, yahoo.com, icloud.com and the like). It is refused:
- when a school's domains are saved;
- when a school is made at sign-up (the registrant's own domain is left off);
- at the sign-in gate;
- after the provider verifies the address. An address on gmail.com is told no school uses the domain, even if a profile somehow held it.
Otherwise anybody with a Gmail address could sign in to that school.
Typing a school email first ("Use your school email instead") exists only where the demo provider runs — development, the test harness, and a demo deployment with DEMO_SSO=on; never on the live site. It only finds the school's provider from the address, which the buttons already do, and on the live site it read as a sign-in of its own. A provider EduSpaze has not registered yet is still said plainly when its button is pressed. Signed-out visits to any school or pupil page land here with next set to that page, and /student/login (printed on older class sheets) opens the Pupil tab. /login stays the general sign-in for everyone — schools, vendors, EduSpaze — and links here. /school/login is served by app/sign-in/school through a middleware rewrite, because every other /school page sits in the portal layout, which needs somebody signed in.
Two rules hold everywhere:
- A school admin always keeps a password. A misconfigured provider must never be able to lock a school out of the settings page where they would fix it.
- Pupils sign in however their school does — its SSO, its LMS, or a username and PIN. *Changed 2026-09-28, deliberately.* The rule was "pupils never touch SSO". Schools that run Google Workspace or Microsoft 365 for pupils, and LMSes that launch tools, identify pupils by their school account; a second, separate credential for a child is friction without a safeguarding gain. What the old rule protected is kept by three other rules:
- The roster is the only authority on who is a pupil. A school account signs a pupil in only when it is the account made from their roster record (the roster's
emailcolumn, held on the pupil's login — never on theStudentrecord the parent module reads). The directory or LMS saying "learner" never creates a pupil; no auto-provisioning applies. - Only active pupils at that school. A leaver's account stops working when the roster says they left, whichever way they sign in.
- Vendors still see a code, never a name or an email. The launch handshake is unchanged (
docs/integration/vendor.md§3).
One account, several schools. A person is one account with a membership per school — the same jeff@ted2.com can teach at one school and run another. After a password sign-in they land in (lib/school/home-school.ts): the school they last switched to on that browser, else the school whose email domains include their address, else the membership with the most authority. "Acting for" at the top of the school portal switches, and shows the role held at each. SSO needs no choice: the provider was the school's own, so it lands in that school.
1.1 The page decides which kind of account signs in
A sign-in only ever looks for the kind of account its page is for — never for "whichever account these credentials find":
| Started on | Signs in | Never |
|---|---|---|
/school/login, /login (School tab), /student/login | school staff and pupils, through their school | a startup or EduSpaze account, even one linked to the same Microsoft or Google identity |
/startup/login, /login?as=startup | startup team members, by the identity they linked | a school account; and a refusal does not fall through to a school |
/admin/login | EduSpaze admins, by the identity they linked | anybody else |
/parent/login | parents | anybody else |
Single sign-on carries the page in its transaction (from, portalScope); the callback asks only for that kind. The password forms carry it too (portal), and the action refuses an account of another kind — after the password matched, so it gives nothing away — and says which page is theirs. One address is one account (User.email is unique), and one Microsoft or Google identity links to one account; the page decides whether that account may come in here. The demo list (/login?demo=1) is the one form that signs in any kind.
2. What the platform is connected to
EduSpaze is the OAuth relying party. It registers *one* application per provider and brokers every school through it — schools never supply a client id or secret, they choose a provider and narrow it to their own domains and directory.
| Variable | Provider |
|---|---|
GOOGLE_CLIENT_ID / GOOGLE_CLIENT_SECRET | Google Workspace |
MICROSOFT_CLIENT_ID / MICROSOFT_CLIENT_SECRET | Microsoft Entra ID |
APPLE_CLIENT_ID (Services ID), APPLE_TEAM_ID, APPLE_KEY_ID, APPLE_PRIVATE_KEY (.p8) | Sign in with Apple — optional (§2.4) |
| *(built in)* | Demo identity provider — test sign-ins and demonstrations only |
Register <app base URL>/api/auth/sso/callback as the redirect URI with each provider, and request openid email profile. The credentials themselves are environment variables on the service and are never rows in this database.
Admin → Settings → Identity & sign-in is where this is done. It carries a four-step checklist that reads the running service rather than describing an ideal one:
| # | Step | Turns green when |
|---|---|---|
| 1 | Tell the service its own public address | APP_BASE_URL is set |
| 2 | Register EduSpaze with Google (§2.1) | GOOGLE_CLIENT_ID / _SECRET are set |
| 3 | Register EduSpaze with Entra (§2.2) | MICROSOFT_CLIENT_ID / _SECRET are set |
| 4 | Switch a school on (§3) | a school is live on Google or Entra |
Two things the order is doing. Steps 2 and 3 read waiting, not *to do*, until step 1 is done: the redirect URI is derived from the public address, so registering it against a guessed address fails every sign-in afterwards with redirect_uri_mismatch — and by then a school has been told it is live. For the same reason the page prints *no* redirect URI while APP_BASE_URL is unset, rather than a plausible one somebody would copy.
And step 4 does not count a school live on the demo provider. That proves the screens and registers nothing with anybody; treating it as done would report the work finished while both consoles are still empty.
The protocol is authorization code + PKCE (lib/identity/oidc.ts); the state and verifier live in a short-lived signed cookie, and the id token is verified against the provider's JWKS (HS256 against the app secret for the demo provider only).
2.1 Registering EduSpaze with Google Workspace
Done once, by EduSpaze, not by each school. The account that owns it can be an ordinary @gmail.com account — a Google Cloud project and an OAuth client do not require Workspace — but two things about that account matter:
- it becomes the owner of the OAuth client, so it should be an account EduSpaze controls permanently, with two-factor on, not a personal address that leaves with a person;
- it cannot supply the authorised domain the consent screen needs (see below).
gmail.comis not accepted there.
1 · Google Cloud console → the eduspaze project → *APIs & Services*
*OAuth consent screen* first:
| Field | Value |
|---|---|
| User type | External |
| App name | EduSpaze |
| User support email | the owning account |
| Authorised domains | the EduSpaze domain — not gmail.com, and not run.app |
| Application home page / privacy policy / terms | URLs on that same domain |
| Scopes | openid, .../auth/userinfo.email, .../auth/userinfo.profile — all non-sensitive |
Then *Credentials* → Create credentials → *OAuth client ID* → Web application:
| Field | Value |
|---|---|
| Authorised redirect URI | <app base URL>/api/auth/sso/callback |
| Authorised JavaScript origins | not needed — the flow is server-side |
2 · The EduSpaze service. Store the two values in Secret Manager and set them on Cloud Run:
GOOGLE_CLIENT_ID the client ID, ending .apps.googleusercontent.com
GOOGLE_CLIENT_SECRET the client secret
3 · Each school, in its own portal. School Settings → Sign-in & identity: provider *Google Workspace*, the school's hosted domain (hd) as the directory restriction, and its email domains. Then test sign-in, then switch on (§3). Nothing is needed from Google at the school's end — a Workspace directory consents per user.
What the platform requires of a Google token (lib/identity/claims.ts), beyond its signature, issuer, audience and nonce:
email_verifiedistrue— absent is refused, not assumed;- an
hdclaim is present — which is what proves the account belongs to a Workspace; hdequals the school's configured Workspace, or with none configured, one of its domains.
The hd sent *with the request* is only a hint to Google's account chooser. What matters is the hd *claim in the returned token*, and it must be required rather than merely compared when present: a consumer Google account can be registered against any address its owner can receive mail at, so teacher@school.edu.sg can arrive in a genuine, verified Google token from an account that is not in the school's Workspace at all — and carries no hd. An earlier version rejected a wrong hd but waved through a missing one, which is exactly that token.
hd is the Workspace's primary domain even for a person on a secondary domain, so it is matched against the Workspace, never against the email's own domain.
The person chooses the account. When nobody typed an address, Google and Microsoft are sent prompt=select_account, so the provider shows its account list instead of quietly using whichever account the browser is signed in to — a work profile's, say, which no school knows. A typed address goes as login_hint instead and names the account. If the account that came back belongs to no school, is not set up at the school, or is not on the pupil list, the notice offers Use a different Google (or Microsoft) account, which starts the same provider again with the chooser (retryWith in lib/identity/sign-in-notice.ts). A wrong provider, SSO switched off or a lapsed plan get no such offer: another account would not help.
Testing needs a Workspace account. A personal @gmail.com account is now correctly refused — it has no hd. Test with an account in a real Google Workspace whose domain is configured on a school, or the refusal will look like a fault.
The domain, in two phases. The consent screen will not accept gmail.com or run.app as an authorised domain, and Google authorises the *registrable* domain — so a platform served from eduspazeconnect.kb-lynx.com puts kb-lynx.com on the consent screen. That is acceptable for testing and not for schools, so the client is set up once and grows:
| Phase | Served from | Authorised domain | Publishing status |
|---|---|---|---|
| Testing (now) | eduspazeconnect.kb-lynx.com | kb-lynx.com | Testing — named test users only |
| Production | www.eduspazeconnect.com (the bare domain redirects there) | eduspazeconnect.com | In production |
Testing status is the right tool rather than a limitation here: only accounts listed as test users can sign in, so a consent screen naming kb-lynx.com is never shown to a school. Google's seven-day expiry in Testing applies to refresh tokens, which this flow never requests — every sign-in is a fresh authorisation — so it does not get in the way.
Moving to production changes the client, not the code. One OAuth client holds several redirect URIs, so the production URI is *added* alongside the testing one and the client ID and secret stay the same — no secret rotation, no redeploy for credentials. The platform derives its redirect URI from APP_BASE_URL, so switching that to https://www.eduspazeconnect.com moves it. The steps, in order: map and verify eduspazeconnect.com (one Search Console verification by the project-owning account serves both the Cloud Run mapping and the consent screen); add it as an authorised domain and add https://www.eduspazeconnect.com/api/auth/sso/callback; switch APP_BASE_URL and rebuild (it is baked into prerendered pages); update the home, privacy and terms links; then Publish app. Remove the kb-lynx.com URI once nothing uses it.
Order matters when the credentials go in. Setting GOOGLE_CLIENT_ID / _SECRET on Cloud Run creates a new revision from the image *already deployed*. Make sure that image carries the claims rules above before the credentials are added, or Google sign-in switches on without them.
Two further consequences of External + published, once the domain exists:
- a consent screen serving only
openid email profilestays in the non-sensitive tier, so it needs no Google security assessment; - in Testing mode a client is limited to explicitly listed test users and its tokens expire after seven days, which is enough to prove the flow and not enough to run a school on.
2.2 Registering EduSpaze with Microsoft Entra ID
Done once, by EduSpaze, not by each school. Three places, in this order.
An app registration has to live in a directory, so EduSpaze needs a tenant of its own even though no EduSpaze person signs in through it. A consumer address — including the @gmail.com account that owns the Google client — can be made into a Microsoft account and then create a free Entra tenant (*Microsoft Entra admin centre* → *Manage tenants* → *Create*); the default eduspaze.onmicrosoft.com domain is fine, because schools are sent to their own tenant, never to ours. Unlike Google, Entra does not gate the registration on a verified domain, so this half can be finished today.
1 · Microsoft Entra admin centre → *App registrations* → *New registration*
| Field | Value |
|---|---|
| Name | EduSpaze |
| Supported account types | Accounts in any organizational directory (multitenant) |
| Redirect URI | *Web* → <app base URL>/api/auth/sso/callback |
Multitenant is not optional. The platform sends a school to login.microsoftonline.com/<their tenant id>/…, so a single-tenant registration would only ever work for EduSpaze's own directory.
Then, on the same registration:
- *Certificates & secrets* → New client secret. Copy the value immediately; Entra shows it once. Note the expiry — a secret that lapses takes every school's sign-in down at once.
- *Token configuration* → Add optional claim → ID →
email. Without it Entra may omit theemailclaim entirely, and the platform falls back topreferred_username, which is the UPN and is not always the address the school expects (see §3). - *API permissions* — the delegated
openid,email,profilescopes are enough. Nothing needs Microsoft Graph, and nothing needs admin-only permissions.
2 · The EduSpaze service. The client ID is not a secret (it is in every sign-in URL), so it is a plain variable; the client secret goes to Secret Manager. From your own terminal — the secret is typed at a hidden prompt, so it is never on screen or in the shell history:
read -rs MS_SECRET # paste the secret *value*, press Enter
printf %s "$MS_SECRET" | gcloud secrets create eduspaze-microsoft-client-secret --project=eduspaze --data-file=-
unset MS_SECRET
gcloud secrets add-iam-policy-binding eduspaze-microsoft-client-secret --project=eduspaze \
--member=serviceAccount:221250764718-compute@developer.gserviceaccount.com --role=roles/secretmanager.secretAccessor
gcloud run services update eduspaze-platform --project=eduspaze --region=asia-southeast1 \
--update-env-vars=MICROSOFT_CLIENT_ID=<Application (client) ID> \
--update-secrets=MICROSOFT_CLIENT_SECRET=eduspaze-microsoft-client-secret:latest
--update-*, never --set-*: a --set-secrets naming only this one would drop every other secret on the service. A new secret value later is gcloud secrets versions add eduspaze-microsoft-client-secret --data-file=- followed by the same services update, so a new revision picks it up.
Admin → Settings → Identity & sign-in then shows Microsoft Entra ID as connected, and the redirect URI to register is on that page so it never has to be remembered.
3 · Each school, in its own portal. School Settings → Sign-in & identity: provider *Microsoft Entra ID*, the school's tenant id as the directory restriction, and its verified email domains. Then test sign-in, then switch on (§3).
2.4 Registering EduSpaze with Apple (optional)
Only for schools whose staff and pupils have Managed Apple Accounts on the school's own domain (Apple School Manager). Needs a paid Apple Developer membership and the custom domain.
Deferred (2026-10-26) until EduSpaze takes out the membership. The steps below are also on Admin → Settings → Identity, folded out under *Sign in with Apple* (components/admin/apple-setup.tsx), with the site's own host and redirect URI filled in.
- *Certificates, Identifiers & Profiles* → Identifiers → an App ID (type App) with *Sign in with Apple*, e.g.
com.eduspaze.connect. - Identifiers → a Services ID, e.g.
com.eduspaze.connect.web— this isAPPLE_CLIENT_ID. *Configure* Sign in with Apple on it: the App ID from step 1, domain the app's host (www.eduspazeconnect.com), return URL the redirect URI above. - Keys → a key with *Sign in with Apple*, configured with that App ID. Download the
.p8(once — Apple keeps no copy): its contents areAPPLE_PRIVATE_KEY, its idAPPLE_KEY_ID; your team id (Membership) isAPPLE_TEAM_ID. - On the service: the
.p8into Secret Manager (gcloud secrets create APPLE_PRIVATE_KEY --data-file=…), readable by the service account, thengcloud run services update … --update-env-vars=APPLE_CLIENT_ID=…,APPLE_TEAM_ID=…,APPLE_KEY_ID=… --update-secrets=APPLE_PRIVATE_KEY=APPLE_PRIVATE_KEY:latest—--update-*, never--set-*. The key never goes in the database or the repository. - Admin → Settings → Identity shows Apple connected; switch it on for Schools (§2.5) and have a test school run its test sign-in (§3).
How Apple differs, and why it is still safe:
- The client secret is a JWT the platform signs with that key for each token request (ES256, five minutes), not a string Apple issued.
- Apple returns by POST (
response_mode=form_post); the callback takes POST as well as GET, and the short-lived transaction cookie isSameSite=None; Securefor Apple alone so it survives that cross-site POST. Apple takes no PKCE; state and nonce still bind the reply. - There is no directory claim, so the email address is the only proof: it must be verified by Apple and on one of the school's domains. A "Hide my email" relay address never is, so a personal Apple ID is refused whatever the button says.
2.3 What each school's IT lead may still have to do
A multitenant app is not automatically trusted by another organisation's directory, and under Microsoft's default consent policy ordinary users cannot consent to a multitenant app from an unverified publisher — which EduSpaze is until it completes publisher verification (a Microsoft AI Cloud Partner Program ID, set on the app registration under *Branding & properties*). So, in practice, an Entra administrator at the school approves EduSpaze once for the whole directory.
The school's settings page makes that one click. With the provider set to Microsoft Entra ID and the tenant ID saved, *School Settings → Single sign-on* shows Approve EduSpaze in Microsoft Entra: Microsoft's admin-consent page for *that* directory (login.microsoftonline.com/<tenant id>/adminconsent?client_id=…, built by entraAdminConsentUrl). It returns to the one registered redirect URI with state=entra-admin-consent; the callback recognises that, signs nobody in, writes nothing, and sends the person back to the settings page saying what Microsoft reported. Somebody with the Global, Cloud Application or Application Administrator role has to accept.
Without the link the alternatives still work: the administrator signs in first themselves and consents for the organisation, or approves EduSpaze under *Enterprise applications* after a first attempt raises a consent request.
Either way the school's test sign-in (§3) is what surfaces it: a refusal at this point is a consent problem at their end, not a configuration problem at ours. Tell them to have somebody with directory rights run the test.
2.4a The demo identity provider is never on the live site
The built-in demo provider (MOCK, /mock-idp) stands in for Google or Microsoft in demonstrations: its page signs in whatever address is typed, after one click, with no password and nobody vouching for it. A school set up with it on the live site could be signed into as any of its staff — its administrators included — by anybody who knows an address.
So in production it is off at every step (lib/identity/demo-provider.ts): its page and endpoints answer 404, it never counts as configured (a sign-on with it is refused at the start), it issues and redeems no codes, and it cannot be chosen for a school. A school already set up with it signs in with passwords and emailed links until it chooses a real provider. Only a deliberate DEMO_SSO=on on a demo deployment brings it back; development and the test harness keep it.
2.5 Switching a provider off — Admin → Settings → Identity → Sign-in buttons
Each of Google, Microsoft and Apple has a switch per portal — the EduSpaze team's, schools' (staff and pupils), startups' — and an All switch that sets the three together. A provider is offered in a portal when its credentials are set *and* its switch there is on (lib/identity/provider-switch.ts). A portal's switch never written falls back to the provider's switch from before switches were per portal, and that, never written, is on — so a provider appears as soon as its credentials do. *All* shows on only when every portal is on, with *some on* beneath it otherwise. Apple is offered to schools only (Managed Apple Accounts, §2.4), so its EduSpaze team and startup cells show "—".
Switching one off for a portal:
- removes its button from that portal's sign-in pages —
/school/loginand/login(school tab) for schools;/startup/loginand/login?as=startupfor startups;/admin/loginfor the EduSpaze team — and from that portal's invitations and Account & settings → *Sign in with Microsoft or Google*; - refuses its sign-ons there at the start (
/api/auth/sso/start, by the page the sign-on began on), when an invitation is sent off or accepted (by the invited account's portal), and again at the callback, so a bookmarked link — or one switched off while somebody was at the provider — cannot reach it: provider first says *isn't available*, email first refuses as usual; - deletes nothing. Schools set up for it keep their configuration, people keep their linked identities, and all of it works again when the switch goes back on. While Schools is off, those schools' staff sign in with passwords or emailed links — the page says how many schools are set up for each provider.
Use it to hold back a provider that is not ready (Apple, until it has been tested end to end), to offer one to one audience before another, or to stop one quickly if it misbehaves. It needs platform.identity EDIT; with VIEW alone the switches are shown but cannot be flipped. Each flip is audited (platform.sso_provider_switched, with the provider, the portal or ALL, and on/off) on top of the settings write.
3. What a school configures
One SsoConfig per school:
| Field | Meaning |
|---|---|
provider | Google, Microsoft, or the demo provider |
allowedDomains | email domains permitted to sign in — an address outside them is refused whatever the provider asserts |
Entra caveat: where a user has no email claim the platform falls back to preferred_username, which is the UPN. A school whose UPNs are name@school.onmicrosoft.com but whose mail is name@school.edu.sg must list the UPN domain here, or add the email optional claim on the app registration (§2.2) so the mail address is asserted instead. | |
directoryId | Google hosted domain or Entra tenant id; sent to the provider *and* re-checked on the claims (hd for Google, tid for Entra) |
autoProvisionRole | what a first-time signer-in becomes, or null = must already have an account |
status | DRAFT → VERIFIED → ACTIVE |
What is checked on save
Every path that saves email domains (the school's own settings, the admin's sign-in page and profile page, creating a school) runs lib/validation/domain.ts:
- Shape. A hostname — labels of letters, digits and inner hyphens, an alphabetic TLD. No
@, nohttps://. Public mail providers (gmail.com,outlook.com, …) are refused. - DNS. Each *newly added* domain must publish an MX record. A domain that does not exist (
ted2.comddd) or receives no mail cannot be a staff email domain. A DNS failure refuses with "try again" rather than guessing. Domains already saved are not looked up again, so a DNS blip — or a seeded demo domain — never blocks an unrelated save.
The directory restriction is checked against what the provider sends back, because a value in the wrong form can never match and every sign-in would be refused: for Google a domain, for Microsoft a tenant GUID.
None of this proves the school owns the domain — anybody can type a real one. Ownership is proved by the test sign-in (§3, the three states): somebody signs in through the school's identity provider with an address on the domain, and for Google the Workspace asserts it in hd. That is why DRAFT cannot be switched on.
The directory restriction, in plain terms
The email domain checks the *address*; the directory restriction checks *which organisation's directory issued the account*. They differ more often than one would expect:
- Google. The value is the Workspace's primary domain (Google's
hd). The platform already refuses a Google account with nohd(a consumer account registered against a school address), so for Google the restriction is optional: left blank,hdmust be one of the email domains. Set it when the Workspace's primary domain differs from the staff domains, or to pin sign-in to exactly one Workspace. - Microsoft. The value is the Entra tenant ID (
tid), a GUID from the Entra admin centre's Overview page. Strongly recommended: without it, the email domain is the only check, and an Entra token'semailis not always a verified claim.
autoProvisionRole is the setting worth arguing about: leaving it null means the directory alone cannot create access, which is the safer default for a school that has not thought about who is in its directory.
The three states
| State | Meaning |
|---|---|
| DRAFT | Saved, never proven. Staff cannot use it. |
| VERIFIED | A test sign-in succeeded. Staff still use passwords until it is switched on. |
| ACTIVE | Staff on a verified domain are sent to the provider. |
Switching on is only reachable from VERIFIED — nothing goes live on a configuration nobody has proved works, whoever is asking. Changing the provider drops it back to DRAFT and clears verifiedAt: the old test proved the old provider and says nothing about the new one.
The gate
Before anyone is sent to a provider (lib/identity/gate.ts), five things are checked: the address has a domain; the domain belongs to a school we signed; that school has a config; the domain is in allowedDomains; the config is ACTIVE and the subscription is valid. Every refusal returns the same neutral sentence, so the login page cannot be used to find out which schools are on the platform or how they are configured. The same checks run again on the claims the provider actually returns.
A lapsed subscription blocks SSO and nothing else: passwords keep working, so a school can still reach its own settings and its own data.
4. What a platform admin can do
Module platform.identity (docs/rbac-spec.md), VIEW and EDIT:
| Where | What |
|---|---|
| Admin → Settings → Identity & sign-in | Which providers the platform is connected to, the redirect URI to register, and every school's provider, domains, status and auto-provision setting in one list |
| **Admin → Schools → *school* → Sign-in & single sign-on** | Set that school's provider, domains, directory and auto-provision on its behalf; switch SSO on or off once verified |
| **Admin → Schools → *school* → User accounts** | The Signs in with column: password (with two-factor state and when it last changed), a linked provider (with when it was last used), or username + PIN |
Shipped defaults: Operations may view and edit (setting a school up is onboarding work, and operations already creates that school's accounts); Support may view only — every "our staff cannot sign in" call starts by reading this, and a support person changing a provider could lock a school out; Analyst has neither. Owner roles hold everything.
These reach an existing environment too: a shipped role nobody has edited absorbs newly registered modules on the next deploy (docs/rbac-spec.md §4.1). A role somebody has retuned keeps what it holds — a deploy must not undo that decision — so there a platform owner grants it in Settings → Roles; surfacing that remaining drift is backlog BL-18.
Every change a platform admin makes is written to that school's own audit chain with the admin named (byPlatformAdmin: true), and the school's admins are notified. Changing how a tenant signs in is the last thing that should ever happen quietly.
The one thing an admin cannot do for a school is the test sign-in. It has to be performed by somebody holding an address on the school's own domains — the school admin from School Settings, or a platform admin inside a support session, acting as them. That is the point of the test: it proves a real account on that domain reaches this platform.
5. Who is told, and when
Switching SSO on is announced to every member of staff, not only the administrators — a teacher given a temporary password months ago has no other way of learning that they can now use their school account, and an unannounced switch reads as a broken login rather than a new one.
| Moment | Who hears | How |
|---|---|---|
| A colleague is given access | that person | in-app notice and the *Welcome — school staff* email; the temporary password is shown to the administrator to pass on separately |
| SSO switched on | every active member of staff | in-app notice and the *Single sign-on switched on* email, which says what to do and that their password still works |
| SSO switched off | every active member of staff | in-app notice: use your password as before |
| A platform admin changes the school's SSO | the school's administrators | in-app notice naming the admin who did it |
| A roster sync fails, or ends pupils | the school's administrators | in-app notice; the run is on the sync history either way |
The staff email matters more than it looks: an in-app notice sits behind the very sign-in it is telling somebody about, so it cannot be the only thing that reaches them.
6. What the school sees
School Settings carries the same controls: domains and provider, run test sign-in, switch on for staff — plus the subscription line that says whether SSO is currently allowed. Staff accounts are managed under School → People, pupil accounts under School → Students (roster import, batch issue of usernames and PINs), and who may do what under the school's own role editor (docs/rbac-spec.md §8).
7. What is recorded
| Event | When |
|---|---|
school.identity_settings_changed | provider, domains, directory or auto-provision changed |
school.sso_status_changed | switched on or off for staff |
school.sso_removed | the provider was removed and the school returned to passwords |
auth.sso_login / auth.sso_refused | a person signed in, or was refused |
All on the school's tenant chain. SsoConfig and SsoIdentity are both covered by the Postgres capture trigger, and SsoIdentity is marked PII-bearing (email, subject), so an erasure request reaches a person's linked identity like anything else.
8. The identifiers, end to end
One question decides every integration: what is the common identifier? The answer is a *pseudonymous subject, per school*, and it is the same idea for everybody.
| Person | Subject | Where it comes from | Who sees it |
|---|---|---|---|
| Pupil | Student.externalId — e.g. RB-4213 | the school's own SIS code, from the roster CSV | the vendor, on launch, roster and telemetry |
| Staff | SchoolMembership.externalId — e.g. STF-0003 | the school's staff code, or minted STF-nnnn on first use | the vendor, on a staff launch and in the roster |
| Class, group | the row id | EduSpaze | the vendor, as an opaque code with a teaching label |
Both subjects are unique within a school (@@unique([tenantId, externalId]) and @@unique([schoolId, externalId])) and live in one namespace, so a vendor keeps one subject column for pupils and teachers alike. A subject is never an email, never a name, and never the provider's sub claim — which stays inside EduSpaze, so a vendor cannot learn which directory a school uses, and a school changing identity provider changes nothing downstream.
Staff subjects are minted lazily, the first time one is actually needed: a school that later imports its own staff codes can set them, and a membership that never reaches a vendor never acquires an identifier it did not need.
The whole chain
Google / Entra EduSpaze Vendor
──────────── ──────── ──────
sub claim ──► SsoIdentity → User → Membership
│
├─ pupil launch ──► subject=RB-4213, tenant, class, groups (signed)
├─ staff launch ──► subject=STF-0003, tenant, role, classes (signed)
└─ GET /roster ──► the same subjects, classes and groups
│
telemetry ◄── heartbeat / sessions, keyed on tenant + subject
The provider's identity stops at the first arrow. Everything to the right of EduSpaze is pseudonymous, and it is the same string in the launch, the roster, the telemetry, the engagement heat map and the audit ledger.
Launch versions
v1 carries subject, tenant, ts, nonce, sig. v2 adds v, role, classes and, for a pupil, class, className, year, groups — and signs over all of them, which is why it is opt in per vendor (Startup.launchRosterClaims). A vendor that hard-coded the v1 four-key canonical string would stop verifying the moment extra parameters appeared, so nothing changes for them until they ask. tests/roster.test.ts asserts the v1 signature is byte-identical to the published contract; if that check ever fails, every live integration is about to break.
9. Phase 2
No SIS sync yet: rosters arrive as a CSV upload, so Student.externalId is only as stable as the school's export. A OneRoster or Google Classroom sync would replace the upload and leave everything downstream unchanged, because the roster endpoint already speaks in codes.
Keycloak or a hosted identity provider can replace the in-app broker behind the same tables: SsoConfig remains the per-school policy and SsoIdentity remains the link. What would change is lib/identity/oidc.ts and nothing above it — which is why the gate is a pure function over rows rather than anything the provider hands back.
10. Platform admins and startup teams: invitation and sign-in
EduSpaze staff (platform admins) are not in any school, so a school's single sign-on never signs them in — the callback refuses any account that is not a school account (§3). They are invited, and choose how they will sign in.
The invitation. Admin → Settings → Platform users → *Invite a platform admin* makes the account without a password and emails a single-use link (AuthToken purpose INVITE, seven days, only its hash stored; sending again voids the earlier link). The email never carries a password. If it could not be delivered, the link is shown to the inviter once, to pass on themselves. Until it is accepted the person is listed as *invited*, with Send a new invitation (platform.settings.users EDIT).
/invite?token=… — opening it changes nothing. Mail scanners (Microsoft Defender Safe Links among them) open every link in a message before the person does, so each way in is a button, and the invitation is spent — atomically, once — by whichever completes first:
| Choice | What happens |
|---|---|
| Continue with Microsoft / Google | Offered for providers EduSpaze is registered with, the one hosting the address's mail first and *recommended* (its MX records: *.mail.protection.outlook.com → Microsoft, Google's mail hosts or Gmail → Google; personal Outlook/Hotmail addresses are not Entra accounts and get no suggestion). The provider is sent the address as login_hint. At the callback the account is linked only if the invitation is still unspent and the provider's address is the invited one — Google: verified; Microsoft: a work or school account (tid present). Then the invitation is spent, the identity linked, and they are signed in. A mismatch, a cancel or a failure returns to the invitation, still usable. |
| Set a password | Chosen there and then; signs them in. |
| Without a password | The invitation proved the mailbox; signs them in. Each later sign-in is *Email me a link* on the sign-in page (15 minutes, once). |
Signing in afterwards. /admin/login — the EduSpaze team's own sign-in page — shows *Sign in with Microsoft* and *Sign in with Google* (provider first, §1; ui-ux-spec.md §7.16). For a platform admin the callback looks for an identity linked at acceptance — provider and subject, never the address the provider sends — belonging to an active admin, and signs them in. Anyone else carries on to the school flow. So an Entra account in somebody else's directory claiming an admin's address gets nowhere: only the account the invited person linked, with the invitation in hand, is recognised.
Email sign-in links (/auth/link) work the same way: the link opens a page with a *Sign in* button, and the button spends it — so a scanner opening it first no longer uses it up. Both pages send no Referer, so the token in their address never leaks to another site.
Every step is on the audit trail: auth.invite_sent, auth.invite_accepted (with how), auth.invite_sso_refused, auth.sso_login. Enforced by tests/invite.test.ts.
10.1 Startup teams
Startup accounts work the same way (2026-10-09). Invited, never given a password:
- someone new an owner adds to the team (*Team → Add*), and
- the owner EduSpaze creates when it lists a company (Admin → Vendors → New).
They get *Invitation — startup team* (INVITE_VENDOR). It says which company and which role, and its page offers the same choices. Someone who already has a startup account and joins another team is told by WELCOME_VENDOR_MEMBER and signs in as before. Pending invitations show *invited — not yet accepted*, with Send a new invitation, on the startup's Team page (vendor.team EDIT) and on its EduSpaze record (platform.vendors EDIT).
/startup/login shows *Sign in with Microsoft / Google*. A startup member is recognised by a linked identity only, and only while they are still on a team (an active VendorMembership).
10.2 Linking later — Account & settings → Sign in with Microsoft or Google
An admin or startup member who already signs in with a password (a founder who registered themselves, say) links Microsoft or Google from their own account page. They press *Continue with…* and sign in at the provider. The callback links that account only while the same person is still signed in, and only if its address is the account's own (the same rule as an invitation). It never takes an identity already linked to someone else. Unlink removes it; a password or an emailed link still works. Both are on the audit trail (auth.sso_linked, auth.sso_unlinked). School staff sign in through their school's provider, so this is not offered to them.
Not yet: Microsoft or Google for parents.
