@atol-sh/js 0.1.0 → 0.1.1

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/CHANGELOG.md CHANGED
@@ -8,6 +8,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
8
8
 
9
9
  No unreleased changes yet.
10
10
 
11
+ ## [0.1.1] - 2026-07-08
12
+
13
+ ### Added
14
+
15
+ - `seedTestSession(tokens)` on the browser auth client, gated behind a new
16
+ `allowTestSessions` config flag (default `false`). It establishes an
17
+ authenticated session directly from a token response — bypassing the OIDC
18
+ redirect/callback and signature/state/nonce checks — so browser e2e tests
19
+ can bootstrap a logged-in session against the in-memory token store without
20
+ a live IdP. Adopted through the same `applyTokens` path as a real login, so
21
+ `onSessionChange` subscribers flip to authenticated. Deny-by-default: it
22
+ throws unless `allowTestSessions: true`; enabling it logs a one-time
23
+ `console.warn`, and seeding a token without a future `exp` warns too (such a
24
+ token triggers an immediate renewal that can drop the session). Never enable
25
+ in production. Consumed by `@atol-sh/react/testing`.
26
+
11
27
  ## [0.1.0] - 2026-07-05
12
28
 
13
29
  Initial release. Framework-agnostic browser security core extracted from
package/dist/index.cjs CHANGED
@@ -873,6 +873,12 @@ function createAtolBrowserAuth(config) {
873
873
  const useRefreshTokens = config.useRefreshTokens ?? false;
874
874
  const useRefreshTokensFallback = config.useRefreshTokensFallback ?? false;
875
875
  const deriveEncryptionKey = config.deriveEncryptionKey ?? false;
876
+ const allowTestSessions = config.allowTestSessions ?? false;
877
+ if (allowTestSessions && typeof console !== "undefined") {
878
+ console.warn(
879
+ "[Atol] allowTestSessions is ENABLED: seedTestSession can establish a session without OIDC validation. This is for tests only and must never be enabled in production."
880
+ );
881
+ }
876
882
  const requestedScopes = config.scopes ?? DEFAULT_SCOPES;
877
883
  const scope = useRefreshTokens && !requestedScopes.split(" ").includes("offline_access") ? `${requestedScopes} offline_access` : requestedScopes;
878
884
  const manager = createUserManager(issuer, clientId, redirectUri, scope, audience);
@@ -1290,6 +1296,21 @@ function createAtolBrowserAuth(config) {
1290
1296
  const proof = dpop ? await dpop.signProof(method, url, { accessToken: token }) : void 0;
1291
1297
  return { token, proof };
1292
1298
  }
1299
+ async function seedTestSession(tokens) {
1300
+ if (!allowTestSessions) {
1301
+ throw new Error(
1302
+ "seedTestSession is disabled: pass allowTestSessions:true to createAtolBrowserAuth to enable it. It bypasses OIDC signature, state, and nonce validation and must never be enabled in production."
1303
+ );
1304
+ }
1305
+ const exp = getTokenExpiry(tokens.access_token);
1306
+ if ((exp === null || exp <= Date.now()) && typeof console !== "undefined") {
1307
+ console.warn(
1308
+ "[Atol] seedTestSession: the access token has no future `exp` claim; the seeded session may immediately attempt renewal and drop. Seed a token whose exp is in the future."
1309
+ );
1310
+ }
1311
+ await applyTokens(tokens);
1312
+ return session();
1313
+ }
1293
1314
  function onSessionChange(cb) {
1294
1315
  subscribers.add(cb);
1295
1316
  try {
@@ -1327,6 +1348,7 @@ function createAtolBrowserAuth(config) {
1327
1348
  signDPoPProof,
1328
1349
  isDPoPActive: () => dpop !== null,
1329
1350
  onSessionChange,
1351
+ seedTestSession,
1330
1352
  destroy
1331
1353
  };
1332
1354
  }