Repository navigation
Commit b70d9aa
feat(plugin-auth,platform-objects): per-provider SSO sign-in options; invite_only refuses an uninvited SSO sign-in unless the provider allows JIT (#31448)
<!-- claude-projects-attribution: {"github_login":"os-project-manager"}
-->
_Requested by **Leehom** · [project
thread](https://claude.ai/code/project/chan_01TenzsRopZj4jMbvjX8uz1X?thread=cmsg_01TenzsRopZj4jMbvjX8uz1XHR2BUbd1Pb1WoomJ6MRTiD)_
Refs #30967
Clause-②: yes (widening)
Metadata-protocol: semantic
## 维护者速读
- 改了什么:每个 SSO 提供方(SAML / OIDC)多两个开关,默认关闭:允许 IdP
发起的登录(allowIdpInitiated)、允许即时开通账号(allowJit);`invite_only` 下没有账号也没有邀请的人通过
SSO 登录会被拒绝(SELF_REGISTRATION_CLOSED),除非该提供方打开 allowJit。
- 为什么改:按裁决 A(记录 6718355623)落地 #30967 第 1、2、4 项;只暴露 `@better-auth/sso`
已有的能力,不新增登录机制;第 3 项(组映射)不做。
- 风险与回滚:`invite_only` 是默认受众策略,已用 SSO 自动开户的部署,新用户首次登录会被拒;对应提供方打开 allowJit
即恢复旧行为。回滚即 revert 本 PR,两个新列可留在库里无害。
-
先看:`packages/plugins/plugin-auth/src/audience-posture.ts`(`decideAudienceAdmission`
的 provider
分支)、`packages/plugins/plugin-auth/src/sso-sign-in-options.ts`(SAML 请求作用域
getter 与 OIDC
读写两半)、`packages/plugins/plugin-auth/src/auth-manager.ts`(`runSsoCallback`
的 SAML 作用域)。
- 两分钟验证:`cd packages/plugins/plugin-auth && pnpm vitest run
src/sso-saml-refusal-landing.test.ts
src/sso-oidc-refusal-cause.test.ts`,预期全绿,其中关闭时 302
`unsolicited_response` / `state_not_found`,`invite_only` 未受邀 302
`SELF_REGISTRATION_CLOSED`。
- 需要你做的:无,席位落地。
## What changes
**Two options per SSO provider, both off by default** (ruling A, record
6718355623).
- `sys_sso_provider` gains `allow_idp_initiated` and `allow_jit`:
boolean, default false, `trackHistory`. They are declared to
`@better-auth/sso` as `schema.ssoProvider.additionalFields`, so the
vendor's own `/sso/register` and `/sso/update-provider` accept them,
typed: a non-boolean answers 400 `VALIDATION_ERROR`.
- No new writer population. The writers are the ones that write a
provider today: the platform-admin registration gate on register, and
the vendor's provider-access check on update-provider, with held callers
refused as before.
- Setup: the SSO Providers list shows both, and each row has an **Edit
Sign-In Options** action (`edit_sso_sign_in_options`, POST
`/api/v1/auth/sso/update-provider`). It declares no `ai` block, so it is
human-only under ADR-0011.
**IdP-initiated sign-in (items 1 and 2).** Only the vendor's own
mechanism runs; nothing new is added.
- **SAML.** The vendor reads one plugin-wide `saml.allowIdpInitiated`
while it validates a Response (`validateInResponseTo`). plugin-auth now
hands it an options object whose `allowIdpInitiated` is a getter. The
getter answers the value `AuthManager.runSsoCallback` put in an
`AsyncLocalStorage` scope for this ACS request: the provider row's
column, read through a system-context reader before the vendor runs.
With no scope (any other path) it answers false.
- **OIDC.** The vendor reads `provider.oidcConfig.allowIdpInitiated` in
`bounceIfIdpInitiated`, and its register and update schemas strip that
member from a body. So the column is the only place it is authored:
- on read, the objectql adapter writes the column's value into the OIDC
blob it hands the vendor;
- on write, it strips the member from the stored blob, so the
update-provider merge cannot write a second copy back.
- Off answers as today: SAML 302 `error=unsolicited_response`, OIDC 302
`error=state_not_found`, and nobody is signed in.
**Unknown users under `invite_only` (item 4).**
- `decideAudienceAdmission`'s provider branch now refuses an
`@better-auth/sso` creation (source `sso-oidc` / `sso-saml`) under
`invite_only` when the provider's `allowJit` is off. It refuses with the
existing ledger code `SELF_REGISTRATION_CLOSED`, which the vendor
rethrows to the redirect's `error=`.
- These are still admitted: the bootstrap carve-out, a pending
invitation, and a provider with `allowJit` on.
- A source naming no provider reads every option OFF, and so does an
unreadable row.
- `email_domain`, `open`, an invalid posture, and enterprise
`oidcProviders` (oauth) answer as before.
- The changeset says plainly that this is a behaviour change for
existing `invite_only` deployments, and it names the `allowJit` escape
hatch.
Docs: a new **Per-provider sign-in options** section in
`content/docs/permissions/sso.mdx`. i18n: the new labels, help texts and
action strings are translated in all six locale bundles.
## Tests
All new pins sit in the existing harness files as top-level describes
(shared-harness ruling 6583487846), plus one new unit file.
- `sso-saml-refusal-landing.test.ts` (real samlify IdP):
- IdP-initiated off: 302 `unsolicited_response`, no session.
- On: the same Response signs the person in.
- Another provider's toggle does not open this one.
- CONTROL: SP-initiated sign-in.
- JIT under `invite_only`: refused 302 `{ base: sign-in-failed, error:
SELF_REGISTRATION_CLOSED }` and no user is created; `allowJit` admits.
- CONTROLs: an invited user; the `open` posture.
- `sso-oidc-refusal-cause.test.ts`:
- Off: 302 `state_not_found`.
- On: bounces to the IdP's authorize with a fresh state, and finishing
the flow signs the person in.
- A value smuggled into the stored blob is not read, and an adapter
update strips it.
- JIT refused, with `allowJit`, invited and `email_domain` legs, as for
SAML.
- `sso-register-platform-admin-gate.test.ts` (real SQL):
- Default off.
- The owner's update-provider turns each toggle on and off, and the
store reads it back.
- A non-boolean answers 400 `VALIDATION_ERROR`, and nothing is written.
- A member who is not the provider's writer answers 403, and nothing is
written.
- `plugin-audit/audit-internal-field-omission.test.ts`: both
declarations are boolean, `trackHistory` and default false. Flipping
each toggle 0→1→0 writes two `sys_audit_log` update rows, each carrying
both sides, and two `updated` activity rows naming the field.
- `audience-posture.test.ts`: the decision matrix, with CONTROL rows for
`email_domain`, `open`, invalid posture and `oidcProviders`.
- `sso-sign-in-options.test.ts`: the declaration; the reader (the 1/0
carrier, fail-closed); source classification; OIDC read and write; the
SAML getter's scope, including two concurrent scopes.
- `objectql-adapter.test.ts`: the snake/camel read pin now expects the
injected `allowIdpInitiated: false` in the OIDC blob.
<details><summary>Red first, then each negative pin ablated</summary>
- **Red first.** With the seven production files at the base commit (the
new module left in place, unwired), 14 pins go red across the six files:
11 in plugin-auth and 3 in plugin-audit. The default-off and CONTROL
pins stay green, as they should, because off was already the vendor's
default.
- **Ablations.** Each was run through `scripts/ablation-replace.mjs`,
which mutates the file on disk, runs the tests and restores the file:
| Ablation | Red |
|---|---|
| SAML getter forced `true` | SAML off pin, another-provider pin, scope
unit pin |
| OIDC read forced `true` | OIDC off pin, smuggled-value pin, read unit
pin |
| OIDC read line deleted | OIDC on pin, smuggled-value pin, read unit
pin |
| strip-on-write deleted | smuggled-value pin, write unit pin |
| JIT gate forced `false` | SAML and OIDC refusal pins, two matrix pins
|
| `allow_jit` `trackHistory: false` | declaration pin |
The ledger rows themselves do not depend on `trackHistory`: plugin-audit
mirrors every engine write. The flag is pinned by the declaration pin.
</details>
## Acceptance notes
- **ADR-0011 not edited.** It is a governed surface. The new action has
no `ai` block, so it is human-only, as `list_platform_admins` is.
- **The env-side bridges do not forward the toggles.**
`/admin/sso/register` and `register-saml` do not pass them on, so a
provider registered through Setup starts with both off and is then
edited with Edit Sign-In Options. The vendor's own register takes both
members.
- **Enterprise `oidcProviders` (genericOAuth) are untouched.** Their JIT
stays admitted under every posture, as before.
- **Invalid posture is unchanged.** An off-vocabulary posture admits a
provider-class creation as before, and only a valid `invite_only` judges
`allowJit`. A CONTROL row pins this.
- **Item 3 (group mapping) is excluded**, per the order.
- **Serial constraint with #30959.** Whichever of the two lands second
merges `origin/main` once and reruns the plugin-auth and
platform-objects suites.
## Verification
Head `9c8e1977`. Every command below was captured with its exit code
before any pipe.
<details><summary>Suites, gates, lint, typecheck</summary>
- `@objectstack/plugin-auth` full suite: 241 files, 4279 passed, 10
skipped, exit 0.
- `@objectstack/plugin-audit` full suite: 78 files, 1220 passed, exit 0.
- `@objectstack/platform-objects` full suite: 120 files, 1751 passed,
exit 0.
- `packages/runtime` `action-execution-destructive.test.ts`: 57 passed,
exit 0.
- `pnpm --filter` typecheck for plugin-auth, platform-objects and
plugin-audit: exit 0.
- ESLint (the root `pnpm lint` command) over the three packages: exit 0.
- `node scripts/pm/dispatch-gates.mjs --commands --repo
objectstack-ai/objectstack` derived 107 commands, and all 107 exit 0.
- Three first answered 3 (prerequisite not met): a fixture commit was
missing from the shallow clone, and two gates need built output. They
exit 0 after fetching that commit and running a full workspace build.
- `--ran` reconciles 107 derived, 107 run, 0 NOT-MEASURED, 0 UNRUN.
- i18n: `check:i18n`, `check:i18n-coverage` and `check:i18n-stale-fill`
exit 0, with the bundles regenerated by `check-i18n-bundles.mjs
--write`.
</details>
---
_Generated by [Claude
Code](https://claude.ai/code/session_01FEkQ5nXM5CEyYnbaY58Spo)_
<!-- signed: domain:server#6 · os-project-manager ·
session_01FEkQ5nXM5CEyYnbaY58Spo -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 9431c45 commit b70d9aa
27 files changed
Lines changed: 1196 additions & 25 deletions
File tree
- .changeset
- content/docs/permissions
- packages
- platform-objects/src
- apps/translations
- identity
- plugins
- plugin-audit/src
- plugin-auth/src
- spec/src/system
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
368 | 368 | | |
369 | 369 | | |
370 | 370 | | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
371 | 429 | | |
372 | 430 | | |
373 | 431 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2048 | 2048 | | |
2049 | 2049 | | |
2050 | 2050 | | |
| 2051 | + | |
| 2052 | + | |
| 2053 | + | |
| 2054 | + | |
| 2055 | + | |
| 2056 | + | |
| 2057 | + | |
| 2058 | + | |
2051 | 2059 | | |
2052 | 2060 | | |
2053 | 2061 | | |
| |||
2168 | 2176 | | |
2169 | 2177 | | |
2170 | 2178 | | |
| 2179 | + | |
| 2180 | + | |
| 2181 | + | |
| 2182 | + | |
2171 | 2183 | | |
2172 | 2184 | | |
2173 | 2185 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2048 | 2048 | | |
2049 | 2049 | | |
2050 | 2050 | | |
| 2051 | + | |
| 2052 | + | |
| 2053 | + | |
| 2054 | + | |
| 2055 | + | |
| 2056 | + | |
| 2057 | + | |
| 2058 | + | |
2051 | 2059 | | |
2052 | 2060 | | |
2053 | 2061 | | |
| |||
2168 | 2176 | | |
2169 | 2177 | | |
2170 | 2178 | | |
| 2179 | + | |
| 2180 | + | |
| 2181 | + | |
| 2182 | + | |
2171 | 2183 | | |
2172 | 2184 | | |
2173 | 2185 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2048 | 2048 | | |
2049 | 2049 | | |
2050 | 2050 | | |
| 2051 | + | |
| 2052 | + | |
| 2053 | + | |
| 2054 | + | |
| 2055 | + | |
| 2056 | + | |
| 2057 | + | |
| 2058 | + | |
2051 | 2059 | | |
2052 | 2060 | | |
2053 | 2061 | | |
| |||
2168 | 2176 | | |
2169 | 2177 | | |
2170 | 2178 | | |
| 2179 | + | |
| 2180 | + | |
| 2181 | + | |
| 2182 | + | |
2171 | 2183 | | |
2172 | 2184 | | |
2173 | 2185 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2048 | 2048 | | |
2049 | 2049 | | |
2050 | 2050 | | |
| 2051 | + | |
| 2052 | + | |
| 2053 | + | |
| 2054 | + | |
| 2055 | + | |
| 2056 | + | |
| 2057 | + | |
| 2058 | + | |
2051 | 2059 | | |
2052 | 2060 | | |
2053 | 2061 | | |
| |||
2168 | 2176 | | |
2169 | 2177 | | |
2170 | 2178 | | |
| 2179 | + | |
| 2180 | + | |
| 2181 | + | |
| 2182 | + | |
2171 | 2183 | | |
2172 | 2184 | | |
2173 | 2185 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2048 | 2048 | | |
2049 | 2049 | | |
2050 | 2050 | | |
| 2051 | + | |
| 2052 | + | |
| 2053 | + | |
| 2054 | + | |
| 2055 | + | |
| 2056 | + | |
| 2057 | + | |
| 2058 | + | |
2051 | 2059 | | |
2052 | 2060 | | |
2053 | 2061 | | |
| |||
2168 | 2176 | | |
2169 | 2177 | | |
2170 | 2178 | | |
| 2179 | + | |
| 2180 | + | |
| 2181 | + | |
| 2182 | + | |
2171 | 2183 | | |
2172 | 2184 | | |
2173 | 2185 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2048 | 2048 | | |
2049 | 2049 | | |
2050 | 2050 | | |
| 2051 | + | |
| 2052 | + | |
| 2053 | + | |
| 2054 | + | |
| 2055 | + | |
| 2056 | + | |
| 2057 | + | |
| 2058 | + | |
2051 | 2059 | | |
2052 | 2060 | | |
2053 | 2061 | | |
| |||
2168 | 2176 | | |
2169 | 2177 | | |
2170 | 2178 | | |
| 2179 | + | |
| 2180 | + | |
| 2181 | + | |
| 2182 | + | |
2171 | 2183 | | |
2172 | 2184 | | |
2173 | 2185 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2048 | 2048 | | |
2049 | 2049 | | |
2050 | 2050 | | |
| 2051 | + | |
| 2052 | + | |
| 2053 | + | |
| 2054 | + | |
| 2055 | + | |
| 2056 | + | |
| 2057 | + | |
| 2058 | + | |
2051 | 2059 | | |
2052 | 2060 | | |
2053 | 2061 | | |
| |||
2168 | 2176 | | |
2169 | 2177 | | |
2170 | 2178 | | |
| 2179 | + | |
| 2180 | + | |
| 2181 | + | |
| 2182 | + | |
2171 | 2183 | | |
2172 | 2184 | | |
2173 | 2185 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2048 | 2048 | | |
2049 | 2049 | | |
2050 | 2050 | | |
| 2051 | + | |
| 2052 | + | |
| 2053 | + | |
| 2054 | + | |
| 2055 | + | |
| 2056 | + | |
| 2057 | + | |
| 2058 | + | |
2051 | 2059 | | |
2052 | 2060 | | |
2053 | 2061 | | |
| |||
2168 | 2176 | | |
2169 | 2177 | | |
2170 | 2178 | | |
| 2179 | + | |
| 2180 | + | |
| 2181 | + | |
| 2182 | + | |
2171 | 2183 | | |
2172 | 2184 | | |
2173 | 2185 | | |
| |||
0 commit comments