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