@eventuras/fides-auth-next 0.1.5
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 +71 -0
- package/dist/cookies.d.ts +143 -0
- package/dist/cookies.d.ts.map +1 -0
- package/dist/cookies.js +81 -0
- package/dist/fides-auth/dist/build-CNL3v39v.js +977 -0
- package/dist/fides-auth/dist/decode_jwt-1J26fl4I.js +25 -0
- package/dist/fides-auth/dist/decrypt-Cahlu_6Y.js +88 -0
- package/dist/fides-auth/dist/deflate-koSuX7FB.js +969 -0
- package/dist/fides-auth/dist/logger.js +46 -0
- package/dist/fides-auth/dist/oauth.js +165 -0
- package/dist/fides-auth/dist/rate-limit.js +26 -0
- package/dist/fides-auth/dist/session-refresh.js +27 -0
- package/dist/fides-auth/dist/session-validation-BxObT3wC.js +64 -0
- package/dist/fides-auth/dist/silent-login.js +50 -0
- package/dist/fides-auth/dist/utils-ByMRF7b2.js +379 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +18 -0
- package/dist/oidc-callback.d.ts +46 -0
- package/dist/oidc-callback.d.ts.map +1 -0
- package/dist/oidc-callback.js +33 -0
- package/dist/oidc-login.d.ts +26 -0
- package/dist/oidc-login.d.ts.map +1 -0
- package/dist/oidc-login.js +20 -0
- package/dist/request.d.ts +3 -0
- package/dist/request.d.ts.map +1 -0
- package/dist/request.js +26 -0
- package/dist/session.d.ts +111 -0
- package/dist/session.d.ts.map +1 -0
- package/dist/session.js +61 -0
- package/dist/store/configure-logger.d.ts +15 -0
- package/dist/store/configure-logger.d.ts.map +1 -0
- package/dist/store/configure-logger.js +10 -0
- package/dist/store/hooks.d.ts +64 -0
- package/dist/store/hooks.d.ts.map +1 -0
- package/dist/store/hooks.js +36 -0
- package/dist/store/index.d.ts +107 -0
- package/dist/store/index.d.ts.map +1 -0
- package/dist/store/index.js +6 -0
- package/dist/store/session-monitor.d.ts +51 -0
- package/dist/store/session-monitor.d.ts.map +1 -0
- package/dist/store/session-monitor.js +49 -0
- package/dist/store/store.d.ts +83 -0
- package/dist/store/store.d.ts.map +1 -0
- package/dist/store/store.js +134 -0
- package/dist/store/use-session-monitor.d.ts +28 -0
- package/dist/store/use-session-monitor.d.ts.map +1 -0
- package/dist/store/use-session-monitor.js +13 -0
- package/package.json +60 -0
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
import { i as e } from "./logger.js";
|
|
2
|
+
import { He as t, I as n, Je as r, Ke as i, N as a, Pe as o, S as s, Ue as c, ae as l, b as u, d, e as f, he as p, me as m, ne as h, r as g, re as _, s as v, t as y, ve as b } from "./deflate-koSuX7FB.js";
|
|
3
|
+
import { i as x } from "./decode_jwt-1J26fl4I.js";
|
|
4
|
+
//#region ../fides-auth/dist/utils-ByMRF7b2.js
|
|
5
|
+
var S = class {
|
|
6
|
+
#e;
|
|
7
|
+
#t;
|
|
8
|
+
#n;
|
|
9
|
+
#r;
|
|
10
|
+
#i;
|
|
11
|
+
#a;
|
|
12
|
+
#o;
|
|
13
|
+
#s;
|
|
14
|
+
constructor(e) {
|
|
15
|
+
if (!(e instanceof Uint8Array)) throw TypeError("plaintext must be an instance of Uint8Array");
|
|
16
|
+
this.#e = e;
|
|
17
|
+
}
|
|
18
|
+
setKeyManagementParameters(e) {
|
|
19
|
+
return p(this.#s, "setKeyManagementParameters"), this.#s = e, this;
|
|
20
|
+
}
|
|
21
|
+
setProtectedHeader(e) {
|
|
22
|
+
return p(this.#t, "setProtectedHeader"), this.#t = e, this;
|
|
23
|
+
}
|
|
24
|
+
setSharedUnprotectedHeader(e) {
|
|
25
|
+
return p(this.#n, "setSharedUnprotectedHeader"), this.#n = e, this;
|
|
26
|
+
}
|
|
27
|
+
setUnprotectedHeader(e) {
|
|
28
|
+
return p(this.#r, "setUnprotectedHeader"), this.#r = e, this;
|
|
29
|
+
}
|
|
30
|
+
setAdditionalAuthenticatedData(e) {
|
|
31
|
+
return this.#i = e, this;
|
|
32
|
+
}
|
|
33
|
+
setContentEncryptionKey(e) {
|
|
34
|
+
return p(this.#a, "setContentEncryptionKey"), this.#a = e, this;
|
|
35
|
+
}
|
|
36
|
+
setInitializationVector(e) {
|
|
37
|
+
return p(this.#o, "setInitializationVector"), this.#o = e, this;
|
|
38
|
+
}
|
|
39
|
+
async encrypt(e, n) {
|
|
40
|
+
if (!this.#t && !this.#r && !this.#n) throw new s("either setProtectedHeader, setUnprotectedHeader, or sharedUnprotectedHeader must be called before #encrypt()");
|
|
41
|
+
if (!b(this.#t, this.#r, this.#n)) throw new s("JWE Protected, JWE Shared Unprotected and JWE Per-Recipient Header Parameter names must be disjoint");
|
|
42
|
+
let l = {
|
|
43
|
+
...this.#t,
|
|
44
|
+
...this.#r,
|
|
45
|
+
...this.#n
|
|
46
|
+
};
|
|
47
|
+
if (c(s, /* @__PURE__ */ new Map(), n?.crit, this.#t, l), l.zip !== void 0 && l.zip !== "DEF") throw new u("Unsupported JWE \"zip\" (Compression Algorithm) Header Parameter value.");
|
|
48
|
+
if (l.zip !== void 0 && !this.#t?.zip) throw new s("JWE \"zip\" (Compression Algorithm) Header Parameter MUST be in a protected header.");
|
|
49
|
+
let { alg: f, enc: p } = l;
|
|
50
|
+
if (typeof f != "string" || !f) throw new s("JWE \"alg\" (Algorithm) Header Parameter missing or invalid");
|
|
51
|
+
if (typeof p != "string" || !p) throw new s("JWE \"enc\" (Encryption Algorithm) Header Parameter missing or invalid");
|
|
52
|
+
let h;
|
|
53
|
+
if (this.#a && (f === "dir" || f === "ECDH-ES")) throw TypeError(`setContentEncryptionKey cannot be called with JWE "alg" (Algorithm) Header ${f}`);
|
|
54
|
+
i(f === "dir" ? p : f, e, "encrypt");
|
|
55
|
+
let _;
|
|
56
|
+
{
|
|
57
|
+
let r, i = await o(e, f);
|
|
58
|
+
({cek: _, encryptedKey: h, parameters: r} = await t(f, p, i, this.#a, this.#s)), r && (n && m in n ? this.#r ? this.#r = {
|
|
59
|
+
...this.#r,
|
|
60
|
+
...r
|
|
61
|
+
} : this.setUnprotectedHeader(r) : this.#t ? this.#t = {
|
|
62
|
+
...this.#t,
|
|
63
|
+
...r
|
|
64
|
+
} : this.setProtectedHeader(r));
|
|
65
|
+
}
|
|
66
|
+
let y, x, S, C;
|
|
67
|
+
if (this.#t ? (x = d(JSON.stringify(this.#t)), S = v(x)) : (x = "", S = new Uint8Array()), this.#i) {
|
|
68
|
+
C = d(this.#i);
|
|
69
|
+
let e = v(C);
|
|
70
|
+
y = g(S, v("."), e);
|
|
71
|
+
} else y = S;
|
|
72
|
+
let w = this.#e;
|
|
73
|
+
l.zip === "DEF" && (w = await r(w).catch((e) => {
|
|
74
|
+
throw new s("Failed to compress plaintext", { cause: e });
|
|
75
|
+
}));
|
|
76
|
+
let { ciphertext: T, tag: E, iv: D } = await a(p, w, _, this.#o, y), O = { ciphertext: d(T) };
|
|
77
|
+
return D && (O.iv = d(D)), E && (O.tag = d(E)), h && (O.encrypted_key = d(h)), C && (O.aad = C), this.#t && (O.protected = x), this.#n && (O.unprotected = this.#n), this.#r && (O.header = this.#r), O;
|
|
78
|
+
}
|
|
79
|
+
}, C = (e) => Math.floor(e.getTime() / 1e3), w = 60, T = w * 60, E = T * 24, D = E * 7, O = E * 365.25, k = /^(\+|\-)? ?(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)(?: (ago|from now))?$/i;
|
|
80
|
+
function A(e) {
|
|
81
|
+
let t = k.exec(e);
|
|
82
|
+
if (!t || t[4] && t[1]) throw TypeError("Invalid time period format");
|
|
83
|
+
let n = parseFloat(t[2]), r = t[3].toLowerCase(), i;
|
|
84
|
+
switch (r) {
|
|
85
|
+
case "sec":
|
|
86
|
+
case "secs":
|
|
87
|
+
case "second":
|
|
88
|
+
case "seconds":
|
|
89
|
+
case "s":
|
|
90
|
+
i = Math.round(n);
|
|
91
|
+
break;
|
|
92
|
+
case "minute":
|
|
93
|
+
case "minutes":
|
|
94
|
+
case "min":
|
|
95
|
+
case "mins":
|
|
96
|
+
case "m":
|
|
97
|
+
i = Math.round(n * w);
|
|
98
|
+
break;
|
|
99
|
+
case "hour":
|
|
100
|
+
case "hours":
|
|
101
|
+
case "hr":
|
|
102
|
+
case "hrs":
|
|
103
|
+
case "h":
|
|
104
|
+
i = Math.round(n * T);
|
|
105
|
+
break;
|
|
106
|
+
case "day":
|
|
107
|
+
case "days":
|
|
108
|
+
case "d":
|
|
109
|
+
i = Math.round(n * E);
|
|
110
|
+
break;
|
|
111
|
+
case "week":
|
|
112
|
+
case "weeks":
|
|
113
|
+
case "w":
|
|
114
|
+
i = Math.round(n * D);
|
|
115
|
+
break;
|
|
116
|
+
default:
|
|
117
|
+
i = Math.round(n * O);
|
|
118
|
+
break;
|
|
119
|
+
}
|
|
120
|
+
return t[1] === "-" || t[4] === "ago" ? -i : i;
|
|
121
|
+
}
|
|
122
|
+
function j(e, t) {
|
|
123
|
+
if (!Number.isFinite(t)) throw TypeError(`Invalid ${e} input`);
|
|
124
|
+
return t;
|
|
125
|
+
}
|
|
126
|
+
var M = (e) => e.includes("/") ? e.toLowerCase() : `application/${e.toLowerCase()}`, N = (e, t) => typeof e == "string" ? t.includes(e) : Array.isArray(e) ? t.some(Set.prototype.has.bind(new Set(e))) : !1;
|
|
127
|
+
function P(e, t, r = {}) {
|
|
128
|
+
let i;
|
|
129
|
+
try {
|
|
130
|
+
i = JSON.parse(y.decode(t));
|
|
131
|
+
} catch {}
|
|
132
|
+
if (!n(i)) throw new l("JWT Claims Set must be a top-level JSON object");
|
|
133
|
+
let { typ: a } = r;
|
|
134
|
+
if (a && (typeof e.typ != "string" || M(e.typ) !== M(a))) throw new h("unexpected \"typ\" JWT header value", i, "typ", "check_failed");
|
|
135
|
+
let { requiredClaims: o = [], issuer: s, subject: c, audience: u, maxTokenAge: d } = r, f = [...o];
|
|
136
|
+
d !== void 0 && f.push("iat"), u !== void 0 && f.push("aud"), c !== void 0 && f.push("sub"), s !== void 0 && f.push("iss");
|
|
137
|
+
for (let e of new Set(f.reverse())) if (!(e in i)) throw new h(`missing required "${e}" claim`, i, e, "missing");
|
|
138
|
+
if (s && !(Array.isArray(s) ? s : [s]).includes(i.iss)) throw new h("unexpected \"iss\" claim value", i, "iss", "check_failed");
|
|
139
|
+
if (c && i.sub !== c) throw new h("unexpected \"sub\" claim value", i, "sub", "check_failed");
|
|
140
|
+
if (u && !N(i.aud, typeof u == "string" ? [u] : u)) throw new h("unexpected \"aud\" claim value", i, "aud", "check_failed");
|
|
141
|
+
let p;
|
|
142
|
+
switch (typeof r.clockTolerance) {
|
|
143
|
+
case "string":
|
|
144
|
+
p = A(r.clockTolerance);
|
|
145
|
+
break;
|
|
146
|
+
case "number":
|
|
147
|
+
p = r.clockTolerance;
|
|
148
|
+
break;
|
|
149
|
+
case "undefined":
|
|
150
|
+
p = 0;
|
|
151
|
+
break;
|
|
152
|
+
default: throw TypeError("Invalid clockTolerance option type");
|
|
153
|
+
}
|
|
154
|
+
let { currentDate: m } = r, g = C(m || /* @__PURE__ */ new Date());
|
|
155
|
+
if ((i.iat !== void 0 || d) && typeof i.iat != "number") throw new h("\"iat\" claim must be a number", i, "iat", "invalid");
|
|
156
|
+
if (i.nbf !== void 0) {
|
|
157
|
+
if (typeof i.nbf != "number") throw new h("\"nbf\" claim must be a number", i, "nbf", "invalid");
|
|
158
|
+
if (i.nbf > g + p) throw new h("\"nbf\" claim timestamp check failed", i, "nbf", "check_failed");
|
|
159
|
+
}
|
|
160
|
+
if (i.exp !== void 0) {
|
|
161
|
+
if (typeof i.exp != "number") throw new h("\"exp\" claim must be a number", i, "exp", "invalid");
|
|
162
|
+
if (i.exp <= g - p) throw new _("\"exp\" claim timestamp check failed", i, "exp", "check_failed");
|
|
163
|
+
}
|
|
164
|
+
if (d) {
|
|
165
|
+
let e = g - i.iat, t = typeof d == "number" ? d : A(d);
|
|
166
|
+
if (e - p > t) throw new _("\"iat\" claim timestamp check failed (too far in the past)", i, "iat", "check_failed");
|
|
167
|
+
if (e < 0 - p) throw new h("\"iat\" claim timestamp check failed (it should be in the past)", i, "iat", "check_failed");
|
|
168
|
+
}
|
|
169
|
+
return i;
|
|
170
|
+
}
|
|
171
|
+
var F = class {
|
|
172
|
+
#e;
|
|
173
|
+
constructor(e) {
|
|
174
|
+
if (!n(e)) throw TypeError("JWT Claims Set MUST be an object");
|
|
175
|
+
this.#e = structuredClone(e);
|
|
176
|
+
}
|
|
177
|
+
data() {
|
|
178
|
+
return f.encode(JSON.stringify(this.#e));
|
|
179
|
+
}
|
|
180
|
+
get iss() {
|
|
181
|
+
return this.#e.iss;
|
|
182
|
+
}
|
|
183
|
+
set iss(e) {
|
|
184
|
+
this.#e.iss = e;
|
|
185
|
+
}
|
|
186
|
+
get sub() {
|
|
187
|
+
return this.#e.sub;
|
|
188
|
+
}
|
|
189
|
+
set sub(e) {
|
|
190
|
+
this.#e.sub = e;
|
|
191
|
+
}
|
|
192
|
+
get aud() {
|
|
193
|
+
return this.#e.aud;
|
|
194
|
+
}
|
|
195
|
+
set aud(e) {
|
|
196
|
+
this.#e.aud = e;
|
|
197
|
+
}
|
|
198
|
+
set jti(e) {
|
|
199
|
+
this.#e.jti = e;
|
|
200
|
+
}
|
|
201
|
+
set nbf(e) {
|
|
202
|
+
typeof e == "number" ? this.#e.nbf = j("setNotBefore", e) : e instanceof Date ? this.#e.nbf = j("setNotBefore", C(e)) : this.#e.nbf = C(/* @__PURE__ */ new Date()) + A(e);
|
|
203
|
+
}
|
|
204
|
+
set exp(e) {
|
|
205
|
+
typeof e == "number" ? this.#e.exp = j("setExpirationTime", e) : e instanceof Date ? this.#e.exp = j("setExpirationTime", C(e)) : this.#e.exp = C(/* @__PURE__ */ new Date()) + A(e);
|
|
206
|
+
}
|
|
207
|
+
set iat(e) {
|
|
208
|
+
e === void 0 ? this.#e.iat = C(/* @__PURE__ */ new Date()) : e instanceof Date ? this.#e.iat = j("setIssuedAt", C(e)) : typeof e == "string" ? this.#e.iat = j("setIssuedAt", C(/* @__PURE__ */ new Date()) + A(e)) : this.#e.iat = j("setIssuedAt", e);
|
|
209
|
+
}
|
|
210
|
+
}, I = class {
|
|
211
|
+
#e;
|
|
212
|
+
constructor(e) {
|
|
213
|
+
this.#e = new S(e);
|
|
214
|
+
}
|
|
215
|
+
setContentEncryptionKey(e) {
|
|
216
|
+
return this.#e.setContentEncryptionKey(e), this;
|
|
217
|
+
}
|
|
218
|
+
setInitializationVector(e) {
|
|
219
|
+
return this.#e.setInitializationVector(e), this;
|
|
220
|
+
}
|
|
221
|
+
setProtectedHeader(e) {
|
|
222
|
+
return this.#e.setProtectedHeader(e), this;
|
|
223
|
+
}
|
|
224
|
+
setKeyManagementParameters(e) {
|
|
225
|
+
return this.#e.setKeyManagementParameters(e), this;
|
|
226
|
+
}
|
|
227
|
+
async encrypt(e, t) {
|
|
228
|
+
let n = await this.#e.encrypt(e, t);
|
|
229
|
+
return [
|
|
230
|
+
n.protected,
|
|
231
|
+
n.encrypted_key,
|
|
232
|
+
n.iv,
|
|
233
|
+
n.ciphertext,
|
|
234
|
+
n.tag
|
|
235
|
+
].join(".");
|
|
236
|
+
}
|
|
237
|
+
}, L = class {
|
|
238
|
+
#e;
|
|
239
|
+
#t;
|
|
240
|
+
#n;
|
|
241
|
+
#r;
|
|
242
|
+
#i;
|
|
243
|
+
#a;
|
|
244
|
+
#o;
|
|
245
|
+
#s;
|
|
246
|
+
constructor(e = {}) {
|
|
247
|
+
this.#s = new F(e);
|
|
248
|
+
}
|
|
249
|
+
setIssuer(e) {
|
|
250
|
+
return this.#s.iss = e, this;
|
|
251
|
+
}
|
|
252
|
+
setSubject(e) {
|
|
253
|
+
return this.#s.sub = e, this;
|
|
254
|
+
}
|
|
255
|
+
setAudience(e) {
|
|
256
|
+
return this.#s.aud = e, this;
|
|
257
|
+
}
|
|
258
|
+
setJti(e) {
|
|
259
|
+
return this.#s.jti = e, this;
|
|
260
|
+
}
|
|
261
|
+
setNotBefore(e) {
|
|
262
|
+
return this.#s.nbf = e, this;
|
|
263
|
+
}
|
|
264
|
+
setExpirationTime(e) {
|
|
265
|
+
return this.#s.exp = e, this;
|
|
266
|
+
}
|
|
267
|
+
setIssuedAt(e) {
|
|
268
|
+
return this.#s.iat = e, this;
|
|
269
|
+
}
|
|
270
|
+
setProtectedHeader(e) {
|
|
271
|
+
return p(this.#r, "setProtectedHeader"), this.#r = e, this;
|
|
272
|
+
}
|
|
273
|
+
setKeyManagementParameters(e) {
|
|
274
|
+
return p(this.#n, "setKeyManagementParameters"), this.#n = e, this;
|
|
275
|
+
}
|
|
276
|
+
setContentEncryptionKey(e) {
|
|
277
|
+
return p(this.#e, "setContentEncryptionKey"), this.#e = e, this;
|
|
278
|
+
}
|
|
279
|
+
setInitializationVector(e) {
|
|
280
|
+
return p(this.#t, "setInitializationVector"), this.#t = e, this;
|
|
281
|
+
}
|
|
282
|
+
replicateIssuerAsHeader() {
|
|
283
|
+
return this.#i = !0, this;
|
|
284
|
+
}
|
|
285
|
+
replicateSubjectAsHeader() {
|
|
286
|
+
return this.#a = !0, this;
|
|
287
|
+
}
|
|
288
|
+
replicateAudienceAsHeader() {
|
|
289
|
+
return this.#o = !0, this;
|
|
290
|
+
}
|
|
291
|
+
async encrypt(e, t) {
|
|
292
|
+
let n = new I(this.#s.data());
|
|
293
|
+
return this.#r && (this.#i || this.#a || this.#o) && (this.#r = {
|
|
294
|
+
...this.#r,
|
|
295
|
+
iss: this.#i ? this.#s.iss : void 0,
|
|
296
|
+
sub: this.#a ? this.#s.sub : void 0,
|
|
297
|
+
aud: this.#o ? this.#s.aud : void 0
|
|
298
|
+
}), n.setProtectedHeader(this.#r), this.#t && n.setInitializationVector(this.#t), this.#e && n.setContentEncryptionKey(this.#e), this.#n && n.setKeyManagementParameters(this.#n), n.encrypt(e, t);
|
|
299
|
+
}
|
|
300
|
+
}, R = e({ namespace: "fides-auth:utils" });
|
|
301
|
+
function z(e) {
|
|
302
|
+
if (e.length % 2 != 0) throw Error("Invalid hex string: odd length");
|
|
303
|
+
if (e.length > 0 && !/^[0-9a-fA-F]+$/.test(e)) throw Error("Invalid hex string: contains non-hex characters");
|
|
304
|
+
let t = new Uint8Array(e.length / 2);
|
|
305
|
+
for (let n = 0; n < t.length; n++) t[n] = Number.parseInt(e.slice(n * 2, n * 2 + 2), 16);
|
|
306
|
+
return t;
|
|
307
|
+
}
|
|
308
|
+
function B(e) {
|
|
309
|
+
return typeof e == "string" ? z(e) : e;
|
|
310
|
+
}
|
|
311
|
+
async function V(e, t) {
|
|
312
|
+
return new L(e).setProtectedHeader({
|
|
313
|
+
alg: "dir",
|
|
314
|
+
enc: "A256GCM"
|
|
315
|
+
}).setIssuedAt().encrypt(B(t));
|
|
316
|
+
}
|
|
317
|
+
async function H(e, t) {
|
|
318
|
+
let n = B(t), r = await crypto.subtle.importKey("raw", n, { name: "AES-GCM" }, !1, ["encrypt"]), i = crypto.getRandomValues(new Uint8Array(12)), a = new TextEncoder().encode(e), o = await crypto.subtle.encrypt({
|
|
319
|
+
name: "AES-GCM",
|
|
320
|
+
iv: i,
|
|
321
|
+
tagLength: 128
|
|
322
|
+
}, r, a), s = new Uint8Array(o), c = s.slice(0, s.length - 16), l = s.slice(s.length - 16);
|
|
323
|
+
return [
|
|
324
|
+
Y(i),
|
|
325
|
+
Y(l),
|
|
326
|
+
Y(c)
|
|
327
|
+
].join(":");
|
|
328
|
+
}
|
|
329
|
+
async function U(e, t) {
|
|
330
|
+
let [n, r, i] = e.split(":");
|
|
331
|
+
if (!n || !r || !i) throw Error("Invalid encrypted data format");
|
|
332
|
+
let a = z(n), o = z(r), s = z(i), c = new Uint8Array(s.length + o.length);
|
|
333
|
+
c.set(s), c.set(o, s.length);
|
|
334
|
+
let l = B(t), u = new Uint8Array([...l]), d = new Uint8Array([...a]), f = await crypto.subtle.importKey("raw", u, { name: "AES-GCM" }, !1, ["decrypt"]), p = await crypto.subtle.decrypt({
|
|
335
|
+
name: "AES-GCM",
|
|
336
|
+
iv: d,
|
|
337
|
+
tagLength: 128
|
|
338
|
+
}, f, c.buffer);
|
|
339
|
+
return new TextDecoder().decode(p);
|
|
340
|
+
}
|
|
341
|
+
function W(e) {
|
|
342
|
+
return typeof e == "string" ? new TextEncoder().encode(e) : e;
|
|
343
|
+
}
|
|
344
|
+
async function G(e) {
|
|
345
|
+
let t = W(e), n = await crypto.subtle.digest("SHA-256", t);
|
|
346
|
+
return Y(new Uint8Array(n));
|
|
347
|
+
}
|
|
348
|
+
async function K(e) {
|
|
349
|
+
let t = W(e), n = await crypto.subtle.digest("SHA-512", t);
|
|
350
|
+
return Y(new Uint8Array(n));
|
|
351
|
+
}
|
|
352
|
+
function q() {
|
|
353
|
+
let e = process.env.SESSION_SECRET;
|
|
354
|
+
if (!e) throw Error("SESSION_SECRET is not defined");
|
|
355
|
+
return e;
|
|
356
|
+
}
|
|
357
|
+
function J() {
|
|
358
|
+
let e = z(q());
|
|
359
|
+
return new Uint8Array([...e]);
|
|
360
|
+
}
|
|
361
|
+
function Y(e) {
|
|
362
|
+
return Array.from(e).map((e) => e.toString(16).padStart(2, "0")).join("");
|
|
363
|
+
}
|
|
364
|
+
function X(e = 32) {
|
|
365
|
+
let t = new Uint8Array(e);
|
|
366
|
+
return crypto.getRandomValues(t), Y(t);
|
|
367
|
+
}
|
|
368
|
+
var Z = (e, t = 10) => {
|
|
369
|
+
try {
|
|
370
|
+
let n = x(e);
|
|
371
|
+
if (!n.exp) return !1;
|
|
372
|
+
let r = Date.now() / 1e3;
|
|
373
|
+
return n.exp - r < t;
|
|
374
|
+
} catch (e) {
|
|
375
|
+
return R.error({ error: e }, "Error decoding access token"), !0;
|
|
376
|
+
}
|
|
377
|
+
};
|
|
378
|
+
//#endregion
|
|
379
|
+
export { G, H, J, K, P, U, V, X, Y, Z, q, z };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export * from './request';
|
|
2
|
+
export * from './session';
|
|
3
|
+
export * from './cookies';
|
|
4
|
+
export * from './oidc-callback';
|
|
5
|
+
export * from './oidc-login';
|
|
6
|
+
export * from './store';
|
|
7
|
+
export * from '@eventuras/fides-auth/oauth';
|
|
8
|
+
export type { OAuthConfig } from '@eventuras/fides-auth/oauth';
|
|
9
|
+
export * from '@eventuras/fides-auth/session-refresh';
|
|
10
|
+
export * from '@eventuras/fides-auth/session-validation';
|
|
11
|
+
export * from '@eventuras/fides-auth/silent-login';
|
|
12
|
+
export * from '@eventuras/fides-auth/utils';
|
|
13
|
+
export * from '@eventuras/fides-auth/types';
|
|
14
|
+
export { TokenBucket } from '@eventuras/fides-auth/rate-limit';
|
|
15
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAG7B,cAAc,SAAS,CAAC;AAGxB,cAAc,6BAA6B,CAAC;AAC5C,YAAY,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC/D,cAAc,uCAAuC,CAAC;AACtD,cAAc,0CAA0C,CAAC;AACzD,cAAc,oCAAoC,CAAC;AACnD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,6BAA6B,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,kCAAkC,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { e } from "./fides-auth/dist/rate-limit.js";
|
|
2
|
+
import { globalGETRateLimit as t, globalPOSTRateLimit as n } from "./request.js";
|
|
3
|
+
import { G as r, H as i, J as a, K as o, U as s, V as c, X as l, Y as u, Z as d, q as f, z as p } from "./fides-auth/dist/utils-ByMRF7b2.js";
|
|
4
|
+
import { c as m, u as h } from "./fides-auth/dist/session-validation-BxObT3wC.js";
|
|
5
|
+
import { _ as g, b as _, d as v, f as y, g as b, h as x, m as S, p as C, v as w, x as T, y as E } from "./fides-auth/dist/oauth.js";
|
|
6
|
+
import { r as D } from "./fides-auth/dist/session-refresh.js";
|
|
7
|
+
import { defaultOAuthCookieOptions as O, defaultSessionCookieOptions as k, deleteAuthCookie as A, deleteAuthCookies as j, deleteSessionCookie as M, getAuthCookie as N, getSessionCookie as P, setAuthCookie as F, setSessionCookie as I } from "./cookies.js";
|
|
8
|
+
import { clearCurrentSession as L, createAndPersistSession as R, createSession as z, getCurrentSession as B, refreshCurrentSession as V } from "./session.js";
|
|
9
|
+
import { handleOidcCallback as H } from "./oidc-callback.js";
|
|
10
|
+
import { handleOidcLogin as U } from "./oidc-login.js";
|
|
11
|
+
import { checkAuth as W, createAuthStore as G, initializeAuth as K } from "./store/store.js";
|
|
12
|
+
import { createAuthStoreHooks as q } from "./store/hooks.js";
|
|
13
|
+
import { startSessionMonitor as J } from "./store/session-monitor.js";
|
|
14
|
+
import { useSessionMonitor as Y } from "./store/use-session-monitor.js";
|
|
15
|
+
import { configureAuthLogger as X } from "./store/configure-logger.js";
|
|
16
|
+
import "./store/index.js";
|
|
17
|
+
import { a as Z, c as Q, o as $, s as ee } from "./fides-auth/dist/silent-login.js";
|
|
18
|
+
export { ee as SilentLoginErrors, e as TokenBucket, d as accessTokenExpires, S as buildAuthorizationUrl, _ as buildOidcLogoutUrl, C as buildPKCEOptions, w as buildSessionFromTokens, Z as buildSilentLoginUrl, W as checkAuth, $ as checkSilentLoginResult, L as clearCurrentSession, T as clientCredentialsGrant, X as configureAuthLogger, R as createAndPersistSession, G as createAuthStore, q as createAuthStoreHooks, c as createEncryptedJWT, z as createSession, s as decrypt, O as defaultOAuthCookieOptions, v as defaultScope, k as defaultSessionCookieOptions, A as deleteAuthCookie, j as deleteAuthCookies, M as deleteSessionCookie, x as discoverAndBuildAuthorizationUrl, i as encrypt, b as exchangeAuthorizationCode, g as extractUserFromTokens, l as generateToken, N as getAuthCookie, B as getCurrentSession, P as getSessionCookie, f as getSessionSecret, a as getSessionSecretUint8Array, t as globalGETRateLimit, n as globalPOSTRateLimit, H as handleOidcCallback, U as handleOidcLogin, p as hexToUint8Array, K as initializeAuth, h as isSession, y as refreshAccessToken, V as refreshCurrentSession, D as refreshSession, Q as requiresInteractiveLogin, F as setAuthCookie, I as setSessionCookie, r as sha256, o as sha512, J as startSessionMonitor, u as toHex, Y as useSessionMonitor, E as validateReturnUrl, m as validateSessionJwt };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { OAuthConfig } from '@eventuras/fides-auth/oauth';
|
|
2
|
+
export interface OidcCallbackConfig {
|
|
3
|
+
/** OAuth/OIDC configuration (issuer, clientId, clientSecret, redirect_uri, scope) */
|
|
4
|
+
oauthConfig: OAuthConfig;
|
|
5
|
+
/** Public application URL (used to reconstruct the callback URL and validate redirects) */
|
|
6
|
+
applicationUrl: string;
|
|
7
|
+
/**
|
|
8
|
+
* Name of the ID token claim that contains user roles.
|
|
9
|
+
* @default 'roles'
|
|
10
|
+
*/
|
|
11
|
+
rolesClaim?: string;
|
|
12
|
+
/**
|
|
13
|
+
* Session duration in days.
|
|
14
|
+
* @default 7
|
|
15
|
+
*/
|
|
16
|
+
sessionDurationDays?: number;
|
|
17
|
+
/**
|
|
18
|
+
* Default path to redirect to after login if no returnTo cookie is set.
|
|
19
|
+
* @default '/'
|
|
20
|
+
*/
|
|
21
|
+
defaultRedirectPath?: string;
|
|
22
|
+
/**
|
|
23
|
+
* Optional function to validate the returnTo path.
|
|
24
|
+
* If not provided, only same-origin paths are allowed.
|
|
25
|
+
*/
|
|
26
|
+
validateReturnTo?: (path: string) => boolean;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Handles the OIDC callback in a Next.js route handler.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* // In app/api/auth/callback/oidc/route.ts
|
|
34
|
+
* import { handleOidcCallback } from '@eventuras/fides-auth-next/oidc-callback';
|
|
35
|
+
*
|
|
36
|
+
* export async function GET(request: Request) {
|
|
37
|
+
* return handleOidcCallback(request, {
|
|
38
|
+
* oauthConfig,
|
|
39
|
+
* applicationUrl: 'https://example.com',
|
|
40
|
+
* rolesClaim: 'roles',
|
|
41
|
+
* });
|
|
42
|
+
* }
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export declare function handleOidcCallback(request: Request, config: OidcCallbackConfig): Promise<Response>;
|
|
46
|
+
//# sourceMappingURL=oidc-callback.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oidc-callback.d.ts","sourceRoot":"","sources":["../src/oidc-callback.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAkB/D,MAAM,WAAW,kBAAkB;IACjC,qFAAqF;IACrF,WAAW,EAAE,WAAW,CAAC;IAEzB,2FAA2F;IAC3F,cAAc,EAAE,MAAM,CAAC;IAEvB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;OAGG;IACH,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAE7B;;;OAGG;IACH,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAE7B;;;OAGG;IACH,gBAAgB,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC;CAC9C;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,kBAAkB,CACtC,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,kBAAkB,GACzB,OAAO,CAAC,QAAQ,CAAC,CAqEnB"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { globalGETRateLimit as e } from "./request.js";
|
|
2
|
+
import { g as t, v as n, y as r } from "./fides-auth/dist/oauth.js";
|
|
3
|
+
import { deleteAuthCookies as i, getAuthCookie as a, setSessionCookie as o } from "./cookies.js";
|
|
4
|
+
import { createSession as s } from "./session.js";
|
|
5
|
+
import { Logger as c } from "@eventuras/logger";
|
|
6
|
+
//#region src/oidc-callback.ts
|
|
7
|
+
var l = c.create({ namespace: "fides-auth-next:oidc-callback" });
|
|
8
|
+
async function u(c, u) {
|
|
9
|
+
let { oauthConfig: d, applicationUrl: f, rolesClaim: p = "roles", sessionDurationDays: m = 7, defaultRedirectPath: h = "/", validateReturnTo: g } = u;
|
|
10
|
+
if (!await e()) return l.warn("Rate limit exceeded"), new Response("Too many requests", { status: 429 });
|
|
11
|
+
try {
|
|
12
|
+
let e = new URL(c.url), u = new URL(f);
|
|
13
|
+
u.search = e.search;
|
|
14
|
+
let _ = await a("oauth_state"), v = await a("oauth_code_verifier");
|
|
15
|
+
if (!_ || !v) return l.warn("Missing state or code verifier"), new Response("Please restart the login process.", { status: 400 });
|
|
16
|
+
await o(await s(n(await t(d, u, v, _), p), { sessionDurationDays: m }));
|
|
17
|
+
let y = await a("returnTo");
|
|
18
|
+
await i([
|
|
19
|
+
"oauth_state",
|
|
20
|
+
"oauth_code_verifier",
|
|
21
|
+
"returnTo"
|
|
22
|
+
]);
|
|
23
|
+
let b = r(y, f, h, g);
|
|
24
|
+
return b.searchParams.set("login", "success"), l.info({ redirectUrl: b.toString() }, "Login successful, redirecting"), new Response(null, {
|
|
25
|
+
status: 302,
|
|
26
|
+
headers: { Location: b.toString() }
|
|
27
|
+
});
|
|
28
|
+
} catch (e) {
|
|
29
|
+
return l.error({ error: e }, "OIDC callback error"), new Response("An unexpected error occurred. Please restart the login process.", { status: 500 });
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
//#endregion
|
|
33
|
+
export { u as handleOidcCallback };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { OAuthConfig } from '@eventuras/fides-auth/oauth';
|
|
2
|
+
export interface OidcLoginConfig {
|
|
3
|
+
/** OAuth/OIDC configuration */
|
|
4
|
+
oauthConfig: OAuthConfig;
|
|
5
|
+
/**
|
|
6
|
+
* Validates and sanitizes the returnTo parameter.
|
|
7
|
+
* Should return a safe path or null to use the default.
|
|
8
|
+
* @default Only allows relative paths starting with /
|
|
9
|
+
*/
|
|
10
|
+
validateReturnTo?: (rawReturnTo: string) => string | null;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Handles OIDC login initiation in a Next.js route handler.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* // In app/api/auth/login/route.ts
|
|
18
|
+
* import { handleOidcLogin } from '@eventuras/fides-auth-next/oidc-login';
|
|
19
|
+
*
|
|
20
|
+
* export async function GET(request: Request) {
|
|
21
|
+
* return handleOidcLogin(request, { oauthConfig });
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare function handleOidcLogin(request: Request, config: OidcLoginConfig): Promise<Response>;
|
|
26
|
+
//# sourceMappingURL=oidc-login.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oidc-login.d.ts","sourceRoot":"","sources":["../src/oidc-login.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAa/D,MAAM,WAAW,eAAe;IAC9B,+BAA+B;IAC/B,WAAW,EAAE,WAAW,CAAC;IAEzB;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,CAAC,WAAW,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,CAAC;CAC3D;AAKD;;;;;;;;;;;;GAYG;AACH,wBAAsB,eAAe,CACnC,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,eAAe,GACtB,OAAO,CAAC,QAAQ,CAAC,CAkCnB"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { globalGETRateLimit as e } from "./request.js";
|
|
2
|
+
import { h as t, p as n } from "./fides-auth/dist/oauth.js";
|
|
3
|
+
import { defaultOAuthCookieOptions as r } from "./cookies.js";
|
|
4
|
+
import { cookies as i } from "next/headers";
|
|
5
|
+
import { Logger as a } from "@eventuras/logger";
|
|
6
|
+
//#region src/oidc-login.ts
|
|
7
|
+
var o = a.create({ namespace: "fides-auth-next:oidc-login" }), s = (e) => /^\/(?!\/)/.test(e) ? e : null;
|
|
8
|
+
async function c(a, c) {
|
|
9
|
+
let { oauthConfig: l, validateReturnTo: u = s } = c;
|
|
10
|
+
if (!await e()) return o.warn("Rate limit exceeded"), new Response("Too many requests", { status: 429 });
|
|
11
|
+
let d = new URL(a.url).searchParams.get("returnTo"), f = d ? u(d) : null, p = await n(l), m = await t(l, p);
|
|
12
|
+
o.info("Redirecting to OIDC provider for login");
|
|
13
|
+
let h = await i(), g = r;
|
|
14
|
+
return h.set("oauth_state", p.state, g), h.set("oauth_code_verifier", p.code_verifier, g), f && h.set("returnTo", f, g), new Response(null, {
|
|
15
|
+
status: 302,
|
|
16
|
+
headers: { Location: m.toString() }
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
//#endregion
|
|
20
|
+
export { c as handleOidcLogin };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../src/request.ts"],"names":[],"mappings":"AAgBA,wBAAsB,kBAAkB,IAAI,OAAO,CAAC,OAAO,CAAC,CAiB3D;AAED,wBAAsB,mBAAmB,IAAI,OAAO,CAAC,OAAO,CAAC,CAiB5D"}
|
package/dist/request.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { e } from "./fides-auth/dist/rate-limit.js";
|
|
2
|
+
import { headers as t } from "next/headers";
|
|
3
|
+
import { Logger as n } from "@eventuras/logger";
|
|
4
|
+
//#region src/request.ts
|
|
5
|
+
var r = n.create({ namespace: "fides-auth-next:request" }), i = null;
|
|
6
|
+
function a() {
|
|
7
|
+
return i ||= new e(100, 1), i;
|
|
8
|
+
}
|
|
9
|
+
async function o() {
|
|
10
|
+
try {
|
|
11
|
+
let e = (await t()).get("X-Forwarded-For");
|
|
12
|
+
return e === null ? !0 : a().consume(e, 1);
|
|
13
|
+
} catch (e) {
|
|
14
|
+
return e instanceof Error && e.message.includes("worker") ? r.error({ error: e }, "Worker thread error in globalGETRateLimit") : r.error({ error: e }, "Unexpected error in globalGETRateLimit"), !0;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
async function s() {
|
|
18
|
+
try {
|
|
19
|
+
let e = (await t()).get("X-Forwarded-For");
|
|
20
|
+
return e === null ? !0 : a().consume(e, 3);
|
|
21
|
+
} catch (e) {
|
|
22
|
+
return e instanceof Error && e.message.includes("worker") ? r.error({ error: e }, "Worker thread error in globalPOSTRateLimit") : r.error({ error: e }, "Unexpected error in globalPOSTRateLimit"), !0;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
//#endregion
|
|
26
|
+
export { o as globalGETRateLimit, s as globalPOSTRateLimit };
|