Skip to content

Commit 9087e14

Browse files
committed
feat(spec): declare features.sso on the auth config response
AuthFeaturesConfigSchema gains the optional boolean `sso` that GET /api/v1/auth/config already serves (refined to "usable" by isSsoUsable) and the console login form reads. Claude-Session: https://claude.ai/code/session_01ADHkmPzZFPzq2roY9uo1me Co-authored-by: Claude <noreply@anthropic.com>
1 parent 96fb7b5 commit 9087e14

3 files changed

Lines changed: 69 additions & 0 deletions

File tree

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
'@objectstack/spec': minor
3+
---
4+
5+
feat(spec): declare `features.sso` on the `GET /api/v1/auth/config` response
6+
7+
Clause-②: yes (widening)
8+
Metadata-protocol: added
9+
10+
`AuthFeaturesConfigSchema` gains an optional boolean `sso`. The server has served it for a long time, and the console login form reads it to decide whether to show "Sign in with SSO", but the contract did not declare it. A client that parsed the response through `GetAuthConfigResponseSchema` lost the flag, because a plain object schema strips keys it does not know.
11+
12+
- **What the value means.** `true` when enterprise SSO is usable: the SSO plugin is wired and at least one SSO provider is configured. `false` when SSO is off, or on with no provider yet. The `/auth/config` route answers this "usable" value, not the coarser "wired" flag, and falls back to "wired" when providers cannot be counted.
13+
- **How it differs from `ssoEnforced`.** `ssoEnforced` takes the password form away. `sso` only says whether the SSO entry exists.
14+
- **Absent** means not usable. The schema sets no default.
15+
16+
What to do: nothing. Every payload accepted before is accepted unchanged. A client that typed the response from `@objectstack/spec` (for example through `@objectstack/client`'s re-exported `AuthFeaturesConfig`) now sees `sso?: boolean`.

‎packages/spec/src/api/auth-endpoints.test.ts‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
AuthEndpointSchema,
88
AuthEndpointAliases,
99
AuthFeaturesConfigSchema,
10+
GetAuthConfigResponseSchema,
1011
EndpointMapping,
1112
getAuthEndpointUrl,
1213
} from './auth-endpoints.zod';
@@ -132,6 +133,49 @@ describe('AuthFeaturesConfig retired flags (ruled: stop advertising them)', () =
132133
});
133134
});
134135

136+
// `features.sso` is served (plugin-auth's `/config` route and the hono
137+
// adapter's, both refined to "usable") and read (the console LoginForm), so
138+
// the contract declares it: a parse keeps it instead of stripping it.
139+
describe('AuthFeaturesConfig.sso (served, now declared)', () => {
140+
const valid = { twoFactor: false, organization: true };
141+
142+
it.each([true, false])('keeps a served `sso: %s` through a parse', (sso) => {
143+
const parsed = AuthFeaturesConfigSchema.parse({ ...valid, sso });
144+
expect(parsed.sso).toBe(sso);
145+
});
146+
147+
it('keeps it through the whole GET /auth/config response parse', () => {
148+
const parsed = GetAuthConfigResponseSchema.parse({
149+
emailPassword: { enabled: true },
150+
socialProviders: [],
151+
features: { ...valid, sso: true, ssoEnforced: false },
152+
});
153+
expect(parsed.features.sso).toBe(true);
154+
expect(parsed.features.ssoEnforced).toBe(false);
155+
});
156+
157+
it('CONTROL: an absent `sso` stays absent (no default is invented)', () => {
158+
const parsed = AuthFeaturesConfigSchema.parse(valid);
159+
expect(parsed).not.toHaveProperty('sso');
160+
});
161+
162+
it.each([['yes'], [1], [null]])('refuses a non-boolean `sso` (%j)', (sso) => {
163+
const result = AuthFeaturesConfigSchema.safeParse({ ...valid, sso });
164+
expect(result.success).toBe(false);
165+
if (result.success) return;
166+
expect(result.error.issues).toEqual([
167+
expect.objectContaining({ code: 'invalid_type', expected: 'boolean', path: ['sso'] }),
168+
]);
169+
});
170+
171+
it('says it is the usable answer and how it differs from ssoEnforced', () => {
172+
const description = AuthFeaturesConfigSchema.shape.sso.description ?? '';
173+
expect(description).toMatch(/isSsoUsable/);
174+
expect(description).toMatch(/ssoEnforced/);
175+
expect(description).not.toMatch(/#\d{3,}/);
176+
});
177+
});
178+
135179
describe('AuthEndpointAliases', () => {
136180
it('should map common names to canonical endpoints', () => {
137181
expect(AuthEndpointAliases.login).toBe('/sign-in/email');

‎packages/spec/src/api/auth-endpoints.zod.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,15 @@ export const AuthFeaturesConfigSchema = lazySchema(() => z.object({
230230
passkeys: retiredKey(PASSKEYS_UNADVERTISED),
231231
magicLink: retiredKey(MAGIC_LINK_UNADVERTISED),
232232
organization: z.boolean().default(false).describe('Multi-tenant organization support enabled'),
233+
// Served by plugin-auth (`getPublicConfig()`, refined by `isSsoUsable()` in
234+
// the `/config` route) and by the hono adapter's `/auth/config` route, which
235+
// applies the same refinement; read by the console LoginForm (#29344).
236+
sso: z.boolean().optional().describe(
237+
'Enterprise SSO sign-in usable: the domain-routed SSO plugin is wired AND at least one SSO provider is configured, so the login UI offers its "Sign in with SSO" entry; '
238+
+ 'false when SSO is off, or on with no provider yet. The served value is that usable answer (isSsoUsable), not the coarse wired flag: '
239+
+ 'GET /auth/config refines it before answering, and falls open to the wired flag when providers cannot be counted. '
240+
+ 'Unlike ssoEnforced, which takes the password form away, this only says whether the SSO entry exists; absent means not usable',
241+
),
233242
ssoEnforced: z.boolean().optional().describe(
234243
'SSO-only login enforced: the UI hides the local password form + self-registration (a break-glass "use a password" link remains)',
235244
),

0 commit comments

Comments
 (0)