@shellui/core 0.6.2 → 0.7.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/package.json +2 -2
  2. package/schemas/shellui.config.schema.json +116 -72
  3. package/src/app.tsx +2 -0
  4. package/src/components/ContentView.tsx +2 -22
  5. package/src/components/iframeUrlSafety.spec.ts +67 -0
  6. package/src/components/iframeUrlSafety.ts +50 -0
  7. package/src/features/auth/AuthProvider.tsx +24 -1
  8. package/src/features/auth/appBackend/AppBackendSessionHost.tsx +58 -0
  9. package/src/features/auth/appBackend/appBackendSessions.spec.ts +195 -0
  10. package/src/features/auth/appBackend/appBackendSessions.ts +292 -0
  11. package/src/features/auth/appBackend/configSchema.spec.ts +41 -0
  12. package/src/features/auth/appBackend/frameAuth.ts +167 -0
  13. package/src/features/auth/appBackend/identity.spec.ts +201 -0
  14. package/src/features/auth/appBackend/identity.ts +173 -0
  15. package/src/features/auth/appBackend/silentSignIn.spec.ts +207 -0
  16. package/src/features/auth/appBackend/silentSignIn.ts +240 -0
  17. package/src/features/auth/backends/shellui.spec.ts +51 -19
  18. package/src/features/auth/backends/shellui.ts +20 -5
  19. package/src/features/auth/backends/types.ts +7 -2
  20. package/src/features/auth/components/LoginView.tsx +40 -18
  21. package/src/features/auth/components/OAuthCallbackView.tsx +33 -4
  22. package/src/features/auth/utils/authRequestError.ts +3 -0
  23. package/src/features/auth/utils/buildOAuthSessionRedirectTo.spec.ts +42 -1
  24. package/src/features/auth/utils/buildOAuthSessionRedirectTo.ts +23 -0
  25. package/src/features/auth/utils/index.ts +14 -1
  26. package/src/features/auth/utils/loginCancelTarget.spec.ts +73 -0
  27. package/src/features/auth/utils/loginCancelTarget.ts +45 -0
  28. package/src/features/auth/utils/loginPanelFrame.spec.ts +24 -0
  29. package/src/features/auth/utils/loginPanelFrame.ts +14 -0
  30. package/src/features/auth/utils/webPkce.spec.ts +119 -0
  31. package/src/features/auth/utils/webPkce.ts +169 -0
  32. package/src/features/config/types.ts +41 -0
  33. package/src/features/settings/SettingsProvider.tsx +45 -32
  34. package/src/features/settings/utils/buildSettingsForPropagation.spec.ts +374 -0
  35. package/src/features/settings/utils/buildSettingsForPropagation.ts +61 -33
  36. package/src/i18n/translations/en/common.json +2 -0
  37. package/src/i18n/translations/fr/common.json +2 -0
  38. package/src/index.ts +1 -0
