@iqauth/sdk 2.1.0 → 2.3.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.
Files changed (64) hide show
  1. package/README.md +43 -3
  2. package/dist/browser-session.d.mts +1 -2
  3. package/dist/browser-session.d.ts +1 -2
  4. package/dist/browser-session.js +89 -68
  5. package/dist/browser-session.mjs +2 -1
  6. package/dist/browser.d.mts +2 -2
  7. package/dist/browser.d.ts +2 -2
  8. package/dist/browser.js +69 -7
  9. package/dist/browser.mjs +2 -2
  10. package/dist/{chunk-ZESHDJDU.mjs → chunk-EKTNEZIH.mjs} +5 -8
  11. package/dist/{chunk-JQRTY5MY.mjs → chunk-KGEPDXHU.mjs} +12 -8
  12. package/dist/{chunk-S3M2IXCE.mjs → chunk-RACIPVLD.mjs} +15 -9
  13. package/dist/chunk-UNYDG2L4.mjs +209 -0
  14. package/dist/{chunk-MDUHPQMM.mjs → chunk-W3F4JYGP.mjs} +8 -180
  15. package/dist/chunk-WQWBJSSS.mjs +119 -0
  16. package/dist/cli/index.js +21 -0
  17. package/dist/cli/index.mjs +1 -1
  18. package/dist/{client-DXbHb2ul.d.ts → client-DTX4hNdS.d.ts} +16 -21
  19. package/dist/{client-Dv4v92Mj.d.mts → client-vdh2a9fJ.d.mts} +16 -21
  20. package/dist/{doctor-OHJRZBBT.mjs → doctor-A5E7LSFW.mjs} +2 -1
  21. package/dist/{express-BZmF1llh.d.mts → express-A0-dWEMy.d.mts} +1 -1
  22. package/dist/{express-B4o3P8vK.d.ts → express-Bo_pJKHN.d.ts} +1 -1
  23. package/dist/express.d.mts +75 -5
  24. package/dist/express.d.ts +75 -5
  25. package/dist/express.js +353 -94
  26. package/dist/express.mjs +210 -12
  27. package/dist/fastify.js +153 -88
  28. package/dist/fastify.mjs +10 -9
  29. package/dist/hono.js +152 -88
  30. package/dist/hono.mjs +9 -9
  31. package/dist/index.d.mts +3 -4
  32. package/dist/index.d.ts +3 -4
  33. package/dist/index.js +148 -72
  34. package/dist/index.mjs +16 -12
  35. package/dist/mobile.d.mts +1 -2
  36. package/dist/mobile.d.ts +1 -2
  37. package/dist/mobile.js +89 -68
  38. package/dist/mobile.mjs +2 -1
  39. package/dist/next.d.mts +9 -0
  40. package/dist/next.d.ts +9 -0
  41. package/dist/next.js +164 -1649
  42. package/dist/next.mjs +13 -16
  43. package/dist/{publishableKey-B5DIK81A.d.mts → publishableKey-BaR0HoAH.d.mts} +10 -1
  44. package/dist/{publishableKey-B5DIK81A.d.ts → publishableKey-BaR0HoAH.d.ts} +10 -1
  45. package/dist/react.d.mts +35 -3
  46. package/dist/react.d.ts +35 -3
  47. package/dist/react.js +78 -18
  48. package/dist/react.mjs +14 -2
  49. package/dist/server/handlers.d.mts +2 -0
  50. package/dist/server/handlers.d.ts +2 -0
  51. package/dist/server/handlers.js +72 -17
  52. package/dist/server/handlers.mjs +3 -2
  53. package/dist/server.d.mts +2 -3
  54. package/dist/server.d.ts +2 -3
  55. package/dist/server.js +151 -89
  56. package/dist/server.mjs +7 -6
  57. package/dist/service.d.mts +1 -2
  58. package/dist/service.d.ts +1 -2
  59. package/dist/service.js +89 -68
  60. package/dist/service.mjs +2 -1
  61. package/dist/{signIn-CEMdUAwd.d.mts → signIn-Cd0P4y9d.d.mts} +9 -1
  62. package/dist/{signIn-VRNzlNyG.d.ts → signIn-DKakyzeu.d.ts} +9 -1
  63. package/package.json +3 -2
  64. package/dist/chunk-5WFR6Y33.mjs +0 -59
package/dist/fastify.mjs CHANGED
@@ -1,15 +1,16 @@
1
+ import {
2
+ IQAuthClient
3
+ } from "./chunk-W3F4JYGP.mjs";
1
4
  import {
2
5
  handleCallback,
3
6
  handleRefresh,
4
7
  handleSignout,
5
8
  serializeCookie
6
- } from "./chunk-JQRTY5MY.mjs";
9
+ } from "./chunk-KGEPDXHU.mjs";
7
10
  import {
8
- parsePublishableKey
9
- } from "./chunk-5WFR6Y33.mjs";
10
- import {
11
- IQAuthClient
12
- } from "./chunk-MDUHPQMM.mjs";
11
+ assertPublishableKey
12
+ } from "./chunk-WQWBJSSS.mjs";
13
+ import "./chunk-UNYDG2L4.mjs";
13
14
  import {
14
15
  IQAuthError
15
16
  } from "./chunk-6I6RM4MN.mjs";
