@iqauth/sdk 2.0.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/LICENSE +21 -0
- package/README.md +287 -0
- package/dist/browser-session.d.mts +12 -0
- package/dist/browser-session.d.ts +12 -0
- package/dist/browser-session.js +1812 -0
- package/dist/browser-session.mjs +28 -0
- package/dist/browser.d.mts +46 -0
- package/dist/browser.d.ts +46 -0
- package/dist/browser.js +768 -0
- package/dist/browser.mjs +47 -0
- package/dist/chunk-5HF3OBNO.mjs +189 -0
- package/dist/chunk-5WFR6Y33.mjs +59 -0
- package/dist/chunk-6I6RM4MN.mjs +51 -0
- package/dist/chunk-73R6BEGO.mjs +176 -0
- package/dist/chunk-E46DKOVI.mjs +632 -0
- package/dist/chunk-JQWYIIIS.mjs +1740 -0
- package/dist/chunk-X3K3WOBR.mjs +64 -0
- package/dist/chunk-Y6FXYEAI.mjs +10 -0
- package/dist/cli/index.d.mts +1 -0
- package/dist/cli/index.d.ts +1 -0
- package/dist/cli/index.js +581 -0
- package/dist/cli/index.mjs +57 -0
- package/dist/client-C1DXfB8Z.d.mts +911 -0
- package/dist/client-CggvJmmm.d.ts +911 -0
- package/dist/dev-FUTJZSWN.mjs +56 -0
- package/dist/doctor-OHJRZBBT.mjs +89 -0
- package/dist/errors-CDdl24MP.d.mts +52 -0
- package/dist/errors-CDdl24MP.d.ts +52 -0
- package/dist/express-BKAXB5Nl.d.ts +61 -0
- package/dist/express-CpfyYTmw.d.mts +61 -0
- package/dist/express.d.mts +45 -0
- package/dist/express.d.ts +45 -0
- package/dist/express.js +2252 -0
- package/dist/express.mjs +122 -0
- package/dist/fastify.d.mts +23 -0
- package/dist/fastify.d.ts +23 -0
- package/dist/fastify.js +2062 -0
- package/dist/fastify.mjs +118 -0
- package/dist/hono.d.mts +22 -0
- package/dist/hono.d.ts +22 -0
- package/dist/hono.js +2051 -0
- package/dist/hono.mjs +107 -0
- package/dist/index.d.mts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +2070 -0
- package/dist/index.mjs +83 -0
- package/dist/init-LLCSQGNL.mjs +198 -0
- package/dist/keys-NLWFAOEM.mjs +63 -0
- package/dist/mobile.d.mts +11 -0
- package/dist/mobile.d.ts +11 -0
- package/dist/mobile.js +1809 -0
- package/dist/mobile.mjs +25 -0
- package/dist/next.d.mts +37 -0
- package/dist/next.d.ts +37 -0
- package/dist/next.js +2078 -0
- package/dist/next.mjs +130 -0
- package/dist/publishableKey-B5DIK81A.d.mts +24 -0
- package/dist/publishableKey-B5DIK81A.d.ts +24 -0
- package/dist/react.d.mts +196 -0
- package/dist/react.d.ts +196 -0
- package/dist/react.js +1457 -0
- package/dist/react.mjs +787 -0
- package/dist/server/handlers.d.mts +96 -0
- package/dist/server/handlers.d.ts +96 -0
- package/dist/server/handlers.js +243 -0
- package/dist/server/handlers.mjs +14 -0
- package/dist/server.d.mts +14 -0
- package/dist/server.d.ts +14 -0
- package/dist/server.js +2195 -0
- package/dist/server.mjs +47 -0
- package/dist/service.d.mts +11 -0
- package/dist/service.d.ts +11 -0
- package/dist/service.js +1809 -0
- package/dist/service.mjs +25 -0
- package/dist/signIn-C8f6qVjD.d.mts +238 -0
- package/dist/signIn-Cy2lbEXb.d.ts +238 -0
- package/dist/types-Cxl3bQHt.d.mts +900 -0
- package/dist/types-Cxl3bQHt.d.ts +900 -0
- package/docs/APP_INTEGRATION_MATRIX.md +59 -0
- package/docs/BROWSER_SESSION_MIGRATION.md +69 -0
- package/docs/FRESH_IMPLEMENTATION_GUIDE.md +188 -0
- package/docs/TARBALL_RELEASE_WORKFLOW.md +98 -0
- package/docs/V1_TO_V2_UPGRADE_GUIDE.md +318 -0
- package/docs/guides/api-keys.md +130 -0
- package/docs/guides/app-registration.md +149 -0
- package/docs/guides/auth-flows.md +168 -0
- package/docs/guides/branding.md +160 -0
- package/docs/guides/entitlements.md +115 -0
- package/docs/guides/entity-hierarchy.md +200 -0
- package/docs/guides/error-handling.md +251 -0
- package/docs/guides/gdpr-compliance.md +123 -0
- package/docs/guides/invitations.md +143 -0
- package/docs/guides/mfa-enrollment.md +170 -0
- package/docs/guides/middleware-reference.md +205 -0
- package/docs/guides/mobile-native.md +110 -0
- package/docs/guides/roles-and-permissions.md +220 -0
- package/docs/guides/scoped-authorization.md +247 -0
- package/docs/guides/server-platform-integration.md +52 -0
- package/docs/guides/service-automation-integration.md +36 -0
- package/docs/guides/session-management.md +97 -0
- package/docs/guides/tenant-management.md +216 -0
- package/docs/guides/token-verification.md +178 -0
- package/docs/guides/user-management.md +184 -0
- package/docs/guides/webhooks.md +136 -0
- package/docs/integration-prompts/README.md +20 -0
- package/docs/integration-prompts/first-party-browser-app.md +29 -0
- package/docs/integration-prompts/install-from-tarball.md +41 -0
- package/docs/integration-prompts/migrate-from-local-packages-source.md +57 -0
- package/docs/integration-prompts/native-mobile-app.md +24 -0
- package/docs/integration-prompts/server-platform-app.md +20 -0
- package/docs/integration-prompts/service-automation-app.md +20 -0
- package/package.json +115 -0
package/dist/express.mjs
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DEFAULT_REFRESH_COOKIE,
|
|
3
|
+
iqAuthMiddleware
|
|
4
|
+
} from "./chunk-73R6BEGO.mjs";
|
|
5
|
+
import {
|
|
6
|
+
handleCallback,
|
|
7
|
+
handleRefresh,
|
|
8
|
+
handleSignout
|
|
9
|
+
} from "./chunk-5HF3OBNO.mjs";
|
|
10
|
+
import {
|
|
11
|
+
parsePublishableKey
|
|
12
|
+
} from "./chunk-5WFR6Y33.mjs";
|
|
13
|
+
import {
|
|
14
|
+
IQAuthClient
|
|
15
|
+
} from "./chunk-JQWYIIIS.mjs";
|
|
16
|
+
import {
|
|
17
|
+
ErrorCodes,
|
|
18
|
+
IQAuthError
|
|
19
|
+
} from "./chunk-6I6RM4MN.mjs";
|
|
20
|
+
import "./chunk-Y6FXYEAI.mjs";
|
|
21
|
+
|
|
22
|
+
// src/express.ts
|
|
23
|
+
function applyHandlerResponse(res, hr) {
|
|
24
|
+
for (const c of hr.cookies) {
|
|
25
|
+
if (typeof res.cookie === "function") {
|
|
26
|
+
const opts = {
|
|
27
|
+
httpOnly: c.httpOnly,
|
|
28
|
+
secure: c.secure,
|
|
29
|
+
sameSite: c.sameSite,
|
|
30
|
+
path: c.path,
|
|
31
|
+
maxAge: c.maxAge * 1e3
|
|
32
|
+
};
|
|
33
|
+
if (c.domain) opts.domain = c.domain;
|
|
34
|
+
res.cookie(c.name, c.value, opts);
|
|
35
|
+
} else {
|
|
36
|
+
const existing = res.getHeader?.("Set-Cookie") || [];
|
|
37
|
+
const list = Array.isArray(existing) ? existing : [existing];
|
|
38
|
+
const parts = [`${c.name}=${encodeURIComponent(c.value)}`, `Path=${c.path}`, `Max-Age=${c.maxAge}`, `SameSite=${c.sameSite}`];
|
|
39
|
+
if (c.secure) parts.push("Secure");
|
|
40
|
+
if (c.httpOnly) parts.push("HttpOnly");
|
|
41
|
+
if (c.domain) parts.push(`Domain=${c.domain}`);
|
|
42
|
+
list.push(parts.join("; "));
|
|
43
|
+
res.setHeader?.("Set-Cookie", list);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
res.status(hr.status).json(hr.body);
|
|
47
|
+
}
|
|
48
|
+
function readBody(req) {
|
|
49
|
+
return req.body && typeof req.body === "object" ? req.body : {};
|
|
50
|
+
}
|
|
51
|
+
function readCookieFromReq(req, name) {
|
|
52
|
+
if (req.cookies && typeof req.cookies[name] === "string") return req.cookies[name];
|
|
53
|
+
const header = req.headers?.cookie;
|
|
54
|
+
if (typeof header !== "string") return void 0;
|
|
55
|
+
const target = `${name}=`;
|
|
56
|
+
for (const seg of header.split(";")) {
|
|
57
|
+
const t = seg.trim();
|
|
58
|
+
if (t.startsWith(target)) {
|
|
59
|
+
try {
|
|
60
|
+
return decodeURIComponent(t.slice(target.length));
|
|
61
|
+
} catch {
|
|
62
|
+
return t.slice(target.length);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return void 0;
|
|
67
|
+
}
|
|
68
|
+
function iqAuth(options) {
|
|
69
|
+
const parsed = parsePublishableKey(options.publishableKey);
|
|
70
|
+
if (!parsed) {
|
|
71
|
+
throw new Error("@iqauth/sdk/express: invalid publishable key");
|
|
72
|
+
}
|
|
73
|
+
const issuer = (options.issuer ?? (parsed.iss.startsWith("http") ? parsed.iss : `https://${parsed.iss}`)).replace(/\/+$/, "");
|
|
74
|
+
const client = new IQAuthClient({
|
|
75
|
+
baseUrl: issuer,
|
|
76
|
+
environment: "server"
|
|
77
|
+
});
|
|
78
|
+
const verify = iqAuthMiddleware(client, options);
|
|
79
|
+
const helperConfig = { ...options, issuer };
|
|
80
|
+
const mount = (options.mountPath ?? "/api/iqauth").replace(/\/+$/, "");
|
|
81
|
+
const refreshCookie = options.refreshCookieName ?? DEFAULT_REFRESH_COOKIE;
|
|
82
|
+
const accessCookie = options.accessCookieName ?? "iqauth_at";
|
|
83
|
+
const mountHelpers = options.mountHelperRoutes !== false;
|
|
84
|
+
const middleware = (req, res, next) => {
|
|
85
|
+
const path = req.path || req.url || "";
|
|
86
|
+
if (mountHelpers && path.startsWith(mount + "/")) return next();
|
|
87
|
+
return verify(req, res, next);
|
|
88
|
+
};
|
|
89
|
+
const attachHelpers = (app) => {
|
|
90
|
+
app.post(`${mount}/callback`, async (req, res) => {
|
|
91
|
+
const body = readBody(req);
|
|
92
|
+
const hr = await handleCallback(helperConfig, {
|
|
93
|
+
code: body.code,
|
|
94
|
+
codeVerifier: body.codeVerifier,
|
|
95
|
+
redirectUri: body.redirectUri
|
|
96
|
+
});
|
|
97
|
+
applyHandlerResponse(res, hr);
|
|
98
|
+
});
|
|
99
|
+
app.post(`${mount}/refresh`, async (req, res) => {
|
|
100
|
+
const body = readBody(req);
|
|
101
|
+
const refreshToken = body.refreshToken || readCookieFromReq(req, refreshCookie);
|
|
102
|
+
const hr = await handleRefresh(helperConfig, { refreshToken });
|
|
103
|
+
applyHandlerResponse(res, hr);
|
|
104
|
+
});
|
|
105
|
+
app.post(`${mount}/signout`, async (req, res) => {
|
|
106
|
+
const accessToken = req.headers?.authorization?.replace(/^Bearer /i, "") || readCookieFromReq(req, accessCookie);
|
|
107
|
+
const hr = await handleSignout(helperConfig, { accessToken });
|
|
108
|
+
applyHandlerResponse(res, hr);
|
|
109
|
+
});
|
|
110
|
+
};
|
|
111
|
+
const composed = (req, res, next) => middleware(req, res, next);
|
|
112
|
+
composed.middleware = middleware;
|
|
113
|
+
composed.attachHelpers = attachHelpers;
|
|
114
|
+
composed.client = client;
|
|
115
|
+
return composed;
|
|
116
|
+
}
|
|
117
|
+
export {
|
|
118
|
+
ErrorCodes,
|
|
119
|
+
IQAuthError,
|
|
120
|
+
iqAuth,
|
|
121
|
+
iqAuthMiddleware
|
|
122
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { IQAuthHelperConfig } from './server/handlers.mjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @iqauth/sdk/fastify — Fastify adapter.
|
|
5
|
+
*
|
|
6
|
+
* import Fastify from "fastify";
|
|
7
|
+
* import { iqAuth } from "@iqauth/sdk/fastify";
|
|
8
|
+
* const app = Fastify();
|
|
9
|
+
* await app.register(iqAuth, { publishableKey: ..., secretKey: ... });
|
|
10
|
+
*
|
|
11
|
+
* The plugin verifies bearer / cookie tokens, attaches `request.auth`, and
|
|
12
|
+
* mounts /api/iqauth/{callback,refresh,signout}.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
interface IQAuthFastifyOptions extends IQAuthHelperConfig {
|
|
16
|
+
mountPath?: string;
|
|
17
|
+
mountHelperRoutes?: boolean;
|
|
18
|
+
/** Routes that bypass verification (e.g. health checks). */
|
|
19
|
+
publicPaths?: string[] | ((path: string) => boolean);
|
|
20
|
+
}
|
|
21
|
+
declare function iqAuth(fastify: any, options: IQAuthFastifyOptions): Promise<void>;
|
|
22
|
+
|
|
23
|
+
export { type IQAuthFastifyOptions, iqAuth as default, iqAuth };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { IQAuthHelperConfig } from './server/handlers.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @iqauth/sdk/fastify — Fastify adapter.
|
|
5
|
+
*
|
|
6
|
+
* import Fastify from "fastify";
|
|
7
|
+
* import { iqAuth } from "@iqauth/sdk/fastify";
|
|
8
|
+
* const app = Fastify();
|
|
9
|
+
* await app.register(iqAuth, { publishableKey: ..., secretKey: ... });
|
|
10
|
+
*
|
|
11
|
+
* The plugin verifies bearer / cookie tokens, attaches `request.auth`, and
|
|
12
|
+
* mounts /api/iqauth/{callback,refresh,signout}.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
interface IQAuthFastifyOptions extends IQAuthHelperConfig {
|
|
16
|
+
mountPath?: string;
|
|
17
|
+
mountHelperRoutes?: boolean;
|
|
18
|
+
/** Routes that bypass verification (e.g. health checks). */
|
|
19
|
+
publicPaths?: string[] | ((path: string) => boolean);
|
|
20
|
+
}
|
|
21
|
+
declare function iqAuth(fastify: any, options: IQAuthFastifyOptions): Promise<void>;
|
|
22
|
+
|
|
23
|
+
export { type IQAuthFastifyOptions, iqAuth as default, iqAuth };
|