@iqauth/sdk 2.6.4 → 2.8.1
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 +173 -1
- package/dist/browser-session.d.mts +4 -4
- package/dist/browser-session.d.ts +4 -4
- package/dist/browser-session.js +212 -46
- package/dist/browser-session.mjs +3 -3
- package/dist/browser.d.mts +5 -5
- package/dist/browser.d.ts +5 -5
- package/dist/browser.js +293 -34
- package/dist/browser.mjs +5 -5
- package/dist/{chunk-BVV54LPI.mjs → chunk-25SSYDIP.mjs} +10 -4
- package/dist/{chunk-XAWYUPMO.mjs → chunk-4V7FKOTG.mjs} +242 -22
- package/dist/{chunk-6I6RM4MN.mjs → chunk-6PJRLRB4.mjs} +33 -3
- package/dist/{chunk-SL3KRS4W.mjs → chunk-CIJORODR.mjs} +23 -1
- package/dist/{chunk-LIZYFXH7.mjs → chunk-DFWHSDYQ.mjs} +1 -1
- package/dist/chunk-GLXSIGVS.mjs +66 -0
- package/dist/{chunk-DJIBN2N7.mjs → chunk-GN37E64I.mjs} +29 -7
- package/dist/{chunk-WQWBJSSS.mjs → chunk-HVHNYPDC.mjs} +6 -6
- package/dist/chunk-JRDVUWAL.mjs +46 -0
- package/dist/{chunk-UNYDG2L4.mjs → chunk-NUO2I65G.mjs} +56 -23
- package/dist/{chunk-5T7GHBX6.mjs → chunk-TLET552H.mjs} +36 -0
- package/dist/chunk-VYQ3ETCK.mjs +244 -0
- package/dist/{chunk-3JULWS6F.mjs → chunk-WCELYTJ3.mjs} +3 -3
- package/dist/chunk-WHT6WKTY.mjs +3180 -0
- package/dist/{chunk-MKKZULZR.mjs → chunk-WIFG74IK.mjs} +1 -1
- package/dist/chunk-WSH4SW7F.mjs +490 -0
- package/dist/{chunk-W3F4JYGP.mjs → chunk-ZLJPABB7.mjs} +139 -23
- package/dist/cli/index.js +2 -2
- package/dist/cli/index.mjs +2 -2
- package/dist/{client-BNQe3AgF.d.ts → client-D8L-PaWr.d.mts} +59 -6
- package/dist/{client-kYlJFgPv.d.mts → client-DkPL0EPZ.d.ts} +59 -6
- package/dist/{doctor-YYNHNMLD.mjs → doctor-JAFXWU3X.mjs} +2 -2
- package/dist/errors-Jl1Jtm-6.d.mts +107 -0
- package/dist/errors-Jl1Jtm-6.d.ts +107 -0
- package/dist/{express-CHpfa7D_.d.ts → express-Budysq4h.d.ts} +2 -2
- package/dist/{express-B6_1vBYZ.d.mts → express-DDTA3qV1.d.mts} +2 -2
- package/dist/express.d.mts +7 -6
- package/dist/express.d.ts +7 -6
- package/dist/express.js +563 -85
- package/dist/express.mjs +73 -34
- package/dist/fastify.d.mts +10 -0
- package/dist/fastify.d.ts +10 -0
- package/dist/fastify.js +589 -65
- package/dist/fastify.mjs +101 -11
- package/dist/hono.d.mts +10 -0
- package/dist/hono.d.ts +10 -0
- package/dist/hono.js +566 -65
- package/dist/hono.mjs +78 -11
- package/dist/index-Cko-d5po.d.mts +1848 -0
- package/dist/index-RNqwEcmY.d.ts +1848 -0
- package/dist/index.d.mts +56 -8
- package/dist/index.d.ts +56 -8
- package/dist/index.js +694 -75
- package/dist/index.mjs +30 -10
- package/dist/{keys-NLWFAOEM.mjs → keys-6Y776TG2.mjs} +2 -2
- package/dist/locales.d.mts +1 -1
- package/dist/locales.d.ts +1 -1
- package/dist/locales.js +36 -0
- package/dist/locales.mjs +1 -1
- package/dist/mobile.d.mts +77 -7
- package/dist/mobile.d.ts +77 -7
- package/dist/mobile.js +307 -46
- package/dist/mobile.mjs +98 -3
- package/dist/next.d.mts +10 -1
- package/dist/next.d.ts +10 -1
- package/dist/next.js +596 -205
- package/dist/next.mjs +83 -10
- package/dist/{provisioningBridge-88xjOS2n.d.mts → provisioningBridge-BXPMZCLe.d.ts} +30 -2
- package/dist/{provisioningBridge-DnTfzdZK.d.ts → provisioningBridge-IEycmsgb.d.mts} +30 -2
- package/dist/{publishableKey-BaR0HoAH.d.ts → publishableKey-f2kq-rKw.d.mts} +1 -1
- package/dist/{publishableKey-BaR0HoAH.d.mts → publishableKey-f2kq-rKw.d.ts} +1 -1
- package/dist/react-permissions.d.mts +52 -0
- package/dist/react-permissions.d.ts +52 -0
- package/dist/react-permissions.js +239 -0
- package/dist/react-permissions.mjs +98 -0
- package/dist/react.d.mts +9 -1624
- package/dist/react.d.ts +9 -1624
- package/dist/react.js +882 -73
- package/dist/react.mjs +71 -2631
- package/dist/{reverify-4UEJXUS6.mjs → reverify-C64QXKJO.mjs} +2 -2
- package/dist/server/handlers.d.mts +200 -4
- package/dist/server/handlers.d.ts +200 -4
- package/dist/server/handlers.js +530 -16
- package/dist/server/handlers.mjs +14 -3
- package/dist/server.d.mts +171 -8
- package/dist/server.d.ts +171 -8
- package/dist/server.js +579 -61
- package/dist/server.mjs +99 -12
- package/dist/service.d.mts +4 -4
- package/dist/service.d.ts +4 -4
- package/dist/service.js +212 -46
- package/dist/service.mjs +3 -3
- package/dist/{signIn-CiIBTJIh.d.mts → signIn-CReqfXsh.d.mts} +95 -3
- package/dist/{signIn-OCr88Zf8.d.ts → signIn-Cfa1GTpO.d.ts} +95 -3
- package/dist/{signIn-4OKLDEIH.mjs → signIn-SHBW6Z4T.mjs} +1 -1
- package/dist/test.mjs +3 -3
- package/dist/{tokens-DCyzzn8L.d.mts → tokens-9F6ETrzk.d.ts} +9 -2
- package/dist/{tokens-aHiGFr_E.d.ts → tokens-B06VtvUi.d.mts} +9 -2
- package/dist/{types-DZAflmmq.d.mts → types-Bn8O-OEd.d.mts} +164 -11
- package/dist/{types-DZAflmmq.d.ts → types-Bn8O-OEd.d.ts} +164 -11
- package/dist/{types-6bNdxesb.d.ts → types-DnU2LhXR.d.mts} +7 -1
- package/dist/{types-6bNdxesb.d.mts → types-DnU2LhXR.d.ts} +7 -1
- package/dist/webhooks.d.mts +113 -17
- package/dist/webhooks.d.ts +113 -17
- package/dist/webhooks.js +179 -15
- package/dist/webhooks.mjs +7 -1
- package/dist/ws.d.mts +2 -2
- package/dist/ws.d.ts +2 -2
- package/dist/ws.js +80 -30
- package/dist/ws.mjs +4 -4
- package/docs/error-handling.md +101 -0
- package/docs/guides/effective-permissions.md +171 -0
- package/docs/guides/invitations.md +65 -0
- package/package.json +19 -4
- package/dist/chunk-6TDJJER7.mjs +0 -217
- package/dist/chunk-UKZLOHZG.mjs +0 -83
- package/dist/errors-CDdl24MP.d.mts +0 -52
- package/dist/errors-CDdl24MP.d.ts +0 -52
package/dist/hono.mjs
CHANGED
|
@@ -1,29 +1,37 @@
|
|
|
1
|
+
import {
|
|
2
|
+
sanitizeReturnTo
|
|
3
|
+
} from "./chunk-JRDVUWAL.mjs";
|
|
1
4
|
import {
|
|
2
5
|
handleCallback,
|
|
3
6
|
handleRefresh,
|
|
4
7
|
handleSignout,
|
|
8
|
+
handleUserinfo,
|
|
5
9
|
serializeCookie
|
|
6
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-WSH4SW7F.mjs";
|
|
7
11
|
import {
|
|
8
12
|
assertPublishableKey
|
|
9
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-HVHNYPDC.mjs";
|
|
10
14
|
import {
|
|
11
15
|
IQAuthClient
|
|
12
|
-
} from "./chunk-
|
|
13
|
-
import "./chunk-
|
|
16
|
+
} from "./chunk-ZLJPABB7.mjs";
|
|
17
|
+
import "./chunk-NUO2I65G.mjs";
|
|
14
18
|
import {
|
|
15
19
|
IQAuthError
|
|
16
|
-
} from "./chunk-
|
|
20
|
+
} from "./chunk-6PJRLRB4.mjs";
|
|
17
21
|
import "./chunk-Y6FXYEAI.mjs";
|
|
18
22
|
|
|
19
23
|
// src/hono.ts
|
|
24
|
+
var PKCE_COOKIE = "iqauth_pkce";
|
|
20
25
|
var KNOWN_AUTH_ERRORS = /* @__PURE__ */ new Set([
|
|
21
26
|
"TOKEN_INVALID",
|
|
22
27
|
"TOKEN_EXPIRED",
|
|
23
28
|
"TOKEN_REVOKED",
|
|
24
29
|
"SESSION_EXPIRED",
|
|
25
30
|
"SESSION_INVALID",
|
|
26
|
-
"AUTH_REQUIRED"
|
|
31
|
+
"AUTH_REQUIRED",
|
|
32
|
+
// Task #127 — typed `IQAuthErrorCode` taxonomy.
|
|
33
|
+
"token_invalid",
|
|
34
|
+
"token_expired"
|
|
27
35
|
]);
|
|
28
36
|
function readCookieFromHeader(header, name) {
|
|
29
37
|
if (!header) return void 0;
|
|
@@ -45,6 +53,36 @@ function honoResponse(hr) {
|
|
|
45
53
|
for (const c of hr.cookies) headers.append("set-cookie", serializeCookie(c));
|
|
46
54
|
return new Response(JSON.stringify(hr.body), { status: hr.status, headers });
|
|
47
55
|
}
|
|
56
|
+
function honoCallbackResponse(hr, requestOrigin, returnToCookieValue, returnToCookieName) {
|
|
57
|
+
const returnTo = sanitizeReturnTo(
|
|
58
|
+
returnToCookieValue || hr.body?.returnTo,
|
|
59
|
+
{ currentOrigin: requestOrigin, fallback: "/" }
|
|
60
|
+
);
|
|
61
|
+
const headers = new Headers({ "Content-Type": "application/json" });
|
|
62
|
+
for (const c of hr.cookies) headers.append("set-cookie", serializeCookie(c));
|
|
63
|
+
if (hr.status < 400) {
|
|
64
|
+
headers.append("set-cookie", `${returnToCookieName}=; Path=/; Max-Age=0; SameSite=Lax`);
|
|
65
|
+
}
|
|
66
|
+
const body = { ...hr.body, returnTo };
|
|
67
|
+
return new Response(JSON.stringify(body), { status: hr.status, headers });
|
|
68
|
+
}
|
|
69
|
+
function honoCallbackRedirect(hr, requestOrigin, returnToCookieValue, cookieNames) {
|
|
70
|
+
const headers = new Headers();
|
|
71
|
+
for (const c of hr.cookies) headers.append("set-cookie", serializeCookie(c));
|
|
72
|
+
headers.append("set-cookie", `${cookieNames.state}=; Path=/; Max-Age=0; SameSite=Lax`);
|
|
73
|
+
headers.append("set-cookie", `${cookieNames.pkce}=; Path=/; Max-Age=0; SameSite=Lax`);
|
|
74
|
+
if (hr.status >= 400) {
|
|
75
|
+
headers.set("location", "/");
|
|
76
|
+
return new Response(null, { status: 302, headers });
|
|
77
|
+
}
|
|
78
|
+
const dest = sanitizeReturnTo(returnToCookieValue, {
|
|
79
|
+
currentOrigin: requestOrigin,
|
|
80
|
+
fallback: "/"
|
|
81
|
+
});
|
|
82
|
+
headers.append("set-cookie", `${cookieNames.returnTo}=; Path=/; Max-Age=0; SameSite=Lax`);
|
|
83
|
+
headers.set("location", dest);
|
|
84
|
+
return new Response(null, { status: 302, headers });
|
|
85
|
+
}
|
|
48
86
|
function iqAuth(options) {
|
|
49
87
|
const parsed = assertPublishableKey(options.publishableKey, { context: "@iqauth/sdk/hono" });
|
|
50
88
|
const issuer = (options.issuer ?? (parsed.iss.startsWith("http") ? parsed.iss : `https://${parsed.iss}`)).replace(/\/+$/, "");
|
|
@@ -52,6 +90,7 @@ function iqAuth(options) {
|
|
|
52
90
|
const client = new IQAuthClient({ baseUrl: issuer, environment: "server" });
|
|
53
91
|
const accessCookie = options.accessCookieName ?? "iqauth_at";
|
|
54
92
|
const refreshCookie = options.refreshCookieName ?? "iqauth_rt";
|
|
93
|
+
const returnToCookie = options.returnToCookieName ?? "iqauth_return_to";
|
|
55
94
|
const mount = (options.mountPath ?? "/api/iqauth").replace(/\/+$/, "");
|
|
56
95
|
const mountHelpers = options.mountHelperRoutes !== false;
|
|
57
96
|
const isPublic = (p) => {
|
|
@@ -62,24 +101,52 @@ function iqAuth(options) {
|
|
|
62
101
|
return async (c, next) => {
|
|
63
102
|
const url = new URL(c.req.url);
|
|
64
103
|
const path = url.pathname;
|
|
104
|
+
if (options.mountUserinfo && path === `${mount}/me` && c.req.method === "GET") {
|
|
105
|
+
const auth2 = c.req.header("authorization");
|
|
106
|
+
const accessToken = auth2 && auth2.replace(/^Bearer /i, "") || readCookieFromHeader(c.req.header("cookie"), accessCookie);
|
|
107
|
+
return honoResponse(await handleUserinfo(helperConfig, { accessToken, req: c.req }));
|
|
108
|
+
}
|
|
109
|
+
if (mountHelpers && path === `${mount}/callback` && c.req.method === "GET") {
|
|
110
|
+
const cookieHeader = c.req.header("cookie");
|
|
111
|
+
const stateCookie = helperConfig.stateCookieName ?? "iqauth_state";
|
|
112
|
+
const hr = await handleCallback(helperConfig, {
|
|
113
|
+
code: url.searchParams.get("code") ?? void 0,
|
|
114
|
+
codeVerifier: readCookieFromHeader(cookieHeader, PKCE_COOKIE),
|
|
115
|
+
redirectUri: `${url.origin}${url.pathname}`,
|
|
116
|
+
state: url.searchParams.get("state") ?? void 0,
|
|
117
|
+
expectedState: readCookieFromHeader(cookieHeader, stateCookie)
|
|
118
|
+
});
|
|
119
|
+
return honoCallbackRedirect(hr, url.origin, readCookieFromHeader(cookieHeader, returnToCookie), {
|
|
120
|
+
returnTo: returnToCookie,
|
|
121
|
+
state: stateCookie,
|
|
122
|
+
pkce: PKCE_COOKIE
|
|
123
|
+
});
|
|
124
|
+
}
|
|
65
125
|
if (mountHelpers && path.startsWith(mount + "/") && c.req.method === "POST") {
|
|
66
126
|
const body = await c.req.json().catch(() => ({}));
|
|
67
127
|
const cookieHeader = c.req.header("cookie");
|
|
68
128
|
if (path === `${mount}/callback`) {
|
|
69
|
-
|
|
129
|
+
const hr = await handleCallback(helperConfig, {
|
|
70
130
|
code: body.code,
|
|
71
131
|
codeVerifier: body.codeVerifier,
|
|
72
|
-
redirectUri: body.redirectUri
|
|
73
|
-
|
|
132
|
+
redirectUri: body.redirectUri,
|
|
133
|
+
// M-2: bind callback to this browser; handleCallback fails closed.
|
|
134
|
+
state: body.state,
|
|
135
|
+
expectedState: readCookieFromHeader(cookieHeader, helperConfig.stateCookieName ?? "iqauth_state")
|
|
136
|
+
});
|
|
137
|
+
return honoCallbackResponse(hr, url.origin, readCookieFromHeader(cookieHeader, returnToCookie), returnToCookie);
|
|
74
138
|
}
|
|
75
139
|
if (path === `${mount}/refresh`) {
|
|
76
140
|
const refreshToken = body.refreshToken || readCookieFromHeader(cookieHeader, refreshCookie);
|
|
77
|
-
|
|
141
|
+
const idempotencyToken = c.req.header("x-iqauth-idempotency") || body.idempotencyToken;
|
|
142
|
+
return honoResponse(await handleRefresh(helperConfig, { refreshToken, idempotencyToken }));
|
|
78
143
|
}
|
|
79
144
|
if (path === `${mount}/signout`) {
|
|
80
145
|
const auth2 = c.req.header("authorization");
|
|
81
146
|
const accessToken = auth2 && auth2.replace(/^Bearer /i, "") || readCookieFromHeader(cookieHeader, accessCookie);
|
|
82
|
-
|
|
147
|
+
const refreshToken = readCookieFromHeader(cookieHeader, refreshCookie);
|
|
148
|
+
const idempotencyToken = c.req.header("x-iqauth-idempotency");
|
|
149
|
+
return honoResponse(await handleSignout(helperConfig, { accessToken, refreshToken, idempotencyToken, ssoCookieHeader: cookieHeader }));
|
|
83
150
|
}
|
|
84
151
|
}
|
|
85
152
|
if (isPublic(path)) return next();
|