@shellui/core 0.5.0 → 0.5.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 (51) hide show
  1. package/package.json +2 -2
  2. package/schemas/shellui.config.schema.json +98 -33
  3. package/src/app.tsx +2 -0
  4. package/src/components/ContentView.tsx +3 -5
  5. package/src/components/contentIframeSandbox.spec.ts +25 -0
  6. package/src/components/contentIframeSandbox.ts +43 -0
  7. package/src/features/auth/AuthProvider.tsx +156 -33
  8. package/src/features/auth/backends/index.ts +2 -0
  9. package/src/features/auth/backends/shellui.ts +43 -35
  10. package/src/features/auth/backends/supabase.ts +1 -0
  11. package/src/features/auth/backends/types.ts +5 -0
  12. package/src/features/auth/components/LoginView.tsx +5 -1
  13. package/src/features/auth/components/OAuthCallbackView.tsx +115 -44
  14. package/src/features/auth/constants/oauth.ts +2 -0
  15. package/src/features/auth/hooks/useAuth.tsx +4 -0
  16. package/src/features/auth/utils/authSessionPersistence.spec.ts +93 -0
  17. package/src/features/auth/utils/authSessionPersistence.ts +138 -0
  18. package/src/features/auth/utils/authStorageKeys.ts +8 -0
  19. package/src/features/auth/utils/bffAuthClient.ts +107 -0
  20. package/src/features/auth/utils/buildOAuthSessionRedirectTo.spec.ts +22 -0
  21. package/src/features/auth/utils/buildOAuthSessionRedirectTo.ts +17 -0
  22. package/src/features/auth/utils/buildSessionFromTokenPayload.spec.ts +29 -0
  23. package/src/features/auth/utils/buildSessionFromTokenPayload.ts +24 -0
  24. package/src/features/auth/utils/index.ts +18 -3
  25. package/src/features/auth/utils/isBffAuthEnabled.ts +12 -0
  26. package/src/features/config/types.ts +49 -2
  27. package/src/features/messaging/MessagingSecurityBootstrap.tsx +19 -0
  28. package/src/features/messaging/deriveAllowedMessageOrigins.spec.ts +86 -0
  29. package/src/features/messaging/deriveAllowedMessageOrigins.ts +74 -0
  30. package/src/features/modal/ModalContext.spec.ts +13 -2
  31. package/src/features/modal/validateAndNormalizeUrl.ts +9 -23
  32. package/src/features/security/trustedFrames.spec.ts +129 -0
  33. package/src/features/security/trustedFrames.ts +79 -0
  34. package/src/features/security/urlAllowlist.spec.ts +99 -0
  35. package/src/features/security/urlAllowlist.ts +122 -0
  36. package/src/features/settings/SettingsProvider.tsx +10 -46
  37. package/src/features/settings/utils/buildSettingsForPropagation.spec.ts +23 -1
  38. package/src/features/settings/utils/buildSettingsForPropagation.ts +7 -0
  39. package/src/features/storage/StorageBridge.spec.ts +82 -0
  40. package/src/features/storage/StorageBridge.tsx +25 -3
  41. package/src/features/storage/StoragePickerContext.tsx +3 -4
  42. package/src/features/storage/uploads/uploadQueue.ts +2 -5
  43. package/src/routes/components/NavigationItemRoute.tsx +30 -15
  44. package/src/routes/utils/navigationRouteAccess.spec.ts +85 -0
  45. package/src/routes/utils/navigationRouteAccess.ts +43 -0
  46. package/src/features/auth/utils/clearStoredAuthSession.spec.ts +0 -23
  47. package/src/features/auth/utils/clearStoredAuthSession.ts +0 -10
  48. package/src/features/auth/utils/persistAuthSession.spec.ts +0 -35
  49. package/src/features/auth/utils/persistAuthSession.ts +0 -12
  50. package/src/features/auth/utils/readStoredAuthSession.spec.ts +0 -34
  51. package/src/features/auth/utils/readStoredAuthSession.ts +0 -14
@@ -1,5 +1,5 @@
1
1
  import { type ReactNode, useCallback, useEffect, useMemo, useRef, useState } from 'react';
