@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
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import {
|
|
2
|
+
loadEnv,
|
|
3
|
+
parseFlags
|
|
4
|
+
} from "./chunk-X3K3WOBR.mjs";
|
|
5
|
+
import "./chunk-Y6FXYEAI.mjs";
|
|
6
|
+
|
|
7
|
+
// src/cli/dev.ts
|
|
8
|
+
import { spawn } from "child_process";
|
|
9
|
+
import { dirname, resolve } from "path";
|
|
10
|
+
import { fileURLToPath } from "url";
|
|
11
|
+
import { existsSync } from "fs";
|
|
12
|
+
function getHere() {
|
|
13
|
+
const cjsDir = globalThis.__dirname;
|
|
14
|
+
if (typeof cjsDir === "string" && cjsDir.length > 0) return cjsDir;
|
|
15
|
+
try {
|
|
16
|
+
const url = import.meta?.url;
|
|
17
|
+
if (typeof url === "string" && url.length > 0) return dirname(fileURLToPath(url));
|
|
18
|
+
} catch {
|
|
19
|
+
}
|
|
20
|
+
const argv1 = process.argv[1];
|
|
21
|
+
if (argv1) return dirname(argv1);
|
|
22
|
+
return process.cwd();
|
|
23
|
+
}
|
|
24
|
+
async function runDev(argv) {
|
|
25
|
+
const { flags } = parseFlags(argv);
|
|
26
|
+
const env = await loadEnv(flags.get("env-file") || ".env");
|
|
27
|
+
const pk = env.IQAUTH_PUBLISHABLE_KEY;
|
|
28
|
+
if (!pk) {
|
|
29
|
+
console.error("\u2717 IQAUTH_PUBLISHABLE_KEY missing in .env. Run `iqauth init` first.");
|
|
30
|
+
process.exit(1);
|
|
31
|
+
}
|
|
32
|
+
const here = getHere();
|
|
33
|
+
let example = flags.get("example");
|
|
34
|
+
if (!example) {
|
|
35
|
+
const candidates = [
|
|
36
|
+
resolve(here, "..", "..", "..", "..", "examples", "react-vite"),
|
|
37
|
+
resolve(here, "..", "..", "examples", "react-vite"),
|
|
38
|
+
resolve(process.cwd(), "examples", "react-vite")
|
|
39
|
+
];
|
|
40
|
+
example = candidates.find((p) => existsSync(p)) || candidates[0];
|
|
41
|
+
}
|
|
42
|
+
console.log(`\u2192 Starting example at ${example}`);
|
|
43
|
+
console.log(` using IQAUTH_PUBLISHABLE_KEY=${pk.slice(0, 12)}\u2026`);
|
|
44
|
+
const child = spawn("npm", ["run", "dev"], {
|
|
45
|
+
cwd: example,
|
|
46
|
+
stdio: "inherit",
|
|
47
|
+
env: {
|
|
48
|
+
...process.env,
|
|
49
|
+
VITE_IQAUTH_PUBLISHABLE_KEY: pk
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
child.on("exit", (code) => process.exit(code ?? 0));
|
|
53
|
+
}
|
|
54
|
+
export {
|
|
55
|
+
runDev
|
|
56
|
+
};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import {
|
|
2
|
+
loadEnv,
|
|
3
|
+
parseFlags,
|
|
4
|
+
symbol
|
|
5
|
+
} from "./chunk-X3K3WOBR.mjs";
|
|
6
|
+
import {
|
|
7
|
+
parsePublishableKey
|
|
8
|
+
} from "./chunk-5WFR6Y33.mjs";
|
|
9
|
+
import "./chunk-Y6FXYEAI.mjs";
|
|
10
|
+
|
|
11
|
+
// src/cli/doctor.ts
|
|
12
|
+
async function runDoctor(argv) {
|
|
13
|
+
const { flags } = parseFlags(argv);
|
|
14
|
+
const envFile = flags.get("env-file") || ".env";
|
|
15
|
+
const env = await loadEnv(envFile);
|
|
16
|
+
const probes = [];
|
|
17
|
+
const pkRaw = env.IQAUTH_PUBLISHABLE_KEY;
|
|
18
|
+
const issuerEnv = env.IQAUTH_ISSUER;
|
|
19
|
+
const redirect = env.IQAUTH_REDIRECT_URI;
|
|
20
|
+
probes.push({
|
|
21
|
+
name: ".env present",
|
|
22
|
+
ok: !!pkRaw,
|
|
23
|
+
detail: pkRaw ? `${envFile} loaded; IQAUTH_PUBLISHABLE_KEY=${pkRaw.slice(0, 10)}\u2026` : `IQAUTH_PUBLISHABLE_KEY missing in ${envFile}`
|
|
24
|
+
});
|
|
25
|
+
const parsed = pkRaw ? parsePublishableKey(pkRaw) : null;
|
|
26
|
+
probes.push({
|
|
27
|
+
name: "publishable key parses",
|
|
28
|
+
ok: !!parsed,
|
|
29
|
+
detail: parsed ? `mode=${parsed.mode} appId=${parsed.appId} tenantId=${parsed.tenantId} kid=${parsed.kid}` : "key did not match pk_<test|live>_<base64> format"
|
|
30
|
+
});
|
|
31
|
+
const issuer = (issuerEnv || (parsed?.iss.startsWith("http") ? parsed.iss : parsed ? `https://${parsed.iss}` : "")).replace(/\/+$/, "");
|
|
32
|
+
if (issuer) {
|
|
33
|
+
try {
|
|
34
|
+
const res = await fetch(`${issuer}/.well-known/openid-configuration`);
|
|
35
|
+
probes.push({
|
|
36
|
+
name: "issuer reachable",
|
|
37
|
+
ok: res.ok,
|
|
38
|
+
detail: `${issuer}/.well-known/openid-configuration \u2192 ${res.status}`
|
|
39
|
+
});
|
|
40
|
+
} catch (err) {
|
|
41
|
+
probes.push({
|
|
42
|
+
name: "issuer reachable",
|
|
43
|
+
ok: false,
|
|
44
|
+
detail: `fetch failed: ${err.message}`
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
} else {
|
|
48
|
+
probes.push({ name: "issuer reachable", ok: false, detail: "issuer URL unknown (no IQAUTH_ISSUER and no key)" });
|
|
49
|
+
}
|
|
50
|
+
if (issuer) {
|
|
51
|
+
try {
|
|
52
|
+
const res = await fetch(`${issuer}/.well-known/jwks.json`);
|
|
53
|
+
const json = await res.json().catch(() => ({}));
|
|
54
|
+
const keys = json.keys;
|
|
55
|
+
probes.push({
|
|
56
|
+
name: "JWKS reachable",
|
|
57
|
+
ok: res.ok && Array.isArray(keys) && keys.length > 0,
|
|
58
|
+
detail: `${issuer}/.well-known/jwks.json \u2192 ${res.status} (${Array.isArray(keys) ? keys.length : 0} keys)`
|
|
59
|
+
});
|
|
60
|
+
} catch (err) {
|
|
61
|
+
probes.push({ name: "JWKS reachable", ok: false, detail: `fetch failed: ${err.message}` });
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if (redirect) {
|
|
65
|
+
try {
|
|
66
|
+
const res = await fetch(redirect, { method: "GET" });
|
|
67
|
+
probes.push({
|
|
68
|
+
name: "redirect URI reachable",
|
|
69
|
+
ok: res.status > 0 && res.status < 500,
|
|
70
|
+
detail: `${redirect} \u2192 ${res.status}`
|
|
71
|
+
});
|
|
72
|
+
} catch (err) {
|
|
73
|
+
probes.push({ name: "redirect URI reachable", ok: false, detail: `fetch failed: ${err.message}` });
|
|
74
|
+
}
|
|
75
|
+
} else {
|
|
76
|
+
probes.push({ name: "redirect URI reachable", ok: false, detail: "IQAUTH_REDIRECT_URI not set" });
|
|
77
|
+
}
|
|
78
|
+
let allOk = true;
|
|
79
|
+
for (const p of probes) {
|
|
80
|
+
console.log(`${symbol(p.ok)} ${p.name.padEnd(28)} ${p.detail}`);
|
|
81
|
+
if (!p.ok) allOk = false;
|
|
82
|
+
}
|
|
83
|
+
console.log("");
|
|
84
|
+
console.log(allOk ? "\u2705 All checks passed." : "\u274C One or more checks failed \u2014 see above.");
|
|
85
|
+
process.exit(allOk ? 0 : 1);
|
|
86
|
+
}
|
|
87
|
+
export {
|
|
88
|
+
runDoctor
|
|
89
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SOURCE REFS:
|
|
3
|
+
* - Route file: src/lib/response.ts (error envelope: { success: false, error: { code, message } })
|
|
4
|
+
* - All route files for error code extraction
|
|
5
|
+
* - Verified claims: N/A (error module)
|
|
6
|
+
* - Last verified: Phase 0 Research Summary
|
|
7
|
+
*/
|
|
8
|
+
declare class IQAuthError extends Error {
|
|
9
|
+
code: string;
|
|
10
|
+
status?: number;
|
|
11
|
+
raw?: unknown;
|
|
12
|
+
constructor(code: string, message: string, status?: number, raw?: unknown);
|
|
13
|
+
}
|
|
14
|
+
declare const ErrorCodes: {
|
|
15
|
+
readonly VALIDATION_ERROR: "VALIDATION_ERROR";
|
|
16
|
+
readonly INVALID_CREDENTIALS: "INVALID_CREDENTIALS";
|
|
17
|
+
readonly ACCOUNT_INACTIVE: "ACCOUNT_INACTIVE";
|
|
18
|
+
readonly ACCOUNT_LOCKED: "ACCOUNT_LOCKED";
|
|
19
|
+
readonly INSUFFICIENT_PERMISSIONS: "INSUFFICIENT_PERMISSIONS";
|
|
20
|
+
readonly TOKEN_INVALID: "TOKEN_INVALID";
|
|
21
|
+
readonly TOKEN_EXPIRED: "TOKEN_EXPIRED";
|
|
22
|
+
readonly TOKEN_REVOKED: "TOKEN_REVOKED";
|
|
23
|
+
readonly USER_INACTIVE: "USER_INACTIVE";
|
|
24
|
+
readonly INTERNAL_ERROR: "INTERNAL_ERROR";
|
|
25
|
+
readonly NOT_FOUND: "NOT_FOUND";
|
|
26
|
+
readonly SESSION_INVALID: "SESSION_INVALID";
|
|
27
|
+
readonly SESSION_EXPIRED: "SESSION_EXPIRED";
|
|
28
|
+
readonly REFRESH_TOKEN_REUSED: "REFRESH_TOKEN_REUSED";
|
|
29
|
+
readonly PASSWORD_EXPIRED: "PASSWORD_EXPIRED";
|
|
30
|
+
readonly PIN_EXPIRED: "PIN_EXPIRED";
|
|
31
|
+
readonly PASSWORD_POLICY_VIOLATION: "PASSWORD_POLICY_VIOLATION";
|
|
32
|
+
readonly MFA_INVALID_CODE: "MFA_INVALID_CODE";
|
|
33
|
+
readonly MFA_METHOD_UNAVAILABLE: "MFA_METHOD_UNAVAILABLE";
|
|
34
|
+
readonly MFA_RATE_LIMITED: "MFA_RATE_LIMITED";
|
|
35
|
+
readonly MFA_ENROLLMENT_REQUIRED: "MFA_ENROLLMENT_REQUIRED";
|
|
36
|
+
readonly API_KEY_REQUIRED: "API_KEY_REQUIRED";
|
|
37
|
+
readonly API_KEY_INVALID: "API_KEY_INVALID";
|
|
38
|
+
readonly AUTH_REQUIRED: "AUTH_REQUIRED";
|
|
39
|
+
readonly ALREADY_EXISTS: "ALREADY_EXISTS";
|
|
40
|
+
readonly FORBIDDEN: "FORBIDDEN";
|
|
41
|
+
readonly OAUTH_NOT_CONFIGURED: "OAUTH_NOT_CONFIGURED";
|
|
42
|
+
readonly UPLOAD_ERROR: "UPLOAD_ERROR";
|
|
43
|
+
readonly EMAIL_SERVICE_UNAVAILABLE: "EMAIL_SERVICE_UNAVAILABLE";
|
|
44
|
+
readonly INVALID_CODE: "INVALID_CODE";
|
|
45
|
+
readonly CODE_ALREADY_USED: "CODE_ALREADY_USED";
|
|
46
|
+
readonly CODE_EXPIRED: "CODE_EXPIRED";
|
|
47
|
+
readonly CODE_IP_MISMATCH: "CODE_IP_MISMATCH";
|
|
48
|
+
readonly UNKNOWN_PAYLOAD: "UNKNOWN_PAYLOAD";
|
|
49
|
+
};
|
|
50
|
+
type ErrorCode = (typeof ErrorCodes)[keyof typeof ErrorCodes];
|
|
51
|
+
|
|
52
|
+
export { ErrorCodes as E, IQAuthError as I, type ErrorCode as a };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SOURCE REFS:
|
|
3
|
+
* - Route file: src/lib/response.ts (error envelope: { success: false, error: { code, message } })
|
|
4
|
+
* - All route files for error code extraction
|
|
5
|
+
* - Verified claims: N/A (error module)
|
|
6
|
+
* - Last verified: Phase 0 Research Summary
|
|
7
|
+
*/
|
|
8
|
+
declare class IQAuthError extends Error {
|
|
9
|
+
code: string;
|
|
10
|
+
status?: number;
|
|
11
|
+
raw?: unknown;
|
|
12
|
+
constructor(code: string, message: string, status?: number, raw?: unknown);
|
|
13
|
+
}
|
|
14
|
+
declare const ErrorCodes: {
|
|
15
|
+
readonly VALIDATION_ERROR: "VALIDATION_ERROR";
|
|
16
|
+
readonly INVALID_CREDENTIALS: "INVALID_CREDENTIALS";
|
|
17
|
+
readonly ACCOUNT_INACTIVE: "ACCOUNT_INACTIVE";
|
|
18
|
+
readonly ACCOUNT_LOCKED: "ACCOUNT_LOCKED";
|
|
19
|
+
readonly INSUFFICIENT_PERMISSIONS: "INSUFFICIENT_PERMISSIONS";
|
|
20
|
+
readonly TOKEN_INVALID: "TOKEN_INVALID";
|
|
21
|
+
readonly TOKEN_EXPIRED: "TOKEN_EXPIRED";
|
|
22
|
+
readonly TOKEN_REVOKED: "TOKEN_REVOKED";
|
|
23
|
+
readonly USER_INACTIVE: "USER_INACTIVE";
|
|
24
|
+
readonly INTERNAL_ERROR: "INTERNAL_ERROR";
|
|
25
|
+
readonly NOT_FOUND: "NOT_FOUND";
|
|
26
|
+
readonly SESSION_INVALID: "SESSION_INVALID";
|
|
27
|
+
readonly SESSION_EXPIRED: "SESSION_EXPIRED";
|
|
28
|
+
readonly REFRESH_TOKEN_REUSED: "REFRESH_TOKEN_REUSED";
|
|
29
|
+
readonly PASSWORD_EXPIRED: "PASSWORD_EXPIRED";
|
|
30
|
+
readonly PIN_EXPIRED: "PIN_EXPIRED";
|
|
31
|
+
readonly PASSWORD_POLICY_VIOLATION: "PASSWORD_POLICY_VIOLATION";
|
|
32
|
+
readonly MFA_INVALID_CODE: "MFA_INVALID_CODE";
|
|
33
|
+
readonly MFA_METHOD_UNAVAILABLE: "MFA_METHOD_UNAVAILABLE";
|
|
34
|
+
readonly MFA_RATE_LIMITED: "MFA_RATE_LIMITED";
|
|
35
|
+
readonly MFA_ENROLLMENT_REQUIRED: "MFA_ENROLLMENT_REQUIRED";
|
|
36
|
+
readonly API_KEY_REQUIRED: "API_KEY_REQUIRED";
|
|
37
|
+
readonly API_KEY_INVALID: "API_KEY_INVALID";
|
|
38
|
+
readonly AUTH_REQUIRED: "AUTH_REQUIRED";
|
|
39
|
+
readonly ALREADY_EXISTS: "ALREADY_EXISTS";
|
|
40
|
+
readonly FORBIDDEN: "FORBIDDEN";
|
|
41
|
+
readonly OAUTH_NOT_CONFIGURED: "OAUTH_NOT_CONFIGURED";
|
|
42
|
+
readonly UPLOAD_ERROR: "UPLOAD_ERROR";
|
|
43
|
+
readonly EMAIL_SERVICE_UNAVAILABLE: "EMAIL_SERVICE_UNAVAILABLE";
|
|
44
|
+
readonly INVALID_CODE: "INVALID_CODE";
|
|
45
|
+
readonly CODE_ALREADY_USED: "CODE_ALREADY_USED";
|
|
46
|
+
readonly CODE_EXPIRED: "CODE_EXPIRED";
|
|
47
|
+
readonly CODE_IP_MISMATCH: "CODE_IP_MISMATCH";
|
|
48
|
+
readonly UNKNOWN_PAYLOAD: "UNKNOWN_PAYLOAD";
|
|
49
|
+
};
|
|
50
|
+
type ErrorCode = (typeof ErrorCodes)[keyof typeof ErrorCodes];
|
|
51
|
+
|
|
52
|
+
export { ErrorCodes as E, IQAuthError as I, type ErrorCode as a };
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { I as IQAuthClient } from './client-CggvJmmm.js';
|
|
2
|
+
import { J as JwtClaims, N as ExpressMiddlewareOptions, Q as IQAuthRequestLike, R as IQAuthResponseLike, V as IQAuthNextFunction } from './types-Cxl3bQHt.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* SOURCE REFS:
|
|
6
|
+
* - Route file: src/middleware/requireAuth.ts (Bearer token verification, req.user assignment)
|
|
7
|
+
* - Route file: src/types/index.ts (JwtPayload interface for req.user/req.auth)
|
|
8
|
+
* - Verified claims: sub, email, name, tenantId, vendorId, roles, entitlements, sessionId, jti, iss, aud, exp, iat
|
|
9
|
+
* - Last verified: Phase 0 Research Summary
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
declare global {
|
|
13
|
+
namespace Express {
|
|
14
|
+
interface Request {
|
|
15
|
+
auth?: JwtClaims;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Default cookie names looked at by the cookie-aware path. Phase B's browser
|
|
21
|
+
* SDK writes the refresh token to `iqauth_rt`. The optional `iqauth_at`
|
|
22
|
+
* cookie is set by the helper routes when the app's backend wants to keep
|
|
23
|
+
* the access token in an httpOnly cookie.
|
|
24
|
+
*/
|
|
25
|
+
declare const DEFAULT_ACCESS_COOKIE = "iqauth_at";
|
|
26
|
+
declare const DEFAULT_REFRESH_COOKIE = "iqauth_rt";
|
|
27
|
+
interface CookieAwareMiddlewareOptions extends ExpressMiddlewareOptions {
|
|
28
|
+
/** Cookie name carrying an httpOnly access token. Defaults to `iqauth_at`. */
|
|
29
|
+
accessCookieName?: string;
|
|
30
|
+
/** Cookie name carrying the refresh token. Defaults to `iqauth_rt`. */
|
|
31
|
+
refreshCookieName?: string;
|
|
32
|
+
/**
|
|
33
|
+
* If true (default), accept tokens from either Authorization header or the
|
|
34
|
+
* configured access cookie. When false, only the bearer header is checked.
|
|
35
|
+
*/
|
|
36
|
+
cookieAware?: boolean;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Express middleware that verifies access tokens via the SDK's token verifier.
|
|
40
|
+
*
|
|
41
|
+
* - Extracts a Bearer token from `Authorization` OR the configured access
|
|
42
|
+
* cookie (`iqauth_at` by default). The cookie path enables full-stack apps
|
|
43
|
+
* to keep the access token httpOnly and out of browser JS.
|
|
44
|
+
* - Verifies it using RS256 via JWKS (client.tokens.verify)
|
|
45
|
+
* - Attaches decoded claims to `req.auth`
|
|
46
|
+
* - Returns 401 for missing/invalid/expired tokens
|
|
47
|
+
* - Returns 403 for insufficient roles/entitlements
|
|
48
|
+
* - Maps unexpected errors to a generic 500 INTERNAL_ERROR response without
|
|
49
|
+
* leaking implementation details to the client
|
|
50
|
+
*
|
|
51
|
+
* @remarks Uses client.tokens.verify() which fetches JWKS from /.well-known/jwks.json
|
|
52
|
+
*/
|
|
53
|
+
interface PublishableKeyMiddlewareOptions extends CookieAwareMiddlewareOptions {
|
|
54
|
+
/** A `pk_test_…` / `pk_live_…` publishable key. Issuer + JWKS are auto-discovered from it. */
|
|
55
|
+
publishableKey: string;
|
|
56
|
+
/** Optional override for the issuer derived from the publishable key. */
|
|
57
|
+
issuer?: string;
|
|
58
|
+
}
|
|
59
|
+
declare function iqAuthMiddleware(clientOrOptions: IQAuthClient | PublishableKeyMiddlewareOptions, options?: CookieAwareMiddlewareOptions): (req: IQAuthRequestLike, res: IQAuthResponseLike, next: IQAuthNextFunction) => Promise<void>;
|
|
60
|
+
|
|
61
|
+
export { type CookieAwareMiddlewareOptions as C, DEFAULT_ACCESS_COOKIE as D, DEFAULT_REFRESH_COOKIE as a, iqAuthMiddleware as i };
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { I as IQAuthClient } from './client-C1DXfB8Z.mjs';
|
|
2
|
+
import { J as JwtClaims, N as ExpressMiddlewareOptions, Q as IQAuthRequestLike, R as IQAuthResponseLike, V as IQAuthNextFunction } from './types-Cxl3bQHt.mjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* SOURCE REFS:
|
|
6
|
+
* - Route file: src/middleware/requireAuth.ts (Bearer token verification, req.user assignment)
|
|
7
|
+
* - Route file: src/types/index.ts (JwtPayload interface for req.user/req.auth)
|
|
8
|
+
* - Verified claims: sub, email, name, tenantId, vendorId, roles, entitlements, sessionId, jti, iss, aud, exp, iat
|
|
9
|
+
* - Last verified: Phase 0 Research Summary
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
declare global {
|
|
13
|
+
namespace Express {
|
|
14
|
+
interface Request {
|
|
15
|
+
auth?: JwtClaims;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Default cookie names looked at by the cookie-aware path. Phase B's browser
|
|
21
|
+
* SDK writes the refresh token to `iqauth_rt`. The optional `iqauth_at`
|
|
22
|
+
* cookie is set by the helper routes when the app's backend wants to keep
|
|
23
|
+
* the access token in an httpOnly cookie.
|
|
24
|
+
*/
|
|
25
|
+
declare const DEFAULT_ACCESS_COOKIE = "iqauth_at";
|
|
26
|
+
declare const DEFAULT_REFRESH_COOKIE = "iqauth_rt";
|
|
27
|
+
interface CookieAwareMiddlewareOptions extends ExpressMiddlewareOptions {
|
|
28
|
+
/** Cookie name carrying an httpOnly access token. Defaults to `iqauth_at`. */
|
|
29
|
+
accessCookieName?: string;
|
|
30
|
+
/** Cookie name carrying the refresh token. Defaults to `iqauth_rt`. */
|
|
31
|
+
refreshCookieName?: string;
|
|
32
|
+
/**
|
|
33
|
+
* If true (default), accept tokens from either Authorization header or the
|
|
34
|
+
* configured access cookie. When false, only the bearer header is checked.
|
|
35
|
+
*/
|
|
36
|
+
cookieAware?: boolean;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Express middleware that verifies access tokens via the SDK's token verifier.
|
|
40
|
+
*
|
|
41
|
+
* - Extracts a Bearer token from `Authorization` OR the configured access
|
|
42
|
+
* cookie (`iqauth_at` by default). The cookie path enables full-stack apps
|
|
43
|
+
* to keep the access token httpOnly and out of browser JS.
|
|
44
|
+
* - Verifies it using RS256 via JWKS (client.tokens.verify)
|
|
45
|
+
* - Attaches decoded claims to `req.auth`
|
|
46
|
+
* - Returns 401 for missing/invalid/expired tokens
|
|
47
|
+
* - Returns 403 for insufficient roles/entitlements
|
|
48
|
+
* - Maps unexpected errors to a generic 500 INTERNAL_ERROR response without
|
|
49
|
+
* leaking implementation details to the client
|
|
50
|
+
*
|
|
51
|
+
* @remarks Uses client.tokens.verify() which fetches JWKS from /.well-known/jwks.json
|
|
52
|
+
*/
|
|
53
|
+
interface PublishableKeyMiddlewareOptions extends CookieAwareMiddlewareOptions {
|
|
54
|
+
/** A `pk_test_…` / `pk_live_…` publishable key. Issuer + JWKS are auto-discovered from it. */
|
|
55
|
+
publishableKey: string;
|
|
56
|
+
/** Optional override for the issuer derived from the publishable key. */
|
|
57
|
+
issuer?: string;
|
|
58
|
+
}
|
|
59
|
+
declare function iqAuthMiddleware(clientOrOptions: IQAuthClient | PublishableKeyMiddlewareOptions, options?: CookieAwareMiddlewareOptions): (req: IQAuthRequestLike, res: IQAuthResponseLike, next: IQAuthNextFunction) => Promise<void>;
|
|
60
|
+
|
|
61
|
+
export { type CookieAwareMiddlewareOptions as C, DEFAULT_ACCESS_COOKIE as D, DEFAULT_REFRESH_COOKIE as a, iqAuthMiddleware as i };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { I as IQAuthClient } from './client-C1DXfB8Z.mjs';
|
|
2
|
+
import { C as CookieAwareMiddlewareOptions } from './express-CpfyYTmw.mjs';
|
|
3
|
+
export { i as iqAuthMiddleware } from './express-CpfyYTmw.mjs';
|
|
4
|
+
import { IQAuthHelperConfig } from './server/handlers.mjs';
|
|
5
|
+
import { Q as IQAuthRequestLike, R as IQAuthResponseLike, V as IQAuthNextFunction } from './types-Cxl3bQHt.mjs';
|
|
6
|
+
export { E as ErrorCodes, I as IQAuthError } from './errors-CDdl24MP.mjs';
|
|
7
|
+
import 'jsonwebtoken';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @iqauth/sdk/express — drop-in Express adapter.
|
|
11
|
+
*
|
|
12
|
+
* Use this from a full-stack Express app to:
|
|
13
|
+
* - verify access tokens (Authorization Bearer or `iqauth_at` cookie),
|
|
14
|
+
* - auto-mount /api/iqauth/{callback,refresh,signout} so the browser SDK
|
|
15
|
+
* can rotate cookies through your own domain (httpOnly).
|
|
16
|
+
*
|
|
17
|
+
* Five-line shape:
|
|
18
|
+
* import express from "express";
|
|
19
|
+
* import { iqAuth } from "@iqauth/sdk/express";
|
|
20
|
+
* const app = express();
|
|
21
|
+
* app.use(express.json());
|
|
22
|
+
* app.use(iqAuth({ publishableKey: process.env.IQAUTH_PUBLISHABLE_KEY!, secretKey: process.env.IQAUTH_SECRET_KEY! }));
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
interface IQAuthExpressOptions extends IQAuthHelperConfig, CookieAwareMiddlewareOptions {
|
|
26
|
+
/** Mount path prefix for the auto-mounted helper routes. */
|
|
27
|
+
mountPath?: string;
|
|
28
|
+
/** Set to false to skip mounting helper routes (verify-only mode). */
|
|
29
|
+
mountHelperRoutes?: boolean;
|
|
30
|
+
}
|
|
31
|
+
interface ExpressLikeApp {
|
|
32
|
+
post(path: string, handler: (req: any, res: any) => unknown | Promise<unknown>): unknown;
|
|
33
|
+
use?: (...args: unknown[]) => unknown;
|
|
34
|
+
}
|
|
35
|
+
interface ExpressLikeRouter {
|
|
36
|
+
post(path: string, handler: (req: any, res: any) => unknown | Promise<unknown>): unknown;
|
|
37
|
+
}
|
|
38
|
+
declare function iqAuth(options: IQAuthExpressOptions): {
|
|
39
|
+
(req: IQAuthRequestLike, res: IQAuthResponseLike, next: IQAuthNextFunction): unknown;
|
|
40
|
+
middleware: (req: IQAuthRequestLike, res: IQAuthResponseLike, next: IQAuthNextFunction) => void | Promise<void>;
|
|
41
|
+
attachHelpers: (app: ExpressLikeApp | ExpressLikeRouter) => void;
|
|
42
|
+
client: IQAuthClient;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export { CookieAwareMiddlewareOptions, type IQAuthExpressOptions, iqAuth };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { I as IQAuthClient } from './client-CggvJmmm.js';
|
|
2
|
+
import { C as CookieAwareMiddlewareOptions } from './express-BKAXB5Nl.js';
|
|
3
|
+
export { i as iqAuthMiddleware } from './express-BKAXB5Nl.js';
|
|
4
|
+
import { IQAuthHelperConfig } from './server/handlers.js';
|
|
5
|
+
import { Q as IQAuthRequestLike, R as IQAuthResponseLike, V as IQAuthNextFunction } from './types-Cxl3bQHt.js';
|
|
6
|
+
export { E as ErrorCodes, I as IQAuthError } from './errors-CDdl24MP.js';
|
|
7
|
+
import 'jsonwebtoken';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @iqauth/sdk/express — drop-in Express adapter.
|
|
11
|
+
*
|
|
12
|
+
* Use this from a full-stack Express app to:
|
|
13
|
+
* - verify access tokens (Authorization Bearer or `iqauth_at` cookie),
|
|
14
|
+
* - auto-mount /api/iqauth/{callback,refresh,signout} so the browser SDK
|
|
15
|
+
* can rotate cookies through your own domain (httpOnly).
|
|
16
|
+
*
|
|
17
|
+
* Five-line shape:
|
|
18
|
+
* import express from "express";
|
|
19
|
+
* import { iqAuth } from "@iqauth/sdk/express";
|
|
20
|
+
* const app = express();
|
|
21
|
+
* app.use(express.json());
|
|
22
|
+
* app.use(iqAuth({ publishableKey: process.env.IQAUTH_PUBLISHABLE_KEY!, secretKey: process.env.IQAUTH_SECRET_KEY! }));
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
interface IQAuthExpressOptions extends IQAuthHelperConfig, CookieAwareMiddlewareOptions {
|
|
26
|
+
/** Mount path prefix for the auto-mounted helper routes. */
|
|
27
|
+
mountPath?: string;
|
|
28
|
+
/** Set to false to skip mounting helper routes (verify-only mode). */
|
|
29
|
+
mountHelperRoutes?: boolean;
|
|
30
|
+
}
|
|
31
|
+
interface ExpressLikeApp {
|
|
32
|
+
post(path: string, handler: (req: any, res: any) => unknown | Promise<unknown>): unknown;
|
|
33
|
+
use?: (...args: unknown[]) => unknown;
|
|
34
|
+
}
|
|
35
|
+
interface ExpressLikeRouter {
|
|
36
|
+
post(path: string, handler: (req: any, res: any) => unknown | Promise<unknown>): unknown;
|
|
37
|
+
}
|
|
38
|
+
declare function iqAuth(options: IQAuthExpressOptions): {
|
|
39
|
+
(req: IQAuthRequestLike, res: IQAuthResponseLike, next: IQAuthNextFunction): unknown;
|
|
40
|
+
middleware: (req: IQAuthRequestLike, res: IQAuthResponseLike, next: IQAuthNextFunction) => void | Promise<void>;
|
|
41
|
+
attachHelpers: (app: ExpressLikeApp | ExpressLikeRouter) => void;
|
|
42
|
+
client: IQAuthClient;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export { CookieAwareMiddlewareOptions, type IQAuthExpressOptions, iqAuth };
|