@@ -0,0 +1,201 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import type { ShellUIConfig } from '../../config/types';
3
+ import { listDistinctAppBackends, normalizeBackendUrl, resolveFrameAppBackend } from './identity';
4
+
5
+ const shellBackend = {
6
+ type: 'shellui' as const,
7
+ url: 'https://id.example.com/',
8
+ companyId: 1,
9
+ login: { oauthProviders: ['google'] },
10
+ };
11
+
12
+ function config(extra?: Partial<ShellUIConfig>): ShellUIConfig {
13
+ return {
14
+ backend: shellBackend,
15
+ navigation: [
16
+ {
17
+ label: 'Billing',
18
+ path: 'billing',
19
+ url: 'https://billing.example/',
20
+ safeForAuthToken: true,
21
+ },
22
+ ],
23
+ ...extra,
24
+ };
25
+ }
26
+
27
+ describe('normalizeBackendUrl', () => {
28
+ it('drops a trailing slash and lowercases the host', () => {
29
+ expect(normalizeBackendUrl('HTTPS://ID.Example.com/')).toBe('https://id.example.com');
30
+ });
31
+
32
+ it('rejects non-http URLs', () => {
33
+ expect(normalizeBackendUrl('javascript:alert(1)')).toBeNull();
34
+ expect(normalizeBackendUrl('')).toBeNull();
35
+ });
36
+ });
37
+
38
+ describe('resolveFrameAppBackend', () => {
39
+ it('falls back to the shell backend when the item has no override', () => {
40
+ expect(resolveFrameAppBackend('https://billing.example/', config())).toEqual({ kind: 'shell' });
41
+ });
42
+
43
+ it('falls back when the override URL is the shell server, including a trailing slash', () => {
44
+ const next = config({
45
+ navigation: [
46
+ {
47
+ label: 'Billing',
48
+ path: 'billing',
49
+ url: 'https://billing.example/',
50
+ safeForAuthToken: true,
51
+ backend: { url: 'https://id.example.com/' },
52
+ },
53
+ ],
54
+ });
55
+ expect(resolveFrameAppBackend('https://billing.example/app', next)).toEqual({ kind: 'shell' });
56
+ });
57
+
58
+ it('falls back when companyId is omitted on the same server', () => {
59
+ const next = config({
60
+ navigation: [
61
+ {
62
+ label: 'Billing',
63
+ path: 'billing',
64
+ url: 'https://billing.example/',
65
+ backend: { url: 'https://id.example.com', type: 'shellui' },
66
+ },
67
+ ],
68
+ });
69
+ expect(resolveFrameAppBackend('https://billing.example/', next).kind).toBe('shell');
70
+ });
71
+
72
+ it('treats a different URL as a foreign identity server', () => {
73
+ const next = config({
74
+ navigation: [
75
+ {
76
+ label: 'Directory',
77
+ path: 'directory',
78
+ url: 'https://directory.example/',
79
+ safeForAuthToken: true,
80
+ backend: { url: 'https://id.directory.example/', companyId: 4, provider: 'Google' },
81
+ },
82
+ ],
83
+ });
84
+ const resolved = resolveFrameAppBackend('https://directory.example/people', next);
85
+ expect(resolved.kind).toBe('foreign');
86
+ if (resolved.kind !== 'foreign') return;
87
+ expect(resolved.identity.url).toBe('https://id.directory.example');
88
+ expect(resolved.identity.companyId).toBe(4);
89
+ expect(resolved.identity.provider).toBe('google');
90
+ expect(resolved.identity.key).not.toContain('https://id.example.com');
91
+ });
92
+
93
+ it('treats a different company id on the same URL as a foreign server', () => {
94
+ const next = config({
95
+ navigation: [
96
+ {
97
+ label: 'Directory',
98
+ path: 'directory',
99
+ url: 'https://directory.example/',
100
+ backend: { url: 'https://id.example.com', companyId: 9 },
101
+ },
102
+ ],
103
+ });
104
+ expect(resolveFrameAppBackend('https://directory.example/', next).kind).toBe('foreign');
105
+ });
106
+
107
+ it('withholds the shell session when the override URL cannot be used', () => {
108
+ const next = config({
109
+ navigation: [
110
+ {
111
+ label: 'Directory',
112
+ path: 'directory',
113
+ url: 'https://directory.example/',
114
+ backend: { url: 'not a url' },
115
+ },
116
+ ],
117
+ });
118
+ expect(resolveFrameAppBackend('https://directory.example/', next)).toEqual({
119
+ kind: 'withhold',
120
+ });
121
+ });
122
+
123
+ it('lets a more specific item without a backend keep the shell session', () => {
124
+ const next = config({
125
+ navigation: [
126
+ {
127
+ label: 'Apps',
128
+ path: 'apps',
129
+ url: 'https://apps.example/',
130
+ backend: { url: 'https://id.other.example' },
131
+ },
132
+ {
133
+ label: 'Billing',
134
+ path: 'billing',
135
+ url: 'https://apps.example/billing',
136
+ safeForAuthToken: true,
137
+ },
138
+ ],
139
+ });
140
+ expect(resolveFrameAppBackend('https://apps.example/billing/invoices', next).kind).toBe(
141
+ 'shell',
142
+ );
143
+ expect(resolveFrameAppBackend('https://apps.example/other', next).kind).toBe('foreign');
144
+ });
145
+
146
+ it('ignores external items and reads administration items', () => {
147
+ const next = config({
148
+ navigation: [
149
+ {
150
+ label: 'Away',
151
+ path: 'away',
152
+ url: 'https://directory.example/',
153
+ openIn: 'external',
154
+ backend: { url: 'https://id.external.example' },
155
+ },
156
+ ],
157
+ administration: {
158
+ title: 'Admin',
159
+ navigation: [
160
+ {
161
+ label: 'Directory',
162
+ path: 'directory',
163
+ url: 'https://directory.example/',
164
+ backend: { url: 'https://id.directory.example' },
165
+ },
166
+ ],
167
+ },
168
+ });
169
+ const resolved = resolveFrameAppBackend('https://directory.example/', next);
170
+ expect(resolved.kind).toBe('foreign');
171
+ if (resolved.kind !== 'foreign') return;
172
+ expect(resolved.identity.url).toBe('https://id.directory.example');
173
+ });
174
+
175
+ it('lists each foreign server once', () => {
176
+ const next = config({
177
+ navigation: [
178
+ {
179
+ label: 'One',
180
+ path: 'one',
181
+ url: 'https://one.example/',
182
+ backend: { url: 'https://id.other.example' },
183
+ },
184
+ {
185
+ label: 'Two',
186
+ path: 'two',
187
+ url: 'https://two.example/',
188
+ backend: { url: 'https://id.other.example/' },
189
+ },
190
+ {
191
+ label: 'Billing',
192
+ path: 'billing',
193
+ url: 'https://billing.example/',
194
+ },
195
+ ],
196
+ });
197
+ expect(listDistinctAppBackends(next).map((item) => item.url)).toEqual([
198
+ 'https://id.other.example',
199
+ ]);
200
+ });
201
+ });
@@ -0,0 +1,173 @@
1
+ import type { AppBackendConfig, NavigationItem, ShellUIConfig } from '../../config/types';
2
+ import { isFrameForAppUrl } from '../../layouts/utils';
3
+ import { flattenNavigationItems } from '../../settings/utils/flattenNavigationItems';
4
+
5
+ export type ResolvedAppBackend = {
6
+ key: string;
7
+ type: 'shellui' | 'supabase';
8
+ url: string;
9
+ companyId?: string | number;
10
+ publishableKey?: string;
11
+ provider: string | null;
12
+ };
13
+
14
+ export type FrameAppBackend =
15
+ | { kind: 'shell' }
16
+ | { kind: 'foreign'; identity: ResolvedAppBackend }
17
+ | { kind: 'withhold' };
18
+
19
+ /** http(s) base URL without trailing slash, query, or hash. Host is lowercased. */
20
+ export function normalizeBackendUrl(raw: string | null | undefined): string | null {
21
+ const trimmed = raw?.trim() ?? '';
22
+ if (!trimmed) return null;
23
+ try {
24
+ const url = new URL(trimmed);
25
+ if (url.protocol !== 'http:' && url.protocol !== 'https:') return null;
26
+ const path = url.pathname.replace(/\/+$/, '');
27
+ return `${url.origin}${path === '/' ? '' : path}`;
28
+ } catch {
29
+ return null;
30
+ }
31
+ }
32
+
33
+ function companyKey(companyId: string | number | undefined): string {
34
+ if (companyId === undefined || companyId === null) return '';
35
+ const text = `${companyId}`.trim();
36
+ return text;
37
+ }
38
+
39
+ export function appBackendKey(parts: {
40
+ type: string;
41
+ url: string;
42
+ companyId?: string | number;
43
+ }): string {
44
+ return `${parts.type}\n${parts.url}\n${companyKey(parts.companyId)}`;
45
+ }
46
+
47
+ function shellProvider(config?: ShellUIConfig): string | null {
48
+ const providers = config?.backend?.login?.oauthProviders;
49
+ const first = providers?.find((provider) => typeof provider === 'string' && provider.trim());
50
+ return first ? first.trim().toLowerCase() : null;
51
+ }
52
+
53
+ function resolveType(
54
+ override: AppBackendConfig,
55
+ config?: ShellUIConfig,
56
+ ): 'shellui' | 'supabase' | null {
57
+ const type = override.type ?? config?.backend?.type ?? 'shellui';
58
+ if (type === 'shellui' || type === 'supabase') return type;
59
+ return null;
60
+ }
61
+
62
+ /**
63
+ * Same server as the shell when type and URL match and the app does not name
64
+ * a different tenant. An omitted `companyId` keeps the shell session.
65
+ */
66
+ export function isDistinctFromShell(identity: ResolvedAppBackend, config?: ShellUIConfig): boolean {
67
+ const shell = config?.backend;
68
+ const shellUrl = normalizeBackendUrl(shell?.url);
69
+ if (!shell?.type || !shellUrl) return true;
70
+ if (identity.type !== shell.type || identity.url !== shellUrl) return true;
71
+ if (companyKey(identity.companyId) === '') return false;
72
+ return `${identity.companyId}` !== `${shell.companyId ?? ''}`;
73
+ }
74
+
75
+ export function resolveAppBackendConfig(
76
+ override: AppBackendConfig | undefined,
77
+ config?: ShellUIConfig,
78
+ ): ResolvedAppBackend | null {
79
+ if (!override) return null;
80
+ const type = resolveType(override, config);
81
+ const url = normalizeBackendUrl(override.url);
82
+ if (!type || !url) return null;
83
+ const provider = override.provider?.trim().toLowerCase() || shellProvider(config);
84
+ const companyId = companyKey(override.companyId) === '' ? undefined : override.companyId;
85
+ return {
86
+ type,
87
+ url,
88
+ ...(companyId !== undefined ? { companyId } : {}),
89
+ ...(override.publishableKey?.trim() ? { publishableKey: override.publishableKey.trim() } : {}),
90
+ provider,
91
+ key: appBackendKey({ type, url, companyId }),
92
+ };
93
+ }
94
+
95
+ function embeddedItems(config?: ShellUIConfig): NavigationItem[] {
96
+ const top = flattenNavigationItems(config?.navigation ?? []);
97
+ const admin = config?.administration?.navigation ?? [];
98
+ return [...top, ...admin].filter(
99
+ (item) => item.openIn !== 'external' && Boolean(item.url?.trim()),
100
+ );
101
+ }
102
+
103
+ /** Longer pathname wins so a site-root item does not override a nested app. */
104
+ export function appUrlSpecificity(appUrl: string): number {
105
+ try {
106
+ const url = new URL(appUrl, 'http://localhost');
107
+ const path = url.pathname.replace(/\/+$/, '');
108
+ const hash = (url.hash || '').replace(/^#\/?/, '').replace(/\/+$/, '');
109
+ return path.length * 1000 + hash.length;
110
+ } catch {
111
+ return 0;
112
+ }
113
+ }
114
+
115
+ function hasDistinctBackend(item: NavigationItem, config?: ShellUIConfig): boolean {
116
+ if (!item.backend) return false;
117
+ const identity = resolveAppBackendConfig(item.backend, config);
118
+ if (!identity) return true;
119
+ return isDistinctFromShell(identity, config);
120
+ }
121
+
122
+ function matchingItems(frameSrc: string, config?: ShellUIConfig): NavigationItem[] {
123
+ const matches = embeddedItems(config).filter((item) => isFrameMatch(frameSrc, item.url));
124
+ matches.sort((a, b) => {
125
+ const score = appUrlSpecificity(b.url) - appUrlSpecificity(a.url);
126
+ if (score !== 0) return score;
127
+ const aForeign = hasDistinctBackend(a, config) ? 1 : 0;
128
+ const bForeign = hasDistinctBackend(b, config) ? 1 : 0;
129
+ return bForeign - aForeign;
130
+ });
131
+ return matches;
132
+ }
133
+
134
+ /** Most specific embedded item for this frame, if any. */
135
+ export function resolveFrameNavigationItem(
136
+ frameSrc: string,
137
+ config?: ShellUIConfig,
138
+ ): NavigationItem | null {
139
+ return matchingItems(frameSrc, config)[0] ?? null;
140
+ }
141
+
142
+ /**
143
+ * Which identity server a frame should use.
144
+ * `shell` keeps today's single backend. `withhold` means the item named a backend
145
+ * we cannot use, so the shell token must not be sent. `foreign` is a different server.
146
+ */
147
+ export function resolveFrameAppBackend(frameSrc: string, config?: ShellUIConfig): FrameAppBackend {
148
+ const winner = matchingItems(frameSrc, config)[0];
149
+ if (!winner?.backend) return { kind: 'shell' };
150
+ const identity = resolveAppBackendConfig(winner.backend, config);
151
+ if (!identity) return { kind: 'withhold' };
152
+ if (!isDistinctFromShell(identity, config)) return { kind: 'shell' };
153
+ return { kind: 'foreign', identity };
154
+ }
155
+
156
+ function isFrameMatch(frameSrc: string, appUrl: string): boolean {
157
+ return isFrameForAppUrl(frameSrc, appUrl);
158
+ }
159
+
160
+ /** Distinct foreign identity servers referenced by embedded apps. */
161
+ export function listDistinctAppBackends(config?: ShellUIConfig): ResolvedAppBackend[] {
162
+ const seen = new Set<string>();
163
+ const list: ResolvedAppBackend[] = [];
164
+ for (const item of embeddedItems(config)) {
165
+ if (!item.backend) continue;
166
+ const identity = resolveAppBackendConfig(item.backend, config);
167
+ if (!identity || !isDistinctFromShell(identity, config)) continue;
168
+ if (seen.has(identity.key)) continue;
169
+ seen.add(identity.key);
170
+ list.push(identity);
171
+ }
172
+ return list;
173
+ }
@@ -0,0 +1,207 @@
1
+ import { describe, expect, it, vi } from 'vitest';
2
+ import {
3
+ SILENT_AUTH_RESULT_TYPE,
4
+ buildSilentAuthorizeUrl,
5
+ publishSilentAuthCallbackResult,
6
+ readSilentAuthMessage,
7
+ runSilentPkceSignIn,
8
+ type SilentAuthFrame,
9
+ type SilentAuthHost,
10
+ } from './silentSignIn';
11
+
12
+ describe('buildSilentAuthorizeUrl', () => {
13
+ it('uses PKCE, prompt=none, and code delivery without a shell token', () => {
14
+ const shellToken = 'shell-access-token.should.not.appear';
15
+ const url = new URL(
16
+ buildSilentAuthorizeUrl({
17
+ backendUrl: 'https://id.other.example/',
18
+ provider: 'google',
19
+ redirectTo:
20
+ 'https://shell.example/login/callback?shellui_silent=1&shellui_silent_state=abc',
21
+ codeChallenge: 'challenge-value',
22
+ companyId: 4,
23
+ }),
24
+ );
25
+ expect(`${url.origin}${url.pathname}`).toBe('https://id.other.example/api/v1/authorize');
26
+ expect(url.searchParams.get('prompt')).toBe('none');
27
+ expect(url.searchParams.get('token_delivery')).toBe('code');
28
+ expect(url.searchParams.get('code_challenge')).toBe('challenge-value');
29
+ expect(url.searchParams.get('code_challenge_method')).toBe('S256');
30
+ expect(url.searchParams.get('provider')).toBe('google');
31
+ expect(url.searchParams.get('company_id')).toBe('4');
32
+ expect(url.searchParams.get('code_verifier')).toBeNull();
33
+ expect(url.searchParams.get('access_token')).toBeNull();
34
+ expect(url.toString()).not.toContain(shellToken);
35
+ });
36
+ });
37
+
38
+ describe('readSilentAuthMessage', () => {
39
+ const source = { id: 'frame' };
40
+ const expected = { origin: 'https://shell.example', source, state: 'state-1' };
41
+
42
+ it('accepts a matching code from the opened frame', () => {
43
+ expect(
44
+ readSilentAuthMessage(
45
+ {
46
+ origin: 'https://shell.example',
47
+ source,
48
+ data: { type: SILENT_AUTH_RESULT_TYPE, state: 'state-1', authCode: 'one-time' },
49
+ },
50
+ expected,
51
+ ),
52
+ ).toEqual({ ok: true, authCode: 'one-time' });
53
+ });
54
+
55
+ it('rejects a wildcard origin, a different source, and a different state', () => {
56
+ const data = { type: SILENT_AUTH_RESULT_TYPE, state: 'state-1', authCode: 'one-time' };
57
+ expect(
58
+ readSilentAuthMessage({ origin: '*', source, data }, { ...expected, origin: '*' }),
59
+ ).toBeNull();
60
+ expect(
61
+ readSilentAuthMessage({ origin: 'https://evil.example', source, data }, expected),
62
+ ).toBeNull();
63
+ expect(
64
+ readSilentAuthMessage(
65
+ { origin: 'https://shell.example', source: { id: 'other' }, data },
66
+ expected,
67
+ ),
68
+ ).toBeNull();
69
+ expect(
70
+ readSilentAuthMessage(
71
+ {
72
+ origin: 'https://shell.example',
73
+ source,
74
+ data: { type: SILENT_AUTH_RESULT_TYPE, state: 'other', authCode: 'one-time' },
75
+ },
76
+ expected,
77
+ ),
78
+ ).toBeNull();
79
+ });
80
+ });
81
+
82
+ describe('publishSilentAuthCallbackResult', () => {
83
+ it('posts to the same origin and never to *', () => {
84
+ const postMessage = vi.fn();
85
+ const parent = { location: { origin: 'https://shell.example' }, postMessage };
86
+ const win = {
87
+ parent,
88
+ location: {
89
+ origin: 'https://shell.example',
90
+ search: '?shellui_silent=1&shellui_silent_state=abc&shellui_auth_code=one-time',
91
+ },
92
+ } as unknown as Window;
93
+
94
+ expect(publishSilentAuthCallbackResult(win)).toBe(true);
95
+ expect(postMessage).toHaveBeenCalledTimes(1);
96
+ expect(postMessage.mock.calls[0][1]).toBe('https://shell.example');
97
+ expect(postMessage.mock.calls[0][1]).not.toBe('*');
98
+ expect(postMessage.mock.calls[0][0]).toMatchObject({
99
+ type: SILENT_AUTH_RESULT_TYPE,
100
+ state: 'abc',
101
+ authCode: 'one-time',
102
+ });
103
+ });
104
+
105
+ it('does not post the code to a cross-origin parent', () => {
106
+ const postMessage = vi.fn();
107
+ const parent = { postMessage };
108
+ Object.defineProperty(parent, 'location', {
109
+ get() {
110
+ throw new Error('cross-origin');
111
+ },
112
+ });
113
+ const win = {
114
+ parent,
115
+ location: {
116
+ origin: 'https://shell.example',
117
+ search: '?shellui_silent=1&shellui_silent_state=abc&shellui_auth_code=one-time',
118
+ },
119
+ } as unknown as Window;
120
+
121
+ expect(publishSilentAuthCallbackResult(win)).toBe(true);
122
+ expect(postMessage).not.toHaveBeenCalled();
123
+ });
124
+
125
+ it('ignores a top-level window', () => {
126
+ const win = {
127
+ location: {
128
+ origin: 'https://shell.example',
129
+ search: '?shellui_silent=1&shellui_silent_state=abc',
130
+ },
131
+ } as unknown as Window;
132
+ (win as { parent: Window }).parent = win;
133
+ expect(publishSilentAuthCallbackResult(win)).toBe(false);
134
+ });
135
+ });
136
+
137
+ describe('runSilentPkceSignIn', () => {
138
+ function host(): SilentAuthHost & {
139
+ frame: SilentAuthFrame;
140
+ src: () => string;
141
+ deliver: (event: { origin: string; source: unknown; data: unknown }) => void;
142
+ } {
143
+ const frame: SilentAuthFrame = { contentWindow: { id: 'frame' }, remove: vi.fn() };
144
+ let deliver = (_event: { origin: string; source: unknown; data: unknown }) => {};
145
+ let src = '';
146
+ return {
147
+ frame,
148
+ origin: 'https://shell.example',
149
+ callbackPath: '/login/callback',
150
+ timeoutMs: 50,
151
+ src: () => src,
152
+ deliver: (event) => deliver(event),
153
+ createFrame(next) {
154
+ src = next;
155
+ return frame;
156
+ },
157
+ listen(fn) {
158
+ deliver = fn;
159
+ return () => {};
160
+ },
161
+ };
162
+ }
163
+
164
+ it('returns the code and verifier for a matching frame message', async () => {
165
+ const silent = host();
166
+ const pending = runSilentPkceSignIn(
167
+ { backendUrl: 'https://id.other.example', provider: 'google', companyId: 4 },
168
+ silent,
169
+ );
170
+ await vi.waitUntil(() => silent.src() !== '');
171
+ const authorize = new URL(silent.src());
172
+ const redirect = new URL(authorize.searchParams.get('redirect_to') ?? '');
173
+ const state = redirect.searchParams.get('shellui_silent_state') ?? '';
174
+ expect(authorize.searchParams.get('prompt')).toBe('none');
175
+ expect(authorize.toString()).not.toContain('code_verifier');
176
+
177
+ silent.deliver({
178
+ origin: 'https://evil.example',
179
+ source: silent.frame.contentWindow,
180
+ data: { type: SILENT_AUTH_RESULT_TYPE, state, authCode: 'stolen' },
181
+ });
182
+ silent.deliver({
183
+ origin: 'https://shell.example',
184
+ source: silent.frame.contentWindow,
185
+ data: { type: SILENT_AUTH_RESULT_TYPE, state, authCode: 'one-time' },
186
+ });
187
+
188
+ const outcome = await pending;
189
+ expect(outcome.ok).toBe(true);
190
+ if (!outcome.ok) return;
191
+ expect(outcome.authCode).toBe('one-time');
192
+ expect(outcome.redirectTo).toBe(redirect.toString());
193
+ expect(outcome.codeVerifier).toMatch(/^[A-Za-z0-9\-._~]{43,128}$/);
194
+ expect(authorize.toString()).not.toContain(outcome.codeVerifier);
195
+ expect(silent.frame.remove).toHaveBeenCalled();
196
+ });
197
+
198
+ it('times out without a result', async () => {
199
+ const silent = host();
200
+ const outcome = await runSilentPkceSignIn(
201
+ { backendUrl: 'https://id.other.example', provider: 'google' },
202
+ silent,
203
+ );
204
+ expect(outcome).toEqual({ ok: false, reason: 'timeout' });
205
+ expect(silent.frame.remove).toHaveBeenCalled();
206
+ });
207
+ });