Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
fc767d8
wip(plugin-auth): environment-user outbox and remove-sso-user door
claude Nov 15, 2026
7fd9f5a
feat(plugin-auth): remove door, outbox worker tests, docs and admin s…
claude Nov 15, 2026
67b5beb
chore(changeset): remove pending person and environment-user outbox
claude Nov 15, 2026
e1f1164
chore(platform-objects): regenerate translation bundles for the envir…
claude Nov 15, 2026
f51a0c4
feat(plugin-auth): boot the environment-user outbox through one gated…
claude Nov 15, 2026
c6435db
fix(plugin-auth): keep the outbox field null when the outbox does not…
claude Nov 15, 2026
17f7933
Merge remote-tracking branch 'origin/main' into claude/project-thread…
claude Nov 15, 2026
9bb42bb
fix(plugin-auth): hold the environment-user outbox to the invitation …
claude Nov 15, 2026
01d65d8
Merge remote-tracking branch 'origin/main' into claude/project-thread…
claude Nov 15, 2026
3c25103
Merge remote-tracking branch 'origin/main' into claude/project-thread…
claude Nov 16, 2026
1f1f43c
Merge remote-tracking branch 'origin/main' into claude/project-thread…
claude Nov 16, 2026
b2af63e
refactor(auth): reshape the pending-person remove door to ruling A, w…
claude Nov 16, 2026
e10b14b
fix(auth): keep the remove door's ledger note a valid string literal
claude Nov 16, 2026
1f9b39d
fix(auth): hold the remove door to pending people at the row delete, …
claude Nov 16, 2026
2e868fa
fix(auth): state the remove door's pending check as the engine delive…
claude Nov 16, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .changeset/33228-remove-pending-sso-user.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
'@objectstack/plugin-auth': patch
---

feat(auth): a cloud-managed environment can remove a pending person, cancelling their invitation at the host

Clause-②: yes (widening) — added: `POST /api/v1/auth/admin/remove-sso-user` (platform administrators, cloud-managed environments only); an optional `userRemoved` member on the environment-user host contract and the `'removed'` event kind; the `'deactivated'` value of the host outcome's `reason`. Nothing that was accepted is refused.
Metadata-protocol: none

On a cloud-managed environment, a person added to sign in through the hosting organisation's identity provider stays pending until their first sign-in. Before this change a pending person with a typo in their email could only be deactivated.

**Removing a pending person.** `POST /api/v1/auth/admin/remove-sso-user` with `{ "userId": "…" }` asks the host first, outside any transaction, then removes the person with their positions, permission sets and membership in one unit of work:

- The host is told through `userRemoved`. A host without it is told through `userDeactivated` with `source: 'idp_pending'`, which already means "cancel the invitation". A host should implement `userRemoved`.
- A host refusal (403/409) answers with the host's sentence, and no one is removed.
- A host that cannot be reached refuses the removal with `503 SERVICE_UNAVAILABLE`, and no one is removed: the door calls the host once and keeps no record to ask again from, so try again. Durable retry is the host's job.
- With no host wired, the person is removed and the answer says `host: { notified: false, reason: 'no_host' }`.
- A person who is not pending answers `409`: deactivate them instead. This holds at the removal itself: the person is re-checked inside the unit of work and the delete carries `source: 'idp_pending'`, so a person whose first sign-in lands while the host is asked is not removed. On an object with cascading lookups (such as `sys_user`) the engine re-deletes by id after the cascade, so a first sign-in committing in that narrow window is not yet refused.
- A person that other records still point at (`deleteBehavior: 'restrict'`) answers the engine's refusal, and nothing is removed. If the host had already cancelled the invitation of a person who is still pending and not deactivated, the door sends it again through `userAdded`, once, and the answer says whether that worked.
- An unknown id answers `404`; a body with any key but `userId` answers `400`. Off a cloud-managed environment the door answers `409` and removes no one.

**A deactivated person is never sent an invitation.** Adding a deactivated pending person again no longer calls `userAdded`; the answer says `host: { notified: false, reason: 'deactivated' }`. Reactivating them (`admin/unban-user`) is what tells the host again.

Nothing to migrate.
40 changes: 39 additions & 1 deletion content/docs/permissions/authentication.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -1316,7 +1316,8 @@ in the directory.