2
- import { getLogger, shellui, type Settings } from '@shellui/sdk';
2
+ import { getLogger, postShellMessage, shellui, type Settings } from '@shellui/sdk';
3
3
  import urls from '../../constants/urls';
4
4
  import { useConfig } from '../config/useConfig';
5
5
  import { createAuthBackend } from './backends';
@@ -8,14 +8,18 @@ import type { AuthEvent, AuthSession, AuthUser, UserPreferences } from './types'
8
8
  import {
9
9
  AuthRequestError,
10
10
  clearStoredAuthSession,
11
+ establishBffAuthSession,
11
12
  getAccessTokenFromSdkSettings,
12
13
  getAuthRequestErrorCode,
13
14
  getUserFromSdkSettings,
14
15
  inferAccessPendingErrorCode,
16
+ isBffAuthEnabledFromConfig,
15
17
  isSessionExpired,
16
18
  isTokenAutoRefreshDisabled,
19
+ logoutBffAuthSession,
17
20
  persistAuthSession,
18
21
  readStoredAuthSession,
22
+ refreshBffAuthSession,
19
23
  toAuthSessionFromSettingsUser,
20
24
  } from './utils';
21
25
 
@@ -36,11 +40,37 @@ type LoginMessagePayload = {
36
40
 
37
41
  export const AuthProvider = ({ children }: { children: ReactNode }) => {
38
42
  const { config } = useConfig();
43
+ const bffAuthEnabled = isBffAuthEnabledFromConfig(config.security);
39
44
  const backend = useMemo(
40
45
  () => createAuthBackend(config.backend),
41
46
  [config.backend?.publishableKey, config.backend?.type, config.backend?.url],
42
47
  );
43
48
 
49
+ const commitAuthSession = useCallback(
50
+ async (nextSession: AuthSession, nowSeconds: number): Promise<AuthSession> => {
51
+ if (bffAuthEnabled) {
52
+ const bffSession = await establishBffAuthSession(nextSession, nowSeconds);
53
+ if (bffSession) {
54
+ persistAuthSession(bffSession, { storeRefreshToken: false });
55
+ return bffSession;
56
+ }
57
+ }
58
+ persistAuthSession(nextSession);
59
+ return nextSession;
60
+ },
61
+ [bffAuthEnabled],
62
+ );
63
+
64
+ const refreshAuthSession = useCallback(
65
+ async (current: AuthSession, nowSeconds: number): Promise<AuthSession | null> => {
66
+ if (bffAuthEnabled) {
67
+ return refreshBffAuthSession(current, nowSeconds);
68
+ }
69
+ return backend.refreshAuthSession(current, nowSeconds);
70
+ },
71
+ [backend, bffAuthEnabled],
72
+ );
73
+
44
74
  const [session, setSession] = useState<AuthSession | null>(null);
45
75
  const [isLoading, setIsLoading] = useState(true);
46
76
  const [error, setError] = useState<string | null>(null);
@@ -70,8 +100,13 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => {
70
100
  const sessionFromHash = backend.readSessionFromCallback(window.location.hash, now);
71
101
  if (sessionFromHash) {
72
102
  if (!cancelled) {
73
- persistAuthSession(sessionFromHash);
74
- setSession(sessionFromHash);
103
+ try {
104
+ const committed = await commitAuthSession(sessionFromHash, now);
105
+ setSession(committed);
106
+ } catch {
107
+ persistAuthSession(sessionFromHash);
108
+ setSession(sessionFromHash);
109
+ }
75
110
  setAuthEvent('oauth_callback');
76
111
  if (window.location.hash) {
77
112
  window.history.replaceState(
@@ -104,6 +139,40 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => {
104
139
  return;
105
140
  }
106
141
 
142
+ if (!stored.accessToken && (stored.refreshToken || bffAuthEnabled)) {
143
+ if (isTokenAutoRefreshDisabled()) {
144
+ if (!cancelled) {
145
+ setSession(stored);
146
+ setIsLoading(false);
147
+ }
148
+ return;
149
+ }
150
+ try {
151
+ const restored = await refreshAuthSession(stored, now);
152
+ if (!restored) {
153
+ clearStoredAuthSession();
154
+ if (!cancelled) {
155
+ setSession(null);
156
+ setIsLoading(false);
157
+ }
158
+ return;
159
+ }
160
+ persistAuthSession(restored, { storeRefreshToken: !bffAuthEnabled });
161
+ if (!cancelled) {
162
+ setSession(restored);
163
+ setIsLoading(false);
164
+ }
165
+ return;
166
+ } catch {
167
+ clearStoredAuthSession();
168
+ if (!cancelled) {
169
+ setSession(null);
170
+ setIsLoading(false);
171
+ }
172
+ return;
173
+ }
174
+ }
175
+
107
176
  if (!isSessionExpired(stored)) {
108
177
  if (!cancelled) {
109
178
  setSession(stored);
@@ -125,7 +194,7 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => {
125
194
  }
126
195
 
127
196
  try {
128
- const restored = await backend.restoreSession(stored, now);
197
+ const restored = await refreshAuthSession(stored, now);
129
198
  if (!restored) {
130
199
  clearStoredAuthSession();
131
200
  if (!cancelled) {
@@ -136,7 +205,7 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => {
136
205
  }
137
206
 
138
207
  if (!cancelled) {
139
- persistAuthSession(restored);
208
+ persistAuthSession(restored, { storeRefreshToken: !bffAuthEnabled });
140
209
  setSession(restored);
141
210
  setIsLoading(false);
142
211
  }
@@ -153,13 +222,13 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => {
153
222
  return () => {
154
223
  cancelled = true;
155
224
  };
156
- }, [backend]);
225
+ }, [backend, bffAuthEnabled, commitAuthSession, refreshAuthSession]);
157
226
 
158
227
  useEffect(() => {
159
228
  if (typeof window === 'undefined' || window.parent !== window || isLoading) {
160
229
  return;
161
230
  }
162
- if (!session?.refreshToken) {
231
+ if (!session || (!bffAuthEnabled && !session.refreshToken)) {
163
232
  return;
164
233
  }
165
234
 
@@ -169,7 +238,8 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => {
169
238
  const runRefresh = async () => {
170
239
  if (cancelled) return;
171
240
  const current = sessionRef.current;
172
- if (!current?.refreshToken || refreshInFlightRef.current) return;
241
+ if (!current || refreshInFlightRef.current) return;
242
+ if (!bffAuthEnabled && !current.refreshToken) return;
173
243
 
174
244
  const now = Math.floor(Date.now() / 1000);
175
245
  const secondsLeft = current.expiresAt - now;
@@ -191,9 +261,9 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => {
191
261
 
192
262
  refreshInFlightRef.current = true;
193
263
  try {
194
- const next = await backend.refreshAuthSession(current, now);
264
+ const next = await refreshAuthSession(current, now);
195
265
  if (cancelled || !next) return;
196
- persistAuthSession(next);
266
+ persistAuthSession(next, { storeRefreshToken: !bffAuthEnabled });
197
267
  sessionRef.current = next;
198
268
  setSession(next);
199
269
  } catch (err) {
@@ -230,7 +300,7 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => {
230
300
  document.removeEventListener('visibilitychange', maybeRefreshOnResume);
231
301
  window.removeEventListener('focus', maybeRefreshOnResume);
232
302
  };
233
- }, [backend, isLoading, session?.refreshToken, session?.expiresAt]);
303
+ }, [bffAuthEnabled, isLoading, refreshAuthSession, session, session?.expiresAt]);
234
304
 
235
305
  useEffect(() => {
236
306
  if (typeof window === 'undefined' || window.parent === window) {
@@ -275,6 +345,64 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => {
275
345
  [backend],
276
346
  );
277
347
 
348
+ const persistOAuthSession = useCallback(
349
+ async (nextSession: AuthSession) => {
350
+ const now = Math.floor(Date.now() / 1000);
351
+ try {
352
+ const committed = await commitAuthSession(nextSession, now);
353
+ setSession(committed);
354
+ } catch {
355
+ persistAuthSession(nextSession, { storeRefreshToken: !bffAuthEnabled });
356
+ setSession(nextSession);
357
+ }
358
+ setAuthEvent('oauth_callback');
359
+ },
360
+ [bffAuthEnabled, commitAuthSession],
361
+ );
362
+
363
+ const mapOAuthCallbackError = useCallback((err: unknown): OAuthCallbackResult => {
364
+ const message = err instanceof Error ? err.message : 'Unable to complete OAuth login.';
365
+ const oauthErrorCode =
366
+ getAuthRequestErrorCode(err) ??
367
+ inferAccessPendingErrorCode(message) ??
368
+ (err instanceof AuthRequestError ? err.code : null);
369
+ setError(message);
370
+ setErrorCode(oauthErrorCode);
371
+ return { ok: false, error: message, errorCode: oauthErrorCode };
372
+ }, []);
373
+
374
+ const completeOAuthSessionCallback = useCallback(
375
+ async ({
376
+ authCode,
377
+ redirectTo,
378
+ }: {
379
+ authCode: string;
380
+ redirectTo: string;
381
+ }): Promise<OAuthCallbackResult> => {
382
+ try {
383
+ setError(null);
384
+ setErrorCode(null);
385
+ const now = Math.floor(Date.now() / 1000);
386
+ const nextSession = await backend.exchangeOAuthSessionCode({
387
+ authCode,
388
+ redirectTo,
389
+ nowSeconds: now,
390
+ });
391
+ if (!nextSession) {
392
+ const message = 'Unable to complete OAuth login.';
393
+ setError(message);
394
+ setErrorCode(null);
395
+ return { ok: false, error: message, errorCode: null };
396
+ }
397
+ await persistOAuthSession(nextSession);
398
+ return { ok: true };
399
+ } catch (err) {
400
+ return mapOAuthCallbackError(err);
401
+ }
402
+ },
403
+ [backend, mapOAuthCallbackError, persistOAuthSession],
404
+ );
405
+
278
406
  const completeOAuthCallback = useCallback(
279
407
  async ({
280
408
  provider,
@@ -304,22 +432,13 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => {
304
432
  setErrorCode(null);
305
433
  return { ok: false, error: message, errorCode: null };
306
434
  }
307
- persistAuthSession(nextSession);
308
- setSession(nextSession);
309
- setAuthEvent('oauth_callback');
435
+ await persistOAuthSession(nextSession);
310
436
  return { ok: true };
311
437
  } catch (err) {
312
- const message = err instanceof Error ? err.message : 'Unable to complete OAuth login.';
313
- const oauthErrorCode =
314
- getAuthRequestErrorCode(err) ??
315
- inferAccessPendingErrorCode(message) ??
316
- (err instanceof AuthRequestError ? err.code : null);
317
- setError(message);
318
- setErrorCode(oauthErrorCode);
319
- return { ok: false, error: message, errorCode: oauthErrorCode };
438
+ return mapOAuthCallbackError(err);
320
439
  }
321
440
  },
322
- [backend],
441
+ [backend, mapOAuthCallbackError, persistOAuthSession],
323
442
  );
324
443
 
325
444
  const startWeb3Ethereum = useCallback(async () => {
@@ -332,15 +451,16 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => {
332
451
  setErrorCode(null);
333
452
  return false;
334
453
  }
335
- persistAuthSession(nextSession);
336
- setSession(nextSession);
454
+ const now = Math.floor(Date.now() / 1000);
455
+ const committed = await commitAuthSession(nextSession, now);
456
+ setSession(committed);
337
457
  return true;
338
458
  } catch (err) {
339
459
  setError(err instanceof Error ? err.message : 'Unable to start Ethereum wallet login.');
340
460
  setErrorCode(err instanceof AuthRequestError ? err.code : null);
341
461
  return false;
342
462
  }
343
- }, [backend]);
463
+ }, [backend, commitAuthSession]);
344
464
 
345
465
  const getAuthSettings = useCallback(() => backend.getAuthSettings(), [backend]);
346
466
 
@@ -374,9 +494,7 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => {
374
494
  );
375
495
  nextSession = null;
376
496
  } else {
377
- nextSession = sessionAtStart
378
- ? await backend.refreshAuthSession(sessionAtStart, now)
379
- : null;
497
+ nextSession = sessionAtStart ? await refreshAuthSession(sessionAtStart, now) : null;
380
498
  }
381
499
  } catch (refreshErr) {
382
500
  logger.error('Failed to refresh auth session after syncing preferences', { refreshErr });
@@ -390,7 +508,7 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => {
390
508
  // Keep stored snapshot aligned with what we synced (JWT claims can lag the PUT).
391
509
  nextSession = { ...nextSession, userPreferences: preferences };
392
510
  if (typeof window !== 'undefined' && window.parent === window) {
393
- persistAuthSession(nextSession);
511
+ persistAuthSession(nextSession, { storeRefreshToken: !bffAuthEnabled });
394
512
  }
395
513
  setSession(nextSession);
396
514
  }
@@ -398,7 +516,7 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => {
398
516
  logger.error('Failed to sync user preferences to auth provider metadata', { err });
399
517
  }
400
518
  },
401
- [backend],
519
+ [backend, bffAuthEnabled, refreshAuthSession],
402
520
  );
403
521
 
404
522
  const loadUserPreferences = useCallback(async () => {
@@ -412,6 +530,9 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => {
412
530
 
413
531
  const logout = useCallback(async () => {
414
532
  try {
533
+ if (bffAuthEnabled) {
534
+ await logoutBffAuthSession(session?.accessToken);
535
+ }
415
536
  await backend.logout(session);
416
537
  } catch {
417
538
  // Even if API sign-out fails, still clear local session.
@@ -422,7 +543,7 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => {
422
543
  setAuthEvent(null);
423
544
  setError(null);
424
545
  setErrorCode(null);
425
- }, [backend, session]);
546
+ }, [backend, bffAuthEnabled, session]);
426
547
 
427
548
  useEffect(() => {
428
549
  if (typeof window === 'undefined' || window.parent !== window) {
@@ -450,7 +571,7 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => {
450
571
  void (async () => {
451
572
  const started = await startWeb3Ethereum();
452
573
  if (started && typeof window !== 'undefined') {
453
- window.postMessage({ type: 'SHELLUI_CLOSE_MODAL', payload: {} }, '*');
574
+ postShellMessage({ type: 'SHELLUI_CLOSE_MODAL', payload: {} });
454
575
  }
455
576
  })();
456
577
  return;
@@ -498,6 +619,7 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => {
498
619
  errorCode,
499
620
  authEvent,
500
621
  clearAuthEvent,
622
+ completeOAuthSessionCallback,
501
623
  completeOAuthCallback,
502
624
  startOAuth,
503
625
  startWeb3Ethereum,
@@ -515,6 +637,7 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => {
515
637
  errorCode,
516
638
  authEvent,
517
639
  clearAuthEvent,
640
+ completeOAuthSessionCallback,
518
641
  completeOAuthCallback,
519
642
  startOAuth,
520
643
  startWeb3Ethereum,
@@ -6,6 +6,8 @@ import type { AuthBackend } from './types';
6
6
  const createNoopBackend = (): AuthBackend => ({
7
7
  type: 'none',
8
8
  readSessionFromCallback: () => null,
9
+ exchangeOAuthSessionCode: async () => null,
10
+ exchangeOAuthCode: async () => null,
9
11
  restoreSession: async () => null,
10
12
  refreshAuthSession: async () => null,
11
13
  startOAuth: () => {
@@ -1,4 +1,5 @@
1
1
  import {
2
+ buildSessionFromTokenPayload,
2
3
  buildSessionFromParams,
3
4
  getShellUILoginClientTimezone,
4
5
  getShellUILoginDeviceId,
@@ -13,6 +14,20 @@ import type { AuthBackend } from './types';
13
14
 
14
15
  const USER_PREFERENCES_ENDPOINT = '/api/v1/preferences';
15
16
  const OAUTH_EXCHANGE_ENDPOINT = '/api/v1/oauth/exchange';
17
+ const OAUTH_SESSION_ENDPOINT = '/api/v1/oauth/session';
18
+
19
+ const parseAuthErrorPayload = (
20
+ payload: Record<string, unknown> | null,
21
+ response: Response,
22
+ ): never => {
23
+ const err = payload?.error ?? payload?.detail;
24
+ const message = typeof err === 'string' && err.trim() ? err : `HTTP ${response.status}`;
25
+ let errorCode = typeof payload?.error_code === 'string' ? payload.error_code.trim() : null;
26
+ if (!errorCode && response.status === 403) {
27
+ errorCode = 'access_pending';
28
+ }
29
+ throw new AuthRequestError(message, errorCode);
30
+ };
16
31
 
17
32
  export const createShellUIAuthBackend = ({
18
33
  backendUrl,
@@ -46,19 +61,7 @@ export const createShellUIAuthBackend = ({
46
61
  }
47
62
 
48
63
  const payload = (await response.json()) as Record<string, unknown>;
49
- const refreshParams = new URLSearchParams();
50
- if (typeof payload.access_token === 'string')
51
- refreshParams.set('access_token', payload.access_token);
52
- if (typeof payload.refresh_token === 'string')
53
- refreshParams.set('refresh_token', payload.refresh_token);
54
- if (typeof payload.expires_at === 'number' || typeof payload.expires_at === 'string') {
55
- refreshParams.set('expires_at', String(payload.expires_at));
56
- }
57
- if (typeof payload.expires_in === 'number' || typeof payload.expires_in === 'string') {
58
- refreshParams.set('expires_in', String(payload.expires_in));
59
- }
60
- if (typeof payload.token_type === 'string') refreshParams.set('token_type', payload.token_type);
61
- return buildSessionFromParams(refreshParams, nowSeconds);
64
+ return buildSessionFromTokenPayload(payload, nowSeconds);
62
65
  };
63
66
 
64
67
  return {
@@ -67,6 +70,27 @@ export const createShellUIAuthBackend = ({
67
70
  const hashParams = new URLSearchParams(locationHash.replace(/^#/, ''));
68
71
  return buildSessionFromParams(hashParams, nowSeconds);
69
72
  },
73
+ exchangeOAuthSessionCode: async ({ authCode, redirectTo, nowSeconds }) => {
74
+ if (!backendUrl) {
75
+ throw new Error('Missing Shellui backend URL.');
76
+ }
77
+ const response = await fetch(`${backendUrl}${OAUTH_SESSION_ENDPOINT}`, {
78
+ method: 'POST',
79
+ headers: {
80
+ Accept: 'application/json',
81
+ 'Content-Type': 'application/json',
82
+ },
83
+ body: JSON.stringify({
84
+ auth_code: authCode,
85
+ redirect_to: redirectTo,
86
+ }),
87
+ });
88
+ const payload = (await response.json().catch(() => null)) as Record<string, unknown> | null;
89
+ if (!response.ok) {
90
+ parseAuthErrorPayload(payload, response);
91
+ }
92
+ return buildSessionFromTokenPayload(payload, nowSeconds);
93
+ },
70
94
  exchangeOAuthCode: async ({ provider, code, redirectUri, oauthClientId, nowSeconds }) => {
71
95
  if (!backendUrl) {
72
96
  throw new Error('Missing Shellui backend URL.');
@@ -100,29 +124,9 @@ export const createShellUIAuthBackend = ({
100
124
  });
101
125
  const payload = (await response.json().catch(() => null)) as Record<string, unknown> | null;
102
126
  if (!response.ok) {
103
- const err = payload?.error ?? payload?.detail;
104
- const message = typeof err === 'string' && err.trim() ? err : `HTTP ${response.status}`;
105
- let errorCode = typeof payload?.error_code === 'string' ? payload.error_code.trim() : null;
106
- // Exchange uses 403 only for company join denial; default the code if omitted.
107
- if (!errorCode && response.status === 403) {
108
- errorCode = 'access_pending';
109
- }
110
- throw new AuthRequestError(message, errorCode);
111
- }
112
- const refreshParams = new URLSearchParams();
113
- if (typeof payload?.access_token === 'string')
114
- refreshParams.set('access_token', payload.access_token);
115
- if (typeof payload?.refresh_token === 'string')
116
- refreshParams.set('refresh_token', payload.refresh_token);
117
- if (typeof payload?.expires_at === 'number' || typeof payload?.expires_at === 'string') {
118
- refreshParams.set('expires_at', String(payload.expires_at));
119
- }
120
- if (typeof payload?.expires_in === 'number' || typeof payload?.expires_in === 'string') {
121
- refreshParams.set('expires_in', String(payload.expires_in));
127
+ parseAuthErrorPayload(payload, response);
122
128
  }
123
- if (typeof payload?.token_type === 'string')
124
- refreshParams.set('token_type', payload.token_type);
125
- return buildSessionFromParams(refreshParams, nowSeconds);
129
+ return buildSessionFromTokenPayload(payload, nowSeconds);
126
130
  },
127
131
  restoreSession: async (storedSession, nowSeconds) => {
128
132
  if (!storedSession) return null;
@@ -188,8 +192,12 @@ export const createShellUIAuthBackend = ({
188
192
  method: 'POST',
189
193
  headers: {
190
194
  Accept: 'application/json',
195
+ 'Content-Type': 'application/json',
191
196
  Authorization: `Bearer ${session.accessToken}`,
192
197
  },
198
+ body: JSON.stringify({
199
+ ...(session.refreshToken ? { refresh_token: session.refreshToken } : {}),
200
+ }),
193
201
  });
194
202
  },
195
203
  getAuthSettings: async () => {
@@ -107,6 +107,7 @@ export const createSupabaseAuthBackend = ({
107
107
  const hashParams = new URLSearchParams(locationHash.replace(/^#/, ''));
108
108
  return buildSessionFromParams(hashParams, nowSeconds);
109
109
  },
110
+ exchangeOAuthSessionCode: async () => null,
110
111
  exchangeOAuthCode: async () => null,
111
112
  restoreSession: async (storedSession, nowSeconds) => {
112
113
  if (!storedSession) return null;
@@ -4,6 +4,11 @@ import type { AuthSession, AuthSettings, UserPreferences } from '../types';
4
4
  export interface AuthBackend {
5
5
  type: BackendConfig['type'] | 'none';
6
6
  readSessionFromCallback: (locationHash: string, nowSeconds: number) => AuthSession | null;
7
+ exchangeOAuthSessionCode: (params: {
8
+ authCode: string;
9
+ redirectTo: string;
10
+ nowSeconds: number;
11
+ }) => Promise<AuthSession | null>;
7
12
  exchangeOAuthCode: (params: {
8
13
  provider: string;
9
14
  code: string;
@@ -25,6 +25,7 @@ import {
25
25
  import { AppBrandIcon } from '../../layouts/branding/AppBrandIcon';
26
26
  import { DESKTOP_TITLEBAR_HEIGHT_PX } from '../../layouts/chrome/constants';
27
27
  import { useMacTrafficLights } from '../../layouts/chrome/runtime';
28
+ import { validateLoginPanelUrl } from '../../security/urlAllowlist';
28
29
  import { AccessPendingView } from './AccessPendingView';
29
30
  import { LoginPreferencesControls } from './LoginPreferencesControls';
30
31
 
@@ -416,7 +417,10 @@ export const LoginView = () => {
416
417
  }
417
418
  };
418
419
 
419
- const panelUrl = config.backend?.login?.panelUrl?.trim() || null;
420
+ const panelUrl = useMemo(
421
+ () => validateLoginPanelUrl(config.backend?.login?.panelUrl, config),
422
+ [config],
423
+ );
420
424
  const panelImage = config.backend?.login?.panelImage?.trim() || null;
421
425
  const hasCustomPanel = Boolean(panelUrl || panelImage);
422
426
  const legalDocuments = useMemo(() => getLegalDocuments(config), [config]);