@classic-homes/auth 1.49.0 → 1.50.0

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.
package/README.md CHANGED
@@ -230,11 +230,27 @@ async function handleMFAVerify(mfaToken: string, code: string, trustDevice: bool
230
230
 
231
231
  ### SSO account linking
232
232
 
233
- `authService.linkAccount(provider)` (`authApi.linkSSOAccount`) sends the
234
- signed-in user to the IdP. CHAPI then redirects to
235
- `/account?link=pending#sso_link_code=<code>` (or `?link=error&message=…`) and
233
+ `authService.linkAccount(provider, { callback? })` (`authApi.linkSSOAccount`)
234
+ sends the signed-in user to the IdP. CHAPI then redirects back to `callback`
235
+ with `?link=pending#sso_link_code=<code>` (or `?link=error&message=…`) and
236
236
  **links nothing** until the same signed-in user posts that one-time code back.
237
- On your `/account` page:
237
+
238
+ `callback` defaults to the page the link started from
239
+ (`location.origin + location.pathname`), so the user lands where they clicked
240
+ "Link". Its origin must be on CHAPI's SSO allowlist (same rule as the authorize
241
+ endpoint's `callback`). Pass an absolute URL to return elsewhere, or
242
+ `callback: null` to send none (CHAPI then uses its own web `/account` page).
243
+ A callback with its own query (`/account?tab=linked-accounts`) is fine: CHAPI
244
+ adds `link`, and `readSsoLinkResult()` removes only `link`, `message` and
245
+ `sso_link_code`.
246
+
247
+ The authorization URL CHAPI returns is the identity provider's page, so it is
248
+ **not** checked against `allowedRedirectOrigins` (your app's origins). It must
249
+ be https, or, when `sso.idpOrigins` is set (e.g. `['https://auth.example.com']`),
250
+ on one of those origins, `sso.logoutOrigins`, the `authorizeUrl` origin or the
251
+ API origin.
252
+
253
+ On the callback page (any path):
238
254
 
239
255
  ```typescript
240
256
  import { authService, isApiError, readSsoLinkResult } from '@classic-homes/auth/core';
@@ -546,6 +562,10 @@ interface AuthConfig {
546
562
  authorizeUrl?: string;
547
563
  /** Reject SSO callbacks whose client_state is missing or wrong (default false) */
548
564
  requireClientState?: boolean;
565
+ /** Origins the IdP's logout URL may be on */
566
+ logoutOrigins?: string[];
567
+ /** Origins linkSSOAccount may follow the IdP authorization URL to (unset: any https) */
568
+ idpOrigins?: string[];
549
569
  };
550
570
 
551
571
  /** Callback when auth errors occur */
@@ -0,0 +1,3 @@
1
+ export { authActions, authStore, currentUser, isAuthenticated } from './chunk-WARTLLDA.js';
2
+ import './chunk-AY7AKNQT.js';
3
+ import './chunk-SMPUGWF7.js';
@@ -1,4 +1,4 @@
1
- import { isInitialized, getConfig, getUserRoles, clearAccessSubject, getStorage, isTokenExpired, getFetch, isAccessProbeActive, isValidRedirectUrl, ACCESS_DEBUG_HEADER, ACCESS_REDACTED_HEADER, ACCESS_REDACTED_TRUNCATED_HEADER, parseRedactedHeader, reportAccess, requirementFromDenial, decodeJWT } from './chunk-TANYGU4O.js';
1
+ import { isInitialized, getConfig, getUserRoles, clearAccessSubject, getStorage, isTokenExpired, getFetch, isAccessProbeActive, isValidSSOAuthorizationUrl, isValidRedirectUrl, ACCESS_DEBUG_HEADER, ACCESS_REDACTED_HEADER, ACCESS_REDACTED_TRUNCATED_HEADER, parseRedactedHeader, reportAccess, requirementFromDenial, decodeJWT } from './chunk-SMPUGWF7.js';
2
2
 
3
3
  // src/core/sso-state.ts
4
4
  var SSO_CLIENT_STATE_PARAM = "client_state";
@@ -282,7 +282,7 @@ function writeStoredTokens(accessToken, refreshToken) {
282
282
  }
283
283
  async function syncSvelteStore(apply) {
284
284
  try {
285
- const { authStore } = await import('./auth.svelte-D5UAUBOK.js');
285
+ const { authStore } = await import('./auth.svelte-DSBVIXO5.js');
286
286
  apply(authStore);
287
287
  } catch {
288
288
  }
@@ -696,6 +696,24 @@ var api = {
696
696
  };
697
697
 
698
698
  // src/core/api.ts
699
+ function resolveLinkCallback(callback) {
700
+ if (callback === null) return void 0;
701
+ if (callback !== void 0) {
702
+ let parsed;
703
+ try {
704
+ parsed = new URL(callback);
705
+ } catch {
706
+ throw new Error("Invalid SSO link callback: must be an absolute URL");
707
+ }
708
+ if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
709
+ throw new Error("Invalid SSO link callback: must be an http(s) URL");
710
+ }
711
+ return callback;
712
+ }
713
+ const origin = window.location?.origin;
714
+ if (!origin || origin === "null") return void 0;
715
+ return `${origin}${window.location.pathname ?? ""}`;
716
+ }
699
717
  async function fetchWithTimeout(url, init, read) {
700
718
  const config = getConfig();
701
719
  const fetchFn = config.fetch ?? fetch;
@@ -1115,17 +1133,24 @@ var authApi = {
1115
1133
  *
1116
1134
  * Initiates the SSO linking flow by making an authenticated API call.
1117
1135
  * The server returns an authorization URL to redirect the user to.
1118
- * The IdP returns the user to `/account?link=pending#sso_link_code=…`;
1119
- * nothing is linked until that page calls `completeSSOLink(code)`
1120
- * (read the code with `readSsoLinkResult()`).
1136
+ * After the IdP, CHAPI returns the user to `callback` with
1137
+ * `?link=pending#sso_link_code=…` (or `?link=error&message=…`); nothing is
1138
+ * linked until that page calls `completeSSOLink(code)` (read the code with
1139
+ * `readSsoLinkResult()`).
1140
+ *
1141
+ * @param options.callback - Absolute URL to come back to; its origin must be
1142
+ * on CHAPI's SSO allowlist. Defaults to the current page
1143
+ * (`location.origin + location.pathname`). Pass `null` to send none
1144
+ * (CHAPI then uses its own web `/account` page).
1121
1145
  */
1122
- async linkSSOAccount(provider = "authentik") {
1146
+ async linkSSOAccount(provider = "authentik", options = {}) {
1123
1147
  if (typeof window === "undefined") return;
1124
1148
  const accessToken = getAccessToken();
1125
1149
  if (!accessToken) {
1126
1150
  throw new Error("Not authenticated");
1127
1151
  }
1128
1152
  const config = getConfig();
1153
+ const callback = resolveLinkCallback(options.callback);
1129
1154
  const result = await fetchWithTimeout(
1130
1155
  `${config.baseUrl}/auth/sso/link`,
1131
1156
  {
@@ -1134,7 +1159,7 @@ var authApi = {
1134
1159
  "Content-Type": "application/json",
1135
1160
  Authorization: `Bearer ${accessToken}`
1136
1161
  },
1137
- body: JSON.stringify({ provider })
1162
+ body: JSON.stringify(callback ? { provider, callback } : { provider })
1138
1163
  },
1139
1164
  async (response) => {
1140
1165
  if (!response.ok) {
@@ -1146,9 +1171,9 @@ var authApi = {
1146
1171
  );
1147
1172
  const authorizationUrl = extractData(result).authorizationUrl;
1148
1173
  if (authorizationUrl) {
1149
- if (!isValidRedirectUrl(authorizationUrl)) {
1174
+ if (!isValidSSOAuthorizationUrl(authorizationUrl)) {
1150
1175
  throw new Error(
1151
- "SSO link failed: authorization URL is not in the list of allowed redirect origins"
1176
+ "SSO link failed: authorization URL is not an allowed identity provider URL (see sso.idpOrigins)"
1152
1177
  );
1153
1178
  }
1154
1179
  window.location.href = authorizationUrl;
@@ -1157,8 +1182,8 @@ var authApi = {
1157
1182
  /**
1158
1183
  * Finish linking an SSO account (`POST /auth/sso/link/complete`).
1159
1184
  *
1160
- * After the IdP, CHAPI redirects to `/account?link=pending#sso_link_code=…`
1161
- * and writes no link until the signed-in user who started it sends that
1185
+ * After the IdP, CHAPI redirects to the link `callback` (the page that
1186
+ * started it) with `?link=pending#sso_link_code=…` and writes no link until the signed-in user who started it sends that
1162
1187
  * one-time code here. Throws `ApiError`: 400 for an unknown, expired or used
1163
1188
  * code (or an SSO account already linked to another user), 403 when the
1164
1189
  * link was started by a different account or the IdP email is unverified or
@@ -1,6 +1,6 @@
1
- import { authService } from './chunk-KWRXKW3R.js';
2
- import { authStore, currentUser, isAuthenticated, authActions } from './chunk-YLRB4RW5.js';
3
- import { evaluateAccess, effectiveSubject, isAccessProbeActive, reportDecision, isInitialized, initAuth } from './chunk-TANYGU4O.js';
1
+ import { authService } from './chunk-YJUWI2VL.js';
2
+ import { authStore, currentUser, isAuthenticated, authActions } from './chunk-WARTLLDA.js';
3
+ import { evaluateAccess, effectiveSubject, isAccessProbeActive, reportDecision, isInitialized, initAuth } from './chunk-SMPUGWF7.js';
4
4
 
5
5
  // src/svelte/guards/auth-guard.ts
6
6
  function checkAuth(options = {}) {
@@ -140,6 +140,29 @@ function isValidSSOLogoutUrl(url) {
140
140
  }
141
141
  });
142
142
  }
143
+ function isValidSSOAuthorizationUrl(url) {
144
+ const cfg = getConfig();
145
+ let parsed;
146
+ try {
147
+ parsed = new URL(url);
148
+ } catch {
149
+ return false;
150
+ }
151
+ if (parsed.protocol !== "http:" && parsed.protocol !== "https:") return false;
152
+ const idpOrigins = cfg.sso?.idpOrigins ?? [];
153
+ const listed = [...idpOrigins, ...cfg.sso?.logoutOrigins ?? [], cfg.baseUrl];
154
+ if (cfg.sso?.authorizeUrl) listed.push(cfg.sso.authorizeUrl);
155
+ const onListedOrigin = listed.some((origin) => {
156
+ try {
157
+ return new URL(origin).origin === parsed.origin;
158
+ } catch {
159
+ return false;
160
+ }
161
+ });
162
+ if (onListedOrigin) return true;
163
+ if (idpOrigins.length > 0) return false;
164
+ return parsed.protocol === "https:";
165
+ }
143
166
 
144
167
  // src/core/jwt.ts
145
168
  function decodeJWT(token) {
@@ -411,4 +434,4 @@ function hasAllRoles(user, roles) {
411
434
  return allowed;
412
435
  }
413
436
 
414
- export { ACCESS_DEBUG_HEADER, ACCESS_REDACTED_HEADER, ACCESS_REDACTED_TRUNCATED_HEADER, ROLE_HIERARCHY, ROLE_NAMES, clearAccessSubject, computePrimaryRole, createMemoryStorage, createSessionStorage, decodeJWT, effectiveSubject, evaluateAccess, extractClaims, getAccessSubjectOverride, getConfig, getDefaultStorage, getEffectiveLevel, getFetch, getStorage, getTokenExpiration, getTokenRemainingTime, getUserRoles, hasAllRoles, hasAnyRole, hasRole, initAuth, isAccessProbeActive, isInitialized, isTokenExpired, isValidRedirectUrl, isValidSSOLogoutUrl, onAccessSubjectChange, parseRedactedHeader, reportAccess, reportDecision, requirementFromDenial, resetConfig, setAccessProbe, setAccessSubject };
437
+ export { ACCESS_DEBUG_HEADER, ACCESS_REDACTED_HEADER, ACCESS_REDACTED_TRUNCATED_HEADER, ROLE_HIERARCHY, ROLE_NAMES, clearAccessSubject, computePrimaryRole, createMemoryStorage, createSessionStorage, decodeJWT, effectiveSubject, evaluateAccess, extractClaims, getAccessSubjectOverride, getConfig, getDefaultStorage, getEffectiveLevel, getFetch, getStorage, getTokenExpiration, getTokenRemainingTime, getUserRoles, hasAllRoles, hasAnyRole, hasRole, initAuth, isAccessProbeActive, isInitialized, isTokenExpired, isValidRedirectUrl, isValidSSOAuthorizationUrl, isValidSSOLogoutUrl, onAccessSubjectChange, parseRedactedHeader, reportAccess, reportDecision, requirementFromDenial, resetConfig, setAccessProbe, setAccessSubject };
@@ -1,5 +1,5 @@
1
- import { InvalidAuthResponseError, bumpSessionGeneration, authApi } from './chunk-6KCX7A53.js';
2
- import { onAccessSubjectChange, isInitialized, getConfig, isValidSSOLogoutUrl, hasRole, hasAnyRole, hasAllRoles, effectiveSubject, reportDecision, decodeJWT, getStorage, getDefaultStorage } from './chunk-TANYGU4O.js';
1
+ import { InvalidAuthResponseError, bumpSessionGeneration, authApi } from './chunk-AY7AKNQT.js';
2
+ import { onAccessSubjectChange, isInitialized, getConfig, isValidSSOLogoutUrl, hasRole, hasAnyRole, hasAllRoles, effectiveSubject, reportDecision, decodeJWT, getStorage, getDefaultStorage } from './chunk-SMPUGWF7.js';
3
3
 
4
4
  // src/svelte/stores/auth.svelte.ts
5
5
  var STORAGE_VERSION = 2;
@@ -1,5 +1,5 @@
1
- import { authApi, rememberMfaChallengeToken, InvalidAuthResponseError, RoleDeniedError, clearMfaChallengeToken } from './chunk-6KCX7A53.js';
2
- import { getUserRoles } from './chunk-TANYGU4O.js';
1
+ import { authApi, rememberMfaChallengeToken, InvalidAuthResponseError, RoleDeniedError, clearMfaChallengeToken } from './chunk-AY7AKNQT.js';
2
+ import { getUserRoles } from './chunk-SMPUGWF7.js';
3
3
 
4
4
  // src/core/sso-link.ts
5
5
  var SSO_LINK_CODE_PARAM = "sso_link_code";
@@ -48,7 +48,7 @@ function getAvailableMethods(response) {
48
48
  async function setStoreAuth(response) {
49
49
  let store;
50
50
  try {
51
- store = (await import('./auth.svelte-D5UAUBOK.js')).authStore;
51
+ store = (await import('./auth.svelte-DSBVIXO5.js')).authStore;
52
52
  } catch {
53
53
  return;
54
54
  }
@@ -342,14 +342,16 @@ var AuthService = class {
342
342
  return await authApi.getSSOAccounts(customFetch);
343
343
  }
344
344
  /**
345
- * Link an SSO account (redirects to SSO provider).
345
+ * Link an SSO account (redirects to SSO provider). The IdP round trip
346
+ * returns to `options.callback`, by default the current page; finish there
347
+ * with `readSsoLinkResult()` + `completeSSOLink(code)`.
346
348
  */
347
- async linkAccount(provider = "authentik") {
348
- await authApi.linkSSOAccount(provider);
349
+ async linkAccount(provider = "authentik", options) {
350
+ await authApi.linkSSOAccount(provider, options);
349
351
  }
350
352
  /**
351
353
  * Finish linking an SSO account with the one-time `sso_link_code` the
352
- * `/account` page received (see `readSsoLinkResult()`). Throws `ApiError`
354
+ * link callback page received (see `readSsoLinkResult()`). Throws `ApiError`
353
355
  * (400 unknown/used code, 403 different user or unverified/mismatched email).
354
356
  */
355
357
  async completeSSOLink(code) {
@@ -1,6 +1,6 @@
1
- import { o as SSOLinkResult, e as LoginCredentials, f as LoginResponse, g as LogoutResponse, R as RegisterData, l as RegisterResponse, s as User, k as ProfileUpdateData, C as ChangePasswordData, q as Session, A as ApiKey, c as CreateApiKeyRequest, d as CreateApiKeyResponse, U as UpdateApiKeyRequest, j as MFAStatus, i as MFASetupResponse, M as MFAChallengeData, h as MFAChallengeEmailResponse, D as Device, t as UserPreferences, L as LinkedAccount, n as SSOLinkCompleteResponse, p as SecurityEvent, P as Pagination, u as UserRolesResponse } from '../types-YhPCxYU9.js';
2
- export { a as AuthConfig, b as AuthState, m as ResetPasswordData, S as SSOConfig, r as StorageAdapter, v as createMemoryStorage, w as createSessionStorage, x as getConfig, y as getDefaultStorage, z as getFetch, B as getStorage, E as initAuth, F as isInitialized, G as resetConfig } from '../types-YhPCxYU9.js';
3
- export { A as ApiError, a as AuthService, I as InvalidAuthResponseError, L as LoginOptions, M as MFAChallengeEmailError, b as MFAVerifyOptions, R as RoleDeniedError, S as SessionChangedError, c as authService, f as formatUserRoles, g as getAvatarFallback, d as getDisplayName, e as getGreeting, h as getUserEmail, i as getUserInitials, j as isApiError, k as isRoleDeniedError, l as isSessionChangedError } from '../user-utils-CmbXLkt_.js';
1
+ import { o as SSOLinkResult, e as LoginCredentials, f as LoginResponse, g as LogoutResponse, R as RegisterData, l as RegisterResponse, s as User, k as ProfileUpdateData, C as ChangePasswordData, q as Session, A as ApiKey, c as CreateApiKeyRequest, d as CreateApiKeyResponse, U as UpdateApiKeyRequest, j as MFAStatus, i as MFASetupResponse, M as MFAChallengeData, h as MFAChallengeEmailResponse, D as Device, t as UserPreferences, L as LinkedAccount, n as SSOLinkCompleteResponse, p as SecurityEvent, P as Pagination, u as UserRolesResponse } from '../types-To6QJDLW.js';
2
+ export { a as AuthConfig, b as AuthState, m as ResetPasswordData, S as SSOConfig, r as StorageAdapter, v as createMemoryStorage, w as createSessionStorage, x as getConfig, y as getDefaultStorage, z as getFetch, B as getStorage, E as initAuth, F as isInitialized, G as resetConfig } from '../types-To6QJDLW.js';
3
+ export { A as ApiError, a as AuthService, I as InvalidAuthResponseError, L as LoginOptions, M as MFAChallengeEmailError, b as MFAVerifyOptions, R as RoleDeniedError, S as SessionChangedError, c as authService, f as formatUserRoles, g as getAvatarFallback, d as getDisplayName, e as getGreeting, h as getUserEmail, i as getUserInitials, j as isApiError, k as isRoleDeniedError, l as isSessionChangedError } from '../user-utils-_gHXq75w.js';
4
4
 
5
5
  /**
6
6
  * SSO client state
@@ -105,10 +105,11 @@ interface MfaChallengeHashVerification extends SsoClientStateVerification {
105
105
  declare function acceptMfaChallengeHash(input: URLSearchParams | string): MfaChallengeHashVerification;
106
106
 
107
107
  /**
108
- * SSO account linking: the return trip to `/account`.
108
+ * SSO account linking: the return trip to the link callback page.
109
109
  *
110
110
  * `linkSSOAccount()` sends the signed-in user to the IdP. CHAPI then redirects
111
- * to `<frontend>/account?link=pending#sso_link_code=<code>` (or
111
+ * to the link `callback` (by default the page that started it; without one,
112
+ * CHAPI web's `/account`) with `?link=pending#sso_link_code=<code>` (or
112
113
  * `?link=error&message=…`) and writes no link until the same user posts the
113
114
  * one-time code to `POST /auth/sso/link/complete` (`completeSSOLink`).
114
115
  *
@@ -119,7 +120,7 @@ declare function acceptMfaChallengeHash(input: URLSearchParams | string): MfaCha
119
120
 
120
121
  /** Hash-fragment parameter carrying the one-time link code. */
121
122
  declare const SSO_LINK_CODE_PARAM = "sso_link_code";
122
- /** Query parameter CHAPI sets on the `/account` redirect (`pending` | `error`). */
123
+ /** Query parameter CHAPI sets on the link callback redirect (`pending` | `error`). */
123
124
  declare const SSO_LINK_STATUS_PARAM = "link";
124
125
  interface ReadSsoLinkResultOptions {
125
126
  /** URL to read; defaults to `window.location.href`. */
@@ -131,8 +132,9 @@ interface ReadSsoLinkResultOptions {
131
132
  clear?: boolean;
132
133
  }
133
134
  /**
134
- * Read (and by default clear) the outcome of an SSO account-link round trip.
135
- * Returns `null` when the URL is not a link return.
135
+ * Read (and by default clear) the outcome of an SSO account-link round trip,
136
+ * on whatever page the link callback pointed at. Returns `null` when the URL
137
+ * is not a link return.
136
138
  *
137
139
  * @example
138
140
  * ```typescript
@@ -487,16 +489,24 @@ declare const authApi: {
487
489
  *
488
490
  * Initiates the SSO linking flow by making an authenticated API call.
489
491
  * The server returns an authorization URL to redirect the user to.
490
- * The IdP returns the user to `/account?link=pending#sso_link_code=…`;
491
- * nothing is linked until that page calls `completeSSOLink(code)`
492
- * (read the code with `readSsoLinkResult()`).
492
+ * After the IdP, CHAPI returns the user to `callback` with
493
+ * `?link=pending#sso_link_code=…` (or `?link=error&message=…`); nothing is
494
+ * linked until that page calls `completeSSOLink(code)` (read the code with
495
+ * `readSsoLinkResult()`).
496
+ *
497
+ * @param options.callback - Absolute URL to come back to; its origin must be
498
+ * on CHAPI's SSO allowlist. Defaults to the current page
499
+ * (`location.origin + location.pathname`). Pass `null` to send none
500
+ * (CHAPI then uses its own web `/account` page).
493
501
  */
494
- linkSSOAccount(provider?: string): Promise<void>;
502
+ linkSSOAccount(provider?: string, options?: {
503
+ callback?: string | null;
504
+ }): Promise<void>;
495
505
  /**
496
506
  * Finish linking an SSO account (`POST /auth/sso/link/complete`).
497
507
  *
498
- * After the IdP, CHAPI redirects to `/account?link=pending#sso_link_code=…`
499
- * and writes no link until the signed-in user who started it sends that
508
+ * After the IdP, CHAPI redirects to the link `callback` (the page that
509
+ * started it) with `?link=pending#sso_link_code=…` and writes no link until the signed-in user who started it sends that
500
510
  * one-time code here. Throws `ApiError`: 400 for an unknown, expired or used
501
511
  * code (or an SSO account already linked to another user), 403 when the
502
512
  * link was started by a different account or the IdP email is unverified or
@@ -1,3 +1,3 @@
1
- export { AuthService, SSO_LINK_CODE_PARAM, SSO_LINK_STATUS_PARAM, authService, formatUserRoles, getAvailableMethods, getAvatarFallback, getDisplayName, getGreeting, getMfaToken, getUserEmail, getUserInitials, isLoginSuccessResponse, isMfaChallengeResponse, readSsoLinkResult } from '../chunk-KWRXKW3R.js';
2
- export { ApiError, InvalidAuthResponseError, MFAChallengeEmailError, MFA_CHALLENGE_TOKEN_PARAM, RoleDeniedError, SSO_CLIENT_STATE_PARAM, SSO_CLIENT_STATE_TTL_MS, SessionChangedError, acceptMfaChallengeHash, api, apiRequest, authApi, clearMfaChallengeToken, clearStoredAuth, consumeSsoClientState, createSsoClientState, extractData, getAccessToken, getRefreshToken, getSessionToken, initCrossTabSync, isApiError, isRoleDeniedError, isSessionChangedError, refreshSession, rememberMfaChallengeToken, updateStoredTokens, verifySsoClientState } from '../chunk-6KCX7A53.js';
3
- export { ACCESS_DEBUG_HEADER, ACCESS_REDACTED_HEADER, ACCESS_REDACTED_TRUNCATED_HEADER, ROLE_HIERARCHY, ROLE_NAMES, clearAccessSubject, computePrimaryRole, createMemoryStorage, createSessionStorage, decodeJWT, effectiveSubject, evaluateAccess, extractClaims, getAccessSubjectOverride, getConfig, getDefaultStorage, getEffectiveLevel, getFetch, getStorage, getTokenExpiration, getTokenRemainingTime, getUserRoles, hasAllRoles, hasAnyRole, hasRole, initAuth, isAccessProbeActive, isInitialized, isTokenExpired, onAccessSubjectChange, parseRedactedHeader, reportAccess, reportDecision, requirementFromDenial, resetConfig, setAccessProbe, setAccessSubject } from '../chunk-TANYGU4O.js';
1
+ export { AuthService, SSO_LINK_CODE_PARAM, SSO_LINK_STATUS_PARAM, authService, formatUserRoles, getAvailableMethods, getAvatarFallback, getDisplayName, getGreeting, getMfaToken, getUserEmail, getUserInitials, isLoginSuccessResponse, isMfaChallengeResponse, readSsoLinkResult } from '../chunk-YJUWI2VL.js';
2
+ export { ApiError, InvalidAuthResponseError, MFAChallengeEmailError, MFA_CHALLENGE_TOKEN_PARAM, RoleDeniedError, SSO_CLIENT_STATE_PARAM, SSO_CLIENT_STATE_TTL_MS, SessionChangedError, acceptMfaChallengeHash, api, apiRequest, authApi, clearMfaChallengeToken, clearStoredAuth, consumeSsoClientState, createSsoClientState, extractData, getAccessToken, getRefreshToken, getSessionToken, initCrossTabSync, isApiError, isRoleDeniedError, isSessionChangedError, refreshSession, rememberMfaChallengeToken, updateStoredTokens, verifySsoClientState } from '../chunk-AY7AKNQT.js';
3
+ export { ACCESS_DEBUG_HEADER, ACCESS_REDACTED_HEADER, ACCESS_REDACTED_TRUNCATED_HEADER, ROLE_HIERARCHY, ROLE_NAMES, clearAccessSubject, computePrimaryRole, createMemoryStorage, createSessionStorage, decodeJWT, effectiveSubject, evaluateAccess, extractClaims, getAccessSubjectOverride, getConfig, getDefaultStorage, getEffectiveLevel, getFetch, getStorage, getTokenExpiration, getTokenRemainingTime, getUserRoles, hasAllRoles, hasAnyRole, hasRole, initAuth, isAccessProbeActive, isInitialized, isTokenExpired, onAccessSubjectChange, parseRedactedHeader, reportAccess, reportDecision, requirementFromDenial, resetConfig, setAccessProbe, setAccessSubject } from '../chunk-SMPUGWF7.js';
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { A as ApiKey, a as AuthConfig, b as AuthState, C as ChangePasswordData, c as CreateApiKeyRequest, d as CreateApiKeyResponse, D as Device, L as LinkedAccount, e as LoginCredentials, f as LoginResponse, g as LogoutResponse, M as MFAChallengeData, h as MFAChallengeEmailResponse, i as MFASetupResponse, j as MFAStatus, P as Pagination, k as ProfileUpdateData, R as RegisterData, l as RegisterResponse, m as ResetPasswordData, S as SSOConfig, n as SSOLinkCompleteResponse, o as SSOLinkResult, p as SecurityEvent, q as Session, r as StorageAdapter, U as UpdateApiKeyRequest, s as User, t as UserPreferences, u as UserRolesResponse, v as createMemoryStorage, w as createSessionStorage, x as getConfig, y as getDefaultStorage, z as getFetch, B as getStorage, E as initAuth, F as isInitialized, G as resetConfig } from './types-YhPCxYU9.js';
1
+ export { A as ApiKey, a as AuthConfig, b as AuthState, C as ChangePasswordData, c as CreateApiKeyRequest, d as CreateApiKeyResponse, D as Device, L as LinkedAccount, e as LoginCredentials, f as LoginResponse, g as LogoutResponse, M as MFAChallengeData, h as MFAChallengeEmailResponse, i as MFASetupResponse, j as MFAStatus, P as Pagination, k as ProfileUpdateData, R as RegisterData, l as RegisterResponse, m as ResetPasswordData, S as SSOConfig, n as SSOLinkCompleteResponse, o as SSOLinkResult, p as SecurityEvent, q as Session, r as StorageAdapter, U as UpdateApiKeyRequest, s as User, t as UserPreferences, u as UserRolesResponse, v as createMemoryStorage, w as createSessionStorage, x as getConfig, y as getDefaultStorage, z as getFetch, B as getStorage, E as initAuth, F as isInitialized, G as resetConfig } from './types-To6QJDLW.js';
2
2
  export { ACCESS_DEBUG_HEADER, ACCESS_REDACTED_HEADER, ACCESS_REDACTED_TRUNCATED_HEADER, AccessCheckEvent, AccessCheckSource, AccessEvaluation, AccessProbe, AccessRequirement, AccessSubject, ApiRequestOptions, ApiResponse, JWTPayload, MFA_CHALLENGE_TOKEN_PARAM, MfaChallengeHashVerification, ROLE_HIERARCHY, ROLE_NAMES, ReadSsoLinkResultOptions, RedactedField, RefreshOutcome, RefreshSessionOptions, RoleName, SSO_CLIENT_STATE_PARAM, SSO_CLIENT_STATE_TTL_MS, SSO_LINK_CODE_PARAM, SSO_LINK_STATUS_PARAM, SsoClientStateResult, SsoClientStateVerification, acceptMfaChallengeHash, api, apiRequest, authApi, clearAccessSubject, clearMfaChallengeToken, clearStoredAuth, computePrimaryRole, consumeSsoClientState, createSsoClientState, decodeJWT, effectiveSubject, evaluateAccess, extractClaims, extractData, getAccessSubjectOverride, getAccessToken, getAvailableMethods, getEffectiveLevel, getMfaToken, getRefreshToken, getSessionToken, getTokenExpiration, getTokenRemainingTime, getUserRoles, hasAllRoles, hasAnyRole, hasRole, initCrossTabSync, isAccessProbeActive, isLoginSuccessResponse, isMfaChallengeResponse, isTokenExpired, onAccessSubjectChange, parseRedactedHeader, readSsoLinkResult, refreshSession, rememberMfaChallengeToken, reportAccess, reportDecision, requirementFromDenial, setAccessProbe, setAccessSubject, updateStoredTokens, verifySsoClientState } from './core/index.js';
3
- export { A as ApiError, a as AuthService, I as InvalidAuthResponseError, L as LoginOptions, M as MFAChallengeEmailError, b as MFAVerifyOptions, R as RoleDeniedError, S as SessionChangedError, c as authService, f as formatUserRoles, g as getAvatarFallback, d as getDisplayName, e as getGreeting, h as getUserEmail, i as getUserInitials, j as isApiError, k as isRoleDeniedError, l as isSessionChangedError } from './user-utils-CmbXLkt_.js';
3
+ export { A as ApiError, a as AuthService, I as InvalidAuthResponseError, L as LoginOptions, M as MFAChallengeEmailError, b as MFAVerifyOptions, R as RoleDeniedError, S as SessionChangedError, c as authService, f as formatUserRoles, g as getAvatarFallback, d as getDisplayName, e as getGreeting, h as getUserEmail, i as getUserInitials, j as isApiError, k as isRoleDeniedError, l as isSessionChangedError } from './user-utils-_gHXq75w.js';
4
4
  export { AuthClient, AuthGuardOptions, AuthGuardResult, AuthHookOptions, CreateAuthClientOptions, NavFilterOptions, RoleRestrictedItem, authActions, authStore, canAccess, checkAuth, createAuthClient, createAuthGuard, createAuthHook, createNavFilter, currentUser, filterByAccess, filterNavSections, isAuthenticated, matchesRoute, protectedLoad, requireAuth, requirePermission, requireRole, routePatterns } from './svelte/index.js';
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- export { canAccess, checkAuth, createAuthClient, createAuthGuard, createAuthHook, createNavFilter, filterByAccess, filterNavSections, matchesRoute, protectedLoad, requireAuth, requirePermission, requireRole, routePatterns } from './chunk-OP5MZRBE.js';
2
- export { AuthService, SSO_LINK_CODE_PARAM, SSO_LINK_STATUS_PARAM, authService, formatUserRoles, getAvailableMethods, getAvatarFallback, getDisplayName, getGreeting, getMfaToken, getUserEmail, getUserInitials, isLoginSuccessResponse, isMfaChallengeResponse, readSsoLinkResult } from './chunk-KWRXKW3R.js';
3
- export { authActions, authStore, currentUser, isAuthenticated } from './chunk-YLRB4RW5.js';
4
- export { ApiError, InvalidAuthResponseError, MFAChallengeEmailError, MFA_CHALLENGE_TOKEN_PARAM, RoleDeniedError, SSO_CLIENT_STATE_PARAM, SSO_CLIENT_STATE_TTL_MS, SessionChangedError, acceptMfaChallengeHash, api, apiRequest, authApi, clearMfaChallengeToken, clearStoredAuth, consumeSsoClientState, createSsoClientState, extractData, getAccessToken, getRefreshToken, getSessionToken, initCrossTabSync, isApiError, isRoleDeniedError, isSessionChangedError, refreshSession, rememberMfaChallengeToken, updateStoredTokens, verifySsoClientState } from './chunk-6KCX7A53.js';
5
- export { ACCESS_DEBUG_HEADER, ACCESS_REDACTED_HEADER, ACCESS_REDACTED_TRUNCATED_HEADER, ROLE_HIERARCHY, ROLE_NAMES, clearAccessSubject, computePrimaryRole, createMemoryStorage, createSessionStorage, decodeJWT, effectiveSubject, evaluateAccess, extractClaims, getAccessSubjectOverride, getConfig, getDefaultStorage, getEffectiveLevel, getFetch, getStorage, getTokenExpiration, getTokenRemainingTime, getUserRoles, hasAllRoles, hasAnyRole, hasRole, initAuth, isAccessProbeActive, isInitialized, isTokenExpired, onAccessSubjectChange, parseRedactedHeader, reportAccess, reportDecision, requirementFromDenial, resetConfig, setAccessProbe, setAccessSubject } from './chunk-TANYGU4O.js';
1
+ export { canAccess, checkAuth, createAuthClient, createAuthGuard, createAuthHook, createNavFilter, filterByAccess, filterNavSections, matchesRoute, protectedLoad, requireAuth, requirePermission, requireRole, routePatterns } from './chunk-IZYOA3KJ.js';
2
+ export { AuthService, SSO_LINK_CODE_PARAM, SSO_LINK_STATUS_PARAM, authService, formatUserRoles, getAvailableMethods, getAvatarFallback, getDisplayName, getGreeting, getMfaToken, getUserEmail, getUserInitials, isLoginSuccessResponse, isMfaChallengeResponse, readSsoLinkResult } from './chunk-YJUWI2VL.js';
3
+ export { authActions, authStore, currentUser, isAuthenticated } from './chunk-WARTLLDA.js';
4
+ export { ApiError, InvalidAuthResponseError, MFAChallengeEmailError, MFA_CHALLENGE_TOKEN_PARAM, RoleDeniedError, SSO_CLIENT_STATE_PARAM, SSO_CLIENT_STATE_TTL_MS, SessionChangedError, acceptMfaChallengeHash, api, apiRequest, authApi, clearMfaChallengeToken, clearStoredAuth, consumeSsoClientState, createSsoClientState, extractData, getAccessToken, getRefreshToken, getSessionToken, initCrossTabSync, isApiError, isRoleDeniedError, isSessionChangedError, refreshSession, rememberMfaChallengeToken, updateStoredTokens, verifySsoClientState } from './chunk-AY7AKNQT.js';
5
+ export { ACCESS_DEBUG_HEADER, ACCESS_REDACTED_HEADER, ACCESS_REDACTED_TRUNCATED_HEADER, ROLE_HIERARCHY, ROLE_NAMES, clearAccessSubject, computePrimaryRole, createMemoryStorage, createSessionStorage, decodeJWT, effectiveSubject, evaluateAccess, extractClaims, getAccessSubjectOverride, getConfig, getDefaultStorage, getEffectiveLevel, getFetch, getStorage, getTokenExpiration, getTokenRemainingTime, getUserRoles, hasAllRoles, hasAnyRole, hasRole, initAuth, isAccessProbeActive, isInitialized, isTokenExpired, onAccessSubjectChange, parseRedactedHeader, reportAccess, reportDecision, requirementFromDenial, resetConfig, setAccessProbe, setAccessSubject } from './chunk-SMPUGWF7.js';
@@ -1,7 +1,7 @@
1
- import { b as AuthState, s as User, a as AuthConfig } from '../types-YhPCxYU9.js';
2
- export { E as initAuth, F as isInitialized } from '../types-YhPCxYU9.js';
3
- import { c as authService } from '../user-utils-CmbXLkt_.js';
4
- export { I as InvalidAuthResponseError, R as RoleDeniedError, S as SessionChangedError, f as formatUserRoles, g as getAvatarFallback, d as getDisplayName, e as getGreeting, h as getUserEmail, i as getUserInitials, k as isRoleDeniedError, l as isSessionChangedError } from '../user-utils-CmbXLkt_.js';
1
+ import { b as AuthState, s as User, a as AuthConfig } from '../types-To6QJDLW.js';
2
+ export { E as initAuth, F as isInitialized } from '../types-To6QJDLW.js';
3
+ import { c as authService } from '../user-utils-_gHXq75w.js';
4
+ export { I as InvalidAuthResponseError, R as RoleDeniedError, S as SessionChangedError, f as formatUserRoles, g as getAvatarFallback, d as getDisplayName, e as getGreeting, h as getUserEmail, i as getUserInitials, k as isRoleDeniedError, l as isSessionChangedError } from '../user-utils-_gHXq75w.js';
5
5
 
6
6
  /**
7
7
  * Auth Store
@@ -1,5 +1,5 @@
1
- export { canAccess, checkAuth, createAuthClient, createAuthGuard, createAuthHook, createNavFilter, filterByAccess, filterNavSections, matchesRoute, protectedLoad, requireAuth, requirePermission, requireRole, routePatterns } from '../chunk-OP5MZRBE.js';
2
- export { formatUserRoles, getAvatarFallback, getDisplayName, getGreeting, getUserEmail, getUserInitials } from '../chunk-KWRXKW3R.js';
3
- export { authActions, authStore, currentUser, isAuthenticated } from '../chunk-YLRB4RW5.js';
4
- export { InvalidAuthResponseError, RoleDeniedError, SessionChangedError, isRoleDeniedError, isSessionChangedError } from '../chunk-6KCX7A53.js';
5
- export { initAuth, isInitialized } from '../chunk-TANYGU4O.js';
1
+ export { canAccess, checkAuth, createAuthClient, createAuthGuard, createAuthHook, createNavFilter, filterByAccess, filterNavSections, matchesRoute, protectedLoad, requireAuth, requirePermission, requireRole, routePatterns } from '../chunk-IZYOA3KJ.js';
2
+ export { formatUserRoles, getAvatarFallback, getDisplayName, getGreeting, getUserEmail, getUserInitials } from '../chunk-YJUWI2VL.js';
3
+ export { authActions, authStore, currentUser, isAuthenticated } from '../chunk-WARTLLDA.js';
4
+ export { InvalidAuthResponseError, RoleDeniedError, SessionChangedError, isRoleDeniedError, isSessionChangedError } from '../chunk-AY7AKNQT.js';
5
+ export { initAuth, isInitialized } from '../chunk-SMPUGWF7.js';
@@ -1,4 +1,4 @@
1
- import { s as User, D as Device, f as LoginResponse, p as SecurityEvent, q as Session, A as ApiKey, L as LinkedAccount, g as LogoutResponse, i as MFASetupResponse, j as MFAStatus, l as RegisterResponse, t as UserPreferences, r as StorageAdapter, b as AuthState, a as AuthConfig } from '../types-YhPCxYU9.js';
1
+ import { s as User, D as Device, f as LoginResponse, p as SecurityEvent, q as Session, A as ApiKey, L as LinkedAccount, g as LogoutResponse, i as MFASetupResponse, j as MFAStatus, l as RegisterResponse, t as UserPreferences, r as StorageAdapter, b as AuthState, a as AuthConfig } from '../types-To6QJDLW.js';
2
2
 
3
3
  /**
4
4
  * User Fixtures
@@ -1,4 +1,4 @@
1
- import { hasRole, hasAnyRole, hasAllRoles, initAuth, resetConfig, getUserRoles, isTokenExpired, decodeJWT } from '../chunk-TANYGU4O.js';
1
+ import { hasRole, hasAnyRole, hasAllRoles, initAuth, resetConfig, getUserRoles, isTokenExpired, decodeJWT } from '../chunk-SMPUGWF7.js';
2
2
 
3
3
  // src/testing/fixtures/users.ts
4
4
  var mockUser = {
@@ -18,6 +18,15 @@ interface SSOConfig {
18
18
  * a logout URL anywhere else is dropped.
19
19
  */
20
20
  logoutOrigins?: string[];
21
+ /**
22
+ * Origins the identity provider's authorization page may be on (e.g.
23
+ * 'https://auth.example.com'), checked when `linkSSOAccount` follows the
24
+ * authorization URL CHAPI returns. When set, that URL must be on one of
25
+ * these, `logoutOrigins`, the `authorizeUrl` origin or the API origin.
26
+ * When unset, any https URL is accepted. Never checked against
27
+ * `allowedRedirectOrigins`, which lists the app's own origins.
28
+ */
29
+ idpOrigins?: string[];
21
30
  /**
22
31
  * Reject SSO callbacks whose `client_state` is missing or doesn't match the
23
32
  * one this tab sent to the authorize endpoint (see `verifySsoClientState`).
@@ -385,7 +394,7 @@ interface SSOLinkCompleteResponse {
385
394
  provider: string;
386
395
  }
387
396
  /**
388
- * Where an SSO account-link round trip left the `/account` page
397
+ * Where an SSO account-link round trip left the callback page
389
398
  * (`readSsoLinkResult()`):
390
399
  * - `pending`: the IdP verified the identity; call `completeSSOLink(code)`
391
400
  * - `error`: the IdP step failed; `message` is the server's reason
@@ -1,4 +1,4 @@
1
- import { e as LoginCredentials, f as LoginResponse, g as LogoutResponse, R as RegisterData, l as RegisterResponse, s as User, k as ProfileUpdateData, q as Session, A as ApiKey, c as CreateApiKeyRequest, d as CreateApiKeyResponse, U as UpdateApiKeyRequest, j as MFAStatus, i as MFASetupResponse, M as MFAChallengeData, h as MFAChallengeEmailResponse, D as Device, t as UserPreferences, L as LinkedAccount, n as SSOLinkCompleteResponse, p as SecurityEvent, P as Pagination } from './types-YhPCxYU9.js';
1
+ import { e as LoginCredentials, f as LoginResponse, g as LogoutResponse, R as RegisterData, l as RegisterResponse, s as User, k as ProfileUpdateData, q as Session, A as ApiKey, c as CreateApiKeyRequest, d as CreateApiKeyResponse, U as UpdateApiKeyRequest, j as MFAStatus, i as MFASetupResponse, M as MFAChallengeData, h as MFAChallengeEmailResponse, D as Device, t as UserPreferences, L as LinkedAccount, n as SSOLinkCompleteResponse, p as SecurityEvent, P as Pagination } from './types-To6QJDLW.js';
2
2
 
3
3
  /**
4
4
  * Auth Service
@@ -244,12 +244,16 @@ declare class AuthService {
244
244
  */
245
245
  getLinkedAccounts(customFetch?: typeof fetch): Promise<LinkedAccount[]>;
246
246
  /**
247
- * Link an SSO account (redirects to SSO provider).
247
+ * Link an SSO account (redirects to SSO provider). The IdP round trip
248
+ * returns to `options.callback`, by default the current page; finish there
249
+ * with `readSsoLinkResult()` + `completeSSOLink(code)`.
248
250
  */
249
- linkAccount(provider?: string): Promise<void>;
251
+ linkAccount(provider?: string, options?: {
252
+ callback?: string | null;
253
+ }): Promise<void>;
250
254
  /**
251
255
  * Finish linking an SSO account with the one-time `sso_link_code` the
252
- * `/account` page received (see `readSsoLinkResult()`). Throws `ApiError`
256
+ * link callback page received (see `readSsoLinkResult()`). Throws `ApiError`
253
257
  * (400 unknown/used code, 403 different user or unverified/mismatched email).
254
258
  */
255
259
  completeSSOLink(code: string): Promise<SSOLinkCompleteResponse>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@classic-homes/auth",
3
- "version": "1.49.0",
3
+ "version": "1.50.0",
4
4
  "description": "Authentication services and Svelte bindings for Classic Theme apps",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -1,3 +0,0 @@
1
- export { authActions, authStore, currentUser, isAuthenticated } from './chunk-YLRB4RW5.js';
2
- import './chunk-6KCX7A53.js';
3
- import './chunk-TANYGU4O.js';