@@ -52,8 +53,7 @@ function readCookie(req, name) {
52
53
  return void 0;
53
54
  }
54
55
  async function iqAuth(fastify, options) {
55
- const parsed = parsePublishableKey(options.publishableKey);
56
- if (!parsed) throw new Error("@iqauth/sdk/fastify: invalid publishable key");
56
+ const parsed = assertPublishableKey(options.publishableKey, { context: "@iqauth/sdk/fastify" });
57
57
  const issuer = (options.issuer ?? (parsed.iss.startsWith("http") ? parsed.iss : `https://${parsed.iss}`)).replace(/\/+$/, "");
58
58
  const helperConfig = { ...options, issuer };
59
59
  const client = new IQAuthClient({
@@ -115,7 +115,8 @@ async function iqAuth(fastify, options) {
115
115
  fastify.post(`${mount}/signout`, async (req, reply) => {
116
116
  const auth = req.headers?.authorization;
117
117
  const accessToken = (typeof auth === "string" ? auth.replace(/^Bearer /i, "") : void 0) || readCookie(req, accessCookie);
118
- applyResponse(reply, await handleSignout(helperConfig, { accessToken }));
118
+ const ssoCookieHeader = typeof req.headers?.cookie === "string" ? req.headers.cookie : void 0;
119
+ applyResponse(reply, await handleSignout(helperConfig, { accessToken, ssoCookieHeader }));
119
120
  });
120
121
  }
121
122
  fastify.decorate("iqauth", { client, issuer });
package/dist/hono.js CHANGED
@@ -406,8 +406,7 @@ function parseMfaResponse(data, browserSessionMode) {
406
406
  }
407
407
 
408
408
  // src/modules/tokens.ts
409
- var import_crypto = __toESM(require("crypto"));
410
- var import_jsonwebtoken = __toESM(require("jsonwebtoken"));
409
+ var import_jose = require("jose");
411
410
  var JWKS_CACHE_TTL_MS = 60 * 60 * 1e3;
412
411
  var DEFAULT_TOKEN_ISSUER = [
413
412
  "https://auth.dispositioniq.com",
@@ -420,6 +419,24 @@ var DEFAULT_TOKEN_AUDIENCE = [
420
419
  "iqvalidate"
421
420
  ];
422
421
  var DEFAULT_CLOCK_TOLERANCE_SECONDS = 30;
422
+ function decodeProtectedHeader(token) {
423
+ const parts = token.split(".");
424
+ if (parts.length < 2) return null;
425
+ try {
426
+ const padded = parts[0] + "=".repeat((4 - parts[0].length % 4) % 4);
427
+ const b64 = padded.replace(/-/g, "+").replace(/_/g, "/");
428
+ let json;
429
+ if (typeof atob === "function") {
430
+ json = atob(b64);
431
+ } else {
432
+ const { Buffer: Buffer2 } = require("buffer");
433
+ json = Buffer2.from(b64, "base64").toString("utf8");
434
+ }
435
+ return JSON.parse(json);
436
+ } catch {
437
+ return null;
438
+ }
439
+ }
423
440
  var TokensModule = class {
424
441
  constructor(baseUrl, options = {}) {
425
442
  this.jwksCache = null;
@@ -430,49 +447,49 @@ var TokensModule = class {
430
447
  this.defaultClockTolerance = options.clockTolerance ?? DEFAULT_CLOCK_TOLERANCE_SECONDS;
431
448
  }
432
449
  /**
433
- * Verify a JWT access token using RS256 via JWKS from /.well-known/jwks.json.
434
- * Caches JWKS keys for 1 hour. Retries once on unknown `kid`.
435
- *
436
- * @remarks Validates against /.well-known/jwks.json. Issuer, audience, and
437
- * clock tolerance default to client config but can be overridden per call.
450
+ * Verify a JWT access token using RS256/ES256 via JWKS from
451
+ * `/.well-known/jwks.json`. Backed by `jose` (Web Crypto) so it runs on
452
+ * Node, browser, and edge runtimes alike — no `node:crypto` dependency.
453
+ * Caches JWKS for 1 hour and refetches once on unknown `kid`.
438
454
  */
439
455
  async verify(token, options = {}) {
440
- const decoded = import_jsonwebtoken.default.decode(token, { complete: true });
441
- if (!decoded || typeof decoded === "string") {
456
+ const header = decodeProtectedHeader(token);
457
+ if (!header) {
442
458
  throw new IQAuthError("TOKEN_INVALID", "Unable to decode token");
443
459
  }
444
- const kid = decoded.header.kid;
460
+ const kid = header.kid;
445
461
  if (!kid) {
446
462
  throw new IQAuthError("TOKEN_INVALID", "Token missing kid header");
447
463
  }
448
- let publicKey = await this.getPublicKey(kid);
449
- if (!publicKey) {
450
- await this.refreshJwks();
451
- publicKey = await this.getPublicKey(kid);
464
+ let cache = await this.ensureCache();
465
+ if (!cache.byKid.has(kid)) {
466
+ this.jwksCache = null;
467
+ cache = await this.ensureCache();
452
468
  }
453
- if (!publicKey) {
469
+ if (!cache.byKid.has(kid)) {
454
470
  throw new IQAuthError("TOKEN_INVALID", `Unknown key ID: ${kid}`);
455
471
  }
456
472
  const issuer = options.issuer ?? this.defaultIssuer;
457
473
  const audience = options.audience ?? this.defaultAudience;
458
474
  const clockTolerance = options.clockTolerance ?? this.defaultClockTolerance;
459
- const algorithms = options.algorithms ?? ["RS256"];
475
+ const algorithms = options.algorithms ?? ["RS256", "ES256"];
476
+ const verifyOptions = {
477
+ algorithms,
478
+ clockTolerance,
479
+ issuer,
480
+ audience
481
+ };
460
482
  try {
461
- const verifyOptions = {
462
- algorithms,
463
- clockTolerance,
464
- // The jsonwebtoken types insist on tuple types for arrays; runtime
465
- // accepts plain string[] so we cast to satisfy the compiler.
466
- issuer,
467
- audience
468
- };
469
- const verified = import_jsonwebtoken.default.verify(token, publicKey, verifyOptions);
470
- return verified;
483
+ const { payload } = await (0, import_jose.jwtVerify)(token, cache.verifier, verifyOptions);
484
+ return payload;
471
485
  } catch (err) {
486
+ if (err instanceof import_jose.errors.JWTExpired) {
487
+ throw new IQAuthError("TOKEN_EXPIRED", "Token has expired");
488
+ }
489
+ if (err instanceof import_jose.errors.JOSEError) {
490
+ throw new IQAuthError("TOKEN_INVALID", err.message);
491
+ }
472
492
  if (err instanceof Error) {
473
- if (err.name === "TokenExpiredError") {
474
- throw new IQAuthError("TOKEN_EXPIRED", "Token has expired");
475
- }
476
493
  throw new IQAuthError("TOKEN_INVALID", err.message);
477
494
  }
478
495
  throw new IQAuthError("TOKEN_INVALID", "Token verification failed");
@@ -480,29 +497,40 @@ var TokensModule = class {
480
497
  }
481
498
  /**
482
499
  * Decode a JWT without verification. Returns null if malformed.
483
- *
484
- * @remarks Local decode only — no network call
485
500
  */
486
501
  decode(token) {
487
- const decoded = import_jsonwebtoken.default.decode(token);
488
- return decoded;
502
+ try {
503
+ const parts = token.split(".");
504
+ if (parts.length < 2) return null;
505
+ const payload = parts[1];
506
+ const padded = payload + "=".repeat((4 - payload.length % 4) % 4);
507
+ const b64 = padded.replace(/-/g, "+").replace(/_/g, "/");
508
+ let json;
509
+ if (typeof atob === "function") {
510
+ json = atob(b64);
511
+ } else {
512
+ const { Buffer: Buffer2 } = require("buffer");
513
+ json = Buffer2.from(b64, "base64").toString("utf8");
514
+ }
515
+ try {
516
+ json = decodeURIComponent(escape(json));
517
+ } catch {
518
+ }
519
+ const claims = JSON.parse(json);
520
+ if (!claims || typeof claims !== "object") return null;
521
+ return claims;
522
+ } catch {
523
+ return null;
524
+ }
489
525
  }
490
- /**
491
- * Check if a token is expired based on the `exp` claim.
492
- *
493
- * @remarks Local check only — no network call
494
- */
526
+ /** Check if a token is expired based on the `exp` claim. */
495
527
  isExpired(token) {
496
528
  const claims = this.decode(token);
497
529
  if (!claims?.exp) return true;
498
530
  const now = Math.floor(Date.now() / 1e3);
499
531
  return claims.exp <= now;
500
532
  }
501
- /**
502
- * Get the claims from a token without verification.
503
- *
504
- * @remarks Local decode only — no network call
505
- */
533
+ /** Get the claims from a token without verification. */
506
534
  getClaims(token) {
507
535
  const claims = this.decode(token);
508
536
  if (!claims) {
@@ -510,11 +538,15 @@ var TokensModule = class {
510
538
  }
511
539
  return claims;
512
540
  }
513
- async getPublicKey(kid) {
514
- if (!this.jwksCache || Date.now() - this.jwksCache.fetchedAt > JWKS_CACHE_TTL_MS) {
515
- await this.refreshJwks();
541
+ async ensureCache() {
542
+ if (this.jwksCache && Date.now() - this.jwksCache.fetchedAt <= JWKS_CACHE_TTL_MS) {
543
+ return this.jwksCache;
516
544
  }
517
- return this.jwksCache?.keys.get(kid) ?? null;
545
+ await this.refreshJwks();
546
+ if (!this.jwksCache) {
547
+ throw new IQAuthError("INTERNAL_ERROR", "JWKS cache unavailable after refresh");
548
+ }
549
+ return this.jwksCache;
518
550
  }
519
551
  async refreshJwks() {
520
552
  if (this.inFlightRefresh) {
@@ -541,35 +573,24 @@ var TokensModule = class {
541
573
  "Malformed JWKS response: expected { keys: [...] }"
542
574
  );
543
575
  }
544
- const keys = /* @__PURE__ */ new Map();
576
+ const byKid = /* @__PURE__ */ new Set();
545
577
  for (const key of jwks.keys) {
546
- if (!key || typeof key.kid !== "string" || typeof key.n !== "string" || typeof key.e !== "string") {
578
+ if (!key || typeof key.kid !== "string" || typeof key.n !== "string" && typeof key.x !== "string" || key.kty === "RSA" && (typeof key.n !== "string" || typeof key.e !== "string")) {
547
579
  throw new IQAuthError(
548
580
  "INTERNAL_ERROR",
549
581
  "Malformed JWKS response: key missing required fields"
550
582
  );
551
583
  }
552
- const pem = this.jwkToPem(key);
553
- keys.set(key.kid, pem);
584
+ byKid.add(key.kid);
554
585
  }
555
- this.jwksCache = { keys, fetchedAt: Date.now() };
586
+ const verifier = (0, import_jose.createLocalJWKSet)({ keys: jwks.keys });
587
+ this.jwksCache = { raw: jwks.keys, byKid, verifier, fetchedAt: Date.now() };
556
588
  } finally {
557
589
  this.inFlightRefresh = null;
558
590
  }
559
591
  })();
560
592
  return this.inFlightRefresh;
561
593
  }
562
- jwkToPem(jwk) {
563
- const keyObject = import_crypto.default.createPublicKey({
564
- key: {
565
- kty: jwk.kty,
566
- n: jwk.n,
567
- e: jwk.e
568
- },
569
- format: "jwk"
570
- });
571
- return keyObject.export({ type: "spki", format: "pem" });
572
- }
573
594
  /** @internal Exposed for testing — clears JWKS cache */
574
595
  clearCache() {
575
596
  this.jwksCache = null;
@@ -777,7 +798,7 @@ var PermissionsModule = class {
777
798
  };
778
799
 
779
800
  // src/modules/oidc.ts
780
- var import_crypto2 = __toESM(require("crypto"));
801
+ var import_crypto = __toESM(require("crypto"));
781
802
  var InMemoryOidcStateStore = class {
782
803
  constructor() {
783
804
  this.map = /* @__PURE__ */ new Map();
@@ -858,12 +879,12 @@ var OidcModule = class {
858
879
  * ready to redirect the user to.
859
880
  */
860
881
  async createAuthRequest(params) {
861
- const codeVerifier = base64UrlEncode(import_crypto2.default.randomBytes(32));
882
+ const codeVerifier = base64UrlEncode(import_crypto.default.randomBytes(32));
862
883
  const codeChallenge = base64UrlEncode(
863
- import_crypto2.default.createHash("sha256").update(codeVerifier).digest()
884
+ import_crypto.default.createHash("sha256").update(codeVerifier).digest()
864
885
  );
865
- const state = base64UrlEncode(import_crypto2.default.randomBytes(16));
866
- const nonce = base64UrlEncode(import_crypto2.default.randomBytes(16));
886
+ const state = base64UrlEncode(import_crypto.default.randomBytes(16));
887
+ const nonce = base64UrlEncode(import_crypto.default.randomBytes(16));
867
888
  await this.stateStore.set(state, {
868
889
  codeVerifier,
869
890
  state,
@@ -1766,21 +1787,61 @@ function b64urlDecode(input) {
1766
1787
  const { Buffer: Buffer2 } = require("buffer");
1767
1788
  return Buffer2.from(normalized, "base64").toString("utf8");
1768
1789
  }
1769
- function parsePublishableKey(raw) {
1770
- if (typeof raw !== "string") return null;
1771
- const m = raw.match(/^pk_(test|live)_([A-Za-z0-9_-]+)$/);
1772
- if (!m) return null;
1790
+ function isValidIssuerUrl(iss) {
1791
+ if (typeof iss !== "string" || iss.length === 0) return false;
1792
+ if (!iss.startsWith("http://") && !iss.startsWith("https://")) return false;
1773
1793
  try {
1774
- const json = JSON.parse(b64urlDecode(m[2]));
1775
- if (!json || typeof json !== "object") return null;
1776
- if (typeof json.iss !== "string" || typeof json.appId !== "string" || typeof json.tenantId !== "string" || typeof json.kid !== "string") {
1777
- return null;
1778
- }
1779
- return { mode: m[1], iss: json.iss, appId: json.appId, tenantId: json.tenantId, kid: json.kid, raw };
1794
+ const u = new URL(iss);
1795
+ if (u.protocol !== "http:" && u.protocol !== "https:") return false;
1796
+ if (!u.hostname) return false;
1797
+ return true;
1780
1798
  } catch {
1781
- return null;
1799
+ return false;
1782
1800
  }
1783
1801
  }
1802
+ function assertPublishableKey(raw, opts) {
1803
+ const ctx = opts?.context ? `${opts.context}: ` : "";
1804
+ if (typeof raw !== "string" || raw.length === 0) {
1805
+ throw new IQAuthError(
1806
+ "CONFIG_INVALID",
1807
+ `${ctx}IQAuth publishable key is missing. Set IQAUTH_PUBLISHABLE_KEY (or pass publishableKey) to a pk_test_\u2026 or pk_live_\u2026 value from the IQAuth admin console.`
1808
+ );
1809
+ }
1810
+ const shapeMatch = raw.match(/^pk_(test|live)_([A-Za-z0-9_-]+)$/);
1811
+ if (!shapeMatch) {
1812
+ throw new IQAuthError(
1813
+ "CONFIG_INVALID",
1814
+ `${ctx}IQAuth publishable key is malformed (got ${raw.slice(0, 12)}\u2026). Expected pk_test_\u2026 or pk_live_\u2026; regenerate the key from the IQAuth admin console.`
1815
+ );
1816
+ }
1817
+ let decoded;
1818
+ try {
1819
+ decoded = JSON.parse(b64urlDecode(shapeMatch[2]));
1820
+ } catch {
1821
+ throw new IQAuthError(
1822
+ "CONFIG_INVALID",
1823
+ `${ctx}IQAuth publishable key payload is not valid base64url JSON. Regenerate the key from the IQAuth admin console.`
1824
+ );
1825
+ }
1826
+ if (!isPublishableKeyPayload(decoded)) {
1827
+ throw new IQAuthError(
1828
+ "CONFIG_INVALID",
1829
+ `${ctx}IQAuth publishable key payload is missing required fields {iss, appId, tenantId, kid}. Regenerate the key from the IQAuth admin console.`
1830
+ );
1831
+ }
1832
+ if (!isValidIssuerUrl(decoded.iss)) {
1833
+ throw new IQAuthError(
1834
+ "CONFIG_INVALID",
1835
+ `${ctx}IQAuth publishable key encodes an invalid issuer (iss=${JSON.stringify(decoded.iss)}). Expected a fully-qualified URL like "https://auth.example.com" (scheme required). Regenerate the key from the IQAuth admin console \u2014 the new key will encode a valid issuer URL.`
1836
+ );
1837
+ }
1838
+ return { mode: shapeMatch[1], iss: decoded.iss, appId: decoded.appId, tenantId: decoded.tenantId, kid: decoded.kid, raw };
1839
+ }
1840
+ function isPublishableKeyPayload(value) {
1841
+ if (!value || typeof value !== "object") return false;
1842
+ const v = value;
1843
+ return typeof v.iss === "string" && typeof v.appId === "string" && typeof v.tenantId === "string" && typeof v.kid === "string";
1844
+ }
1784
1845
 
1785
1846
  // src/server/handlers.ts
1786
1847
  var TERMINAL_REFRESH_ERROR_CODES = /* @__PURE__ */ new Set([
@@ -1802,12 +1863,7 @@ function shouldClearCookiesOnFailure(policy, status, errorCode) {
1802
1863
  var ACCESS_TOKEN_TTL_SECONDS = 60 * 15;
1803
1864
  var REFRESH_TOKEN_TTL_SECONDS = 60 * 60 * 24 * 30;
1804
1865
  function resolve(config) {
1805
- const parsed = parsePublishableKey(config.publishableKey);
1806
- if (!parsed) {
1807
- throw new Error(
1808
- "@iqauth/sdk: invalid publishable key passed to iqAuth helpers (expected pk_test_\u2026 or pk_live_\u2026)"
1809
- );
1810
- }
1866
+ const parsed = assertPublishableKey(config.publishableKey, { context: "@iqauth/sdk helpers" });
1811
1867
  const inferredIssuer = parsed.iss.startsWith("http") ? parsed.iss : `https://${parsed.iss}`;
1812
1868
  return {
1813
1869
  publishableKey: config.publishableKey,
@@ -1978,6 +2034,15 @@ async function handleSignout(config, input) {
1978
2034
  } catch {
1979
2035
  }
1980
2036
  }
2037
+ if (input.endSsoSession !== false && input.ssoCookieHeader) {
2038
+ try {
2039
+ await cfg.fetchImpl(`${cfg.issuer}/oidc/sso-logout`, {
2040
+ method: "POST",
2041
+ headers: { Cookie: input.ssoCookieHeader }
2042
+ });
2043
+ } catch {
2044
+ }
2045
+ }
1981
2046
  return {
1982
2047
  status: 200,
1983
2048
  body: { success: true, data: { signedOut: true } },
@@ -2015,8 +2080,7 @@ function honoResponse(hr) {
2015
2080
  return new Response(JSON.stringify(hr.body), { status: hr.status, headers });
2016
2081
  }
2017
2082
  function iqAuth(options) {
2018
- const parsed = parsePublishableKey(options.publishableKey);
2019
- if (!parsed) throw new Error("@iqauth/sdk/hono: invalid publishable key");
2083
+ const parsed = assertPublishableKey(options.publishableKey, { context: "@iqauth/sdk/hono" });
2020
2084
  const issuer = (options.issuer ?? (parsed.iss.startsWith("http") ? parsed.iss : `https://${parsed.iss}`)).replace(/\/+$/, "");
2021
2085
  const helperConfig = { ...options, issuer };
2022
2086
  const client = new IQAuthClient({ baseUrl: issuer, environment: "server" });
@@ -2049,7 +2113,7 @@ function iqAuth(options) {
2049
2113
  if (path === `${mount}/signout`) {
2050
2114
  const auth2 = c.req.header("authorization");
2051
2115
  const accessToken = auth2 && auth2.replace(/^Bearer /i, "") || readCookieFromHeader(cookieHeader, accessCookie);
2052
- return honoResponse(await handleSignout(helperConfig, { accessToken }));
2116
+ return honoResponse(await handleSignout(helperConfig, { accessToken, ssoCookieHeader: cookieHeader }));
2053
2117
  }
2054
2118
  }
2055
2119
  if (isPublic(path)) return next();
package/dist/hono.mjs CHANGED
@@ -1,15 +1,16 @@
1
+ import {
2
+ IQAuthClient
3
+ } from "./chunk-W3F4JYGP.mjs";
1
4
  import {
2
5
  handleCallback,
3
6
  handleRefresh,
4
7
  handleSignout,
5
8
  serializeCookie
6
- } from "./chunk-JQRTY5MY.mjs";
9
+ } from "./chunk-KGEPDXHU.mjs";
7
10
  import {
8
- parsePublishableKey
9
- } from "./chunk-5WFR6Y33.mjs";
10
- import {
11
- IQAuthClient
12
- } from "./chunk-MDUHPQMM.mjs";
11
+ assertPublishableKey
12
+ } from "./chunk-WQWBJSSS.mjs";
13
+ import "./chunk-UNYDG2L4.mjs";
13
14
  import {
14
15
  IQAuthError
15
16
  } from "./chunk-6I6RM4MN.mjs";
@@ -45,8 +46,7 @@ function honoResponse(hr) {
45
46
  return new Response(JSON.stringify(hr.body), { status: hr.status, headers });
46
47
  }
47
48
  function iqAuth(options) {
48
- const parsed = parsePublishableKey(options.publishableKey);
49
- if (!parsed) throw new Error("@iqauth/sdk/hono: invalid publishable key");
49
+ const parsed = assertPublishableKey(options.publishableKey, { context: "@iqauth/sdk/hono" });
50
50
  const issuer = (options.issuer ?? (parsed.iss.startsWith("http") ? parsed.iss : `https://${parsed.iss}`)).replace(/\/+$/, "");
51
51
  const helperConfig = { ...options, issuer };
52
52
  const client = new IQAuthClient({ baseUrl: issuer, environment: "server" });
@@ -79,7 +79,7 @@ function iqAuth(options) {
79
79
  if (path === `${mount}/signout`) {
80
80
  const auth2 = c.req.header("authorization");
81
81
  const accessToken = auth2 && auth2.replace(/^Bearer /i, "") || readCookieFromHeader(cookieHeader, accessCookie);
82
- return honoResponse(await handleSignout(helperConfig, { accessToken }));
82
+ return honoResponse(await handleSignout(helperConfig, { accessToken, ssoCookieHeader: cookieHeader }));
83
83
  }
84
84
  }
85
85
  if (isPublic(path)) return next();
package/dist/index.d.mts CHANGED
@@ -1,6 +1,5 @@
1
- export { o as ApiKeysModule, l as AppsModule, A as AuthModule, B as BrandingModule, r as ClientsModule, C as CreateAppRequest, m as CreateAppResponse, h as DEFAULT_CLOCK_TOLERANCE_SECONDS, g as DEFAULT_TOKEN_AUDIENCE, D as DEFAULT_TOKEN_ISSUER, E as EntitlementsModule, G as GdprModule, H as HierarchyModule, I as IQAuthClient, a as InMemoryOidcStateStore, p as InvitesModule, M as MembershipsModule, u as MfaModule, d as OidcAuthRequest, e as OidcCallbackResult, O as OidcModule, f as OidcModuleOptions, b as OidcStateStore, c as OidcStoredRequest, n as PermissionGroupsModule, P as PermissionsModule, t as PinModule, R as RolesModule, s as ScopeModule, S as SessionsModule, q as SourcesModule, k as TenantsModule, i as TokenVerifyOptions, T as TokensModule, j as TokensModuleOptions, U as UsersModule, V as VendorsModule, W as WebhooksModule } from './client-Dv4v92Mj.mjs';
1
+ export { o as ApiKeysModule, l as AppsModule, A as AuthModule, B as BrandingModule, r as ClientsModule, C as CreateAppRequest, m as CreateAppResponse, h as DEFAULT_CLOCK_TOLERANCE_SECONDS, g as DEFAULT_TOKEN_AUDIENCE, D as DEFAULT_TOKEN_ISSUER, E as EntitlementsModule, G as GdprModule, H as HierarchyModule, I as IQAuthClient, a as InMemoryOidcStateStore, p as InvitesModule, M as MembershipsModule, u as MfaModule, d as OidcAuthRequest, e as OidcCallbackResult, O as OidcModule, f as OidcModuleOptions, b as OidcStateStore, c as OidcStoredRequest, n as PermissionGroupsModule, P as PermissionsModule, t as PinModule, R as RolesModule, s as ScopeModule, S as SessionsModule, q as SourcesModule, k as TenantsModule, i as TokenVerifyOptions, T as TokensModule, j as TokensModuleOptions, U as UsersModule, V as VendorsModule, W as WebhooksModule } from './client-vdh2a9fJ.mjs';
2
2
  export { a as ErrorCode, E as ErrorCodes, I as IQAuthError } from './errors-CDdl24MP.mjs';
3
- export { i as iqAuthMiddleware } from './express-BZmF1llh.mjs';
4
- export { K as KeyMode, b as ParsedPublishableKey, P as PublishableKeyPayload, e as encodePublishableKey, i as isPublishableKey, a as isSecretKey, p as parsePublishableKey } from './publishableKey-B5DIK81A.mjs';
3
+ export { i as iqAuthMiddleware } from './express-A0-dWEMy.mjs';
4
+ export { K as KeyMode, c as ParsedPublishableKey, P as PublishableKeyPayload, a as assertPublishableKey, e as encodePublishableKey, i as isPublishableKey, b as isSecretKey, p as parsePublishableKey } from './publishableKey-BaR0HoAH.mjs';
5
5
  export { an as AcceptInviteRequest, aa as AddGroupPermissionRequest, ad as AddUserOverrideRequest, v as ApiErrorResponse, ag as ApiKeyInfo, aj as ApiKeyIntrospection, w as ApiResponse, A as ApiSuccessResponse, _ as AppInfo, Z as AppManifest, a0 as AppSyncResult, a4 as AssignRoleRequest, aM as AvailableScopesTree, a_ as BackupCodeCountResult, aZ as BackupCodesResult, p as BrandingAsset, B as BrandingConfig, r as BrandingDomainMapping, aB as Client, ah as CreateApiKeyRequest, ai as CreateApiKeyResult, aC as CreateClientRequest, al as CreateInviteRequest, aJ as CreateMembershipRequest, a2 as CreateRoleRequest, az as CreateSourceRequest, C as CreateTenantRequest, aw as CreateVendorRequest, ap as CreateWebhookRequest, aq as CreateWebhookResult, ae as EffectivePermission, aY as EmailEnrollResult, at as Entitlement, N as ExpressMiddlewareOptions, aR as GdprExportData, au as GrantEntitlementRequest, a9 as GroupPermission, aG as HierarchyClient, aH as HierarchyLink, aF as HierarchySource, aE as HierarchyVendor, c as IQAuthBrowserSessionClientConfig, a as IQAuthClientConfig, I as IQAuthEnvironment, V as IQAuthNextFunction, Q as IQAuthRequestLike, R as IQAuthResponseLike, W as IQAuthRetryConfig, b as IQAuthTokenClientConfig, X as IQAuthVerifyConfig, ab as InheritanceRelation, ak as Invitation, l as InviteTenantUserRequest, m as InviteTenantUserResult, am as InviteValidation, s as JwksKey, t as JwksResponse, J as JwtClaims, L as LoginResult, aI as Membership, aL as MembershipWithDetails, aU as MfaAvailableMethods, y as MfaEnrollment, x as MfaMethod, F as MfaPolicy, D as MfaVerifyResult, M as MigrateUserRequest, O as OidcDiscovery, u as OidcTokenResponse, E as PasswordPolicy, af as PermissionCheckResult, a8 as PermissionGroup, $ as PermissionNodeInfo, Y as PermissionNodeManifest, aT as PinLoginResult, aS as PinStatus, P as PromoteToVendorRequest, k as PromoteToVendorResult, H as ProvisionUserRequest, K as ProvisionUserResponse, a1 as Role, S as ScopeContext, aQ as ScopeSwitchResult, aN as ScopeTreeClient, aO as ScopeTreeSource, aP as ScopeTreeVendor, h as Session, g as SessionAuthenticatedLoginResult, d as SessionUser, aX as SmsEnrollResult, ay as Source, e as Tenant, i as TenantInfo, a7 as TenantUser, n as TenantUserRoleUpdate, f as TokenAuthenticatedLoginResult, T as TokenPair, aV as TotpEnrollResult, z as TotpEnrollmentResult, aW as TotpVerifyResult, o as UpdateBrandingRequest, aD as UpdateClientRequest, aK as UpdateMembershipRequest, a3 as UpdateRoleRequest, aA as UpdateSourceRequest, j as UpdateTenantRequest, ax as UpdateVendorRequest, q as UploadAssetRequest, a6 as UserGroupAssignment, ac as UserPermissionOverride, G as UserPermissions, U as UserProfile, a5 as UserRoleAssignment, av as Vendor, ar as WebhookDelivery, ao as WebhookEndpoint, as as WebhookTestResult } from './types-Cxl3bQHt.mjs';
6
- import 'jsonwebtoken';
package/dist/index.d.ts CHANGED
@@ -1,6 +1,5 @@
1
- export { o as ApiKeysModule, l as AppsModule, A as AuthModule, B as BrandingModule, r as ClientsModule, C as CreateAppRequest, m as CreateAppResponse, h as DEFAULT_CLOCK_TOLERANCE_SECONDS, g as DEFAULT_TOKEN_AUDIENCE, D as DEFAULT_TOKEN_ISSUER, E as EntitlementsModule, G as GdprModule, H as HierarchyModule, I as IQAuthClient, a as InMemoryOidcStateStore, p as InvitesModule, M as MembershipsModule, u as MfaModule, d as OidcAuthRequest, e as OidcCallbackResult, O as OidcModule, f as OidcModuleOptions, b as OidcStateStore, c as OidcStoredRequest, n as PermissionGroupsModule, P as PermissionsModule, t as PinModule, R as RolesModule, s as ScopeModule, S as SessionsModule, q as SourcesModule, k as TenantsModule, i as TokenVerifyOptions, T as TokensModule, j as TokensModuleOptions, U as UsersModule, V as VendorsModule, W as WebhooksModule } from './client-DXbHb2ul.js';
1
+ export { o as ApiKeysModule, l as AppsModule, A as AuthModule, B as BrandingModule, r as ClientsModule, C as CreateAppRequest, m as CreateAppResponse, h as DEFAULT_CLOCK_TOLERANCE_SECONDS, g as DEFAULT_TOKEN_AUDIENCE, D as DEFAULT_TOKEN_ISSUER, E as EntitlementsModule, G as GdprModule, H as HierarchyModule, I as IQAuthClient, a as InMemoryOidcStateStore, p as InvitesModule, M as MembershipsModule, u as MfaModule, d as OidcAuthRequest, e as OidcCallbackResult, O as OidcModule, f as OidcModuleOptions, b as OidcStateStore, c as OidcStoredRequest, n as PermissionGroupsModule, P as PermissionsModule, t as PinModule, R as RolesModule, s as ScopeModule, S as SessionsModule, q as SourcesModule, k as TenantsModule, i as TokenVerifyOptions, T as TokensModule, j as TokensModuleOptions, U as UsersModule, V as VendorsModule, W as WebhooksModule } from './client-DTX4hNdS.js';
2
2
  export { a as ErrorCode, E as ErrorCodes, I as IQAuthError } from './errors-CDdl24MP.js';
3
- export { i as iqAuthMiddleware } from './express-B4o3P8vK.js';
4
- export { K as KeyMode, b as ParsedPublishableKey, P as PublishableKeyPayload, e as encodePublishableKey, i as isPublishableKey, a as isSecretKey, p as parsePublishableKey } from './publishableKey-B5DIK81A.js';
3
+ export { i as iqAuthMiddleware } from './express-Bo_pJKHN.js';
4
+ export { K as KeyMode, c as ParsedPublishableKey, P as PublishableKeyPayload, a as assertPublishableKey, e as encodePublishableKey, i as isPublishableKey, b as isSecretKey, p as parsePublishableKey } from './publishableKey-BaR0HoAH.js';
5
5
  export { an as AcceptInviteRequest, aa as AddGroupPermissionRequest, ad as AddUserOverrideRequest, v as ApiErrorResponse, ag as ApiKeyInfo, aj as ApiKeyIntrospection, w as ApiResponse, A as ApiSuccessResponse, _ as AppInfo, Z as AppManifest, a0 as AppSyncResult, a4 as AssignRoleRequest, aM as AvailableScopesTree, a_ as BackupCodeCountResult, aZ as BackupCodesResult, p as BrandingAsset, B as BrandingConfig, r as BrandingDomainMapping, aB as Client, ah as CreateApiKeyRequest, ai as CreateApiKeyResult, aC as CreateClientRequest, al as CreateInviteRequest, aJ as CreateMembershipRequest, a2 as CreateRoleRequest, az as CreateSourceRequest, C as CreateTenantRequest, aw as CreateVendorRequest, ap as CreateWebhookRequest, aq as CreateWebhookResult, ae as EffectivePermission, aY as EmailEnrollResult, at as Entitlement, N as ExpressMiddlewareOptions, aR as GdprExportData, au as GrantEntitlementRequest, a9 as GroupPermission, aG as HierarchyClient, aH as HierarchyLink, aF as HierarchySource, aE as HierarchyVendor, c as IQAuthBrowserSessionClientConfig, a as IQAuthClientConfig, I as IQAuthEnvironment, V as IQAuthNextFunction, Q as IQAuthRequestLike, R as IQAuthResponseLike, W as IQAuthRetryConfig, b as IQAuthTokenClientConfig, X as IQAuthVerifyConfig, ab as InheritanceRelation, ak as Invitation, l as InviteTenantUserRequest, m as InviteTenantUserResult, am as InviteValidation, s as JwksKey, t as JwksResponse, J as JwtClaims, L as LoginResult, aI as Membership, aL as MembershipWithDetails, aU as MfaAvailableMethods, y as MfaEnrollment, x as MfaMethod, F as MfaPolicy, D as MfaVerifyResult, M as MigrateUserRequest, O as OidcDiscovery, u as OidcTokenResponse, E as PasswordPolicy, af as PermissionCheckResult, a8 as PermissionGroup, $ as PermissionNodeInfo, Y as PermissionNodeManifest, aT as PinLoginResult, aS as PinStatus, P as PromoteToVendorRequest, k as PromoteToVendorResult, H as ProvisionUserRequest, K as ProvisionUserResponse, a1 as Role, S as ScopeContext, aQ as ScopeSwitchResult, aN as ScopeTreeClient, aO as ScopeTreeSource, aP as ScopeTreeVendor, h as Session, g as SessionAuthenticatedLoginResult, d as SessionUser, aX as SmsEnrollResult, ay as Source, e as Tenant, i as TenantInfo, a7 as TenantUser, n as TenantUserRoleUpdate, f as TokenAuthenticatedLoginResult, T as TokenPair, aV as TotpEnrollResult, z as TotpEnrollmentResult, aW as TotpVerifyResult, o as UpdateBrandingRequest, aD as UpdateClientRequest, aK as UpdateMembershipRequest, a3 as UpdateRoleRequest, aA as UpdateSourceRequest, j as UpdateTenantRequest, ax as UpdateVendorRequest, q as UploadAssetRequest, a6 as UserGroupAssignment, ac as UserPermissionOverride, G as UserPermissions, U as UserProfile, a5 as UserRoleAssignment, av as Vendor, ar as WebhookDelivery, ao as WebhookEndpoint, as as WebhookTestResult } from './types-Cxl3bQHt.js';
6
- import 'jsonwebtoken';