@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/fastify.mjs
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import {
|
|
2
|
+
handleCallback,
|
|
3
|
+
handleRefresh,
|
|
4
|
+
handleSignout,
|
|
5
|
+
serializeCookie
|
|
6
|
+
} from "./chunk-5HF3OBNO.mjs";
|
|
7
|
+
import {
|
|
8
|
+
parsePublishableKey
|
|
9
|
+
} from "./chunk-5WFR6Y33.mjs";
|
|
10
|
+
import {
|
|
11
|
+
IQAuthClient
|
|
12
|
+
} from "./chunk-JQWYIIIS.mjs";
|
|
13
|
+
import {
|
|
14
|
+
IQAuthError
|
|
15
|
+
} from "./chunk-6I6RM4MN.mjs";
|
|
16
|
+
import "./chunk-Y6FXYEAI.mjs";
|
|
17
|
+
|
|
18
|
+
// src/fastify.ts
|
|
19
|
+
var KNOWN_AUTH_ERRORS = /* @__PURE__ */ new Set([
|
|
20
|
+
"TOKEN_INVALID",
|
|
21
|
+
"TOKEN_EXPIRED",
|
|
22
|
+
"TOKEN_REVOKED",
|
|
23
|
+
"SESSION_EXPIRED",
|
|
24
|
+
"SESSION_INVALID",
|
|
25
|
+
"AUTH_REQUIRED"
|
|
26
|
+
]);
|
|
27
|
+
function applyResponse(reply, hr) {
|
|
28
|
+
for (const c of hr.cookies) {
|
|
29
|
+
const cookie = serializeCookie(c);
|
|
30
|
+
const existing = reply.getHeader?.("set-cookie") ?? [];
|
|
31
|
+
const list = Array.isArray(existing) ? existing : [existing];
|
|
32
|
+
list.push(cookie);
|
|
33
|
+
reply.header("set-cookie", list);
|
|
34
|
+
}
|
|
35
|
+
reply.code(hr.status).send(hr.body);
|
|
36
|
+
}
|
|
37
|
+
function readCookie(req, name) {
|
|
38
|
+
if (req.cookies && typeof req.cookies[name] === "string") return req.cookies[name];
|
|
39
|
+
const raw = req.headers?.cookie;
|
|
40
|
+
if (typeof raw !== "string") return void 0;
|
|
41
|
+
const target = `${name}=`;
|
|
42
|
+
for (const seg of raw.split(";")) {
|
|
43
|
+
const t = seg.trim();
|
|
44
|
+
if (t.startsWith(target)) {
|
|
45
|
+
try {
|
|
46
|
+
return decodeURIComponent(t.slice(target.length));
|
|
47
|
+
} catch {
|
|
48
|
+
return t.slice(target.length);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return void 0;
|
|
53
|
+
}
|
|
54
|
+
async function iqAuth(fastify, options) {
|
|
55
|
+
const parsed = parsePublishableKey(options.publishableKey);
|
|
56
|
+
if (!parsed) throw new Error("@iqauth/sdk/fastify: invalid publishable key");
|
|
57
|
+
const issuer = (options.issuer ?? (parsed.iss.startsWith("http") ? parsed.iss : `https://${parsed.iss}`)).replace(/\/+$/, "");
|
|
58
|
+
const helperConfig = { ...options, issuer };
|
|
59
|
+
const client = new IQAuthClient({ baseUrl: issuer, environment: "server" });
|
|
60
|
+
const accessCookie = options.accessCookieName ?? "iqauth_at";
|
|
61
|
+
const refreshCookie = options.refreshCookieName ?? "iqauth_rt";
|
|
62
|
+
const mount = (options.mountPath ?? "/api/iqauth").replace(/\/+$/, "");
|
|
63
|
+
const mountHelpers = options.mountHelperRoutes !== false;
|
|
64
|
+
const isPublic = (p) => {
|
|
65
|
+
if (mountHelpers && p.startsWith(mount + "/")) return true;
|
|
66
|
+
if (Array.isArray(options.publicPaths)) return options.publicPaths.includes(p);
|
|
67
|
+
if (typeof options.publicPaths === "function") return options.publicPaths(p);
|
|
68
|
+
return false;
|
|
69
|
+
};
|
|
70
|
+
fastify.addHook("preHandler", async (req, reply) => {
|
|
71
|
+
const path = req.url?.split("?")[0] ?? "";
|
|
72
|
+
if (isPublic(path)) return;
|
|
73
|
+
const auth = req.headers?.authorization;
|
|
74
|
+
let token;
|
|
75
|
+
if (typeof auth === "string" && auth.startsWith("Bearer ")) token = auth.slice(7);
|
|
76
|
+
if (!token) token = readCookie(req, accessCookie);
|
|
77
|
+
if (!token) {
|
|
78
|
+
reply.code(401).send({ success: false, error: { code: "TOKEN_INVALID", message: "Missing access token" } });
|
|
79
|
+
return reply;
|
|
80
|
+
}
|
|
81
|
+
try {
|
|
82
|
+
req.auth = await client.tokens.verify(token);
|
|
83
|
+
} catch (err) {
|
|
84
|
+
if (err instanceof IQAuthError && KNOWN_AUTH_ERRORS.has(err.code)) {
|
|
85
|
+
reply.code(401).send({ success: false, error: { code: err.code, message: err.message } });
|
|
86
|
+
return reply;
|
|
87
|
+
}
|
|
88
|
+
reply.code(500).send({ success: false, error: { code: "INTERNAL_ERROR", message: "Authentication failed" } });
|
|
89
|
+
return reply;
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
if (mountHelpers) {
|
|
93
|
+
fastify.post(`${mount}/callback`, async (req, reply) => {
|
|
94
|
+
const body = req.body || {};
|
|
95
|
+
applyResponse(reply, await handleCallback(helperConfig, {
|
|
96
|
+
code: body.code,
|
|
97
|
+
codeVerifier: body.codeVerifier,
|
|
98
|
+
redirectUri: body.redirectUri
|
|
99
|
+
}));
|
|
100
|
+
});
|
|
101
|
+
fastify.post(`${mount}/refresh`, async (req, reply) => {
|
|
102
|
+
const body = req.body || {};
|
|
103
|
+
const refreshToken = body.refreshToken || readCookie(req, refreshCookie);
|
|
104
|
+
applyResponse(reply, await handleRefresh(helperConfig, { refreshToken }));
|
|
105
|
+
});
|
|
106
|
+
fastify.post(`${mount}/signout`, async (req, reply) => {
|
|
107
|
+
const auth = req.headers?.authorization;
|
|
108
|
+
const accessToken = (typeof auth === "string" ? auth.replace(/^Bearer /i, "") : void 0) || readCookie(req, accessCookie);
|
|
109
|
+
applyResponse(reply, await handleSignout(helperConfig, { accessToken }));
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
fastify.decorate("iqauth", { client, issuer });
|
|
113
|
+
}
|
|
114
|
+
var fastify_default = iqAuth;
|
|
115
|
+
export {
|
|
116
|
+
fastify_default as default,
|
|
117
|
+
iqAuth
|
|
118
|
+
};
|
package/dist/hono.d.mts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { IQAuthHelperConfig } from './server/handlers.mjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @iqauth/sdk/hono — Hono adapter.
|
|
5
|
+
*
|
|
6
|
+
* import { Hono } from "hono";
|
|
7
|
+
* import { iqAuth } from "@iqauth/sdk/hono";
|
|
8
|
+
* const app = new Hono();
|
|
9
|
+
* app.use("*", iqAuth({ publishableKey, secretKey }));
|
|
10
|
+
*
|
|
11
|
+
* Returns a single middleware function. When `mountHelperRoutes` is true
|
|
12
|
+
* (the default), the middleware also serves the helper POST routes inline.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
interface IQAuthHonoOptions extends IQAuthHelperConfig {
|
|
16
|
+
mountPath?: string;
|
|
17
|
+
mountHelperRoutes?: boolean;
|
|
18
|
+
publicPaths?: string[] | ((path: string) => boolean);
|
|
19
|
+
}
|
|
20
|
+
declare function iqAuth(options: IQAuthHonoOptions): (c: any, next: () => Promise<void>) => Promise<any>;
|
|
21
|
+
|
|
22
|
+
export { type IQAuthHonoOptions, iqAuth };
|
package/dist/hono.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { IQAuthHelperConfig } from './server/handlers.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @iqauth/sdk/hono — Hono adapter.
|
|
5
|
+
*
|
|
6
|
+
* import { Hono } from "hono";
|
|
7
|
+
* import { iqAuth } from "@iqauth/sdk/hono";
|
|
8
|
+
* const app = new Hono();
|
|
9
|
+
* app.use("*", iqAuth({ publishableKey, secretKey }));
|
|
10
|
+
*
|
|
11
|
+
* Returns a single middleware function. When `mountHelperRoutes` is true
|
|
12
|
+
* (the default), the middleware also serves the helper POST routes inline.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
interface IQAuthHonoOptions extends IQAuthHelperConfig {
|
|
16
|
+
mountPath?: string;
|
|
17
|
+
mountHelperRoutes?: boolean;
|
|
18
|
+
publicPaths?: string[] | ((path: string) => boolean);
|
|
19
|
+
}
|
|
20
|
+
declare function iqAuth(options: IQAuthHonoOptions): (c: any, next: () => Promise<void>) => Promise<any>;
|
|
21
|
+
|
|
22
|
+
export { type IQAuthHonoOptions, iqAuth };
|