@eventuras/fides-auth 0.4.0 → 0.6.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.
@@ -1,977 +0,0 @@
1
- //#region ../../node_modules/.pnpm/oauth4webapi@3.8.5/node_modules/oauth4webapi/build/index.js
2
- var e;
3
- (typeof navigator > "u" || !navigator.userAgent?.startsWith?.("Mozilla/5.0 ")) && (e = "oauth4webapi/v3.8.5");
4
- function t(e, t) {
5
- if (e == null) return !1;
6
- try {
7
- return e instanceof t || Object.getPrototypeOf(e)[Symbol.toStringTag] === t.prototype[Symbol.toStringTag];
8
- } catch {
9
- return !1;
10
- }
11
- }
12
- var n = "ERR_INVALID_ARG_VALUE", r = "ERR_INVALID_ARG_TYPE";
13
- function i(e, t, n) {
14
- let r = TypeError(e, { cause: n });
15
- return Object.assign(r, { code: t }), r;
16
- }
17
- var a = Symbol(), o = Symbol(), s = Symbol(), c = Symbol(), l = Symbol(), u = new TextEncoder(), d = new TextDecoder();
18
- function f(e) {
19
- return typeof e == "string" ? u.encode(e) : d.decode(e);
20
- }
21
- var p;
22
- if (Uint8Array.prototype.toBase64) p = (e) => (e instanceof ArrayBuffer && (e = new Uint8Array(e)), e.toBase64({
23
- alphabet: "base64url",
24
- omitPadding: !0
25
- }));
26
- else {
27
- let e = 32768;
28
- p = (t) => {
29
- t instanceof ArrayBuffer && (t = new Uint8Array(t));
30
- let n = [];
31
- for (let r = 0; r < t.byteLength; r += e) n.push(String.fromCharCode.apply(null, t.subarray(r, r + e)));
32
- return btoa(n.join("")).replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
33
- };
34
- }
35
- var ee = Uint8Array.fromBase64 ? (e) => {
36
- try {
37
- return Uint8Array.fromBase64(e, { alphabet: "base64url" });
38
- } catch (e) {
39
- throw i("The input to be decoded is not correctly encoded.", n, e);
40
- }
41
- } : (e) => {
42
- try {
43
- let t = atob(e.replace(/-/g, "+").replace(/_/g, "/").replace(/\s/g, "")), n = new Uint8Array(t.length);
44
- for (let e = 0; e < t.length; e++) n[e] = t.charCodeAt(e);
45
- return n;
46
- } catch (e) {
47
- throw i("The input to be decoded is not correctly encoded.", n, e);
48
- }
49
- };
50
- function m(e) {
51
- return typeof e == "string" ? ee(e) : p(e);
52
- }
53
- var h = class extends Error {
54
- code;
55
- constructor(e, t) {
56
- super(e, t), this.name = this.constructor.name, this.code = P, Error.captureStackTrace?.(this, this.constructor);
57
- }
58
- }, g = class extends Error {
59
- code;
60
- constructor(e, t) {
61
- super(e, t), this.name = this.constructor.name, t?.code && (this.code = t?.code), Error.captureStackTrace?.(this, this.constructor);
62
- }
63
- };
64
- function _(e, t, n) {
65
- return new g(e, {
66
- code: t,
67
- cause: n
68
- });
69
- }
70
- function v(e) {
71
- return !(typeof e != "object" || !e || Array.isArray(e));
72
- }
73
- function te(r) {
74
- t(r, Headers) && (r = Object.fromEntries(r.entries()));
75
- let a = new Headers(r ?? {});
76
- if (e && !a.has("user-agent") && a.set("user-agent", e), a.has("authorization")) throw i("\"options.headers\" must not include the \"authorization\" header name", n);
77
- return a;
78
- }
79
- function y(e, t) {
80
- if (t !== void 0) {
81
- if (typeof t == "function" && (t = t(e.href)), !(t instanceof AbortSignal)) throw i("\"options.signal\" must return or be an instance of AbortSignal", r);
82
- return t;
83
- }
84
- }
85
- function b(e) {
86
- return e.includes("//") ? e.replace("//", "/") : e;
87
- }
88
- function x(e, t, n = !1) {
89
- return e.pathname === "/" ? e.pathname = t : e.pathname = b(`${t}/${n ? e.pathname : e.pathname.replace(/(\/)$/, "")}`), e;
90
- }
91
- function ne(e, t) {
92
- return e.pathname = b(`${e.pathname}/${t}`), e;
93
- }
94
- async function re(e, t, n, o) {
95
- if (!(e instanceof URL)) throw i(`"${t}" must be an instance of URL`, r);
96
- ge(e, o?.[a] !== !0);
97
- let s = n(new URL(e.href)), l = te(o?.headers);
98
- return l.set("accept", "application/json"), (o?.[c] || fetch)(s.href, {
99
- body: void 0,
100
- headers: Object.fromEntries(l.entries()),
101
- method: "GET",
102
- redirect: "manual",
103
- signal: y(s, o?.signal)
104
- });
105
- }
106
- async function ie(e, t) {
107
- return re(e, "issuerIdentifier", (e) => {
108
- switch (t?.algorithm) {
109
- case void 0:
110
- case "oidc":
111
- ne(e, ".well-known/openid-configuration");
112
- break;
113
- case "oauth2":
114
- x(e, ".well-known/oauth-authorization-server");
115
- break;
116
- default: throw i("\"options.algorithm\" must be \"oidc\" (default), or \"oauth2\"", n);
117
- }
118
- return e;
119
- }, t);
120
- }
121
- function S(e, t, a, o, s) {
122
- try {
123
- if (typeof e != "number" || !Number.isFinite(e)) throw i(`${a} must be a number`, r, s);
124
- if (e > 0) return;
125
- if (t) {
126
- if (e !== 0) throw i(`${a} must be a non-negative number`, n, s);
127
- return;
128
- }
129
- throw i(`${a} must be a positive number`, n, s);
130
- } catch (e) {
131
- throw o ? _(e.message, o, s) : e;
132
- }
133
- }
134
- function C(e, t, a, o) {
135
- try {
136
- if (typeof e != "string") throw i(`${t} must be a string`, r, o);
137
- if (e.length === 0) throw i(`${t} must not be empty`, n, o);
138
- } catch (e) {
139
- throw a ? _(e.message, a, o) : e;
140
- }
141
- }
142
- async function ae(e, n) {
143
- let a = e;
144
- if (!(a instanceof URL) && a !== H) throw i("\"expectedIssuerIdentifier\" must be an instance of URL", r);
145
- if (!t(n, Response)) throw i("\"response\" must be an instance of Response", r);
146
- if (n.status !== 200) throw _("\"response\" is not a conform Authorization Server Metadata response (unexpected HTTP status code)", L, n);
147
- B(n);
148
- let o = await ht(n);
149
- if (C(o.issuer, "\"response\" body \"issuer\" property", I, { body: o }), a !== H && new URL(o.issuer).href !== a.href) throw _("\"response\" body \"issuer\" property does not match the expected value", at, {
150
- expected: a.href,
151
- body: o,
152
- attribute: "issuer"
153
- });
154
- return o;
155
- }
156
- function oe(e) {
157
- ce(e, "application/json");
158
- }
159
- function se(e, ...t) {
160
- let n = "\"response\" content-type must be ";
161
- if (t.length > 2) {
162
- let e = t.pop();
163
- n += `${t.join(", ")}, or ${e}`;
164
- } else t.length === 2 ? n += `${t[0]} or ${t[1]}` : n += t[0];
165
- return _(n, nt, e);
166
- }
167
- function ce(e, t) {
168
- if (Fe(e) !== t) throw se(e, t);
169
- }
170
- function le() {
171
- return m(crypto.getRandomValues(new Uint8Array(32)));
172
- }
173
- function ue() {
174
- return le();
175
- }
176
- function de() {
177
- return le();
178
- }
179
- async function fe(e) {
180
- return C(e, "codeVerifier"), m(await crypto.subtle.digest("SHA-256", f(e)));
181
- }
182
- function w(e) {
183
- let t = e?.[o];
184
- return typeof t == "number" && Number.isFinite(t) ? t : 0;
185
- }
186
- function T(e) {
187
- let t = e?.[s];
188
- return typeof t == "number" && Number.isFinite(t) && Math.sign(t) !== -1 ? t : 30;
189
- }
190
- function E() {
191
- return Math.floor(Date.now() / 1e3);
192
- }
193
- function D(e) {
194
- if (typeof e != "object" || !e) throw i("\"as\" must be an object", r);
195
- C(e.issuer, "\"as.issuer\"");
196
- }
197
- function O(e) {
198
- if (typeof e != "object" || !e) throw i("\"client\" must be an object", r);
199
- C(e.client_id, "\"client.client_id\"");
200
- }
201
- function pe(e) {
202
- return C(e, "\"clientSecret\""), (t, n, r, i) => {
203
- r.set("client_id", n.client_id), r.set("client_secret", e);
204
- };
205
- }
206
- function me() {
207
- return (e, t, n, r) => {
208
- n.set("client_id", t.client_id);
209
- };
210
- }
211
- var he = URL.parse ? (e, t) => URL.parse(e, t) : (e, t) => {
212
- try {
213
- return new URL(e, t);
214
- } catch {
215
- return null;
216
- }
217
- };
218
- function ge(e, t) {
219
- if (t && e.protocol !== "https:") throw _("only requests to HTTPS are allowed", rt, e);
220
- if (e.protocol !== "https:" && e.protocol !== "http:") throw _("only HTTP and HTTPS requests are allowed", it, e);
221
- }
222
- function _e(e, t, n, r) {
223
- let i;
224
- if (typeof e != "string" || !(i = he(e))) throw _(`authorization server metadata does not contain a valid ${n ? `"as.mtls_endpoint_aliases.${t}"` : `"as.${t}"`}`, e === void 0 ? ot : st, { attribute: n ? `mtls_endpoint_aliases.${t}` : t });
225
- return ge(i, r), i;
226
- }
227
- function ve(e, t, n, r) {
228
- return n && e.mtls_endpoint_aliases && t in e.mtls_endpoint_aliases ? _e(e.mtls_endpoint_aliases[t], t, n, r) : _e(e[t], t, n, r);
229
- }
230
- function ye(e) {
231
- if (e instanceof Se) {
232
- let { 0: t, length: n } = e.cause;
233
- return n === 1 && t.scheme === "dpop" && t.parameters.error === "use_dpop_nonce";
234
- }
235
- return e instanceof be ? e.error === "use_dpop_nonce" : !1;
236
- }
237
- var be = class extends Error {
238
- cause;
239
- code;
240
- error;
241
- status;
242
- error_description;
243
- response;
244
- constructor(e, t) {
245
- super(e, t), this.name = this.constructor.name, this.code = et, this.cause = t.cause, this.error = t.cause.error, this.status = t.response.status, this.error_description = t.cause.error_description, Object.defineProperty(this, "response", {
246
- enumerable: !1,
247
- value: t.response
248
- }), Error.captureStackTrace?.(this, this.constructor);
249
- }
250
- }, xe = class extends Error {
251
- cause;
252
- code;
253
- error;
254
- error_description;
255
- constructor(e, t) {
256
- super(e, t), this.name = this.constructor.name, this.code = tt, this.cause = t.cause, this.error = t.cause.get("error"), this.error_description = t.cause.get("error_description") ?? void 0, Error.captureStackTrace?.(this, this.constructor);
257
- }
258
- }, Se = class extends Error {
259
- cause;
260
- code;
261
- response;
262
- status;
263
- constructor(e, t) {
264
- super(e, t), this.name = this.constructor.name, this.code = $e, this.cause = t.cause, this.status = t.response.status, this.response = t.response, Object.defineProperty(this, "response", { enumerable: !1 }), Error.captureStackTrace?.(this, this.constructor);
265
- }
266
- }, Ce = "[a-zA-Z0-9!#$%&\\'\\*\\+\\-\\.\\^_`\\|~]+", we = "[a-zA-Z0-9\\-\\._\\~\\+\\/]+={0,2}", Te = "(" + Ce + ")\\s*=\\s*\"((?:[^\"\\\\]|\\\\[\\s\\S])*)\"", Ee = "(" + Ce + ")\\s*=\\s*([a-zA-Z0-9!#$%&\\'\\*\\+\\-\\.\\^_`\\|~]+)", De = RegExp("^[,\\s]*(" + Ce + ")"), Oe = RegExp("^[,\\s]*" + Te + "[,\\s]*(.*)"), ke = RegExp("^[,\\s]*" + Ee + "[,\\s]*(.*)"), Ae = RegExp("^(" + we + ")(?:$|[,\\s])(.*)");
267
- function je(e) {
268
- if (!t(e, Response)) throw i("\"response\" must be an instance of Response", r);
269
- let n = e.headers.get("www-authenticate");
270
- if (n === null) return;
271
- let a = [], o = n;
272
- for (; o;) {
273
- let e = o.match(De), t = e?.["1"].toLowerCase();
274
- if (!t) return;
275
- let n = o.substring(e[0].length);
276
- if (n && !n.match(/^[\s,]/)) return;
277
- let r = n.match(/^\s+(.*)$/), i = !!r;
278
- o = r ? r[1] : void 0;
279
- let s = {}, c;
280
- if (i) for (; o;) {
281
- let t, n;
282
- if (e = o.match(Oe)) {
283
- if ([, t, n, o] = e, n.includes("\\")) try {
284
- n = JSON.parse(`"${n}"`);
285
- } catch {}
286
- s[t.toLowerCase()] = n;
287
- continue;
288
- }
289
- if (e = o.match(ke)) {
290
- [, t, n, o] = e, s[t.toLowerCase()] = n;
291
- continue;
292
- }
293
- if (e = o.match(Ae)) {
294
- if (Object.keys(s).length) break;
295
- [, c, o] = e;
296
- break;
297
- }
298
- return;
299
- }
300
- else o = n || void 0;
301
- let l = {
302
- scheme: t,
303
- parameters: s
304
- };
305
- c && (l.token68 = c), a.push(l);
306
- }
307
- if (a.length) return a;
308
- }
309
- async function Me(e) {
310
- if (e.status > 399 && e.status < 500) {
311
- B(e), oe(e);
312
- try {
313
- let t = await e.clone().json();
314
- if (v(t) && typeof t.error == "string" && t.error.length) return t;
315
- } catch {}
316
- }
317
- }
318
- async function Ne(e, t, n) {
319
- if (e.status !== t) {
320
- Ve(e);
321
- let t;
322
- throw (t = await Me(e)) ? (await e.body?.cancel(), new be("server responded with an error in the response body", {
323
- cause: t,
324
- response: e
325
- })) : _(`"response" is not a conform ${n} response (unexpected HTTP status code)`, L, e);
326
- }
327
- }
328
- function Pe(e) {
329
- if (!j.has(e)) throw i("\"options.DPoP\" is not a valid DPoPHandle", n);
330
- }
331
- function Fe(e) {
332
- return e.headers.get("content-type")?.split(";")[0];
333
- }
334
- async function Ie(e, t, n, r, i, a, o) {
335
- return await n(e, t, i, a), a.set("content-type", "application/x-www-form-urlencoded;charset=UTF-8"), (o?.[c] || fetch)(r.href, {
336
- body: i,
337
- headers: Object.fromEntries(a.entries()),
338
- method: "POST",
339
- redirect: "manual",
340
- signal: y(r, o?.signal)
341
- });
342
- }
343
- async function Le(e, t, n, r, i, o) {
344
- let s = ve(e, "token_endpoint", t.use_mtls_endpoint_aliases, o?.[a] !== !0);
345
- i.set("grant_type", r);
346
- let c = te(o?.headers);
347
- c.set("accept", "application/json"), o?.DPoP !== void 0 && (Pe(o.DPoP), await o.DPoP.addProof(s, c, "POST"));
348
- let l = await Ie(e, t, n, s, i, c, o);
349
- return o?.DPoP?.cacheNonce(l, s), l;
350
- }
351
- async function Re(e, t, n, r, i) {
352
- D(e), O(t), C(r, "\"refreshToken\"");
353
- let a = new URLSearchParams(i?.additionalParameters);
354
- return a.set("refresh_token", r), Le(e, t, n, "refresh_token", a, i);
355
- }
356
- var ze = /* @__PURE__ */ new WeakMap(), Be = /* @__PURE__ */ new WeakMap();
357
- function k(e) {
358
- if (!e.id_token) return;
359
- let t = ze.get(e);
360
- if (!t) throw i("\"ref\" was already garbage collected or did not resolve from the proper sources", n);
361
- return t;
362
- }
363
- async function A(e, n, a, o, s, c) {
364
- if (D(e), O(n), !t(a, Response)) throw i("\"response\" must be an instance of Response", r);
365
- await Ne(a, 200, "Token Endpoint"), B(a);
366
- let l = await ht(a);
367
- if (C(l.access_token, "\"response\" body \"access_token\" property", I, { body: l }), C(l.token_type, "\"response\" body \"token_type\" property", I, { body: l }), l.token_type = l.token_type.toLowerCase(), l.expires_in !== void 0) {
368
- let e = typeof l.expires_in == "number" ? l.expires_in : parseFloat(l.expires_in);
369
- S(e, !0, "\"response\" body \"expires_in\" property", I, { body: l }), l.expires_in = e;
370
- }
371
- if (l.refresh_token !== void 0 && C(l.refresh_token, "\"response\" body \"refresh_token\" property", I, { body: l }), l.scope !== void 0 && typeof l.scope != "string") throw _("\"response\" body \"scope\" property must be a string", I, { body: l });
372
- if (l.id_token !== void 0) {
373
- C(l.id_token, "\"response\" body \"id_token\" property", I, { body: l });
374
- let t = [
375
- "aud",
376
- "exp",
377
- "iat",
378
- "iss",
379
- "sub"
380
- ];
381
- n.require_auth_time === !0 && t.push("auth_time"), n.default_max_age !== void 0 && (S(n.default_max_age, !0, "\"client.default_max_age\""), t.push("auth_time")), o?.length && t.push(...o);
382
- let { claims: r, jwt: i } = await ct(l.id_token, dt.bind(void 0, n.id_token_signed_response_alg, e.id_token_signing_alg_values_supported, "RS256"), w(n), T(n), s).then(Ye.bind(void 0, t)).then(We.bind(void 0, e)).then(Ue.bind(void 0, n.client_id));
383
- if (Array.isArray(r.aud) && r.aud.length !== 1) {
384
- if (r.azp === void 0) throw _("ID Token \"aud\" (audience) claim includes additional untrusted audiences", z, {
385
- claims: r,
386
- claim: "aud"
387
- });
388
- if (r.azp !== n.client_id) throw _("unexpected ID Token \"azp\" (authorized party) claim value", z, {
389
- expected: n.client_id,
390
- claims: r,
391
- claim: "azp"
392
- });
393
- }
394
- r.auth_time !== void 0 && S(r.auth_time, !0, "ID Token \"auth_time\" (authentication time)", I, { claims: r }), Be.set(a, i), ze.set(l, r);
395
- }
396
- if (c?.[l.token_type] !== void 0) c[l.token_type](a, l);
397
- else if (l.token_type !== "dpop" && l.token_type !== "bearer") throw new h("unsupported `token_type` value", { cause: { body: l } });
398
- return l;
399
- }
400
- function Ve(e) {
401
- let t;
402
- if (t = je(e)) throw new Se("server responded with a challenge in the WWW-Authenticate HTTP Header", {
403
- cause: t,
404
- response: e
405
- });
406
- }
407
- async function He(e, t, n, r) {
408
- return A(e, t, n, void 0, r?.[l], r?.recognizedTokenTypes);
409
- }
410
- function Ue(e, t) {
411
- if (Array.isArray(t.claims.aud)) {
412
- if (!t.claims.aud.includes(e)) throw _("unexpected JWT \"aud\" (audience) claim value", z, {
413
- expected: e,
414
- claims: t.claims,
415
- claim: "aud"
416
- });
417
- } else if (t.claims.aud !== e) throw _("unexpected JWT \"aud\" (audience) claim value", z, {
418
- expected: e,
419
- claims: t.claims,
420
- claim: "aud"
421
- });
422
- return t;
423
- }
424
- function We(e, t) {
425
- let n = e[gt]?.(t) ?? e.issuer;
426
- if (t.claims.iss !== n) throw _("unexpected JWT \"iss\" (issuer) claim value", z, {
427
- expected: n,
428
- claims: t.claims,
429
- claim: "iss"
430
- });
431
- return t;
432
- }
433
- var j = /* @__PURE__ */ new WeakSet();
434
- function Ge(e) {
435
- return j.add(e), e;
436
- }
437
- var Ke = Symbol();
438
- async function qe(e, t, r, a, o, s, c) {
439
- if (D(e), O(t), !j.has(a)) throw i("\"callbackParameters\" must be an instance of URLSearchParams obtained from \"validateAuthResponse()\", or \"validateJwtAuthResponse()", n);
440
- C(o, "\"redirectUri\"");
441
- let l = V(a, "code");
442
- if (!l) throw _("no authorization code in \"callbackParameters\"", I);
443
- let u = new URLSearchParams(c?.additionalParameters);
444
- return u.set("redirect_uri", o), u.set("code", l), s !== Ke && (C(s, "\"codeVerifier\""), u.set("code_verifier", s)), Le(e, t, r, "authorization_code", u, c);
445
- }
446
- var Je = {
447
- aud: "audience",
448
- c_hash: "code hash",
449
- client_id: "client id",
450
- exp: "expiration time",
451
- iat: "issued at",
452
- iss: "issuer",
453
- jti: "jwt id",
454
- nonce: "nonce",
455
- s_hash: "state hash",
456
- sub: "subject",
457
- ath: "access token hash",
458
- htm: "http method",
459
- htu: "http uri",
460
- cnf: "confirmation",
461
- auth_time: "authentication time"
462
- };
463
- function Ye(e, t) {
464
- for (let n of e) if (t.claims[n] === void 0) throw _(`JWT "${n}" (${Je[n]}) claim missing`, I, { claims: t.claims });
465
- return t;
466
- }
467
- var M = Symbol(), N = Symbol();
468
- async function Xe(e, t, n, r) {
469
- return typeof r?.expectedNonce == "string" || typeof r?.maxAge == "number" || r?.requireIdToken ? Ze(e, t, n, r.expectedNonce, r.maxAge, r[l], r.recognizedTokenTypes) : Qe(e, t, n, r?.[l], r?.recognizedTokenTypes);
470
- }
471
- async function Ze(e, t, n, r, i, a, o) {
472
- let s = [];
473
- switch (r) {
474
- case void 0:
475
- r = M;
476
- break;
477
- case M: break;
478
- default: C(r, "\"expectedNonce\" argument"), s.push("nonce");
479
- }
480
- switch (i ??= t.default_max_age, i) {
481
- case void 0:
482
- i = N;
483
- break;
484
- case N: break;
485
- default: S(i, !0, "\"maxAge\" argument"), s.push("auth_time");
486
- }
487
- let c = await A(e, t, n, s, a, o);
488
- C(c.id_token, "\"response\" body \"id_token\" property", I, { body: c });
489
- let l = k(c);
490
- if (i !== N) {
491
- let e = E() + w(t), n = T(t);
492
- if (l.auth_time + i < e - n) throw _("too much time has elapsed since the last End-User authentication", R, {
493
- claims: l,
494
- now: e,
495
- tolerance: n,
496
- claim: "auth_time"
497
- });
498
- }
499
- if (r === M) {
500
- if (l.nonce !== void 0) throw _("unexpected ID Token \"nonce\" claim value", z, {
501
- expected: void 0,
502
- claims: l,
503
- claim: "nonce"
504
- });
505
- } else if (l.nonce !== r) throw _("unexpected ID Token \"nonce\" claim value", z, {
506
- expected: r,
507
- claims: l,
508
- claim: "nonce"
509
- });
510
- return c;
511
- }
512
- async function Qe(e, t, n, r, i) {
513
- let a = await A(e, t, n, void 0, r, i), o = k(a);
514
- if (o) {
515
- if (t.default_max_age !== void 0) {
516
- S(t.default_max_age, !0, "\"client.default_max_age\"");
517
- let e = E() + w(t), n = T(t);
518
- if (o.auth_time + t.default_max_age < e - n) throw _("too much time has elapsed since the last End-User authentication", R, {
519
- claims: o,
520
- now: e,
521
- tolerance: n,
522
- claim: "auth_time"
523
- });
524
- }
525
- if (o.nonce !== void 0) throw _("unexpected ID Token \"nonce\" claim value", z, {
526
- expected: void 0,
527
- claims: o,
528
- claim: "nonce"
529
- });
530
- }
531
- return a;
532
- }
533
- var $e = "OAUTH_WWW_AUTHENTICATE_CHALLENGE", et = "OAUTH_RESPONSE_BODY_ERROR", P = "OAUTH_UNSUPPORTED_OPERATION", tt = "OAUTH_AUTHORIZATION_RESPONSE_ERROR", F = "OAUTH_PARSE_ERROR", I = "OAUTH_INVALID_RESPONSE", nt = "OAUTH_RESPONSE_IS_NOT_JSON", L = "OAUTH_RESPONSE_IS_NOT_CONFORM", rt = "OAUTH_HTTP_REQUEST_FORBIDDEN", it = "OAUTH_REQUEST_PROTOCOL_FORBIDDEN", R = "OAUTH_JWT_TIMESTAMP_CHECK_FAILED", z = "OAUTH_JWT_CLAIM_COMPARISON_FAILED", at = "OAUTH_JSON_ATTRIBUTE_COMPARISON_FAILED", ot = "OAUTH_MISSING_SERVER_METADATA", st = "OAUTH_INVALID_SERVER_METADATA";
534
- function B(e) {
535
- if (e.bodyUsed) throw i("\"response\" body has been used already", n);
536
- }
537
- async function ct(e, t, n, r, i) {
538
- let { 0: a, 1: o, length: s } = e.split(".");
539
- if (s === 5) if (i !== void 0) e = await i(e), {0: a, 1: o, length: s} = e.split(".");
540
- else throw new h("JWE decryption is not configured", { cause: e });
541
- if (s !== 3) throw _("Invalid JWT", I, e);
542
- let c;
543
- try {
544
- c = JSON.parse(f(m(a)));
545
- } catch (e) {
546
- throw _("failed to parse JWT Header body as base64url encoded JSON", F, e);
547
- }
548
- if (!v(c)) throw _("JWT Header must be a top level object", I, e);
549
- if (t(c), c.crit !== void 0) throw new h("no JWT \"crit\" header parameter extensions are supported", { cause: { header: c } });
550
- let l;
551
- try {
552
- l = JSON.parse(f(m(o)));
553
- } catch (e) {
554
- throw _("failed to parse JWT Payload body as base64url encoded JSON", F, e);
555
- }
556
- if (!v(l)) throw _("JWT Payload must be a top level object", I, e);
557
- let u = E() + n;
558
- if (l.exp !== void 0) {
559
- if (typeof l.exp != "number") throw _("unexpected JWT \"exp\" (expiration time) claim type", I, { claims: l });
560
- if (l.exp <= u - r) throw _("unexpected JWT \"exp\" (expiration time) claim value, expiration is past current timestamp", R, {
561
- claims: l,
562
- now: u,
563
- tolerance: r,
564
- claim: "exp"
565
- });
566
- }
567
- if (l.iat !== void 0 && typeof l.iat != "number") throw _("unexpected JWT \"iat\" (issued at) claim type", I, { claims: l });
568
- if (l.iss !== void 0 && typeof l.iss != "string") throw _("unexpected JWT \"iss\" (issuer) claim type", I, { claims: l });
569
- if (l.nbf !== void 0) {
570
- if (typeof l.nbf != "number") throw _("unexpected JWT \"nbf\" (not before) claim type", I, { claims: l });
571
- if (l.nbf > u + r) throw _("unexpected JWT \"nbf\" (not before) claim value", R, {
572
- claims: l,
573
- now: u,
574
- tolerance: r,
575
- claim: "nbf"
576
- });
577
- }
578
- if (l.aud !== void 0 && typeof l.aud != "string" && !Array.isArray(l.aud)) throw _("unexpected JWT \"aud\" (audience) claim type", I, { claims: l });
579
- return {
580
- header: c,
581
- claims: l,
582
- jwt: e
583
- };
584
- }
585
- async function lt(e) {
586
- if (e.bodyUsed) throw i("form_post Request instances must contain a readable body", n, { cause: e });
587
- return e.text();
588
- }
589
- async function ut(e) {
590
- if (e.method !== "POST") throw i("form_post responses are expected to use the POST method", n, { cause: e });
591
- if (Fe(e) !== "application/x-www-form-urlencoded") throw i("form_post responses are expected to use the application/x-www-form-urlencoded content-type", n, { cause: e });
592
- return lt(e);
593
- }
594
- function dt(e, t, n, r) {
595
- if (e !== void 0) {
596
- if (typeof e == "string" ? r.alg !== e : !e.includes(r.alg)) throw _("unexpected JWT \"alg\" header parameter", I, {
597
- header: r,
598
- expected: e,
599
- reason: "client configuration"
600
- });
601
- return;
602
- }
603
- if (Array.isArray(t)) {
604
- if (!t.includes(r.alg)) throw _("unexpected JWT \"alg\" header parameter", I, {
605
- header: r,
606
- expected: t,
607
- reason: "authorization server metadata"
608
- });
609
- return;
610
- }
611
- if (n !== void 0) {
612
- if (typeof n == "string" ? r.alg !== n : typeof n == "function" ? !n(r.alg) : !n.includes(r.alg)) throw _("unexpected JWT \"alg\" header parameter", I, {
613
- header: r,
614
- expected: n,
615
- reason: "default value"
616
- });
617
- return;
618
- }
619
- throw _("missing client or server configuration to verify used JWT \"alg\" header parameter", void 0, {
620
- client: e,
621
- issuer: t,
622
- fallback: n
623
- });
624
- }
625
- function V(e, t) {
626
- let { 0: n, length: r } = e.getAll(t);
627
- if (r > 1) throw _(`"${t}" parameter must be provided only once`, I);
628
- return n;
629
- }
630
- var ft = Symbol(), pt = Symbol();
631
- function mt(e, t, n, a) {
632
- if (D(e), O(t), n instanceof URL && (n = n.searchParams), !(n instanceof URLSearchParams)) throw i("\"parameters\" must be an instance of URLSearchParams, or URL", r);
633
- if (V(n, "response")) throw _("\"parameters\" contains a JARM response, use validateJwtAuthResponse() instead of validateAuthResponse()", I, { parameters: n });
634
- let o = V(n, "iss"), s = V(n, "state");
635
- if (!o && e.authorization_response_iss_parameter_supported) throw _("response parameter \"iss\" (issuer) missing", I, { parameters: n });
636
- if (o && o !== e.issuer) throw _("unexpected \"iss\" (issuer) response parameter value", I, {
637
- expected: e.issuer,
638
- parameters: n
639
- });
640
- switch (a) {
641
- case void 0:
642
- case pt:
643
- if (s !== void 0) throw _("unexpected \"state\" response parameter encountered", I, {
644
- expected: void 0,
645
- parameters: n
646
- });
647
- break;
648
- case ft: break;
649
- default: if (C(a, "\"expectedState\" argument"), s !== a) throw _(s === void 0 ? "response parameter \"state\" missing" : "unexpected \"state\" response parameter value", I, {
650
- expected: a,
651
- parameters: n
652
- });
653
- }
654
- if (V(n, "error")) throw new xe("authorization response from the server is an error", { cause: n });
655
- let c = V(n, "id_token"), l = V(n, "token");
656
- if (c !== void 0 || l !== void 0) throw new h("implicit and hybrid flows are not supported");
657
- return Ge(new URLSearchParams(n));
658
- }
659
- async function ht(e, t = oe) {
660
- let n;
661
- try {
662
- n = await e.json();
663
- } catch (n) {
664
- throw t(e), _("failed to parse \"response\" body as JSON", F, n);
665
- }
666
- if (!v(n)) throw _("\"response\" body must be a top level object", I, { body: n });
667
- return n;
668
- }
669
- var H = Symbol(), gt = Symbol(), U, _t;
670
- (typeof navigator > "u" || !navigator.userAgent?.startsWith?.("Mozilla/5.0 ")) && (_t = "openid-client/v6.8.3", U = { "user-agent": _t });
671
- var W = (e) => vt.get(e), vt, yt;
672
- function bt(e) {
673
- return e === void 0 ? (yt ||= /* @__PURE__ */ new WeakMap(), (e, t, n, r) => {
674
- let i;
675
- return (i = yt.get(t)) || (xt(t.client_secret, "\"metadata.client_secret\""), i = pe(t.client_secret), yt.set(t, i)), i(e, t, n, r);
676
- }) : pe(e);
677
- }
678
- function xt(e, t) {
679
- if (typeof e != "string") throw J(`${t} must be a string`, q);
680
- if (e.length === 0) throw J(`${t} must not be empty`, K);
681
- }
682
- function St() {
683
- return me();
684
- }
685
- var G = c, K = "ERR_INVALID_ARG_VALUE", q = "ERR_INVALID_ARG_TYPE";
686
- function J(e, t, n) {
687
- let r = TypeError(e, { cause: n });
688
- return Object.assign(r, { code: t }), r;
689
- }
690
- function Ct(e) {
691
- return fe(e);
692
- }
693
- function wt() {
694
- return ue();
695
- }
696
- function Tt() {
697
- return de();
698
- }
699
- var Y = class extends Error {
700
- code;
701
- constructor(e, t) {
702
- super(e, t), this.name = this.constructor.name, this.code = t?.code, Error.captureStackTrace?.(this, this.constructor);
703
- }
704
- };
705
- new TextDecoder();
706
- function X(e, t, n) {
707
- return new Y(e, {
708
- cause: t,
709
- code: n
710
- });
711
- }
712
- function Z(e) {
713
- if (e instanceof TypeError || e instanceof Y || e instanceof be || e instanceof xe || e instanceof Se) throw e;
714
- if (e instanceof g) switch (e.code) {
715
- case rt: throw X("only requests to HTTPS are allowed", e, e.code);
716
- case it: throw X("only requests to HTTP or HTTPS are allowed", e, e.code);
717
- case L: throw X("unexpected HTTP response status code", e.cause, e.code);
718
- case nt: throw X("unexpected response content-type", e.cause, e.code);
719
- case F: throw X("parsing error occured", e, e.code);
720
- case I: throw X("invalid response encountered", e, e.code);
721
- case z: throw X("unexpected JWT claim value encountered", e, e.code);
722
- case at: throw X("unexpected JSON attribute value encountered", e, e.code);
723
- case R: throw X("JWT timestamp claim value failed validation", e, e.code);
724
- default: throw X(e.message, e, e.code);
725
- }
726
- if (e instanceof h) throw X("unsupported operation", e, e.code);
727
- if (e instanceof DOMException) switch (e.name) {
728
- case "OperationError": throw X("runtime operation error", e, P);
729
- case "NotSupportedError": throw X("runtime unsupported operation", e, P);
730
- case "TimeoutError": throw X("operation timed out", e, "OAUTH_TIMEOUT");
731
- case "AbortError": throw X("operation aborted", e, "OAUTH_ABORT");
732
- }
733
- throw new Y("something went wrong", { cause: e });
734
- }
735
- function Et(e, t, n) {
736
- return e.origin === "https://login.microsoftonline.com" && (!n?.algorithm || n.algorithm === "oidc") ? (t[Mt] = !0, !0) : !1;
737
- }
738
- function Dt(e, t) {
739
- return !!(e.hostname.endsWith(".b2clogin.com") && (!t?.algorithm || t.algorithm === "oidc"));
740
- }
741
- async function Ot(e, t, n, r, i) {
742
- let a = new Q(await kt(e, i), t, n, r), o = W(a);
743
- if (i?.[G] && (o.fetch = i[G]), i?.timeout && (o.timeout = i.timeout), i?.execute) for (let e of i.execute) e(a);
744
- return a;
745
- }
746
- async function kt(e, t) {
747
- if (!(e instanceof URL)) throw J("\"server\" must be an instance of URL", q);
748
- let n = !e.href.includes("/.well-known/"), r = t?.timeout ?? 30, i = AbortSignal.timeout(r * 1e3), o = await (n ? ie(e, {
749
- algorithm: t?.algorithm,
750
- [c]: t?.[G],
751
- [a]: t?.execute?.includes(Ft),
752
- signal: i,
753
- headers: new Headers(U)
754
- }) : (t?.[G] || fetch)((ge(e, !t?.execute?.includes(Ft)), e.href), {
755
- headers: Object.fromEntries(new Headers({
756
- accept: "application/json",
757
- ...U
758
- }).entries()),
759
- body: void 0,
760
- method: "GET",
761
- redirect: "manual",
762
- signal: i
763
- })).then((e) => ae(H, e)).catch(Z);
764
- return n && new URL(o.issuer).href !== e.href && (Et(e, o, t) || Dt(e, t) || (() => {
765
- throw new Y("discovered metadata issuer does not match the expected issuer", {
766
- code: "OAUTH_JSON_ATTRIBUTE_COMPARISON_FAILED",
767
- cause: {
768
- expected: e.href,
769
- body: o,
770
- attribute: "issuer"
771
- }
772
- });
773
- })()), o;
774
- }
775
- function At(e) {
776
- return { supportsPKCE: {
777
- __proto__: null,
778
- value(t = "S256") {
779
- return e.code_challenge_methods_supported?.includes(t) === !0;
780
- }
781
- } };
782
- }
783
- function jt(e) {
784
- Object.defineProperties(e, At(e));
785
- }
786
- var Mt = Symbol(), Q = class {
787
- constructor(e, t, n, r) {
788
- if (typeof t != "string" || !t.length) throw J("\"clientId\" must be a non-empty string", q);
789
- if (typeof n == "string" && (n = { client_secret: n }), n?.client_id !== void 0 && t !== n.client_id) throw J("\"clientId\" and \"metadata.client_id\" must be the same", K);
790
- let i = {
791
- ...structuredClone(n),
792
- client_id: t
793
- };
794
- i[o] = n?.[o] ?? 0, i[s] = n?.[s] ?? 30;
795
- let a;
796
- a = r || (typeof i.client_secret == "string" && i.client_secret.length ? bt(i.client_secret) : St());
797
- let c = Object.freeze(i), l = structuredClone(e);
798
- Mt in e && (l[gt] = ({ claims: { tid: t } }) => e.issuer.replace("{tenantid}", t));
799
- let u = Object.freeze(l);
800
- vt ||= /* @__PURE__ */ new WeakMap(), vt.set(this, {
801
- __proto__: null,
802
- as: u,
803
- c,
804
- auth: a,
805
- tlsOnly: !0,
806
- jwksCache: {}
807
- });
808
- }
809
- serverMetadata() {
810
- let e = structuredClone(W(this).as);
811
- return jt(e), e;
812
- }
813
- clientMetadata() {
814
- return structuredClone(W(this).c);
815
- }
816
- get timeout() {
817
- return W(this).timeout;
818
- }
819
- set timeout(e) {
820
- W(this).timeout = e;
821
- }
822
- get [G]() {
823
- return W(this).fetch;
824
- }
825
- set [G](e) {
826
- W(this).fetch = e;
827
- }
828
- };
829
- Object.freeze(Q.prototype);
830
- function Nt(e) {
831
- let t;
832
- if (e.expires_in !== void 0) {
833
- let n = /* @__PURE__ */ new Date();
834
- n.setSeconds(n.getSeconds() + e.expires_in), t = n.getTime();
835
- }
836
- return {
837
- expiresIn: {
838
- __proto__: null,
839
- value() {
840
- if (t) {
841
- let e = Date.now();
842
- return t > e ? Math.floor((t - e) / 1e3) : 0;
843
- }
844
- }
845
- },
846
- claims: {
847
- __proto__: null,
848
- value() {
849
- try {
850
- return k(this);
851
- } catch {
852
- return;
853
- }
854
- }
855
- }
856
- };
857
- }
858
- function Pt(e) {
859
- Object.defineProperties(e, Nt(e));
860
- }
861
- function Ft(e) {
862
- W(e).tlsOnly = !1;
863
- }
864
- function It(e) {
865
- return e = new URL(e), e.search = "", e.hash = "", e.href;
866
- }
867
- function Lt(e, t) {
868
- try {
869
- return Object.getPrototypeOf(e)[Symbol.toStringTag] === t;
870
- } catch {
871
- return !1;
872
- }
873
- }
874
- async function Rt(e, t, n, r, i) {
875
- if (Vt(e), i?.flag !== $ && !(t instanceof URL) && !Lt(t, "Request")) throw J("\"currentUrl\" must be an instance of URL, or Request", q);
876
- let o, s, { as: u, c: d, auth: f, fetch: p, tlsOnly: ee, jarm: m, hybrid: h, nonRepudiation: g, timeout: _, decrypt: v, implicit: te } = W(e);
877
- if (i?.flag === $) o = i.authResponse, s = i.redirectUri;
878
- else {
879
- if (!(t instanceof URL)) {
880
- let e = t;
881
- switch (t = new URL(t.url), e.method) {
882
- case "GET": break;
883
- case "POST":
884
- let n = new URLSearchParams(await ut(e));
885
- if (h) t.hash = n.toString();
886
- else for (let [e, r] of n.entries()) t.searchParams.append(e, r);
887
- break;
888
- default: throw J("unexpected Request HTTP method", K);
889
- }
890
- }
891
- switch (s = It(t), !0) {
892
- case !!m:
893
- o = await m(t, n?.expectedState);
894
- break;
895
- case !!h:
896
- o = await h(t, n?.expectedNonce, n?.expectedState, n?.maxAge);
897
- break;
898
- case !!te: throw TypeError("authorizationCodeGrant() cannot be used by response_type=id_token clients");
899
- default: try {
900
- o = mt(u, d, t.searchParams, n?.expectedState);
901
- } catch (e) {
902
- Z(e);
903
- }
904
- }
905
- }
906
- let y = await qe(u, d, f, o, s, n?.pkceCodeVerifier || Ke, {
907
- additionalParameters: r,
908
- [c]: p,
909
- [a]: !ee,
910
- DPoP: i?.DPoP,
911
- headers: new Headers(U),
912
- signal: Ht(_)
913
- }).catch(Z);
914
- (typeof n?.expectedNonce == "string" || typeof n?.maxAge == "number") && (n.idTokenExpected = !0);
915
- let b = Xe(u, d, y, {
916
- expectedNonce: n?.expectedNonce,
917
- maxAge: n?.maxAge,
918
- requireIdToken: n?.idTokenExpected,
919
- [l]: v
920
- }), x;
921
- try {
922
- x = await b;
923
- } catch (t) {
924
- if (Ut(t, i)) return Rt(e, void 0, n, r, {
925
- ...i,
926
- flag: $,
927
- authResponse: o,
928
- redirectUri: s
929
- });
930
- Z(t);
931
- }
932
- return x.id_token && await g?.(y), Pt(x), x;
933
- }
934
- async function zt(e, t, n, r) {
935
- Vt(e), n = new URLSearchParams(n);
936
- let { as: i, c: o, auth: s, fetch: u, tlsOnly: d, nonRepudiation: f, timeout: p, decrypt: ee } = W(e), m = await Re(i, o, s, t, {
937
- [c]: u,
938
- [a]: !d,
939
- additionalParameters: n,
940
- DPoP: r?.DPoP,
941
- headers: new Headers(U),
942
- signal: Ht(p)
943
- }).catch(Z), h = He(i, o, m, { [l]: ee }), g;
944
- try {
945
- g = await h;
946
- } catch (i) {
947
- if (Ut(i, r)) return zt(e, t, n, {
948
- ...r,
949
- flag: $
950
- });
951
- Z(i);
952
- }
953
- return g.id_token && await f?.(m), Pt(g), g;
954
- }
955
- function Bt(e, t) {
956
- Vt(e);
957
- let { as: n, c: r, tlsOnly: i, hybrid: a, jarm: o, implicit: s } = W(e), c = ve(n, "authorization_endpoint", !1, i);
958
- if (t = new URLSearchParams(t), t.has("client_id") || t.set("client_id", r.client_id), !t.has("request_uri") && !t.has("request")) {
959
- if (t.has("response_type") || t.set("response_type", a ? "code id_token" : s ? "id_token" : "code"), s && !t.has("nonce")) throw J("response_type=id_token clients must provide a nonce parameter in their authorization request parameters", K);
960
- o && t.set("response_mode", "jwt");
961
- }
962
- for (let [e, n] of t.entries()) c.searchParams.append(e, n);
963
- return c;
964
- }
965
- function Vt(e) {
966
- if (!(e instanceof Q)) throw J("\"config\" must be an instance of Configuration", q);
967
- if (Object.getPrototypeOf(e) !== Q.prototype) throw J("subclassing Configuration is not allowed", K);
968
- }
969
- function Ht(e) {
970
- return e ? AbortSignal.timeout(e * 1e3) : void 0;
971
- }
972
- function Ut(e, t) {
973
- return t?.DPoP && t.flag !== $ ? ye(e) : !1;
974
- }
975
- var $ = Symbol();
976
- //#endregion
977
- export { Ot as a, zt as c, Ct as i, Rt as n, wt as o, Bt as r, Tt as s, bt as t };