@eventuras/fides-auth 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/LICENSE +21 -0
- package/README.md +311 -0
- package/dist/build-CNL3v39v.js +977 -0
- package/dist/decode_jwt-1J26fl4I.js +25 -0
- package/dist/decrypt-Cahlu_6Y.js +92 -0
- package/dist/deflate-koSuX7FB.js +1015 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/logger.d.ts +83 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +46 -0
- package/dist/oauth-browser.d.ts +62 -0
- package/dist/oauth-browser.d.ts.map +1 -0
- package/dist/oauth-browser.js +49 -0
- package/dist/oauth.d.ts +145 -0
- package/dist/oauth.d.ts.map +1 -0
- package/dist/oauth.js +165 -0
- package/dist/providers/vipps/client.d.ts +62 -0
- package/dist/providers/vipps/client.d.ts.map +1 -0
- package/dist/providers/vipps/index.d.ts +11 -0
- package/dist/providers/vipps/index.d.ts.map +1 -0
- package/dist/providers/vipps/index.js +120 -0
- package/dist/providers/vipps/types.d.ts +107 -0
- package/dist/providers/vipps/types.d.ts.map +1 -0
- package/dist/rate-limit.d.ts +28 -0
- package/dist/rate-limit.d.ts.map +1 -0
- package/dist/rate-limit.js +26 -0
- package/dist/session-refresh.d.ts +13 -0
- package/dist/session-refresh.d.ts.map +1 -0
- package/dist/session-refresh.js +27 -0
- package/dist/session-validation-BxObT3wC.js +66 -0
- package/dist/session-validation.d.ts +24 -0
- package/dist/session-validation.d.ts.map +1 -0
- package/dist/session-validation.js +2 -0
- package/dist/silent-login.d.ts +103 -0
- package/dist/silent-login.d.ts.map +1 -0
- package/dist/silent-login.js +50 -0
- package/dist/types.d.ts +24 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +0 -0
- package/dist/utils-ByMRF7b2.js +379 -0
- package/dist/utils.d.ts +83 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +2 -0
- package/package.json +101 -0
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
import { createLogger as e } from "./logger.js";
|
|
2
|
+
import { C as t, D as n, E as r, T as i, _ as a, b as o, c as s, f as c, i as l, l as u, m as d, o as f, r as p, s as m, t as h, u as g, v as _, w as v, x as y, y as b } from "./deflate-koSuX7FB.js";
|
|
3
|
+
import { t as x } from "./decode_jwt-1J26fl4I.js";
|
|
4
|
+
//#region ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/jwe/flattened/encrypt.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 g(this.#s, "setKeyManagementParameters"), this.#s = e, this;
|
|
20
|
+
}
|
|
21
|
+
setProtectedHeader(e) {
|
|
22
|
+
return g(this.#t, "setProtectedHeader"), this.#t = e, this;
|
|
23
|
+
}
|
|
24
|
+
setSharedUnprotectedHeader(e) {
|
|
25
|
+
return g(this.#n, "setSharedUnprotectedHeader"), this.#n = e, this;
|
|
26
|
+
}
|
|
27
|
+
setUnprotectedHeader(e) {
|
|
28
|
+
return g(this.#r, "setUnprotectedHeader"), this.#r = e, this;
|
|
29
|
+
}
|
|
30
|
+
setAdditionalAuthenticatedData(e) {
|
|
31
|
+
return this.#i = e, this;
|
|
32
|
+
}
|
|
33
|
+
setContentEncryptionKey(e) {
|
|
34
|
+
return g(this.#a, "setContentEncryptionKey"), this.#a = e, this;
|
|
35
|
+
}
|
|
36
|
+
setInitializationVector(e) {
|
|
37
|
+
return g(this.#o, "setInitializationVector"), this.#o = e, this;
|
|
38
|
+
}
|
|
39
|
+
async encrypt(e, n) {
|
|
40
|
+
if (!this.#t && !this.#r && !this.#n) throw new _("either setProtectedHeader, setUnprotectedHeader, or sharedUnprotectedHeader must be called before #encrypt()");
|
|
41
|
+
if (!s(this.#t, this.#r, this.#n)) throw new _("JWE Protected, JWE Shared Unprotected and JWE Per-Recipient Header Parameter names must be disjoint");
|
|
42
|
+
let i = {
|
|
43
|
+
...this.#t,
|
|
44
|
+
...this.#r,
|
|
45
|
+
...this.#n
|
|
46
|
+
};
|
|
47
|
+
if (l(_, /* @__PURE__ */ new Map(), n?.crit, this.#t, i), i.zip !== void 0 && i.zip !== "DEF") throw new a("Unsupported JWE \"zip\" (Compression Algorithm) Header Parameter value.");
|
|
48
|
+
if (i.zip !== void 0 && !this.#t?.zip) throw new _("JWE \"zip\" (Compression Algorithm) Header Parameter MUST be in a protected header.");
|
|
49
|
+
let { alg: o, enc: u } = i;
|
|
50
|
+
if (typeof o != "string" || !o) throw new _("JWE \"alg\" (Algorithm) Header Parameter missing or invalid");
|
|
51
|
+
if (typeof u != "string" || !u) throw new _("JWE \"enc\" (Encryption Algorithm) Header Parameter missing or invalid");
|
|
52
|
+
let g;
|
|
53
|
+
if (this.#a && (o === "dir" || o === "ECDH-ES")) throw TypeError(`setContentEncryptionKey cannot be called with JWE "alg" (Algorithm) Header ${o}`);
|
|
54
|
+
p(o === "dir" ? u : o, e, "encrypt");
|
|
55
|
+
let y;
|
|
56
|
+
{
|
|
57
|
+
let t, r = await m(e, o);
|
|
58
|
+
({cek: y, encryptedKey: g, parameters: t} = await f(o, u, r, this.#a, this.#s)), t && (n && c in n ? this.#r ? this.#r = {
|
|
59
|
+
...this.#r,
|
|
60
|
+
...t
|
|
61
|
+
} : this.setUnprotectedHeader(t) : this.#t ? this.#t = {
|
|
62
|
+
...this.#t,
|
|
63
|
+
...t
|
|
64
|
+
} : this.setProtectedHeader(t));
|
|
65
|
+
}
|
|
66
|
+
let b, x, S, C;
|
|
67
|
+
if (this.#t ? (x = t(JSON.stringify(this.#t)), S = r(x)) : (x = "", S = new Uint8Array()), this.#i) {
|
|
68
|
+
C = t(this.#i);
|
|
69
|
+
let e = r(C);
|
|
70
|
+
b = v(S, r("."), e);
|
|
71
|
+
} else b = S;
|
|
72
|
+
let w = this.#e;
|
|
73
|
+
i.zip === "DEF" && (w = await h(w).catch((e) => {
|
|
74
|
+
throw new _("Failed to compress plaintext", { cause: e });
|
|
75
|
+
}));
|
|
76
|
+
let { ciphertext: T, tag: E, iv: D } = await d(u, w, y, this.#o, b), O = { ciphertext: t(T) };
|
|
77
|
+
return D && (O.iv = t(D)), E && (O.tag = t(E)), g && (O.encrypted_key = t(g)), 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, n = {}) {
|
|
128
|
+
let r;
|
|
129
|
+
try {
|
|
130
|
+
r = JSON.parse(i.decode(t));
|
|
131
|
+
} catch {}
|
|
132
|
+
if (!u(r)) throw new y("JWT Claims Set must be a top-level JSON object");
|
|
133
|
+
let { typ: a } = n;
|
|
134
|
+
if (a && (typeof e.typ != "string" || M(e.typ) !== M(a))) throw new b("unexpected \"typ\" JWT header value", r, "typ", "check_failed");
|
|
135
|
+
let { requiredClaims: s = [], issuer: c, subject: l, audience: d, maxTokenAge: f } = n, p = [...s];
|
|
136
|
+
f !== void 0 && p.push("iat"), d !== void 0 && p.push("aud"), l !== void 0 && p.push("sub"), c !== void 0 && p.push("iss");
|
|
137
|
+
for (let e of new Set(p.reverse())) if (!(e in r)) throw new b(`missing required "${e}" claim`, r, e, "missing");
|
|
138
|
+
if (c && !(Array.isArray(c) ? c : [c]).includes(r.iss)) throw new b("unexpected \"iss\" claim value", r, "iss", "check_failed");
|
|
139
|
+
if (l && r.sub !== l) throw new b("unexpected \"sub\" claim value", r, "sub", "check_failed");
|
|
140
|
+
if (d && !N(r.aud, typeof d == "string" ? [d] : d)) throw new b("unexpected \"aud\" claim value", r, "aud", "check_failed");
|
|
141
|
+
let m;
|
|
142
|
+
switch (typeof n.clockTolerance) {
|
|
143
|
+
case "string":
|
|
144
|
+
m = A(n.clockTolerance);
|
|
145
|
+
break;
|
|
146
|
+
case "number":
|
|
147
|
+
m = n.clockTolerance;
|
|
148
|
+
break;
|
|
149
|
+
case "undefined":
|
|
150
|
+
m = 0;
|
|
151
|
+
break;
|
|
152
|
+
default: throw TypeError("Invalid clockTolerance option type");
|
|
153
|
+
}
|
|
154
|
+
let { currentDate: h } = n, g = C(h || /* @__PURE__ */ new Date());
|
|
155
|
+
if ((r.iat !== void 0 || f) && typeof r.iat != "number") throw new b("\"iat\" claim must be a number", r, "iat", "invalid");
|
|
156
|
+
if (r.nbf !== void 0) {
|
|
157
|
+
if (typeof r.nbf != "number") throw new b("\"nbf\" claim must be a number", r, "nbf", "invalid");
|
|
158
|
+
if (r.nbf > g + m) throw new b("\"nbf\" claim timestamp check failed", r, "nbf", "check_failed");
|
|
159
|
+
}
|
|
160
|
+
if (r.exp !== void 0) {
|
|
161
|
+
if (typeof r.exp != "number") throw new b("\"exp\" claim must be a number", r, "exp", "invalid");
|
|
162
|
+
if (r.exp <= g - m) throw new o("\"exp\" claim timestamp check failed", r, "exp", "check_failed");
|
|
163
|
+
}
|
|
164
|
+
if (f) {
|
|
165
|
+
let e = g - r.iat, t = typeof f == "number" ? f : A(f);
|
|
166
|
+
if (e - m > t) throw new o("\"iat\" claim timestamp check failed (too far in the past)", r, "iat", "check_failed");
|
|
167
|
+
if (e < 0 - m) throw new b("\"iat\" claim timestamp check failed (it should be in the past)", r, "iat", "check_failed");
|
|
168
|
+
}
|
|
169
|
+
return r;
|
|
170
|
+
}
|
|
171
|
+
var F = class {
|
|
172
|
+
#e;
|
|
173
|
+
constructor(e) {
|
|
174
|
+
if (!u(e)) throw TypeError("JWT Claims Set MUST be an object");
|
|
175
|
+
this.#e = structuredClone(e);
|
|
176
|
+
}
|
|
177
|
+
data() {
|
|
178
|
+
return n.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 g(this.#r, "setProtectedHeader"), this.#r = e, this;
|
|
272
|
+
}
|
|
273
|
+
setKeyManagementParameters(e) {
|
|
274
|
+
return g(this.#n, "setKeyManagementParameters"), this.#n = e, this;
|
|
275
|
+
}
|
|
276
|
+
setContentEncryptionKey(e) {
|
|
277
|
+
return g(this.#e, "setContentEncryptionKey"), this.#e = e, this;
|
|
278
|
+
}
|
|
279
|
+
setInitializationVector(e) {
|
|
280
|
+
return g(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 { X as a, z as c, Y as d, P as f, H as i, G as l, V as n, q as o, U as r, J as s, Z as t, K as u };
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a hex string to a Uint8Array.
|
|
3
|
+
*
|
|
4
|
+
* @param hex - A hexadecimal string.
|
|
5
|
+
* @returns A Uint8Array representing the bytes of the hex string.
|
|
6
|
+
*/
|
|
7
|
+
export declare function hexToUint8Array(hex: string): Uint8Array;
|
|
8
|
+
/**
|
|
9
|
+
* Encrypts a payload into a JWT using the specified secret.
|
|
10
|
+
*
|
|
11
|
+
* @param payload - The payload to encrypt (can be any JSON-serializable value)
|
|
12
|
+
* @param secret - The encryption key as a hex string or Uint8Array (32 bytes for A256GCM)
|
|
13
|
+
* @returns A promise that resolves to the encrypted JWT as a string.
|
|
14
|
+
*/
|
|
15
|
+
export declare function createEncryptedJWT(payload: unknown, secret: string | Uint8Array): Promise<string>;
|
|
16
|
+
/**
|
|
17
|
+
* Encrypts the given text using AES-GCM via the Web Crypto API.
|
|
18
|
+
* Returns a string in the format: iv:authTag:ciphertext, all in hex.
|
|
19
|
+
*
|
|
20
|
+
* @param text - The plaintext to encrypt.
|
|
21
|
+
* @param secret - The encryption key as a hex string or Uint8Array (32 bytes for AES-256).
|
|
22
|
+
* @returns A promise that resolves to the encrypted string.
|
|
23
|
+
*/
|
|
24
|
+
export declare function encrypt(text: string, secret: string | Uint8Array): Promise<string>;
|
|
25
|
+
/**
|
|
26
|
+
* Decrypts data encrypted with AES-256-GCM (using the Web Crypto API).
|
|
27
|
+
* The input is expected to be in the format: iv:authTag:ciphertext (all hex-encoded).
|
|
28
|
+
*
|
|
29
|
+
* @param data - The encrypted data string.
|
|
30
|
+
* @param secret - The decryption key as a hex string or Uint8Array (32 bytes for AES-256).
|
|
31
|
+
* @returns A promise that resolves to the decrypted plaintext.
|
|
32
|
+
*/
|
|
33
|
+
export declare function decrypt(data: string, secret: string | Uint8Array): Promise<string>;
|
|
34
|
+
/**
|
|
35
|
+
* Hashes the input using SHA-256 with the Web Crypto API.
|
|
36
|
+
* @param data - The input data (string or Uint8Array).
|
|
37
|
+
* @returns A Promise that resolves to the SHA-256 hash as a hex string.
|
|
38
|
+
*/
|
|
39
|
+
export declare function sha256(data: string | Uint8Array): Promise<string>;
|
|
40
|
+
/**
|
|
41
|
+
* Hashes the input using SHA-512 with the Web Crypto API.
|
|
42
|
+
* @param data - The input data (string or Uint8Array).
|
|
43
|
+
* @returns A Promise that resolves to the SHA-512 hash as a hex string.
|
|
44
|
+
*/
|
|
45
|
+
export declare function sha512(data: string | Uint8Array): Promise<string>;
|
|
46
|
+
/**
|
|
47
|
+
* Retrieves the session secret from environment variables.
|
|
48
|
+
* Throws an error if the SESSION_SECRET is not defined.
|
|
49
|
+
*
|
|
50
|
+
* @returns {string} The session secret.
|
|
51
|
+
*/
|
|
52
|
+
export declare function getSessionSecret(): string;
|
|
53
|
+
/**
|
|
54
|
+
* Retrieves the session secret from environment variables as Uint8Array .
|
|
55
|
+
* Throws an error if the SESSION_SECRET is not defined.
|
|
56
|
+
*
|
|
57
|
+
* @returns {Uint8Array} The session secret as Uint8Array.
|
|
58
|
+
*/
|
|
59
|
+
export declare function getSessionSecretUint8Array(): Uint8Array;
|
|
60
|
+
/**
|
|
61
|
+
* Converts a Uint8Array to a lowercase hexadecimal string.
|
|
62
|
+
*/
|
|
63
|
+
export declare function toHex(bytes: Uint8Array): string;
|
|
64
|
+
/**
|
|
65
|
+
* Generates a random token of the given byte length and returns it as a hex string.
|
|
66
|
+
* Default token length is 20 bytes (160 bits).
|
|
67
|
+
*
|
|
68
|
+
* @param tokenLength - The number of random bytes to generate (default is 20).
|
|
69
|
+
* @returns A hex string representing the token.
|
|
70
|
+
*/
|
|
71
|
+
export declare function generateToken(tokenLength?: number): string;
|
|
72
|
+
/**
|
|
73
|
+
* Determines if the access token of a session will expire in less than the given threshold.
|
|
74
|
+
*
|
|
75
|
+
* It decodes the access token (assumed to be a JWT) and reads the `exp` claim.
|
|
76
|
+
* The expiration (`exp`) claim is the UNIX timestamp (in seconds) when the token expires.
|
|
77
|
+
*
|
|
78
|
+
* @param accessToken - The access token string.
|
|
79
|
+
* @param seconds - The threshold (in seconds) for checking expiration (default is 10 seconds).
|
|
80
|
+
* @returns True if the access token expires within the threshold; otherwise, false.
|
|
81
|
+
*/
|
|
82
|
+
export declare const accessTokenExpires: (accessToken: string, seconds?: number) => boolean;
|
|
83
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAOA;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAYvD;AAaD;;;;;;GAMG;AACH,wBAAsB,kBAAkB,CACtC,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,MAAM,GAAG,UAAU,GAC1B,OAAO,CAAC,MAAM,CAAC,CAKjB;AAGD;;;;;;;GAOG;AACH,wBAAsB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,CAkCxF;AAED;;;;;;;GAOG;AACH,wBAAsB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,CA4CxF;AAcD;;;;GAIG;AACH,wBAAsB,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,CAIvE;AAED;;;;GAIG;AACH,wBAAsB,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,CAIvE;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,IAAI,MAAM,CAMzC;AAED;;;;;GAKG;AACH,wBAAgB,0BAA0B,IAAI,UAAU,CAKvD;AAED;;GAEG;AACH,wBAAgB,KAAK,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAI/C;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,WAAW,GAAE,MAAW,GAAG,MAAM,CAI9D;AAGD;;;;;;;;;GASG;AACH,eAAO,MAAM,kBAAkB,GAC7B,aAAa,MAAM,EACnB,UAAS,MAAW,KACnB,OAsBF,CAAC"}
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as e, c as t, d as n, i as r, l as i, n as a, o, r as s, s as c, t as l, u } from "./utils-ByMRF7b2.js";
|
|
2
|
+
export { l as accessTokenExpires, a as createEncryptedJWT, s as decrypt, r as encrypt, e as generateToken, o as getSessionSecret, c as getSessionSecretUint8Array, t as hexToUint8Array, i as sha256, u as sha512, n as toHex };
|
package/package.json
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@eventuras/fides-auth",
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "Framework-agnostic OAuth/OIDC authentication library with PKCE, session management, and pluggable logging",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"oauth",
|
|
7
|
+
"oidc",
|
|
8
|
+
"openid-connect",
|
|
9
|
+
"authentication",
|
|
10
|
+
"pkce",
|
|
11
|
+
"session",
|
|
12
|
+
"jwt",
|
|
13
|
+
"identity",
|
|
14
|
+
"vipps"
|
|
15
|
+
],
|
|
16
|
+
"homepage": "https://github.com/losol/eventuras/tree/main/libs/fides-auth#readme",
|
|
17
|
+
"bugs": {
|
|
18
|
+
"url": "https://github.com/losol/eventuras/issues"
|
|
19
|
+
},
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "https://github.com/losol/eventuras.git",
|
|
23
|
+
"directory": "libs/fides-auth"
|
|
24
|
+
},
|
|
25
|
+
"license": "MIT",
|
|
26
|
+
"author": "losol <losol@users.noreply.github.com>",
|
|
27
|
+
"sideEffects": false,
|
|
28
|
+
"type": "module",
|
|
29
|
+
"exports": {
|
|
30
|
+
".": {
|
|
31
|
+
"types": "./dist/index.d.ts",
|
|
32
|
+
"import": "./dist/index.js"
|
|
33
|
+
},
|
|
34
|
+
"./logger": {
|
|
35
|
+
"types": "./dist/logger.d.ts",
|
|
36
|
+
"import": "./dist/logger.js"
|
|
37
|
+
},
|
|
38
|
+
"./session-refresh": {
|
|
39
|
+
"types": "./dist/session-refresh.d.ts",
|
|
40
|
+
"import": "./dist/session-refresh.js"
|
|
41
|
+
},
|
|
42
|
+
"./session-validation": {
|
|
43
|
+
"types": "./dist/session-validation.d.ts",
|
|
44
|
+
"import": "./dist/session-validation.js"
|
|
45
|
+
},
|
|
46
|
+
"./oauth": {
|
|
47
|
+
"types": "./dist/oauth.d.ts",
|
|
48
|
+
"import": "./dist/oauth.js"
|
|
49
|
+
},
|
|
50
|
+
"./oauth-browser": {
|
|
51
|
+
"types": "./dist/oauth-browser.d.ts",
|
|
52
|
+
"import": "./dist/oauth-browser.js"
|
|
53
|
+
},
|
|
54
|
+
"./silent-login": {
|
|
55
|
+
"types": "./dist/silent-login.d.ts",
|
|
56
|
+
"import": "./dist/silent-login.js"
|
|
57
|
+
},
|
|
58
|
+
"./utils": {
|
|
59
|
+
"types": "./dist/utils.d.ts",
|
|
60
|
+
"import": "./dist/utils.js"
|
|
61
|
+
},
|
|
62
|
+
"./types": {
|
|
63
|
+
"types": "./dist/types.d.ts",
|
|
64
|
+
"import": "./dist/types.js"
|
|
65
|
+
},
|
|
66
|
+
"./rate-limit": {
|
|
67
|
+
"types": "./dist/rate-limit.d.ts",
|
|
68
|
+
"import": "./dist/rate-limit.js"
|
|
69
|
+
},
|
|
70
|
+
"./providers/vipps": {
|
|
71
|
+
"types": "./dist/providers/vipps/index.d.ts",
|
|
72
|
+
"import": "./dist/providers/vipps/index.js"
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
"main": "./dist/index.js",
|
|
76
|
+
"types": "./dist/index.d.ts",
|
|
77
|
+
"files": [
|
|
78
|
+
"dist",
|
|
79
|
+
"LICENSE",
|
|
80
|
+
"README.md"
|
|
81
|
+
],
|
|
82
|
+
"scripts": {
|
|
83
|
+
"build": "vite build",
|
|
84
|
+
"dev": "vite build --watch",
|
|
85
|
+
"test": "vitest run",
|
|
86
|
+
"test:watch": "vitest"
|
|
87
|
+
},
|
|
88
|
+
"dependencies": {
|
|
89
|
+
"jose": "6.2.2",
|
|
90
|
+
"openid-client": "^6.8.2"
|
|
91
|
+
},
|
|
92
|
+
"devDependencies": {
|
|
93
|
+
"@eventuras/typescript-config": "workspace:*",
|
|
94
|
+
"@eventuras/vite-config": "workspace:*",
|
|
95
|
+
"vite": "^8.0.3",
|
|
96
|
+
"vitest": "^4.1.2"
|
|
97
|
+
},
|
|
98
|
+
"engines": {
|
|
99
|
+
"node": ">=18"
|
|
100
|
+
}
|
|
101
|
+
}
|