A host can be told about people as they come and go: the `environmentUserHost`
option of the auth plugin is called after a person is added, and before a
person is deactivated (`admin/ban-user`) or reactivated (`admin/unban-user`).
person is deactivated (`admin/ban-user`), reactivated (`admin/unban-user`) or,
while still pending, removed (`admin/remove-sso-user`).
It is never called inside a database transaction. Each event names the
administrator who acted, the administrator at the keyboard when the session
is an impersonation (`impersonatedBy`), and, when the acting administrator
Expand All @@ -1336,6 +1337,43 @@ reason }`. Adding a person who is still pending again tells the host again
and changes nothing else: positions, permission sets or a manager sent with
it are listed on the answer as `notApplied`; set them on the person's record.

A pending person who never signs in, for example one added with a mistyped
address, can be removed: `POST /api/v1/auth/admin/remove-sso-user` takes
`{ userId }`, removes the person with their positions, permission sets and
membership, and cancels their invitation at the host. The host is asked
first, through its `userRemoved` member; a host without that member is asked
through `userDeactivated` for the pending person instead, which means the same
thing, but a host should implement `userRemoved`. A host's refusal leaves the
person as they are. A host that cannot be reached refuses the removal too,
with `503` and nothing removed, as it refuses a deactivation: the door calls
the host once and keeps no record to ask again from, so try again once the
host is back. A person who is not pending (they have signed in, or were not
added this way) is refused with `409`: deactivate them instead. That holds at
the removal itself: the person is checked again inside the removal's unit of
work and the delete carries `source: 'idp_pending'`, so a person whose first
sign-in lands while the host is asked is not removed either, and the answer
says the host was already told. Because `sys_user` has cascading lookups, the
engine deletes the row by id after walking them, so a first sign-in that
commits in that narrow window is not yet refused. A record that
still points at the person through a lookup that restricts deletes refuses the
removal with that lookup's own answer, and nothing is removed; when the host
had already cancelled the invitation of a person who is still pending and not
deactivated, the door sends the invitation again through `userAdded`, once,
and the answer says whether that worked. Like the add doors, it is
platform-admin gated and answers `409` off a managed environment.

A deactivated person is never sent an invitation: adding a deactivated pending
person again calls no host and answers `host: { notified: false, reason:
'deactivated' }`; reactivating them is what tells the host again.

Each door calls the host once and keeps no record of the call. Delivering it
durably, and keeping each person's invitation status, is the host's job: a
host may queue and retry a call it could not complete. A call can reach a host
more than once (adding a person who is still pending again tells the host
again), so a host should treat a repeat as harmless, and should cancel an
invitation by the event's `userId`, never by its email address, which an
administrator may have typed wrong and may type again for someone else.

`admin/ban-user` and `admin/unban-user` work without the admin plugin: on a
deployment without it the ban is written by the platform, and a banned user is
refused a session with the same `403 BANNED_USER` answer the admin plugin
Expand Down
32 changes: 26 additions & 6 deletions packages/plugins/plugin-auth/src/auth-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,12 +389,13 @@ export interface AuthPluginOptions extends Partial<AuthConfig> {
* [#33181] The environment-user host (`environment-user-host.ts`): told
* after a person is added through `admin/add-sso-user` or
* `admin/import-sso-users`, and asked before a person is deactivated
* through `admin/ban-user` or reactivated through `admin/unban-user`. Read
* per call, so a host wired after boot is still found. A typed
* `EnvironmentUserHostRefusal` refuses the operation (a refused add is
* taken back out); any other failure refuses a deactivation (`503`) and is
* reported on an add or a reactivation as `host: { notified: false,
* reason }`, which it never undoes.
* through `admin/ban-user`, reactivated through `admin/unban-user`, or a
* pending person is removed through `admin/remove-sso-user` (`userRemoved`,
* else `userDeactivated`). Read per call, so a host wired after boot is
* still found. A typed `EnvironmentUserHostRefusal` refuses the operation
* (a refused add is taken back out); any other failure refuses a
* deactivation (`503`) and is reported on an add, a reactivation or a
* removal as `host: { notified: false, reason }`, which it never undoes.
*/
environmentUserHost?: EnvironmentUserHostAccessor;

Expand Down Expand Up @@ -5243,6 +5244,25 @@ export class AuthPlugin implements Plugin {
return c.json({ success: false, error: { code: 'INTERNAL_ERROR', message: INTERNAL_ERROR_MESSAGE } }, 500);
}
});

// Remove a person who is still pending (the email-typo case) and cancel
// their invitation at the host. Same gate and attribution as the two
// doors above; logic in `pending-sso-users.ts` (`runRemoveSsoUser`).
rawApp.post(`${basePath}/admin/remove-sso-user`, async (c: any) => {
try {
const actor = await gateAdmin(c);
if (actor instanceof Response) return actor;
const { runRemoveSsoUser } = await import('./pending-sso-users.js');
const { status, body } = await runAttributedToUser(actor, () =>
runRemoveSsoUser(pendingSsoUserDeps(c), actor, c.req.raw),
);
return c.json(body, status as any);
} catch (error) {
const err = error instanceof Error ? error : new Error(String(error));
ctx.logger.error('[AuthPlugin] admin/remove-sso-user failed', err);
return c.json({ success: false, error: { code: 'INTERNAL_ERROR', message: INTERNAL_ERROR_MESSAGE } }, 500);
}
});
}

// ────────────────────────────────────────────────────────────────────
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,10 @@ describe('auth route ledger hygiene', () => {
// below holds it to the same proof — better-auth serves no roster.
'POST /api/v1/auth/admin/list-platform-admins',
'POST /api/v1/auth/admin/oauth2/toggle-disabled',
// The pending-person remove door, on the same terms as the two above:
// `auth-plugin.ts` mounts it itself (a `rawApp.post` on the
// `${basePath}/admin/remove-sso-user` template); better-auth serves none.
'POST /api/v1/auth/admin/remove-sso-user',
// [#30958] On this pin's own terms: `auth-plugin.ts` mounts both itself
// (`rawApp.post` on the `${basePath}/admin/scim/mint-credential` and
// `${basePath}/admin/scim/revoke-credential` templates, ahead of the
Expand Down
3 changes: 2 additions & 1 deletion packages/plugins/plugin-auth/src/auth-route-ledger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,9 @@ export const AUTH_ROUTE_LEDGER: readonly AuthRouteLedgerEntry[] = [
{ route: 'POST /api/v1/auth/admin/import-users', family: 'objectstack-mount', source: 'objectstack', disposition: 'server-only', note: 'no SDK method builds this URL — objectui app-shell\'s identity-import wizard (views/identityImport.ts) posts it directly from the Users list; platform-admin gated (ADR-0068). A dedicated identity-import door rather than the generic sys_user import, because a direct ObjectQL write would bypass better-auth\'s password hashing and mint no sys_account credential' },
// #33181 — the tracker id stays HERE and never in the `note` string, per the
// #16678 note below.
{ route: 'POST /api/v1/auth/admin/add-sso-user', family: 'objectstack-mount', source: 'objectstack', disposition: 'server-only', note: 'no SDK method builds this URL — Setup → Users on a cloud-managed environment posts it; adds one person who signs in only through the hosting organisation identity provider: a sys_user row marked idp_pending (no password, refused a session) with optional positions, permission sets and manager, joined to the organization; 201, or 200 alreadyPending for a person already pending (the host is told again); 409 RESOURCE_CONFLICT off a managed environment or for an address already in use; closed body key set; the environment-user host is told after the write commits, and its answer rides host; platform-admin gated (ADR-0068)' },
{ route: 'POST /api/v1/auth/admin/add-sso-user', family: 'objectstack-mount', source: 'objectstack', disposition: 'server-only', note: 'no SDK method builds this URL — Setup → Users on a cloud-managed environment posts it; adds one person who signs in only through the hosting organisation identity provider: a sys_user row marked idp_pending (no password, refused a session) with optional positions, permission sets and manager, joined to the organization; 201, or 200 alreadyPending for a person already pending (the host is told again, unless the person is deactivated: then host reads deactivated and nothing is sent); 409 RESOURCE_CONFLICT off a managed environment or for an address already in use; closed body key set; the environment-user host is told after the write commits, and its answer rides host; platform-admin gated (ADR-0068)' },
{ route: 'POST /api/v1/auth/admin/import-sso-users', family: 'objectstack-mount', source: 'objectstack', disposition: 'server-only', note: 'no SDK method builds this URL — Setup → Users on a cloud-managed environment posts it; the CSV or JSON twin of admin/add-sso-user (columns email, name, positions, permission_sets, manager_id), at most 500 rows, each judged and written on its own so a bad row fails alone; answers a summary and one result per row; 409 RESOURCE_CONFLICT off a managed environment; platform-admin gated (ADR-0068)' },
{ route: 'POST /api/v1/auth/admin/remove-sso-user', family: 'objectstack-mount', source: 'objectstack', disposition: 'server-only', note: 'no SDK method builds this URL — Setup → Users on a cloud-managed environment posts it; removes a person who is still pending (sys_user.source idp_pending: the email-typo case) with their positions, permission sets and membership, and cancels their invitation at the environment-user host (userRemoved, else userDeactivated), which is asked first so its typed refusal leaves the person as they are; a host that cannot be reached refuses it with 503 SERVICE_UNAVAILABLE and nothing is removed (the door calls the host once and keeps no record to retry from); the person is re-checked inside the unit of work and the row delete carries source idp_pending, so a person who signs in while the host is asked is kept with 409 (on an object with cascading lookups the engine re-deletes by id, so a first sign-in committing in that narrow window is not yet refused); a removal that fails after the host took the cancellation sends the invitation again once through userAdded and says so; body { userId }; 404 RESOURCE_NOT_FOUND for an unknown id; 409 RESOURCE_CONFLICT off a managed environment or for a person who is not pending; a lookup that restricts the delete refuses it with the engine answer; platform-admin gated (ADR-0068)' },
{ route: 'POST /api/v1/auth/admin/list-platform-admins', family: 'objectstack-mount', source: 'objectstack', disposition: 'server-only', note: 'no SDK method builds this URL — the sys_user list_platform_admins action posts it directly from the Users list; answers who holds platform-admin standing (the last-admin guard\'s enumerator, each id confirmed by hasPlatformAdminStanding), served only to a caller who holds that standing; reads no body. ADR-0095 D3' },
{ route: 'POST /api/v1/auth/admin/oauth2/toggle-disabled', family: 'objectstack-mount', source: 'objectstack', disposition: 'server-only', note: 'no SDK method builds this URL — the sys_oauth_application disable/enable actions post it directly; ObjectStack mount closing a vendor gap (better-auth\'s /admin/oauth2/update-client strips `disabled` from its body schema), platform-admin gated (ADR-0068)' },
// #30958 — the tracker id stays HERE and never in the `note` string, per the
Expand Down
Loading
Loading