Skip to content

Commit 40589c8

Browse files
committed
chore: declare the invite_only meaning change as semantic; spec docblocks name allowJit; pin the action's stored-value pre-fill
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FEkQ5nXM5CEyYnbaY58Spo
1 parent 53145b3 commit 40589c8

3 files changed

Lines changed: 75 additions & 4 deletions

File tree

‎.changeset/30967-sso-sign-in-options.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
---
2-
'@objectstack/plugin-auth': patch
3-
'@objectstack/platform-objects': patch
2+
'@objectstack/plugin-auth': minor
3+
'@objectstack/platform-objects': minor
44
---
55

66
feat(plugin-auth,platform-objects): per-provider SSO sign-in options for IdP-initiated sign-in and just-in-time accounts, and `invite_only` now refuses an SSO sign-in by someone who was not invited
77

88
Clause-②: yes (widening)
9-
Metadata-protocol: none
9+
Metadata-protocol: semantic
1010

1111
**Behaviour change for existing deployments.** Under the `invite_only` audience posture, which is the default, an enterprise SSO sign-in (OIDC or SAML, through `@better-auth/sso`) by a person who has no account and no pending invitation is now refused. It redirects to the error page with `error=SELF_REGISTRATION_CLOSED`, and no user is created. Before, such a sign-in created the account. To keep the old behaviour for a provider, turn on its new `allowJit` option: **Setup → SSO Providers → Edit Sign-In Options**, or `POST /api/v1/auth/sso/update-provider` with `{ providerId, allowJit: true }`. Unchanged: a person who already has an account, a person with a pending invitation, the first human of an empty deployment, every sign-in under the `email_domain` or `open` posture, and the social and `oidcProviders` sign-ins.
1212

‎packages/plugins/plugin-auth/src/sso-register-platform-admin-gate.test.ts‎

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ import { ADMIN_FULL_ACCESS_CAPABILITIES } from '@objectstack/spec';
9191
import { relaxTenantColumns } from './pre-18-tenant-column.testkit.js';
9292
import { withSystemReadContext } from './objectql-adapter.js';
9393
import { readSsoProviderSignInOptions } from './sso-sign-in-options.js';
94+
import { SysSsoProvider } from '@objectstack/platform-objects/identity';
9495

9596
const BASE = 'http://localhost:3000';
9697
const AUTH = `${BASE}/api/v1/auth`;
@@ -552,4 +553,68 @@ describe('the per-provider sign-in toggles are written by the provider writer, d
552553
allowJit: false,
553554
});
554555
});
556+
557+
// Setup's "Edit Sign-In Options" pre-fills each toggle from the provider row
558+
// (`defaultFromRow`) and posts it to update-provider, whose body types both
559+
// as booleans. The row reaches the console through the data API's engine
560+
// read; what is stored is better-auth's 1 / 0, or NULL on a row that
561+
// predates the columns. The console seeds a field-backed param with the
562+
// row's value, else the field's own default (objectui `resolveActionParams`:
563+
// `rowDefault ?? param.defaultValue ?? field.defaultValue`), and the dialog
564+
// submits that seed untouched. Each stored carrier must come out a boolean
565+
// the vendor accepts.
566+
for (const [stored, presented] of [
567+
[1, true],
568+
[0, false],
569+
[null, null],
570+
] as const) {
571+
it(`a stored ${String(stored)} pre-fills the Edit Sign-In Options action as a boolean, and the update it sends succeeds`, async () => {
572+
const engine = await bootEngine();
573+
const manager = makeManager(engine);
574+
const send = (r: Request) => manager.handleRequest(r);
575+
const email = 'platformadmin@example.com';
576+
const cookie = await signUp(send, email, engine);
577+
const userId = await userIdOf(engine, email);
578+
await grantPlatformAdmin(engine, userId);
579+
await providerOwnedBy(manager, userId);
580+
581+
const driver = engine.getDriverForObject('sys_sso_provider') as unknown as { getKnex(): any };
582+
await driver
583+
.getKnex()('sys_sso_provider')
584+
.where({ provider_id: 'acme-okta' })
585+
.update({ allow_idp_initiated: stored, allow_jit: stored });
586+
const raw = await driver.getKnex()('sys_sso_provider').where({ provider_id: 'acme-okta' }).first();
587+
expect([raw.allow_idp_initiated, raw.allow_jit]).toEqual([stored, stored]);
588+
589+
// The engine read the data API serves the console from.
590+
const [row] = (await engine.find('sys_sso_provider', { where: { provider_id: 'acme-okta' }, limit: 1 }, SYSTEM as never)) as Record<
591+
string,
592+
unknown
593+
>[];
594+
expect([row.allow_idp_initiated, row.allow_jit]).toEqual([presented, presented]);
595+
596+
// The body the action sends: each param seeded from the row, else the field default.
597+
const action = (SysSsoProvider as any).actions.find((a: any) => a.name === 'edit_sso_sign_in_options');
598+
const body: Record<string, unknown> = {};
599+
for (const param of action.params) {
600+
const fieldDefault = (SysSsoProvider as any).fields[param.field]?.defaultValue;
601+
body[param.name] = row[param.field] ?? fieldDefault;
602+
}
603+
expect(body).toEqual({ providerId: 'acme-okta', allowIdpInitiated: presented ?? false, allowJit: presented ?? false });
604+
605+
const res = await send(
606+
new Request(`${AUTH}/sso/update-provider`, {
607+
method: 'POST',
608+
headers: { 'content-type': 'application/json', origin: BASE, cookie },
609+
body: JSON.stringify(body),
610+
}),
611+
);
612+
expect(res.status, await res.clone().text()).toBe(200);
613+
const expected = presented ?? false;
614+
expect(await readSsoProviderSignInOptions(withSystemReadContext(engine as never) as never, 'acme-okta')).toEqual({
615+
allowIdpInitiated: expected,
616+
allowJit: expected,
617+
});
618+
});
619+
}
555620
});

‎packages/spec/src/system/auth-config.zod.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,9 @@ export function isAudiencePosture(value: unknown): value is AudiencePosture {
395395
* their own act, with no per-user operator act). `invite_only` does not —
396396
* admission there comes only from an explicit operator-side act (a pending
397397
* invitation, admin create/import, SCIM provisioning, an operator-registered
398-
* identity provider).
398+
* identity provider). An enterprise SSO provider (`@better-auth/sso`, OIDC or
399+
* SAML) admits a person with no account and no invitation only when that
400+
* provider sets `allowJit`; it is off by default.
399401
*/
400402
export function audiencePermitsSelfRegistration(posture: AudiencePosture): boolean {
401403
return posture === 'email_domain' || posture === 'open';
@@ -426,6 +428,10 @@ export const AudienceConfigSchema = lazySchema(() => z.object({
426428
* existence only through an operator-side act — a pending invitation
427429
* (which admits the invitee's own sign-up), admin create-user / bulk
428430
* import, SCIM provisioning, or an operator-registered identity provider.
431+
* An enterprise SSO provider (`@better-auth/sso`, OIDC or SAML) admits a
432+
* person with no account and no invitation only when that provider sets
433+
* `allowJit` (`sys_sso_provider.allow_jit`, off by default); a configured
434+
* `oidcProviders` entry admits as before.
429435
* - `email_domain`: self-registration is open ONLY to addresses whose domain
430436
* is on {@link allowedEmailDomains}. Email verification is forced on, with
431437
* no opt-out.

0 commit comments

Comments
 (0)