@iqauth/sdk 2.3.0 → 2.5.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 +110 -0
- package/dist/browser-session.d.mts +3 -2
- package/dist/browser-session.d.ts +3 -2
- package/dist/browser.d.mts +64 -29
- package/dist/browser.d.ts +64 -29
- package/dist/browser.js +782 -38
- package/dist/browser.mjs +43 -3
- package/dist/bundle-LUKDQYVQ.mjs +374 -0
- package/dist/chunk-3JULWS6F.mjs +106 -0
- package/dist/chunk-5T7GHBX6.mjs +1165 -0
- package/dist/{chunk-KGEPDXHU.mjs → chunk-6TDJJER7.mjs} +2 -2
- package/dist/{chunk-RACIPVLD.mjs → chunk-76W5TLQQ.mjs} +262 -220
- package/dist/{chunk-EKTNEZIH.mjs → chunk-BVV54LPI.mjs} +37 -5
- package/dist/chunk-LIZYFXH7.mjs +90 -0
- package/dist/chunk-MKKZULZR.mjs +241 -0
- package/dist/chunk-SL3KRS4W.mjs +54 -0
- package/dist/chunk-TKZTCPEK.mjs +232 -0
- package/dist/chunk-UKZLOHZG.mjs +83 -0
- package/dist/cli/index.js +144 -36
- package/dist/cli/index.mjs +1 -1
- package/dist/{client-DTX4hNdS.d.ts → client-BNQe3AgF.d.ts} +3 -62
- package/dist/{client-vdh2a9fJ.d.mts → client-kYlJFgPv.d.mts} +3 -62
- package/dist/doctor-YYNHNMLD.mjs +198 -0
- package/dist/{express-A0-dWEMy.d.mts → express-B6_1vBYZ.d.mts} +23 -2
- package/dist/{express-Bo_pJKHN.d.ts → express-CHpfa7D_.d.ts} +23 -2
- package/dist/express.d.mts +5 -4
- package/dist/express.d.ts +5 -4
- package/dist/express.js +36 -4
- package/dist/express.mjs +8 -8
- package/dist/fastify.js +2 -2
- package/dist/fastify.mjs +4 -4
- package/dist/hono.js +2 -2
- package/dist/hono.mjs +4 -4
- package/dist/index.d.mts +8 -3
- package/dist/index.d.ts +8 -3
- package/dist/index.js +500 -4
- package/dist/index.mjs +29 -9
- package/dist/locales.d.mts +53 -0
- package/dist/locales.d.ts +53 -0
- package/dist/locales.js +1202 -0
- package/dist/locales.mjs +29 -0
- package/dist/mobile.d.mts +3 -2
- package/dist/mobile.d.ts +3 -2
- package/dist/next.d.mts +1 -1
- package/dist/next.d.ts +1 -1
- package/dist/next.js +2 -2
- package/dist/next.mjs +1 -1
- package/dist/provisioningBridge-88xjOS2n.d.mts +86 -0
- package/dist/provisioningBridge-DnTfzdZK.d.ts +86 -0
- package/dist/react.d.mts +1349 -10
- package/dist/react.d.ts +1349 -10
- package/dist/react.js +2985 -567
- package/dist/react.mjs +1517 -94
- package/dist/reverify-4UEJXUS6.mjs +16 -0
- package/dist/server/handlers.d.mts +10 -1
- package/dist/server/handlers.d.ts +10 -1
- package/dist/server/handlers.js +2 -2
- package/dist/server/handlers.mjs +1 -1
- package/dist/server.d.mts +5 -3
- package/dist/server.d.ts +5 -3
- package/dist/server.js +89 -4
- package/dist/server.mjs +12 -8
- package/dist/service.d.mts +3 -2
- package/dist/service.d.ts +3 -2
- package/dist/signIn-CCY4JE5G.mjs +15 -0
- package/dist/{signIn-Cd0P4y9d.d.mts → signIn-CiIBTJIh.d.mts} +224 -4
- package/dist/{signIn-DKakyzeu.d.ts → signIn-OCr88Zf8.d.ts} +224 -4
- package/dist/test.d.mts +86 -0
- package/dist/test.d.ts +86 -0
- package/dist/test.js +289 -0
- package/dist/test.mjs +9 -0
- package/dist/tokens-DCyzzn8L.d.mts +63 -0
- package/dist/tokens-aHiGFr_E.d.ts +63 -0
- package/dist/types-6bNdxesb.d.mts +196 -0
- package/dist/types-6bNdxesb.d.ts +196 -0
- package/dist/{types-Cxl3bQHt.d.mts → types-DZAflmmq.d.mts} +6 -0
- package/dist/{types-Cxl3bQHt.d.ts → types-DZAflmmq.d.ts} +6 -0
- package/dist/webhooks.d.mts +61 -0
- package/dist/webhooks.d.ts +61 -0
- package/dist/webhooks.js +119 -0
- package/dist/webhooks.mjs +11 -0
- package/dist/ws.d.mts +73 -0
- package/dist/ws.d.ts +73 -0
- package/dist/ws.js +397 -0
- package/dist/ws.mjs +12 -0
- package/package.json +22 -2
- package/dist/doctor-A5E7LSFW.mjs +0 -90
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import {
|
|
2
|
+
PRIOR_SESSION_STORAGE_KEY,
|
|
3
|
+
enterImpersonation,
|
|
4
|
+
exitImpersonation,
|
|
5
|
+
reverify,
|
|
6
|
+
withReverification
|
|
7
|
+
} from "./chunk-LIZYFXH7.mjs";
|
|
8
|
+
import "./chunk-6I6RM4MN.mjs";
|
|
9
|
+
import "./chunk-Y6FXYEAI.mjs";
|
|
10
|
+
export {
|
|
11
|
+
PRIOR_SESSION_STORAGE_KEY,
|
|
12
|
+
enterImpersonation,
|
|
13
|
+
exitImpersonation,
|
|
14
|
+
reverify,
|
|
15
|
+
withReverification
|
|
16
|
+
};
|
|
@@ -47,6 +47,11 @@ interface IQAuthHelperConfig {
|
|
|
47
47
|
accessCookieName?: string;
|
|
48
48
|
/** Override the refresh token cookie name. Defaults to `iqauth_rt`. */
|
|
49
49
|
refreshCookieName?: string;
|
|
50
|
+
/** F14 — Umbrella shorthand for `accessCookieName` / `refreshCookieName`. */
|
|
51
|
+
cookieNames?: {
|
|
52
|
+
access?: string;
|
|
53
|
+
refresh?: string;
|
|
54
|
+
};
|
|
50
55
|
/** Cookie domain (e.g. `.example.com`). Defaults to host-only. */
|
|
51
56
|
cookieDomain?: string;
|
|
52
57
|
/** Cookie sameSite policy. Defaults to `lax`. */
|
|
@@ -82,7 +87,11 @@ interface IQAuthHelperConfig {
|
|
|
82
87
|
*/
|
|
83
88
|
clearCookiesOnRefreshFailure?: "terminal-only" | "always" | "never";
|
|
84
89
|
}
|
|
85
|
-
interface ResolvedConfig extends Required<Omit<IQAuthHelperConfig, "secretKey" | "cookieDomain" | "issuer" | "fetchImpl" | "clearCookiesOnRefreshFailure">> {
|
|
90
|
+
interface ResolvedConfig extends Required<Omit<IQAuthHelperConfig, "secretKey" | "cookieDomain" | "issuer" | "fetchImpl" | "clearCookiesOnRefreshFailure" | "cookieNames">> {
|
|
91
|
+
cookieNames?: {
|
|
92
|
+
access?: string;
|
|
93
|
+
refresh?: string;
|
|
94
|
+
};
|
|
86
95
|
secretKey?: string;
|
|
87
96
|
cookieDomain?: string;
|
|
88
97
|
issuer: string;
|
|
@@ -47,6 +47,11 @@ interface IQAuthHelperConfig {
|
|
|
47
47
|
accessCookieName?: string;
|
|
48
48
|
/** Override the refresh token cookie name. Defaults to `iqauth_rt`. */
|
|
49
49
|
refreshCookieName?: string;
|
|
50
|
+
/** F14 — Umbrella shorthand for `accessCookieName` / `refreshCookieName`. */
|
|
51
|
+
cookieNames?: {
|
|
52
|
+
access?: string;
|
|
53
|
+
refresh?: string;
|
|
54
|
+
};
|
|
50
55
|
/** Cookie domain (e.g. `.example.com`). Defaults to host-only. */
|
|
51
56
|
cookieDomain?: string;
|
|
52
57
|
/** Cookie sameSite policy. Defaults to `lax`. */
|
|
@@ -82,7 +87,11 @@ interface IQAuthHelperConfig {
|
|
|
82
87
|
*/
|
|
83
88
|
clearCookiesOnRefreshFailure?: "terminal-only" | "always" | "never";
|
|
84
89
|
}
|
|
85
|
-
interface ResolvedConfig extends Required<Omit<IQAuthHelperConfig, "secretKey" | "cookieDomain" | "issuer" | "fetchImpl" | "clearCookiesOnRefreshFailure">> {
|
|
90
|
+
interface ResolvedConfig extends Required<Omit<IQAuthHelperConfig, "secretKey" | "cookieDomain" | "issuer" | "fetchImpl" | "clearCookiesOnRefreshFailure" | "cookieNames">> {
|
|
91
|
+
cookieNames?: {
|
|
92
|
+
access?: string;
|
|
93
|
+
refresh?: string;
|
|
94
|
+
};
|
|
86
95
|
secretKey?: string;
|
|
87
96
|
cookieDomain?: string;
|
|
88
97
|
issuer: string;
|
package/dist/server/handlers.js
CHANGED
|
@@ -133,8 +133,8 @@ function resolve(config) {
|
|
|
133
133
|
publishableKey: config.publishableKey,
|
|
134
134
|
secretKey: config.secretKey,
|
|
135
135
|
issuer: (config.issuer ?? inferredIssuer).replace(/\/+$/, ""),
|
|
136
|
-
accessCookieName: config.accessCookieName ?? "iqauth_at",
|
|
137
|
-
refreshCookieName: config.refreshCookieName ?? "iqauth_rt",
|
|
136
|
+
accessCookieName: config.accessCookieName ?? config.cookieNames?.access ?? "iqauth_at",
|
|
137
|
+
refreshCookieName: config.refreshCookieName ?? config.cookieNames?.refresh ?? "iqauth_rt",
|
|
138
138
|
cookieDomain: config.cookieDomain,
|
|
139
139
|
sameSite: config.sameSite ?? "lax",
|
|
140
140
|
secure: config.secure ?? true,
|
package/dist/server/handlers.mjs
CHANGED
package/dist/server.d.mts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { b as IQAuthTokenClientConfig, N as ExpressMiddlewareOptions, Q as IQAuthRequestLike, R as IQAuthResponseLike, V as IQAuthNextFunction } from './types-
|
|
2
|
-
import { I as IQAuthClient } from './client-
|
|
1
|
+
import { b as IQAuthTokenClientConfig, N as ExpressMiddlewareOptions, Q as IQAuthRequestLike, R as IQAuthResponseLike, V as IQAuthNextFunction } from './types-DZAflmmq.mjs';
|
|
2
|
+
import { I as IQAuthClient } from './client-kYlJFgPv.mjs';
|
|
3
3
|
export { E as ErrorCodes, I as IQAuthError } from './errors-CDdl24MP.mjs';
|
|
4
|
-
export { C as CookieAwareMiddlewareOptions, D as DEFAULT_ACCESS_COOKIE, a as DEFAULT_REFRESH_COOKIE, i as iqAuthMiddleware } from './express-
|
|
4
|
+
export { C as CookieAwareMiddlewareOptions, D as DEFAULT_ACCESS_COOKIE, a as DEFAULT_REFRESH_COOKIE, i as iqAuthMiddleware } from './express-B6_1vBYZ.mjs';
|
|
5
5
|
export { HandlerResponse, IQAuthHelperConfig, SetCookieDirective, handleCallback, handleRefresh, handleSignout, serializeCookie } from './server/handlers.mjs';
|
|
6
|
+
export { P as ProvisioningBridge, a as ProvisioningBridgeOptions, d as ProvisioningContext, b as ProvisioningStorage, c as createProvisioningBridge } from './provisioningBridge-88xjOS2n.mjs';
|
|
7
|
+
import './tokens-DCyzzn8L.mjs';
|
|
6
8
|
|
|
7
9
|
declare class ServerIQAuthClient extends IQAuthClient {
|
|
8
10
|
constructor(config: IQAuthTokenClientConfig);
|
package/dist/server.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { b as IQAuthTokenClientConfig, N as ExpressMiddlewareOptions, Q as IQAuthRequestLike, R as IQAuthResponseLike, V as IQAuthNextFunction } from './types-
|
|
2
|
-
import { I as IQAuthClient } from './client-
|
|
1
|
+
import { b as IQAuthTokenClientConfig, N as ExpressMiddlewareOptions, Q as IQAuthRequestLike, R as IQAuthResponseLike, V as IQAuthNextFunction } from './types-DZAflmmq.js';
|
|
2
|
+
import { I as IQAuthClient } from './client-BNQe3AgF.js';
|
|
3
3
|
export { E as ErrorCodes, I as IQAuthError } from './errors-CDdl24MP.js';
|
|
4
|
-
export { C as CookieAwareMiddlewareOptions, D as DEFAULT_ACCESS_COOKIE, a as DEFAULT_REFRESH_COOKIE, i as iqAuthMiddleware } from './express-
|
|
4
|
+
export { C as CookieAwareMiddlewareOptions, D as DEFAULT_ACCESS_COOKIE, a as DEFAULT_REFRESH_COOKIE, i as iqAuthMiddleware } from './express-CHpfa7D_.js';
|
|
5
5
|
export { HandlerResponse, IQAuthHelperConfig, SetCookieDirective, handleCallback, handleRefresh, handleSignout, serializeCookie } from './server/handlers.js';
|
|
6
|
+
export { P as ProvisioningBridge, a as ProvisioningBridgeOptions, d as ProvisioningContext, b as ProvisioningStorage, c as createProvisioningBridge } from './provisioningBridge-DnTfzdZK.js';
|
|
7
|
+
import './tokens-aHiGFr_E.js';
|
|
6
8
|
|
|
7
9
|
declare class ServerIQAuthClient extends IQAuthClient {
|
|
8
10
|
constructor(config: IQAuthTokenClientConfig);
|
package/dist/server.js
CHANGED
|
@@ -36,6 +36,7 @@ __export(server_exports, {
|
|
|
36
36
|
IQAuthClient: () => IQAuthClient,
|
|
37
37
|
IQAuthError: () => IQAuthError,
|
|
38
38
|
ServerIQAuthClient: () => ServerIQAuthClient,
|
|
39
|
+
createProvisioningBridge: () => createProvisioningBridge,
|
|
39
40
|
createServerClient: () => createServerClient,
|
|
40
41
|
handleCallback: () => handleCallback,
|
|
41
42
|
handleRefresh: () => handleRefresh,
|
|
@@ -1925,6 +1926,22 @@ function readCookie(req, name) {
|
|
|
1925
1926
|
}
|
|
1926
1927
|
return void 0;
|
|
1927
1928
|
}
|
|
1929
|
+
function compileMatcher(pat) {
|
|
1930
|
+
if (pat instanceof RegExp) return (p) => pat.test(p);
|
|
1931
|
+
const re = new RegExp(
|
|
1932
|
+
"^" + pat.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*\*/g, "::DOUBLE::").replace(/\*/g, "[^/]*").replace(/::DOUBLE::/g, ".*") + "$"
|
|
1933
|
+
);
|
|
1934
|
+
return (p) => re.test(p);
|
|
1935
|
+
}
|
|
1936
|
+
function compileMatchers(pats) {
|
|
1937
|
+
return (pats ?? []).map(compileMatcher);
|
|
1938
|
+
}
|
|
1939
|
+
function pathOf(req) {
|
|
1940
|
+
const r = req;
|
|
1941
|
+
const raw = r.path || r.originalUrl || r.url || "/";
|
|
1942
|
+
const q = raw.indexOf("?");
|
|
1943
|
+
return q >= 0 ? raw.slice(0, q) : raw;
|
|
1944
|
+
}
|
|
1928
1945
|
function clientFromPublishableKey(opts) {
|
|
1929
1946
|
const parsed = assertPublishableKey(opts.publishableKey, { context: "iqAuthMiddleware" });
|
|
1930
1947
|
const issuer = (opts.issuer ?? (parsed.iss.startsWith("http") ? parsed.iss : `https://${parsed.iss}`)).replace(/\/+$/, "");
|
|
@@ -1952,10 +1969,26 @@ function iqAuthMiddleware(clientOrOptions, options = {}) {
|
|
|
1952
1969
|
onUnauthorized,
|
|
1953
1970
|
onForbidden,
|
|
1954
1971
|
onError,
|
|
1955
|
-
|
|
1956
|
-
|
|
1972
|
+
cookieAware = true,
|
|
1973
|
+
cookieNames,
|
|
1974
|
+
protect,
|
|
1975
|
+
publicRoutes
|
|
1957
1976
|
} = resolvedOptions;
|
|
1977
|
+
const accessCookieName = resolvedOptions.accessCookieName ?? cookieNames?.access ?? DEFAULT_ACCESS_COOKIE;
|
|
1978
|
+
const protectMatchers = compileMatchers(protect);
|
|
1979
|
+
const publicMatchers = compileMatchers(publicRoutes);
|
|
1980
|
+
const hasProtect = protectMatchers.length > 0;
|
|
1981
|
+
const hasPublic = publicMatchers.length > 0;
|
|
1958
1982
|
return async (req, res, next) => {
|
|
1983
|
+
if (hasProtect || hasPublic) {
|
|
1984
|
+
const path = pathOf(req);
|
|
1985
|
+
if (hasPublic && publicMatchers.some((m) => m(path))) {
|
|
1986
|
+
return next();
|
|
1987
|
+
}
|
|
1988
|
+
if (hasProtect && !protectMatchers.some((m) => m(path))) {
|
|
1989
|
+
return next();
|
|
1990
|
+
}
|
|
1991
|
+
}
|
|
1959
1992
|
let token;
|
|
1960
1993
|
const authHeader = getAuthorizationHeader(req);
|
|
1961
1994
|
if (authHeader && authHeader.startsWith("Bearer ")) {
|
|
@@ -2074,8 +2107,8 @@ function resolve(config) {
|
|
|
2074
2107
|
publishableKey: config.publishableKey,
|
|
2075
2108
|
secretKey: config.secretKey,
|
|
2076
2109
|
issuer: (config.issuer ?? inferredIssuer).replace(/\/+$/, ""),
|
|
2077
|
-
accessCookieName: config.accessCookieName ?? "iqauth_at",
|
|
2078
|
-
refreshCookieName: config.refreshCookieName ?? "iqauth_rt",
|
|
2110
|
+
accessCookieName: config.accessCookieName ?? config.cookieNames?.access ?? "iqauth_at",
|
|
2111
|
+
refreshCookieName: config.refreshCookieName ?? config.cookieNames?.refresh ?? "iqauth_rt",
|
|
2079
2112
|
cookieDomain: config.cookieDomain,
|
|
2080
2113
|
sameSite: config.sameSite ?? "lax",
|
|
2081
2114
|
secure: config.secure ?? true,
|
|
@@ -2255,6 +2288,57 @@ async function handleSignout(config, input) {
|
|
|
2255
2288
|
};
|
|
2256
2289
|
}
|
|
2257
2290
|
|
|
2291
|
+
// src/server/provisioningBridge.ts
|
|
2292
|
+
function defaultIsUniqueViolation(err) {
|
|
2293
|
+
if (!err || typeof err !== "object") return false;
|
|
2294
|
+
const e = err;
|
|
2295
|
+
if (e.code === "23505") return true;
|
|
2296
|
+
if (typeof e.code === "string" && e.code.startsWith("SQLITE_CONSTRAINT")) return true;
|
|
2297
|
+
if (typeof e.message === "string" && /unique constraint|duplicate key/i.test(e.message)) return true;
|
|
2298
|
+
return false;
|
|
2299
|
+
}
|
|
2300
|
+
function createProvisioningBridge(options) {
|
|
2301
|
+
const { storage } = options;
|
|
2302
|
+
const isUniqueViolation = options.isUniqueViolation ?? defaultIsUniqueViolation;
|
|
2303
|
+
const roleOf = (claims) => {
|
|
2304
|
+
try {
|
|
2305
|
+
return options.roleMapper?.(claims) ?? null;
|
|
2306
|
+
} catch {
|
|
2307
|
+
return null;
|
|
2308
|
+
}
|
|
2309
|
+
};
|
|
2310
|
+
const ensureUser = async (claims) => {
|
|
2311
|
+
if (!claims?.sub) {
|
|
2312
|
+
throw new Error("createProvisioningBridge: claims.sub is required");
|
|
2313
|
+
}
|
|
2314
|
+
const byId = await storage.findByIqAuthUserId(claims.sub);
|
|
2315
|
+
if (byId) return { user: byId, claims, created: false, adopted: false };
|
|
2316
|
+
if (claims.email) {
|
|
2317
|
+
const byEmail = await storage.findByEmail(claims.email);
|
|
2318
|
+
if (byEmail) {
|
|
2319
|
+
if (storage.adoptByEmail) {
|
|
2320
|
+
const adopted = await storage.adoptByEmail(byEmail, claims, roleOf(claims));
|
|
2321
|
+
return { user: adopted, claims, created: false, adopted: true };
|
|
2322
|
+
}
|
|
2323
|
+
}
|
|
2324
|
+
}
|
|
2325
|
+
try {
|
|
2326
|
+
const created = await storage.insertFromClaims(claims, roleOf(claims));
|
|
2327
|
+
return { user: created, claims, created: true, adopted: false };
|
|
2328
|
+
} catch (err) {
|
|
2329
|
+
if (!isUniqueViolation(err)) throw err;
|
|
2330
|
+
const after = await storage.findByIqAuthUserId(claims.sub);
|
|
2331
|
+
if (after) return { user: after, claims, created: false, adopted: false };
|
|
2332
|
+
if (claims.email) {
|
|
2333
|
+
const byEmail = await storage.findByEmail(claims.email);
|
|
2334
|
+
if (byEmail) return { user: byEmail, claims, created: false, adopted: true };
|
|
2335
|
+
}
|
|
2336
|
+
throw err;
|
|
2337
|
+
}
|
|
2338
|
+
};
|
|
2339
|
+
return { ensureUser };
|
|
2340
|
+
}
|
|
2341
|
+
|
|
2258
2342
|
// src/server.ts
|
|
2259
2343
|
var ServerIQAuthClient = class extends IQAuthClient {
|
|
2260
2344
|
constructor(config) {
|
|
@@ -2275,6 +2359,7 @@ function createServerClient(config) {
|
|
|
2275
2359
|
IQAuthClient,
|
|
2276
2360
|
IQAuthError,
|
|
2277
2361
|
ServerIQAuthClient,
|
|
2362
|
+
createProvisioningBridge,
|
|
2278
2363
|
createServerClient,
|
|
2279
2364
|
handleCallback,
|
|
2280
2365
|
handleRefresh,
|
package/dist/server.mjs
CHANGED
|
@@ -1,18 +1,21 @@
|
|
|
1
|
+
import {
|
|
2
|
+
handleCallback,
|
|
3
|
+
handleRefresh,
|
|
4
|
+
handleSignout,
|
|
5
|
+
serializeCookie
|
|
6
|
+
} from "./chunk-6TDJJER7.mjs";
|
|
7
|
+
import {
|
|
8
|
+
createProvisioningBridge
|
|
9
|
+
} from "./chunk-SL3KRS4W.mjs";
|
|
1
10
|
import {
|
|
2
11
|
DEFAULT_ACCESS_COOKIE,
|
|
3
12
|
DEFAULT_REFRESH_COOKIE,
|
|
4
13
|
iqAuthMiddleware
|
|
5
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-BVV54LPI.mjs";
|
|
15
|
+
import "./chunk-WQWBJSSS.mjs";
|
|
6
16
|
import {
|
|
7
17
|
IQAuthClient
|
|
8
18
|
} from "./chunk-W3F4JYGP.mjs";
|
|
9
|
-
import {
|
|
10
|
-
handleCallback,
|
|
11
|
-
handleRefresh,
|
|
12
|
-
handleSignout,
|
|
13
|
-
serializeCookie
|
|
14
|
-
} from "./chunk-KGEPDXHU.mjs";
|
|
15
|
-
import "./chunk-WQWBJSSS.mjs";
|
|
16
19
|
import "./chunk-UNYDG2L4.mjs";
|
|
17
20
|
import {
|
|
18
21
|
ErrorCodes,
|
|
@@ -39,6 +42,7 @@ export {
|
|
|
39
42
|
IQAuthClient,
|
|
40
43
|
IQAuthError,
|
|
41
44
|
ServerIQAuthClient,
|
|
45
|
+
createProvisioningBridge,
|
|
42
46
|
createServerClient,
|
|
43
47
|
handleCallback,
|
|
44
48
|
handleRefresh,
|
package/dist/service.d.mts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { I as IQAuthClient } from './client-
|
|
2
|
-
import { b as IQAuthTokenClientConfig } from './types-
|
|
1
|
+
import { I as IQAuthClient } from './client-kYlJFgPv.mjs';
|
|
2
|
+
import { b as IQAuthTokenClientConfig } from './types-DZAflmmq.mjs';
|
|
3
3
|
export { E as ErrorCodes, I as IQAuthError } from './errors-CDdl24MP.mjs';
|
|
4
|
+
import './tokens-DCyzzn8L.mjs';
|
|
4
5
|
|
|
5
6
|
declare class ServiceIQAuthClient extends IQAuthClient {
|
|
6
7
|
constructor(config: IQAuthTokenClientConfig);
|
package/dist/service.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { I as IQAuthClient } from './client-
|
|
2
|
-
import { b as IQAuthTokenClientConfig } from './types-
|
|
1
|
+
import { I as IQAuthClient } from './client-BNQe3AgF.js';
|
|
2
|
+
import { b as IQAuthTokenClientConfig } from './types-DZAflmmq.js';
|
|
3
3
|
export { E as ErrorCodes, I as IQAuthError } from './errors-CDdl24MP.js';
|
|
4
|
+
import './tokens-aHiGFr_E.js';
|
|
4
5
|
|
|
5
6
|
declare class ServiceIQAuthClient extends IQAuthClient {
|
|
6
7
|
constructor(config: IQAuthTokenClientConfig);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import {
|
|
2
|
+
buildSignInUrl,
|
|
3
|
+
handleAuthCallback,
|
|
4
|
+
redirectToSignIn,
|
|
5
|
+
signIn,
|
|
6
|
+
signOut
|
|
7
|
+
} from "./chunk-TKZTCPEK.mjs";
|
|
8
|
+
import "./chunk-Y6FXYEAI.mjs";
|
|
9
|
+
export {
|
|
10
|
+
buildSignInUrl,
|
|
11
|
+
handleAuthCallback,
|
|
12
|
+
redirectToSignIn,
|
|
13
|
+
signIn,
|
|
14
|
+
signOut
|
|
15
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { c as ParsedPublishableKey } from './publishableKey-BaR0HoAH.mjs';
|
|
2
|
-
import {
|
|
2
|
+
import { J as JwtClaims, d as SessionUser } from './types-DZAflmmq.mjs';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* SessionManager — core browser-side session state.
|
|
@@ -28,9 +28,17 @@ type SessionStatus = "loading" | "authenticated" | "unauthenticated";
|
|
|
28
28
|
* first-party cookie — convenient for browser-only apps but not as resistant
|
|
29
29
|
* to XSS exfiltration.
|
|
30
30
|
*/
|
|
31
|
+
/**
|
|
32
|
+
* Optional context handed to `RefreshTokenStore.write`. Multi-account stores
|
|
33
|
+
* use it to route the token to the correct per-account cookie when no
|
|
34
|
+
* "active" account is set yet (i.e. immediately after `addAccount()`).
|
|
35
|
+
*/
|
|
36
|
+
interface RefreshTokenWriteContext {
|
|
37
|
+
claims?: JwtClaims | null;
|
|
38
|
+
}
|
|
31
39
|
interface RefreshTokenStore {
|
|
32
40
|
read(): string | null | Promise<string | null>;
|
|
33
|
-
write(token: string): void | Promise<void>;
|
|
41
|
+
write(token: string, ctx?: RefreshTokenWriteContext): void | Promise<void>;
|
|
34
42
|
clear(): void | Promise<void>;
|
|
35
43
|
}
|
|
36
44
|
interface SessionSnapshot {
|
|
@@ -101,6 +109,17 @@ interface SessionManagerOptions {
|
|
|
101
109
|
* Defaults to `false` to preserve pre-2.0.3 behavior.
|
|
102
110
|
*/
|
|
103
111
|
serverManagedSession?: boolean;
|
|
112
|
+
/**
|
|
113
|
+
* F14 — Override the names of the cookies the SDK reads/writes. Useful when
|
|
114
|
+
* a host app already uses `iqauth_rt`/`iqauth_at` for an unrelated purpose
|
|
115
|
+
* or wants to prefix all SDK cookies. Only the `refresh` cookie is written
|
|
116
|
+
* by the browser SDK directly; `access` is for parity with the backend
|
|
117
|
+
* helpers/middleware which read it via the same umbrella option.
|
|
118
|
+
*/
|
|
119
|
+
cookieNames?: {
|
|
120
|
+
refresh?: string;
|
|
121
|
+
access?: string;
|
|
122
|
+
};
|
|
104
123
|
}
|
|
105
124
|
declare class SessionManager {
|
|
106
125
|
private snapshot;
|
|
@@ -115,9 +134,10 @@ declare class SessionManager {
|
|
|
115
134
|
private readonly userinfoPath;
|
|
116
135
|
private readonly useCookies;
|
|
117
136
|
private readonly proactiveRefresh;
|
|
118
|
-
private
|
|
137
|
+
private tokenStore;
|
|
119
138
|
private readonly crossTabLockTimeoutMs;
|
|
120
139
|
private readonly serverManagedSession;
|
|
140
|
+
private readonly refreshCookieName;
|
|
121
141
|
private proactiveTimer;
|
|
122
142
|
private bootstrapped;
|
|
123
143
|
/** Pending refresh awaited by other tabs after a `refresh:claim` from us. */
|
|
@@ -129,6 +149,8 @@ declare class SessionManager {
|
|
|
129
149
|
get appKey(): string;
|
|
130
150
|
get tenantIdFromKey(): string;
|
|
131
151
|
get issuerUrl(): string;
|
|
152
|
+
/** Cookie name the SDK uses for the refresh token (overridable via `cookieNames.refresh`). */
|
|
153
|
+
get refreshCookie(): string;
|
|
132
154
|
getSnapshot(): SessionSnapshot;
|
|
133
155
|
subscribe(listener: (s: SessionSnapshot) => void): () => void;
|
|
134
156
|
/**
|
|
@@ -175,6 +197,12 @@ declare class SessionManager {
|
|
|
175
197
|
* the server-side logout request.
|
|
176
198
|
*/
|
|
177
199
|
signOutLocal(status?: SessionStatus): void;
|
|
200
|
+
/**
|
|
201
|
+
* Replace the refresh-token store at runtime. Used by the F22
|
|
202
|
+
* `<MultisessionAppSupport>` wrapper to swap in a `MultiAccountTokenStore`
|
|
203
|
+
* after the manager has already been constructed by `<IQAuthProvider>`.
|
|
204
|
+
*/
|
|
205
|
+
setTokenStore(store: RefreshTokenStore): void;
|
|
178
206
|
destroy(): void;
|
|
179
207
|
private setStatus;
|
|
180
208
|
private setError;
|
|
@@ -186,6 +214,180 @@ declare class SessionManager {
|
|
|
186
214
|
private onBroadcast;
|
|
187
215
|
}
|
|
188
216
|
|
|
217
|
+
/**
|
|
218
|
+
* Passwordless helpers (Task #91 / F24/F25/F31). Browser-only — these wrap
|
|
219
|
+
* the issuer's `/api/v1/auth/{magic-link,passkeys,identities}` routes so
|
|
220
|
+
* non-React consumers (vanilla JS, Vue, Svelte) can integrate without
|
|
221
|
+
* pulling in framework code. React consumers should prefer the hooks
|
|
222
|
+
* exported from `@iqauth/sdk/react`.
|
|
223
|
+
*
|
|
224
|
+
* All calls use `credentials: "include"` so the issuer can promote the
|
|
225
|
+
* minted session to httpOnly cookies (`iqauth_at` / `iqauth_rt`) when
|
|
226
|
+
* the caller forwards the `x-iqauth-session: cookie` header.
|
|
227
|
+
*
|
|
228
|
+
* `iqAuthBaseUrl` is the issuer URL (e.g. https://auth.example.com); it
|
|
229
|
+
* must NOT end with a slash.
|
|
230
|
+
*/
|
|
231
|
+
type PasswordlessOptions = {
|
|
232
|
+
iqAuthBaseUrl: string;
|
|
233
|
+
/** When true (default), tells the issuer to set httpOnly cookies on success. */
|
|
234
|
+
cookieSession?: boolean;
|
|
235
|
+
};
|
|
236
|
+
type MagicLinkRequestInput = {
|
|
237
|
+
email: string;
|
|
238
|
+
/** App identifier — accepts the app id, key, or omitted for global links. */
|
|
239
|
+
appId?: string;
|
|
240
|
+
redirectUri: string;
|
|
241
|
+
};
|
|
242
|
+
declare function requestMagicLink(opts: PasswordlessOptions, input: MagicLinkRequestInput): Promise<{
|
|
243
|
+
ok: true;
|
|
244
|
+
}>;
|
|
245
|
+
declare function verifyMagicLink(opts: PasswordlessOptions, token: string): Promise<{
|
|
246
|
+
accessToken?: string;
|
|
247
|
+
user?: unknown;
|
|
248
|
+
redirectUri?: string;
|
|
249
|
+
}>;
|
|
250
|
+
type PasskeyAuthInput = {
|
|
251
|
+
email?: string;
|
|
252
|
+
};
|
|
253
|
+
declare function beginPasskeyAuthentication(opts: PasswordlessOptions, input?: PasskeyAuthInput): Promise<unknown>;
|
|
254
|
+
declare function finishPasskeyAuthentication(opts: PasswordlessOptions, response: unknown): Promise<unknown>;
|
|
255
|
+
declare function beginPasskeyRegistration(opts: PasswordlessOptions): Promise<unknown>;
|
|
256
|
+
declare function finishPasskeyRegistration(opts: PasswordlessOptions, response: unknown, name?: string): Promise<unknown>;
|
|
257
|
+
/**
|
|
258
|
+
* End-to-end passkey sign-in convenience. Loads `@simplewebauthn/browser` on
|
|
259
|
+
* demand (peer dependency) so callers that never use passkeys don't pay the
|
|
260
|
+
* bundle cost.
|
|
261
|
+
*/
|
|
262
|
+
declare function signInWithPasskey(opts: PasswordlessOptions, input?: PasskeyAuthInput): Promise<unknown>;
|
|
263
|
+
declare function enrollPasskey(opts: PasswordlessOptions, name?: string): Promise<unknown>;
|
|
264
|
+
type LinkedIdentity = {
|
|
265
|
+
id: string;
|
|
266
|
+
provider: string;
|
|
267
|
+
providerUserId: string | null;
|
|
268
|
+
linkedAt: string;
|
|
269
|
+
label?: string | null;
|
|
270
|
+
name?: string | null;
|
|
271
|
+
canUnlink: boolean;
|
|
272
|
+
};
|
|
273
|
+
declare function listLinkedIdentities(opts: PasswordlessOptions): Promise<LinkedIdentity[]>;
|
|
274
|
+
type LinkProviderInput = {
|
|
275
|
+
provider: "google";
|
|
276
|
+
idToken: string;
|
|
277
|
+
reauth: {
|
|
278
|
+
password?: string;
|
|
279
|
+
};
|
|
280
|
+
} | {
|
|
281
|
+
provider: string;
|
|
282
|
+
opaque: {
|
|
283
|
+
providerUserId: string;
|
|
284
|
+
verifiedBy: string;
|
|
285
|
+
};
|
|
286
|
+
reauth: {
|
|
287
|
+
password?: string;
|
|
288
|
+
};
|
|
289
|
+
};
|
|
290
|
+
declare function linkProvider(opts: PasswordlessOptions, input: LinkProviderInput): Promise<{
|
|
291
|
+
ok: true;
|
|
292
|
+
}>;
|
|
293
|
+
type UnlinkProviderInput = {
|
|
294
|
+
provider: string;
|
|
295
|
+
reauth: {
|
|
296
|
+
password?: string;
|
|
297
|
+
};
|
|
298
|
+
};
|
|
299
|
+
declare function unlinkProvider(opts: PasswordlessOptions, input: UnlinkProviderInput): Promise<{
|
|
300
|
+
ok: true;
|
|
301
|
+
}>;
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* Browser-only storage helpers used by the SessionManager.
|
|
305
|
+
*
|
|
306
|
+
* Storage strategy (Phase B):
|
|
307
|
+
* - Access token: in memory only (held by SessionManager).
|
|
308
|
+
* - Refresh token: first-party cookie on the app's own domain. The cookie
|
|
309
|
+
* is set by the SDK callback handler and cleared on signOut.
|
|
310
|
+
*
|
|
311
|
+
* NOTE: Cookies set from JS cannot be httpOnly. Phase D (cookie-aware
|
|
312
|
+
* middleware) will move refresh-token cookie management into the app's
|
|
313
|
+
* backend so it can be httpOnly. Until then, the SDK uses a `Secure`,
|
|
314
|
+
* `SameSite=Lax` first-party cookie as a pragmatic stopgap. Nothing
|
|
315
|
+
* privileged ever lives in localStorage.
|
|
316
|
+
*/
|
|
317
|
+
declare const REFRESH_COOKIE = "iqauth_rt";
|
|
318
|
+
interface CookieOptions {
|
|
319
|
+
maxAgeSeconds?: number;
|
|
320
|
+
path?: string;
|
|
321
|
+
domain?: string;
|
|
322
|
+
secure?: boolean;
|
|
323
|
+
sameSite?: "lax" | "strict" | "none";
|
|
324
|
+
}
|
|
325
|
+
declare function setCookie(name: string, value: string, opts?: CookieOptions): void;
|
|
326
|
+
declare function getCookie(name: string): string | null;
|
|
327
|
+
declare function clearCookie(name: string, opts?: CookieOptions): void;
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* F22 — Multi-account registry.
|
|
331
|
+
*
|
|
332
|
+
* Persists the set of accounts currently signed in to a given app (keyed by
|
|
333
|
+
* the app's publishableKey appId) plus which one is "active". Each account
|
|
334
|
+
* stores a single per-account refresh cookie named `iqauth_rt_<accountId>`
|
|
335
|
+
* (where `accountId` is the user's `sub` claim), so SessionManager can
|
|
336
|
+
* pivot to any account by reading a different cookie + calling refresh().
|
|
337
|
+
*
|
|
338
|
+
* NOTE: We deliberately do NOT store refresh tokens in localStorage — they
|
|
339
|
+
* stay in cookies (same security posture as the single-account default).
|
|
340
|
+
* localStorage holds only public profile data + ordering metadata.
|
|
341
|
+
*/
|
|
342
|
+
|
|
343
|
+
interface AccountRecord {
|
|
344
|
+
accountId: string;
|
|
345
|
+
userId: string;
|
|
346
|
+
email: string;
|
|
347
|
+
name: string;
|
|
348
|
+
tenantId: string | null;
|
|
349
|
+
addedAt: number;
|
|
350
|
+
}
|
|
351
|
+
declare class AccountRegistry {
|
|
352
|
+
private readonly appId;
|
|
353
|
+
private listeners;
|
|
354
|
+
private storageHandler;
|
|
355
|
+
constructor(appId: string);
|
|
356
|
+
destroy(): void;
|
|
357
|
+
list(): AccountRecord[];
|
|
358
|
+
active(): string | null;
|
|
359
|
+
get(accountId: string): AccountRecord | null;
|
|
360
|
+
upsert(rec: AccountRecord): void;
|
|
361
|
+
setActive(accountId: string | null): void;
|
|
362
|
+
remove(accountId: string): void;
|
|
363
|
+
subscribe(listener: () => void): () => void;
|
|
364
|
+
/**
|
|
365
|
+
* Read the refresh token for a specific account from its per-account
|
|
366
|
+
* cookie. Used by `MultiAccountTokenStore.read()`.
|
|
367
|
+
*/
|
|
368
|
+
readRefreshToken(accountId: string): string | null;
|
|
369
|
+
/**
|
|
370
|
+
* Persist a refresh token to the per-account cookie. Caller is the
|
|
371
|
+
* SessionManager via `MultiAccountTokenStore.write()`.
|
|
372
|
+
*/
|
|
373
|
+
writeRefreshToken(accountId: string, token: string, opts?: CookieOptions): void;
|
|
374
|
+
clearRefreshToken(accountId: string): void;
|
|
375
|
+
private notify;
|
|
376
|
+
}
|
|
377
|
+
/**
|
|
378
|
+
* RefreshTokenStore that reads/writes the active account's per-account
|
|
379
|
+
* cookie. Falls back to a configurable single-account store when no active
|
|
380
|
+
* account is set (e.g. before the first sign-in completes).
|
|
381
|
+
*/
|
|
382
|
+
declare class MultiAccountTokenStore implements RefreshTokenStore {
|
|
383
|
+
private readonly registry;
|
|
384
|
+
private readonly fallback;
|
|
385
|
+
constructor(registry: AccountRegistry, fallback: RefreshTokenStore);
|
|
386
|
+
read(): string | null | Promise<string | null>;
|
|
387
|
+
write(token: string, ctx?: RefreshTokenWriteContext): void | Promise<void>;
|
|
388
|
+
clear(): void | Promise<void>;
|
|
389
|
+
}
|
|
390
|
+
|
|
189
391
|
/**
|
|
190
392
|
* Sign-in / sign-out / callback helpers that build on top of the
|
|
191
393
|
* SessionManager. These are usable both from React (via the hook helpers in
|
|
@@ -208,6 +410,20 @@ interface SignInOptions {
|
|
|
208
410
|
redirectUri?: string;
|
|
209
411
|
/** Extra OIDC scopes beyond `openid` to request. */
|
|
210
412
|
scope?: string;
|
|
413
|
+
/**
|
|
414
|
+
* F14 — Override SDK cookie names. `refresh` controls where the JS
|
|
415
|
+
* fallback writes the refresh token after the callback exchange.
|
|
416
|
+
*/
|
|
417
|
+
cookieNames?: {
|
|
418
|
+
refresh?: string;
|
|
419
|
+
};
|
|
420
|
+
/**
|
|
421
|
+
* OIDC `prompt` parameter. `"login"` forces the IQAuth host to show the
|
|
422
|
+
* sign-in form even if a single-sign-on session already exists — used by
|
|
423
|
+
* the multi-account `addAccount()` helper to add a second account in
|
|
424
|
+
* parallel rather than re-using the active session.
|
|
425
|
+
*/
|
|
426
|
+
prompt?: "login" | "none" | "consent" | "select_account";
|
|
211
427
|
}
|
|
212
428
|
interface SignOutOptions {
|
|
213
429
|
/** Where to send the user after sign out. Defaults to the current page. */
|
|
@@ -258,6 +474,10 @@ declare function handleAuthCallback(manager: SessionManager, options?: {
|
|
|
258
474
|
url?: string;
|
|
259
475
|
tokenPath?: string;
|
|
260
476
|
fetchImpl?: typeof fetch;
|
|
477
|
+
/** F14 — refresh-cookie name override (defaults to `manager.refreshCookie`). */
|
|
478
|
+
cookieNames?: {
|
|
479
|
+
refresh?: string;
|
|
480
|
+
};
|
|
261
481
|
}): Promise<CallbackResult>;
|
|
262
482
|
/**
|
|
263
483
|
* Clear the local session, ask IQAuth to revoke the refresh token, and
|
|
@@ -265,4 +485,4 @@ declare function handleAuthCallback(manager: SessionManager, options?: {
|
|
|
265
485
|
*/
|
|
266
486
|
declare function signOut(manager: SessionManager, opts?: SignOutOptions): Promise<void>;
|
|
267
487
|
|
|
268
|
-
export { type CallbackResult as C,
|
|
488
|
+
export { AccountRegistry as A, clearCookie as B, type CallbackResult as C, getCookie as D, setCookie as E, type LinkedIdentity as L, type MagicLinkRequestInput as M, type PasswordlessOptions as P, type RefreshTokenStore as R, SessionManager as S, type UnlinkProviderInput as U, type SessionManagerOptions as a, type SessionSnapshot as b, type SessionStatus as c, beginPasskeyAuthentication as d, beginPasskeyRegistration as e, finishPasskeyAuthentication as f, finishPasskeyRegistration as g, enrollPasskey as h, linkProvider as i, type PasskeyAuthInput as j, type LinkProviderInput as k, listLinkedIdentities as l, MultiAccountTokenStore as m, type AccountRecord as n, buildSignInUrl as o, handleAuthCallback as p, redirectToSignIn as q, requestMagicLink as r, signInWithPasskey as s, signIn as t, unlinkProvider as u, verifyMagicLink as v, signOut as w, type SignInOptions as x, type SignOutOptions as y, REFRESH_COOKIE as z };
|