@atol-sh/js 0.1.1 → 0.1.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.
- package/CHANGELOG.md +14 -0
- package/dist/index.cjs +15 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +15 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +15 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -411,6 +411,21 @@ interface AtolBrowserAuthConfig {
|
|
|
411
411
|
* production enablement.
|
|
412
412
|
*/
|
|
413
413
|
allowTestSessions?: boolean;
|
|
414
|
+
/**
|
|
415
|
+
* TEST ONLY. A token response to adopt during {@link AtolBrowserAuth.init}
|
|
416
|
+
* INSTEAD of the cold-load silent-renew restore. Requires
|
|
417
|
+
* `allowTestSessions: true` (ignored otherwise). When set, `init()` skips the
|
|
418
|
+
* redirect-callback and hidden-iframe restore paths entirely and settles
|
|
419
|
+
* AUTHENTICATED from these tokens, deterministically -- so a browser e2e test
|
|
420
|
+
* lands on a logged-in app at first paint with no IdP round-trip and no
|
|
421
|
+
* restore iframe. That matters against a stubbed backend with no IdP at the
|
|
422
|
+
* `issuer`, where the restore iframe would otherwise never receive a
|
|
423
|
+
* `web_message` and block until it times out. Equivalent to calling
|
|
424
|
+
* {@link AtolBrowserAuth.seedTestSession} the instant the client is ready,
|
|
425
|
+
* but race-free because it happens inside `init()` before any restore.
|
|
426
|
+
* Provide a token whose `exp` is in the future. Never set in production.
|
|
427
|
+
*/
|
|
428
|
+
initialTestSession?: TokenResponse;
|
|
414
429
|
}
|
|
415
430
|
/** The current auth session, delivered to `onSessionChange` subscribers. */
|
|
416
431
|
interface AtolSession {
|
package/dist/index.d.ts
CHANGED
|
@@ -411,6 +411,21 @@ interface AtolBrowserAuthConfig {
|
|
|
411
411
|
* production enablement.
|
|
412
412
|
*/
|
|
413
413
|
allowTestSessions?: boolean;
|
|
414
|
+
/**
|
|
415
|
+
* TEST ONLY. A token response to adopt during {@link AtolBrowserAuth.init}
|
|
416
|
+
* INSTEAD of the cold-load silent-renew restore. Requires
|
|
417
|
+
* `allowTestSessions: true` (ignored otherwise). When set, `init()` skips the
|
|
418
|
+
* redirect-callback and hidden-iframe restore paths entirely and settles
|
|
419
|
+
* AUTHENTICATED from these tokens, deterministically -- so a browser e2e test
|
|
420
|
+
* lands on a logged-in app at first paint with no IdP round-trip and no
|
|
421
|
+
* restore iframe. That matters against a stubbed backend with no IdP at the
|
|
422
|
+
* `issuer`, where the restore iframe would otherwise never receive a
|
|
423
|
+
* `web_message` and block until it times out. Equivalent to calling
|
|
424
|
+
* {@link AtolBrowserAuth.seedTestSession} the instant the client is ready,
|
|
425
|
+
* but race-free because it happens inside `init()` before any restore.
|
|
426
|
+
* Provide a token whose `exp` is in the future. Never set in production.
|
|
427
|
+
*/
|
|
428
|
+
initialTestSession?: TokenResponse;
|
|
414
429
|
}
|
|
415
430
|
/** The current auth session, delivered to `onSessionChange` subscribers. */
|
|
416
431
|
interface AtolSession {
|
package/dist/index.js
CHANGED
|
@@ -862,6 +862,14 @@ function dpopEnabled(cfg) {
|
|
|
862
862
|
if (typeof cfg === "boolean") return cfg;
|
|
863
863
|
return cfg?.required === true;
|
|
864
864
|
}
|
|
865
|
+
function warnIfSeedTokenNotFresh(accessToken) {
|
|
866
|
+
const exp = getTokenExpiry(accessToken);
|
|
867
|
+
if ((exp === null || exp <= Date.now()) && typeof console !== "undefined") {
|
|
868
|
+
console.warn(
|
|
869
|
+
"[Atol] test session: 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."
|
|
870
|
+
);
|
|
871
|
+
}
|
|
872
|
+
}
|
|
865
873
|
function createAtolBrowserAuth(config) {
|
|
866
874
|
const issuer = config.issuer;
|
|
867
875
|
const clientId = config.clientId;
|
|
@@ -872,6 +880,7 @@ function createAtolBrowserAuth(config) {
|
|
|
872
880
|
const useRefreshTokensFallback = config.useRefreshTokensFallback ?? false;
|
|
873
881
|
const deriveEncryptionKey = config.deriveEncryptionKey ?? false;
|
|
874
882
|
const allowTestSessions = config.allowTestSessions ?? false;
|
|
883
|
+
const initialTestSession = allowTestSessions ? config.initialTestSession : void 0;
|
|
875
884
|
if (allowTestSessions && typeof console !== "undefined") {
|
|
876
885
|
console.warn(
|
|
877
886
|
"[Atol] allowTestSessions is ENABLED: seedTestSession can establish a session without OIDC validation. This is for tests only and must never be enabled in production."
|
|
@@ -1225,6 +1234,11 @@ function createAtolBrowserAuth(config) {
|
|
|
1225
1234
|
broadcast.subscribe((message) => {
|
|
1226
1235
|
void onBroadcast(message);
|
|
1227
1236
|
});
|
|
1237
|
+
if (initialTestSession) {
|
|
1238
|
+
warnIfSeedTokenNotFresh(initialTestSession.access_token);
|
|
1239
|
+
await applyTokens(initialTestSession);
|
|
1240
|
+
return session();
|
|
1241
|
+
}
|
|
1228
1242
|
if (isCallbackUrl()) {
|
|
1229
1243
|
try {
|
|
1230
1244
|
await completeLogin();
|
|
@@ -1300,12 +1314,7 @@ function createAtolBrowserAuth(config) {
|
|
|
1300
1314
|
"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."
|
|
1301
1315
|
);
|
|
1302
1316
|
}
|
|
1303
|
-
|
|
1304
|
-
if ((exp === null || exp <= Date.now()) && typeof console !== "undefined") {
|
|
1305
|
-
console.warn(
|
|
1306
|
-
"[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."
|
|
1307
|
-
);
|
|
1308
|
-
}
|
|
1317
|
+
warnIfSeedTokenNotFresh(tokens.access_token);
|
|
1309
1318
|
await applyTokens(tokens);
|
|
1310
1319
|
return session();
|
|
1311
1320
|
}
|