@ouim/logto-authkit 0.3.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 +823 -0
- package/dist/bundler-config.cjs +1 -0
- package/dist/bundler-config.d.ts +81 -0
- package/dist/bundler-config.js +31 -0
- package/dist/callback.d.ts +3 -0
- package/dist/components/signin-button.d.ts +53 -0
- package/dist/components/ui/alert.d.ts +8 -0
- package/dist/components/ui/avatar.d.ts +6 -0
- package/dist/components/ui/badge.d.ts +9 -0
- package/dist/components/ui/button.d.ts +11 -0
- package/dist/components/ui/card.d.ts +8 -0
- package/dist/components/ui/dialog.d.ts +19 -0
- package/dist/components/ui/dropdown-menu.d.ts +17 -0
- package/dist/components/ui/loading-spinner.d.ts +2 -0
- package/dist/components/ui/skeleton.d.ts +2 -0
- package/dist/components/ui/tooltip.d.ts +7 -0
- package/dist/components/utils/utils.d.ts +2 -0
- package/dist/context.d.ts +57 -0
- package/dist/index.cjs +129 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +9583 -0
- package/dist/navigation.d.ts +10 -0
- package/dist/server/authorization.d.ts +53 -0
- package/dist/server/csrf.d.ts +247 -0
- package/dist/server/index.cjs +1 -0
- package/dist/server/index.d.ts +4 -0
- package/dist/server/index.js +431 -0
- package/dist/server/types.d.ts +62 -0
- package/dist/server/verify-auth.d.ts +296 -0
- package/dist/signin.d.ts +42 -0
- package/dist/types.d.ts +81 -0
- package/dist/useAuth.d.ts +55 -0
- package/dist/usePermission.d.ts +9 -0
- package/dist/user-center.d.ts +49 -0
- package/dist/utils.d.ts +169 -0
- package/package.json +111 -0
|
@@ -0,0 +1,431 @@
|
|
|
1
|
+
import { importJWK as G, jwtVerify as U } from "jose";
|
|
2
|
+
import F from "cookie-parser";
|
|
3
|
+
import { randomUUID as D } from "node:crypto";
|
|
4
|
+
function b(e) {
|
|
5
|
+
return typeof e == "object" && e !== null && "get" in e && typeof e.get == "function";
|
|
6
|
+
}
|
|
7
|
+
function x(e) {
|
|
8
|
+
return typeof e == "object" && e !== null;
|
|
9
|
+
}
|
|
10
|
+
function H(e) {
|
|
11
|
+
return typeof e == "object" && e !== null;
|
|
12
|
+
}
|
|
13
|
+
const f = /* @__PURE__ */ new Map(), L = 300 * 1e3;
|
|
14
|
+
function K(e) {
|
|
15
|
+
return `${e.replace(/\/+$/, "")}/oidc`;
|
|
16
|
+
}
|
|
17
|
+
function l(e, t = "guest_logto_authtoken") {
|
|
18
|
+
if (b(e)) {
|
|
19
|
+
const n = e.get(t);
|
|
20
|
+
return (n == null ? void 0 : n.value) ?? void 0;
|
|
21
|
+
} else if (x(e))
|
|
22
|
+
return e[t] ?? void 0;
|
|
23
|
+
}
|
|
24
|
+
function m(e, t = "logto_authtoken") {
|
|
25
|
+
if (b(e)) {
|
|
26
|
+
const n = e.get(t);
|
|
27
|
+
return (n == null ? void 0 : n.value) || null;
|
|
28
|
+
} else if (x(e))
|
|
29
|
+
return e[t] || null;
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
function p(e) {
|
|
33
|
+
if (!H(e))
|
|
34
|
+
return null;
|
|
35
|
+
const t = typeof e.get == "function" ? e.get("authorization") : e.authorization;
|
|
36
|
+
return typeof t == "string" && t.startsWith("Bearer ") ? t.slice(7) : null;
|
|
37
|
+
}
|
|
38
|
+
function z(e) {
|
|
39
|
+
let t = e.replace(/-/g, "+").replace(/_/g, "/");
|
|
40
|
+
const n = t.length % 4;
|
|
41
|
+
return n && (t += "=".repeat(4 - n)), typeof atob < "u" ? atob(t) : Buffer.from(t, "base64").toString();
|
|
42
|
+
}
|
|
43
|
+
async function $(e) {
|
|
44
|
+
const { logtoUrl: t, jwksCacheTtlMs: n = L, skipJwksCache: o = !1 } = e, r = k(t), i = Date.now(), s = f.get(r);
|
|
45
|
+
if (!o && s && s.expires > i)
|
|
46
|
+
return s.keys;
|
|
47
|
+
try {
|
|
48
|
+
const a = await fetch(r);
|
|
49
|
+
if (!a.ok)
|
|
50
|
+
throw new Error(`Failed to fetch JWKS: ${a.status} ${a.statusText}`);
|
|
51
|
+
const c = (await a.json()).keys || [];
|
|
52
|
+
return !o && n > 0 ? f.set(r, {
|
|
53
|
+
keys: c,
|
|
54
|
+
expires: i + n
|
|
55
|
+
}) : f.delete(r), c;
|
|
56
|
+
} catch (a) {
|
|
57
|
+
throw new Error(`Failed to fetch JWKS from ${r}: ${a instanceof Error ? a.message : "Unknown error"}`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
function k(e) {
|
|
61
|
+
return `${K(e)}/jwks`;
|
|
62
|
+
}
|
|
63
|
+
function ne(e) {
|
|
64
|
+
f.delete(k(e));
|
|
65
|
+
}
|
|
66
|
+
function oe() {
|
|
67
|
+
f.clear();
|
|
68
|
+
}
|
|
69
|
+
function B(e, t, n) {
|
|
70
|
+
if (!e || e.length === 0)
|
|
71
|
+
throw new Error("No keys found in JWKS");
|
|
72
|
+
if (t) {
|
|
73
|
+
const r = e.find((i) => i.kid === t);
|
|
74
|
+
if (r) return r;
|
|
75
|
+
throw new Error(`Key with kid "${t}" not found in JWKS`);
|
|
76
|
+
}
|
|
77
|
+
if (n) {
|
|
78
|
+
const r = e.find((i) => i.alg === n);
|
|
79
|
+
if (r) return r;
|
|
80
|
+
}
|
|
81
|
+
const o = e.find((r) => r.kty === "RSA" && (r.use === "sig" || !r.use));
|
|
82
|
+
return o || e[0];
|
|
83
|
+
}
|
|
84
|
+
function O(e, t) {
|
|
85
|
+
const { logtoUrl: n, audience: o, requiredScope: r } = t, i = typeof e.exp == "number" ? e.exp : void 0, s = typeof e.nbf == "number" ? e.nbf : void 0, a = K(n);
|
|
86
|
+
if (e.iss !== a)
|
|
87
|
+
throw new Error(`Invalid issuer. Expected: ${a}, Got: ${e.iss}`);
|
|
88
|
+
if (o) {
|
|
89
|
+
const c = e.aud, d = Array.isArray(o) ? o : [o];
|
|
90
|
+
if (!(Array.isArray(c) ? c : c !== void 0 ? [c] : []).some((y) => d.includes(y)))
|
|
91
|
+
throw new Error(
|
|
92
|
+
`Invalid audience. Expected one of: ${JSON.stringify(d)}, Got: ${Array.isArray(c) ? JSON.stringify(c) : c}`
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
const u = Math.floor(Date.now() / 1e3);
|
|
96
|
+
if (i !== void 0 && i < u)
|
|
97
|
+
throw new Error("Token has expired");
|
|
98
|
+
if (s !== void 0 && s > u)
|
|
99
|
+
throw new Error("Token is not yet valid");
|
|
100
|
+
if (r && (!e.scope || !e.scope.includes(r)))
|
|
101
|
+
throw new Error(`Missing required scope: ${r}`);
|
|
102
|
+
}
|
|
103
|
+
function P(e) {
|
|
104
|
+
if (typeof e != "object" || e === null)
|
|
105
|
+
throw new Error("JWT payload is missing or not an object");
|
|
106
|
+
const t = e;
|
|
107
|
+
if (typeof t.sub != "string" || t.sub.trim() === "")
|
|
108
|
+
throw new Error('JWT payload is missing required field "sub" (user ID)');
|
|
109
|
+
if (typeof t.iss != "string" || t.iss.trim() === "")
|
|
110
|
+
throw new Error('JWT payload is missing required field "iss" (issuer)');
|
|
111
|
+
if (t.exp !== void 0 && typeof t.exp != "number")
|
|
112
|
+
throw new Error('JWT payload field "exp" must be a number');
|
|
113
|
+
if (t.nbf !== void 0 && typeof t.nbf != "number")
|
|
114
|
+
throw new Error('JWT payload field "nbf" must be a number');
|
|
115
|
+
if (t.aud !== void 0) {
|
|
116
|
+
const n = t.aud;
|
|
117
|
+
if (!(typeof n == "string" || Array.isArray(n) && n.every((r) => typeof r == "string")))
|
|
118
|
+
throw new Error('JWT payload field "aud" must be a string or string[]');
|
|
119
|
+
}
|
|
120
|
+
if (t.scope !== void 0 && typeof t.scope != "string")
|
|
121
|
+
throw new Error('JWT payload field "scope" must be a string');
|
|
122
|
+
}
|
|
123
|
+
function V(e) {
|
|
124
|
+
if (!(e instanceof Error)) return !1;
|
|
125
|
+
if (e.message.startsWith("No keys found in JWKS") || e.message.startsWith("Key with kid"))
|
|
126
|
+
return !0;
|
|
127
|
+
const t = e.code;
|
|
128
|
+
return t === "ERR_JWKS_NO_MATCHING_KEY" || t === "ERR_JWS_SIGNATURE_VERIFICATION_FAILED";
|
|
129
|
+
}
|
|
130
|
+
async function C(e, t, n, o) {
|
|
131
|
+
const r = typeof t.kid == "string" ? t.kid : void 0, i = typeof t.alg == "string" ? t.alg : void 0, s = B(n, r, i), a = await G(s, i || "RS256"), { payload: u } = await U(e, a);
|
|
132
|
+
return P(u), O(u, o), {
|
|
133
|
+
userId: u.sub,
|
|
134
|
+
isAuthenticated: !0,
|
|
135
|
+
payload: u,
|
|
136
|
+
isGuest: !1
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
async function A(e, t) {
|
|
140
|
+
const { logtoUrl: n } = t, o = k(n);
|
|
141
|
+
try {
|
|
142
|
+
const [r] = e.split(".");
|
|
143
|
+
if (!r)
|
|
144
|
+
throw new Error("Invalid JWT format");
|
|
145
|
+
const i = z(r), s = JSON.parse(i), a = await $(t);
|
|
146
|
+
try {
|
|
147
|
+
return await C(e, s, a, t);
|
|
148
|
+
} catch (u) {
|
|
149
|
+
if (!V(u))
|
|
150
|
+
throw u;
|
|
151
|
+
console.warn("[verifyLogtoToken] Key/signature error — invalidating JWKS cache and retrying with fresh keys"), f.delete(o);
|
|
152
|
+
const c = await $(t);
|
|
153
|
+
return await C(e, s, c, t);
|
|
154
|
+
}
|
|
155
|
+
} catch (r) {
|
|
156
|
+
throw new Error(`Token verification failed: ${r instanceof Error ? r.message : "Unknown error"}`);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
function ie(e) {
|
|
160
|
+
const t = F(), n = async (o, r, i) => {
|
|
161
|
+
try {
|
|
162
|
+
let s = m(o.cookies, e.cookieName);
|
|
163
|
+
if (s || (s = p(o.headers)), !s) {
|
|
164
|
+
if (e.allowGuest) {
|
|
165
|
+
const u = l(o.cookies);
|
|
166
|
+
return o.auth = {
|
|
167
|
+
userId: null,
|
|
168
|
+
isAuthenticated: !1,
|
|
169
|
+
payload: null,
|
|
170
|
+
isGuest: !0,
|
|
171
|
+
guestId: u
|
|
172
|
+
}, i();
|
|
173
|
+
}
|
|
174
|
+
return r.status(401).json({
|
|
175
|
+
error: "Authentication required",
|
|
176
|
+
message: "No token found in cookies or Authorization header"
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
const a = await A(s, e);
|
|
180
|
+
return o.auth = a, i();
|
|
181
|
+
} catch (s) {
|
|
182
|
+
if (e.allowGuest) {
|
|
183
|
+
const a = l(o.cookies);
|
|
184
|
+
return o.auth = {
|
|
185
|
+
userId: null,
|
|
186
|
+
isAuthenticated: !1,
|
|
187
|
+
payload: null,
|
|
188
|
+
isGuest: !0,
|
|
189
|
+
guestId: a || void 0
|
|
190
|
+
}, i();
|
|
191
|
+
}
|
|
192
|
+
return r.status(401).json({
|
|
193
|
+
error: "Authentication failed",
|
|
194
|
+
message: s instanceof Error ? s.message : "Unknown error"
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
return async (o, r, i) => {
|
|
199
|
+
o.cookies ? await n(o, r, i) : t(o, r, async (s) => {
|
|
200
|
+
if (s)
|
|
201
|
+
return i(s);
|
|
202
|
+
await n(o, r, i);
|
|
203
|
+
});
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
async function se(e, t) {
|
|
207
|
+
try {
|
|
208
|
+
let n = m(e.cookies, t.cookieName);
|
|
209
|
+
return n || (n = p(e.headers)), n ? {
|
|
210
|
+
success: !0,
|
|
211
|
+
auth: await A(n, t)
|
|
212
|
+
} : t.allowGuest ? {
|
|
213
|
+
success: !0,
|
|
214
|
+
auth: {
|
|
215
|
+
userId: null,
|
|
216
|
+
isAuthenticated: !1,
|
|
217
|
+
payload: null,
|
|
218
|
+
isGuest: !0,
|
|
219
|
+
guestId: l(e.cookies) || void 0
|
|
220
|
+
}
|
|
221
|
+
} : {
|
|
222
|
+
success: !1,
|
|
223
|
+
error: "No token found in cookies or Authorization header"
|
|
224
|
+
};
|
|
225
|
+
} catch (n) {
|
|
226
|
+
if (t.allowGuest) {
|
|
227
|
+
const o = l(e.cookies), r = n instanceof Error ? n.message : "Unknown error";
|
|
228
|
+
return console.warn(`[verifyNextAuth] Token verification failed, falling back to guest: ${r}`), {
|
|
229
|
+
success: !0,
|
|
230
|
+
auth: {
|
|
231
|
+
userId: null,
|
|
232
|
+
isAuthenticated: !1,
|
|
233
|
+
payload: null,
|
|
234
|
+
isGuest: !0,
|
|
235
|
+
guestId: o || void 0
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
return {
|
|
240
|
+
success: !1,
|
|
241
|
+
error: n instanceof Error ? n.message : "Unknown error"
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
async function ae(e, t) {
|
|
246
|
+
let n;
|
|
247
|
+
if (typeof e == "string")
|
|
248
|
+
n = e;
|
|
249
|
+
else {
|
|
250
|
+
const o = m(e.cookies, t.cookieName) || p(e.headers);
|
|
251
|
+
if (!o) {
|
|
252
|
+
if (t.allowGuest)
|
|
253
|
+
return {
|
|
254
|
+
userId: null,
|
|
255
|
+
isAuthenticated: !1,
|
|
256
|
+
payload: null,
|
|
257
|
+
isGuest: !0,
|
|
258
|
+
guestId: l(e.cookies) || void 0
|
|
259
|
+
};
|
|
260
|
+
throw new Error("No token found in request");
|
|
261
|
+
}
|
|
262
|
+
n = o;
|
|
263
|
+
}
|
|
264
|
+
try {
|
|
265
|
+
return await A(n, t);
|
|
266
|
+
} catch (o) {
|
|
267
|
+
if (t.allowGuest && typeof e == "object")
|
|
268
|
+
return {
|
|
269
|
+
userId: null,
|
|
270
|
+
isAuthenticated: !1,
|
|
271
|
+
payload: null,
|
|
272
|
+
isGuest: !0,
|
|
273
|
+
guestId: l(e.cookies) || void 0
|
|
274
|
+
};
|
|
275
|
+
throw o;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
function ue(e, t = {}) {
|
|
279
|
+
const {
|
|
280
|
+
cookieName: n = "logto_authtoken",
|
|
281
|
+
maxAge: o = 10080 * 60,
|
|
282
|
+
// 7 days in seconds
|
|
283
|
+
domain: r,
|
|
284
|
+
path: i = "/",
|
|
285
|
+
sameSite: s = "Strict"
|
|
286
|
+
} = t;
|
|
287
|
+
let a = `${n}=${e}; Max-Age=${o}; Path=${i}; HttpOnly; Secure; SameSite=${s}`;
|
|
288
|
+
return r && (a += `; Domain=${r}`), a;
|
|
289
|
+
}
|
|
290
|
+
const E = "logto_csrf_token", J = "x-csrf-token", Y = /* @__PURE__ */ new Set(["GET", "HEAD", "OPTIONS", "TRACE"]);
|
|
291
|
+
function Q() {
|
|
292
|
+
return D();
|
|
293
|
+
}
|
|
294
|
+
function X(e, t = {}) {
|
|
295
|
+
const {
|
|
296
|
+
cookieName: n = E,
|
|
297
|
+
maxAge: o = 1440 * 60,
|
|
298
|
+
// 1 day
|
|
299
|
+
domain: r,
|
|
300
|
+
path: i = "/",
|
|
301
|
+
sameSite: s = "Strict"
|
|
302
|
+
} = t;
|
|
303
|
+
if (/[\r\n;]/.test(e))
|
|
304
|
+
throw new Error("CSRF token contains invalid characters (newline or semicolon)");
|
|
305
|
+
let a = `${n}=${e}; Max-Age=${o}; Path=${i}; Secure; SameSite=${s}`;
|
|
306
|
+
return r && (a += `; Domain=${r}`), a;
|
|
307
|
+
}
|
|
308
|
+
function ce(e = {}) {
|
|
309
|
+
const {
|
|
310
|
+
cookieName: t = E,
|
|
311
|
+
headerName: n = J,
|
|
312
|
+
domain: o,
|
|
313
|
+
path: r = "/",
|
|
314
|
+
sameSite: i = "Strict",
|
|
315
|
+
maxAge: s = 1440 * 60
|
|
316
|
+
} = e;
|
|
317
|
+
return (a, u, c) => {
|
|
318
|
+
var S, T, I;
|
|
319
|
+
const d = (a.method ?? "GET").toUpperCase();
|
|
320
|
+
if (Y.has(d)) {
|
|
321
|
+
if (!((S = a.cookies) != null && S[t])) {
|
|
322
|
+
const R = Q(), j = X(R, { cookieName: t, maxAge: s, domain: o, path: r, sameSite: i });
|
|
323
|
+
typeof u.setHeader == "function" && u.setHeader("Set-Cookie", j);
|
|
324
|
+
}
|
|
325
|
+
return c();
|
|
326
|
+
}
|
|
327
|
+
const w = (T = a.cookies) == null ? void 0 : T[t], h = (I = a.headers) == null ? void 0 : I[n], y = Array.isArray(h) ? h[0] : h;
|
|
328
|
+
if (!w || !y || w !== y) {
|
|
329
|
+
u.status(403).json({
|
|
330
|
+
error: "CSRF validation failed",
|
|
331
|
+
message: `Include the '${n}' request header with the value from the '${t}' cookie.`
|
|
332
|
+
});
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
335
|
+
return c();
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
function fe(e, t = {}) {
|
|
339
|
+
var s, a;
|
|
340
|
+
const { cookieName: n = E, headerName: o = J } = t, r = (a = (s = e.cookies) == null ? void 0 : s.get(n)) == null ? void 0 : a.value, i = e.headers.get(o);
|
|
341
|
+
return r ? i ? r !== i ? {
|
|
342
|
+
valid: !1,
|
|
343
|
+
error: "CSRF token mismatch. The header value does not match the cookie value."
|
|
344
|
+
} : { valid: !0 } : {
|
|
345
|
+
valid: !1,
|
|
346
|
+
error: `Missing '${o}' request header. Read the '${n}' cookie value and send it in this header.`
|
|
347
|
+
} : {
|
|
348
|
+
valid: !1,
|
|
349
|
+
error: `CSRF cookie '${n}' not found. Ensure GET requests are made first to receive the CSRF cookie.`
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
const _ = ["roles", "role"];
|
|
353
|
+
function Z(e) {
|
|
354
|
+
return typeof e == "object" && e !== null && "isAuthenticated" in e;
|
|
355
|
+
}
|
|
356
|
+
function N(e) {
|
|
357
|
+
return e ? Z(e) ? e.payload : e : null;
|
|
358
|
+
}
|
|
359
|
+
function v(e) {
|
|
360
|
+
return (Array.isArray(e) ? e : [e]).flatMap((t) => t.split(/\s+/)).map((t) => t.trim()).filter(Boolean);
|
|
361
|
+
}
|
|
362
|
+
function g(e) {
|
|
363
|
+
return (Array.isArray(e) ? e : [e]).flatMap((t) => t.split(/[,\s]+/)).map((t) => t.trim()).filter(Boolean);
|
|
364
|
+
}
|
|
365
|
+
function W(e) {
|
|
366
|
+
const t = N(e);
|
|
367
|
+
return t != null && t.scope ? v(t.scope) : [];
|
|
368
|
+
}
|
|
369
|
+
function M(e, t) {
|
|
370
|
+
const n = N(e);
|
|
371
|
+
if (!n) return [];
|
|
372
|
+
for (const o of t) {
|
|
373
|
+
const r = n[o];
|
|
374
|
+
if (Array.isArray(r) && r.every((i) => typeof i == "string") || typeof r == "string")
|
|
375
|
+
return g(r);
|
|
376
|
+
}
|
|
377
|
+
return [];
|
|
378
|
+
}
|
|
379
|
+
function q(e, t, n = {}) {
|
|
380
|
+
const o = v(t);
|
|
381
|
+
if (o.length === 0) return !0;
|
|
382
|
+
const r = W(e), { mode: i = "all" } = n;
|
|
383
|
+
return i === "any" ? o.some((s) => r.includes(s)) : o.every((s) => r.includes(s));
|
|
384
|
+
}
|
|
385
|
+
function le(e, t, n = {}) {
|
|
386
|
+
const o = v(t);
|
|
387
|
+
if (o.length === 0) return;
|
|
388
|
+
const r = W(e), { mode: i = "all" } = n;
|
|
389
|
+
if (q(e, o, { mode: i }))
|
|
390
|
+
return;
|
|
391
|
+
const s = o.filter((u) => !r.includes(u)), a = i === "any" ? "at least one of" : "all of";
|
|
392
|
+
throw new Error(
|
|
393
|
+
`Missing required scopes (${a}: ${o.join(", ")}). Token scopes: ${r.join(", ") || "(none)"}. Missing: ${s.join(", ") || o.join(", ")}`
|
|
394
|
+
);
|
|
395
|
+
}
|
|
396
|
+
function de(e, t, n = {}) {
|
|
397
|
+
var s;
|
|
398
|
+
const o = g(t);
|
|
399
|
+
if (o.length === 0) return !0;
|
|
400
|
+
const r = (s = n.claimKeys) != null && s.length ? n.claimKeys : _, i = M(e, r);
|
|
401
|
+
return o.every((a) => i.includes(a));
|
|
402
|
+
}
|
|
403
|
+
function he(e, t, n = {}) {
|
|
404
|
+
var s;
|
|
405
|
+
const o = g(t);
|
|
406
|
+
if (o.length === 0) return;
|
|
407
|
+
const r = (s = n.claimKeys) != null && s.length ? n.claimKeys : _, i = M(e, r);
|
|
408
|
+
if (!o.every((a) => i.includes(a)))
|
|
409
|
+
throw new Error(
|
|
410
|
+
`Missing required role: ${o.join(", ")}. Checked claims: ${r.join(", ")}. Token roles: ${i.join(", ") || "(none)"}`
|
|
411
|
+
);
|
|
412
|
+
}
|
|
413
|
+
export {
|
|
414
|
+
E as CSRF_COOKIE_NAME,
|
|
415
|
+
J as CSRF_HEADER_NAME,
|
|
416
|
+
ue as buildAuthCookieHeader,
|
|
417
|
+
X as buildCsrfCookieHeader,
|
|
418
|
+
oe as clearJwksCache,
|
|
419
|
+
ce as createCsrfMiddleware,
|
|
420
|
+
ie as createExpressAuthMiddleware,
|
|
421
|
+
Q as generateCsrfToken,
|
|
422
|
+
de as hasRole,
|
|
423
|
+
q as hasScopes,
|
|
424
|
+
ne as invalidateJwksCache,
|
|
425
|
+
he as requireRole,
|
|
426
|
+
le as requireScopes,
|
|
427
|
+
ae as verifyAuth,
|
|
428
|
+
fe as verifyCsrfToken,
|
|
429
|
+
A as verifyLogtoToken,
|
|
430
|
+
se as verifyNextAuth
|
|
431
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
export interface AuthPayload {
|
|
2
|
+
sub: string;
|
|
3
|
+
scope: string;
|
|
4
|
+
iss?: string;
|
|
5
|
+
aud?: string | string[];
|
|
6
|
+
exp?: number;
|
|
7
|
+
nbf?: number;
|
|
8
|
+
iat?: number;
|
|
9
|
+
[key: string]: unknown;
|
|
10
|
+
}
|
|
11
|
+
export interface AuthContext {
|
|
12
|
+
userId: string | null;
|
|
13
|
+
isAuthenticated: boolean;
|
|
14
|
+
payload: AuthPayload | null;
|
|
15
|
+
isGuest?: boolean;
|
|
16
|
+
guestId?: string;
|
|
17
|
+
}
|
|
18
|
+
export interface VerifyAuthOptions {
|
|
19
|
+
logtoUrl: string;
|
|
20
|
+
audience?: string | string[];
|
|
21
|
+
cookieName?: string;
|
|
22
|
+
requiredScope?: string;
|
|
23
|
+
allowGuest?: boolean;
|
|
24
|
+
jwksCacheTtlMs?: number;
|
|
25
|
+
skipJwksCache?: boolean;
|
|
26
|
+
}
|
|
27
|
+
export interface ExpressRequest {
|
|
28
|
+
cookies?: {
|
|
29
|
+
[key: string]: string;
|
|
30
|
+
};
|
|
31
|
+
headers: {
|
|
32
|
+
[key: string]: string | string[] | undefined;
|
|
33
|
+
};
|
|
34
|
+
auth?: AuthContext;
|
|
35
|
+
}
|
|
36
|
+
export interface ExpressResponse {
|
|
37
|
+
status: (code: number) => ExpressResponse;
|
|
38
|
+
json: (obj: unknown) => ExpressResponse;
|
|
39
|
+
/**
|
|
40
|
+
* Set a response header. Present on all real Express `Response` objects
|
|
41
|
+
* (inherited from `http.ServerResponse`). Typed as optional here to keep
|
|
42
|
+
* the interface compatible with minimal test stubs, but the CSRF middleware
|
|
43
|
+
* depends on it being present to set the CSRF cookie.
|
|
44
|
+
*/
|
|
45
|
+
setHeader?: (name: string, value: string) => void;
|
|
46
|
+
}
|
|
47
|
+
export type ExpressNext = (err?: unknown) => void;
|
|
48
|
+
export interface NextRequest {
|
|
49
|
+
cookies?: {
|
|
50
|
+
get: (name: string) => {
|
|
51
|
+
value: string;
|
|
52
|
+
} | undefined;
|
|
53
|
+
};
|
|
54
|
+
headers: {
|
|
55
|
+
get: (name: string) => string | null;
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
export interface NextResponse {
|
|
59
|
+
json: (body: unknown, init?: {
|
|
60
|
+
status?: number;
|
|
61
|
+
}) => NextResponse;
|
|
62
|
+
}
|