@auth0/auth0-spa-js 2.16.0 → 2.17.1
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 +1 -1
- package/dist/auth0-spa-js.development.js +967 -782
- package/dist/auth0-spa-js.development.js.map +1 -1
- package/dist/auth0-spa-js.production.esm.js +1 -1
- package/dist/auth0-spa-js.production.esm.js.map +1 -1
- package/dist/auth0-spa-js.production.js +1 -1
- package/dist/auth0-spa-js.production.js.map +1 -1
- package/dist/auth0-spa-js.worker.development.js +14 -14
- package/dist/auth0-spa-js.worker.development.js.map +1 -1
- package/dist/auth0-spa-js.worker.production.js +1 -1
- package/dist/auth0-spa-js.worker.production.js.map +1 -1
- package/dist/lib/auth0-spa-js.cjs.js +1070 -870
- package/dist/lib/auth0-spa-js.cjs.js.map +1 -1
- package/dist/typings/Auth0Client.d.ts +12 -1
- package/dist/typings/constants.d.ts +6 -0
- package/dist/typings/index.d.ts +1 -1
- package/dist/typings/version.d.ts +1 -1
- package/package.json +7 -8
- package/src/Auth0Client.ts +36 -6
- package/src/constants.ts +7 -0
- package/src/index.ts +1 -1
- package/src/version.ts +1 -1
|
@@ -18,7 +18,7 @@ typeof SuppressedError === "function" ? SuppressedError : function(error, suppre
|
|
|
18
18
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
19
19
|
};
|
|
20
20
|
|
|
21
|
-
var version = "2.
|
|
21
|
+
var version = "2.17.1";
|
|
22
22
|
|
|
23
23
|
const DEFAULT_AUTHORIZE_TIMEOUT_IN_SECONDS = 60;
|
|
24
24
|
|
|
@@ -40,6 +40,8 @@ const INVALID_REFRESH_TOKEN_ERROR_MESSAGE = "invalid refresh token";
|
|
|
40
40
|
|
|
41
41
|
const USER_BLOCKED_ERROR_MESSAGE = "user is blocked";
|
|
42
42
|
|
|
43
|
+
const MFA_STEP_UP_ERROR_DESCRIPTION = "Multifactor authentication required";
|
|
44
|
+
|
|
43
45
|
const DEFAULT_SCOPE = "openid profile email";
|
|
44
46
|
|
|
45
47
|
const DEFAULT_SESSION_CHECK_EXPIRY_DAYS = 1;
|
|
@@ -173,7 +175,7 @@ const parseAuthenticationResult = queryString => {
|
|
|
173
175
|
|
|
174
176
|
const runIframe = function runIframe(authorizeUrl, eventOrigin) {
|
|
175
177
|
let timeoutInSeconds = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : DEFAULT_AUTHORIZE_TIMEOUT_IN_SECONDS;
|
|
176
|
-
return new Promise((
|
|
178
|
+
return new Promise((res, rej) => {
|
|
177
179
|
const iframe = window.document.createElement("iframe");
|
|
178
180
|
iframe.setAttribute("width", "0");
|
|
179
181
|
iframe.setAttribute("height", "0");
|
|
@@ -185,10 +187,10 @@ const runIframe = function runIframe(authorizeUrl, eventOrigin) {
|
|
|
185
187
|
}
|
|
186
188
|
};
|
|
187
189
|
let _iframeEventHandler;
|
|
188
|
-
const timeoutSetTimeoutId = setTimeout((
|
|
190
|
+
const timeoutSetTimeoutId = setTimeout(() => {
|
|
189
191
|
rej(new TimeoutError);
|
|
190
192
|
removeIframe();
|
|
191
|
-
}
|
|
193
|
+
}, timeoutInSeconds * 1e3);
|
|
192
194
|
_iframeEventHandler = function iframeEventHandler(e) {
|
|
193
195
|
if (e.origin != eventOrigin) return;
|
|
194
196
|
if (!e.data || e.data.type !== "authorization_response") return;
|
|
@@ -204,7 +206,7 @@ const runIframe = function runIframe(authorizeUrl, eventOrigin) {
|
|
|
204
206
|
window.addEventListener("message", _iframeEventHandler, false);
|
|
205
207
|
window.document.body.appendChild(iframe);
|
|
206
208
|
iframe.setAttribute("src", authorizeUrl);
|
|
207
|
-
})
|
|
209
|
+
});
|
|
208
210
|
};
|
|
209
211
|
|
|
210
212
|
const openPopup = url => {
|
|
@@ -215,21 +217,21 @@ const openPopup = url => {
|
|
|
215
217
|
return window.open(url, "auth0:authorize:popup", "left=".concat(left, ",top=").concat(top, ",width=").concat(width, ",height=").concat(height, ",resizable,scrollbars=yes,status=1"));
|
|
216
218
|
};
|
|
217
219
|
|
|
218
|
-
const runPopup = config => new Promise((
|
|
220
|
+
const runPopup = config => new Promise((resolve, reject) => {
|
|
219
221
|
let _popupEventListener;
|
|
220
|
-
const popupTimer = setInterval((
|
|
222
|
+
const popupTimer = setInterval(() => {
|
|
221
223
|
if (config.popup && config.popup.closed) {
|
|
222
224
|
clearInterval(popupTimer);
|
|
223
225
|
clearTimeout(timeoutId);
|
|
224
226
|
window.removeEventListener("message", _popupEventListener, false);
|
|
225
227
|
reject(new PopupCancelledError(config.popup));
|
|
226
228
|
}
|
|
227
|
-
}
|
|
228
|
-
const timeoutId = setTimeout((
|
|
229
|
+
}, 1e3);
|
|
230
|
+
const timeoutId = setTimeout(() => {
|
|
229
231
|
clearInterval(popupTimer);
|
|
230
232
|
reject(new PopupTimeoutError(config.popup));
|
|
231
233
|
window.removeEventListener("message", _popupEventListener, false);
|
|
232
|
-
}
|
|
234
|
+
}, (config.timeoutInSeconds || DEFAULT_AUTHORIZE_TIMEOUT_IN_SECONDS) * 1e3);
|
|
233
235
|
_popupEventListener = function popupEventListener(e) {
|
|
234
236
|
if (!e.data || e.data.type !== "authorization_response") {
|
|
235
237
|
return;
|
|
@@ -246,7 +248,7 @@ const runPopup = config => new Promise(((resolve, reject) => {
|
|
|
246
248
|
resolve(e.data.response);
|
|
247
249
|
};
|
|
248
250
|
window.addEventListener("message", _popupEventListener);
|
|
249
|
-
})
|
|
251
|
+
});
|
|
250
252
|
|
|
251
253
|
const getCrypto = () => window.crypto;
|
|
252
254
|
|
|
@@ -254,15 +256,15 @@ const createRandomString = () => {
|
|
|
254
256
|
const charset = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_~.";
|
|
255
257
|
let random = "";
|
|
256
258
|
const randomValues = Array.from(getCrypto().getRandomValues(new Uint8Array(43)));
|
|
257
|
-
randomValues.forEach(
|
|
259
|
+
randomValues.forEach(v => random += charset[v % charset.length]);
|
|
258
260
|
return random;
|
|
259
261
|
};
|
|
260
262
|
|
|
261
263
|
const encode$2 = value => btoa(value);
|
|
262
264
|
|
|
263
|
-
const stripUndefined = params => Object.keys(params).filter(
|
|
265
|
+
const stripUndefined = params => Object.keys(params).filter(k => typeof params[k] !== "undefined").reduce((acc, key) => Object.assign(Object.assign({}, acc), {
|
|
264
266
|
[key]: params[key]
|
|
265
|
-
})
|
|
267
|
+
}), {});
|
|
266
268
|
|
|
267
269
|
const ALLOWED_AUTH0CLIENT_PROPERTIES = [ {
|
|
268
270
|
key: "name",
|
|
@@ -277,16 +279,16 @@ const ALLOWED_AUTH0CLIENT_PROPERTIES = [ {
|
|
|
277
279
|
|
|
278
280
|
const stripAuth0Client = function stripAuth0Client(auth0Client) {
|
|
279
281
|
let excludeEnv = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
280
|
-
return Object.keys(auth0Client).reduce((
|
|
282
|
+
return Object.keys(auth0Client).reduce((acc, key) => {
|
|
281
283
|
if (excludeEnv && key === "env") {
|
|
282
284
|
return acc;
|
|
283
285
|
}
|
|
284
|
-
const allowedProperty = ALLOWED_AUTH0CLIENT_PROPERTIES.find(
|
|
286
|
+
const allowedProperty = ALLOWED_AUTH0CLIENT_PROPERTIES.find(p => p.key === key);
|
|
285
287
|
if (allowedProperty && allowedProperty.type.includes(typeof auth0Client[key])) {
|
|
286
288
|
acc[key] = auth0Client[key];
|
|
287
289
|
}
|
|
288
290
|
return acc;
|
|
289
|
-
}
|
|
291
|
+
}, {});
|
|
290
292
|
};
|
|
291
293
|
|
|
292
294
|
const createQueryParams = _a => {
|
|
@@ -309,10 +311,10 @@ const urlEncodeB64 = input => {
|
|
|
309
311
|
"/": "_",
|
|
310
312
|
"=": ""
|
|
311
313
|
};
|
|
312
|
-
return input.replace(/[+/=]/g,
|
|
314
|
+
return input.replace(/[+/=]/g, m => b64Chars[m]);
|
|
313
315
|
};
|
|
314
316
|
|
|
315
|
-
const decodeB64 = input => decodeURIComponent(atob(input).split("").map(
|
|
317
|
+
const decodeB64 = input => decodeURIComponent(atob(input).split("").map(c => "%" + ("00" + c.charCodeAt(0).toString(16)).slice(-2)).join(""));
|
|
316
318
|
|
|
317
319
|
const urlDecodeB64 = input => decodeB64(input.replace(/_/g, "/").replace(/-/g, "+"));
|
|
318
320
|
|
|
@@ -351,11 +353,11 @@ const parseNumber = value => {
|
|
|
351
353
|
return parseInt(value, 10) || undefined;
|
|
352
354
|
};
|
|
353
355
|
|
|
354
|
-
const fromEntries = iterable => [ ...iterable ].reduce((
|
|
356
|
+
const fromEntries = iterable => [ ...iterable ].reduce((obj, _ref) => {
|
|
355
357
|
let [key, val] = _ref;
|
|
356
358
|
obj[key] = val;
|
|
357
359
|
return obj;
|
|
358
|
-
}
|
|
360
|
+
}, {});
|
|
359
361
|
|
|
360
362
|
var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
|
|
361
363
|
|
|
@@ -390,14 +392,14 @@ var ProcessLocking = function() {
|
|
|
390
392
|
return _this.locked.has(key);
|
|
391
393
|
};
|
|
392
394
|
this.lock = function(key) {
|
|
393
|
-
return new Promise(
|
|
395
|
+
return new Promise(function(resolve, reject) {
|
|
394
396
|
if (_this.isLocked(key)) {
|
|
395
397
|
_this.addToLocked(key, resolve);
|
|
396
398
|
} else {
|
|
397
399
|
_this.addToLocked(key);
|
|
398
400
|
resolve();
|
|
399
401
|
}
|
|
400
|
-
})
|
|
402
|
+
});
|
|
401
403
|
};
|
|
402
404
|
this.unlock = function(key) {
|
|
403
405
|
var callbacks = _this.locked.get(key);
|
|
@@ -428,7 +430,7 @@ function getLock() {
|
|
|
428
430
|
processLock.default = getLock;
|
|
429
431
|
|
|
430
432
|
var __awaiter = commonjsGlobal && commonjsGlobal.__awaiter || function(thisArg, _arguments, P, generator) {
|
|
431
|
-
return new (P || (P = Promise))(
|
|
433
|
+
return new (P || (P = Promise))(function(resolve, reject) {
|
|
432
434
|
function fulfilled(value) {
|
|
433
435
|
try {
|
|
434
436
|
step(generator.next(value));
|
|
@@ -444,12 +446,12 @@ var __awaiter = commonjsGlobal && commonjsGlobal.__awaiter || function(thisArg,
|
|
|
444
446
|
}
|
|
445
447
|
}
|
|
446
448
|
function step(result) {
|
|
447
|
-
result.done ? resolve(result.value) : new P(
|
|
449
|
+
result.done ? resolve(result.value) : new P(function(resolve) {
|
|
448
450
|
resolve(result.value);
|
|
449
|
-
})
|
|
451
|
+
}).then(fulfilled, rejected);
|
|
450
452
|
}
|
|
451
453
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
452
|
-
})
|
|
454
|
+
});
|
|
453
455
|
};
|
|
454
456
|
|
|
455
457
|
var __generator = commonjsGlobal && commonjsGlobal.__generator || function(thisArg, body) {
|
|
@@ -554,39 +556,39 @@ var LOCK_STORAGE_KEY = "browser-tabs-lock-key";
|
|
|
554
556
|
|
|
555
557
|
var DEFAULT_STORAGE_HANDLER = {
|
|
556
558
|
key: function(index) {
|
|
557
|
-
return __awaiter(_this, void 0, void 0,
|
|
558
|
-
return __generator(this,
|
|
559
|
+
return __awaiter(_this, void 0, void 0, function() {
|
|
560
|
+
return __generator(this, function(_a) {
|
|
559
561
|
throw new Error("Unsupported");
|
|
560
|
-
})
|
|
561
|
-
})
|
|
562
|
+
});
|
|
563
|
+
});
|
|
562
564
|
},
|
|
563
565
|
getItem: function(key) {
|
|
564
|
-
return __awaiter(_this, void 0, void 0,
|
|
565
|
-
return __generator(this,
|
|
566
|
+
return __awaiter(_this, void 0, void 0, function() {
|
|
567
|
+
return __generator(this, function(_a) {
|
|
566
568
|
throw new Error("Unsupported");
|
|
567
|
-
})
|
|
568
|
-
})
|
|
569
|
+
});
|
|
570
|
+
});
|
|
569
571
|
},
|
|
570
572
|
clear: function() {
|
|
571
|
-
return __awaiter(_this, void 0, void 0,
|
|
572
|
-
return __generator(this,
|
|
573
|
+
return __awaiter(_this, void 0, void 0, function() {
|
|
574
|
+
return __generator(this, function(_a) {
|
|
573
575
|
return [ 2, window.localStorage.clear() ];
|
|
574
|
-
})
|
|
575
|
-
})
|
|
576
|
+
});
|
|
577
|
+
});
|
|
576
578
|
},
|
|
577
579
|
removeItem: function(key) {
|
|
578
|
-
return __awaiter(_this, void 0, void 0,
|
|
579
|
-
return __generator(this,
|
|
580
|
+
return __awaiter(_this, void 0, void 0, function() {
|
|
581
|
+
return __generator(this, function(_a) {
|
|
580
582
|
throw new Error("Unsupported");
|
|
581
|
-
})
|
|
582
|
-
})
|
|
583
|
+
});
|
|
584
|
+
});
|
|
583
585
|
},
|
|
584
586
|
setItem: function(key, value) {
|
|
585
|
-
return __awaiter(_this, void 0, void 0,
|
|
586
|
-
return __generator(this,
|
|
587
|
+
return __awaiter(_this, void 0, void 0, function() {
|
|
588
|
+
return __generator(this, function(_a) {
|
|
587
589
|
throw new Error("Unsupported");
|
|
588
|
-
})
|
|
589
|
-
})
|
|
590
|
+
});
|
|
591
|
+
});
|
|
590
592
|
},
|
|
591
593
|
keySync: function(index) {
|
|
592
594
|
return window.localStorage.key(index);
|
|
@@ -606,9 +608,9 @@ var DEFAULT_STORAGE_HANDLER = {
|
|
|
606
608
|
};
|
|
607
609
|
|
|
608
610
|
function delay(milliseconds) {
|
|
609
|
-
return new Promise(
|
|
611
|
+
return new Promise(function(resolve) {
|
|
610
612
|
return setTimeout(resolve, milliseconds);
|
|
611
|
-
})
|
|
613
|
+
});
|
|
612
614
|
}
|
|
613
615
|
|
|
614
616
|
function generateRandomString(length) {
|
|
@@ -644,9 +646,9 @@ var SuperTokensLock = function() {
|
|
|
644
646
|
if (timeout === void 0) {
|
|
645
647
|
timeout = 5e3;
|
|
646
648
|
}
|
|
647
|
-
return __awaiter(this, void 0, void 0,
|
|
649
|
+
return __awaiter(this, void 0, void 0, function() {
|
|
648
650
|
var iat, MAX_TIME, STORAGE_KEY, STORAGE, lockObj, TIMEOUT_KEY, lockObjPostDelay, parsedLockObjPostDelay;
|
|
649
|
-
return __generator(this,
|
|
651
|
+
return __generator(this, function(_a) {
|
|
650
652
|
switch (_a.label) {
|
|
651
653
|
case 0:
|
|
652
654
|
iat = Date.now() + generateRandomString(4);
|
|
@@ -705,17 +707,17 @@ var SuperTokensLock = function() {
|
|
|
705
707
|
case 8:
|
|
706
708
|
return [ 2, false ];
|
|
707
709
|
}
|
|
708
|
-
})
|
|
709
|
-
})
|
|
710
|
+
});
|
|
711
|
+
});
|
|
710
712
|
};
|
|
711
713
|
SuperTokensLock.prototype.refreshLockWhileAcquired = function(storageKey, iat) {
|
|
712
|
-
return __awaiter(this, void 0, void 0,
|
|
714
|
+
return __awaiter(this, void 0, void 0, function() {
|
|
713
715
|
var _this = this;
|
|
714
|
-
return __generator(this,
|
|
715
|
-
setTimeout(
|
|
716
|
-
return __awaiter(_this, void 0, void 0,
|
|
716
|
+
return __generator(this, function(_a) {
|
|
717
|
+
setTimeout(function() {
|
|
718
|
+
return __awaiter(_this, void 0, void 0, function() {
|
|
717
719
|
var STORAGE, lockObj, parsedLockObj;
|
|
718
|
-
return __generator(this,
|
|
720
|
+
return __generator(this, function(_a) {
|
|
719
721
|
switch (_a.label) {
|
|
720
722
|
case 0:
|
|
721
723
|
return [ 4, processLock_1.default().lock(iat) ];
|
|
@@ -740,19 +742,19 @@ var SuperTokensLock = function() {
|
|
|
740
742
|
this.refreshLockWhileAcquired(storageKey, iat);
|
|
741
743
|
return [ 2 ];
|
|
742
744
|
}
|
|
743
|
-
})
|
|
744
|
-
})
|
|
745
|
-
}
|
|
745
|
+
});
|
|
746
|
+
});
|
|
747
|
+
}, 1e3);
|
|
746
748
|
return [ 2 ];
|
|
747
|
-
})
|
|
748
|
-
})
|
|
749
|
+
});
|
|
750
|
+
});
|
|
749
751
|
};
|
|
750
752
|
SuperTokensLock.prototype.waitForSomethingToChange = function(MAX_TIME) {
|
|
751
|
-
return __awaiter(this, void 0, void 0,
|
|
752
|
-
return __generator(this,
|
|
753
|
+
return __awaiter(this, void 0, void 0, function() {
|
|
754
|
+
return __generator(this, function(_a) {
|
|
753
755
|
switch (_a.label) {
|
|
754
756
|
case 0:
|
|
755
|
-
return [ 4, new Promise(
|
|
757
|
+
return [ 4, new Promise(function(resolve) {
|
|
756
758
|
var resolvedCalled = false;
|
|
757
759
|
var startedAt = Date.now();
|
|
758
760
|
var MIN_TIME_TO_WAIT = 50;
|
|
@@ -777,14 +779,14 @@ var SuperTokensLock = function() {
|
|
|
777
779
|
window.addEventListener("storage", stopWaiting);
|
|
778
780
|
SuperTokensLock.addToWaiting(stopWaiting);
|
|
779
781
|
var timeOutId = setTimeout(stopWaiting, Math.max(0, MAX_TIME - Date.now()));
|
|
780
|
-
})
|
|
782
|
+
}) ];
|
|
781
783
|
|
|
782
784
|
case 1:
|
|
783
785
|
_a.sent();
|
|
784
786
|
return [ 2 ];
|
|
785
787
|
}
|
|
786
|
-
})
|
|
787
|
-
})
|
|
788
|
+
});
|
|
789
|
+
});
|
|
788
790
|
};
|
|
789
791
|
SuperTokensLock.addToWaiting = function(func) {
|
|
790
792
|
this.removeFromWaiting(func);
|
|
@@ -797,22 +799,22 @@ var SuperTokensLock = function() {
|
|
|
797
799
|
if (SuperTokensLock.waiters === undefined) {
|
|
798
800
|
return;
|
|
799
801
|
}
|
|
800
|
-
SuperTokensLock.waiters = SuperTokensLock.waiters.filter(
|
|
802
|
+
SuperTokensLock.waiters = SuperTokensLock.waiters.filter(function(i) {
|
|
801
803
|
return i !== func;
|
|
802
|
-
})
|
|
804
|
+
});
|
|
803
805
|
};
|
|
804
806
|
SuperTokensLock.notifyWaiters = function() {
|
|
805
807
|
if (SuperTokensLock.waiters === undefined) {
|
|
806
808
|
return;
|
|
807
809
|
}
|
|
808
810
|
var waiters = SuperTokensLock.waiters.slice();
|
|
809
|
-
waiters.forEach(
|
|
811
|
+
waiters.forEach(function(i) {
|
|
810
812
|
return i();
|
|
811
|
-
})
|
|
813
|
+
});
|
|
812
814
|
};
|
|
813
815
|
SuperTokensLock.prototype.releaseLock = function(lockKey) {
|
|
814
|
-
return __awaiter(this, void 0, void 0,
|
|
815
|
-
return __generator(this,
|
|
816
|
+
return __awaiter(this, void 0, void 0, function() {
|
|
817
|
+
return __generator(this, function(_a) {
|
|
816
818
|
switch (_a.label) {
|
|
817
819
|
case 0:
|
|
818
820
|
return [ 4, this.releaseLock__private__(lockKey) ];
|
|
@@ -820,13 +822,13 @@ var SuperTokensLock = function() {
|
|
|
820
822
|
case 1:
|
|
821
823
|
return [ 2, _a.sent() ];
|
|
822
824
|
}
|
|
823
|
-
})
|
|
824
|
-
})
|
|
825
|
+
});
|
|
826
|
+
});
|
|
825
827
|
};
|
|
826
828
|
SuperTokensLock.prototype.releaseLock__private__ = function(lockKey) {
|
|
827
|
-
return __awaiter(this, void 0, void 0,
|
|
829
|
+
return __awaiter(this, void 0, void 0, function() {
|
|
828
830
|
var STORAGE, STORAGE_KEY, lockObj, parsedlockObj;
|
|
829
|
-
return __generator(this,
|
|
831
|
+
return __generator(this, function(_a) {
|
|
830
832
|
switch (_a.label) {
|
|
831
833
|
case 0:
|
|
832
834
|
STORAGE = this.storageHandler === undefined ? DEFAULT_STORAGE_HANDLER : this.storageHandler;
|
|
@@ -850,8 +852,8 @@ var SuperTokensLock = function() {
|
|
|
850
852
|
case 2:
|
|
851
853
|
return [ 2 ];
|
|
852
854
|
}
|
|
853
|
-
})
|
|
854
|
-
})
|
|
855
|
+
});
|
|
856
|
+
});
|
|
855
857
|
};
|
|
856
858
|
SuperTokensLock.lockCorrector = function(storageHandler) {
|
|
857
859
|
var MIN_ALLOWED_TIME = Date.now() - 5e3;
|
|
@@ -893,16 +895,16 @@ var _default = browserTabsLock.default = SuperTokensLock;
|
|
|
893
895
|
class WebLocksApiManager {
|
|
894
896
|
async runWithLock(key, timeout, callback) {
|
|
895
897
|
const controller = new AbortController;
|
|
896
|
-
const timeoutId = setTimeout((
|
|
898
|
+
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
897
899
|
try {
|
|
898
900
|
return await navigator.locks.request(key, {
|
|
899
901
|
mode: "exclusive",
|
|
900
902
|
signal: controller.signal
|
|
901
|
-
},
|
|
903
|
+
}, async lock => {
|
|
902
904
|
clearTimeout(timeoutId);
|
|
903
905
|
if (!lock) throw new Error("Lock not available");
|
|
904
906
|
return await callback();
|
|
905
|
-
})
|
|
907
|
+
});
|
|
906
908
|
} catch (error) {
|
|
907
909
|
clearTimeout(timeoutId);
|
|
908
910
|
if ((error === null || error === void 0 ? void 0 : error.name) === "AbortError") throw new TimeoutError;
|
|
@@ -916,7 +918,7 @@ class LegacyLockManager {
|
|
|
916
918
|
this.activeLocks = new Set;
|
|
917
919
|
this.lock = new _default;
|
|
918
920
|
this.pagehideHandler = () => {
|
|
919
|
-
this.activeLocks.forEach(
|
|
921
|
+
this.activeLocks.forEach(key => this.lock.releaseLock(key));
|
|
920
922
|
this.activeLocks.clear();
|
|
921
923
|
};
|
|
922
924
|
}
|
|
@@ -1304,7 +1306,7 @@ function isGrantTypeSupported(grantType) {
|
|
|
1304
1306
|
return SUPPORTED_GRANT_TYPES.includes(grantType);
|
|
1305
1307
|
}
|
|
1306
1308
|
|
|
1307
|
-
const sendMessage = (message, to) => new Promise(
|
|
1309
|
+
const sendMessage = (message, to) => new Promise(function(resolve, reject) {
|
|
1308
1310
|
const messageChannel = new MessageChannel;
|
|
1309
1311
|
messageChannel.port1.onmessage = function(event) {
|
|
1310
1312
|
if (event.data.error) {
|
|
@@ -1315,7 +1317,7 @@ const sendMessage = (message, to) => new Promise((function(resolve, reject) {
|
|
|
1315
1317
|
messageChannel.port1.close();
|
|
1316
1318
|
};
|
|
1317
1319
|
to.postMessage(message, [ messageChannel.port2 ]);
|
|
1318
|
-
})
|
|
1320
|
+
});
|
|
1319
1321
|
|
|
1320
1322
|
const createAbortController = () => new AbortController;
|
|
1321
1323
|
|
|
@@ -1332,14 +1334,14 @@ const fetchWithoutWorker = async (fetchUrl, fetchOptions, timeout) => {
|
|
|
1332
1334
|
const controller = createAbortController();
|
|
1333
1335
|
fetchOptions.signal = controller.signal;
|
|
1334
1336
|
let timeoutId;
|
|
1335
|
-
return Promise.race([ dofetch(fetchUrl, fetchOptions), new Promise((
|
|
1336
|
-
timeoutId = setTimeout((
|
|
1337
|
+
return Promise.race([ dofetch(fetchUrl, fetchOptions), new Promise((_, reject) => {
|
|
1338
|
+
timeoutId = setTimeout(() => {
|
|
1337
1339
|
controller.abort();
|
|
1338
1340
|
reject(new Error("Timeout when executing 'fetch'"));
|
|
1339
|
-
}
|
|
1340
|
-
})
|
|
1341
|
+
}, timeout);
|
|
1342
|
+
}) ]).finally(() => {
|
|
1341
1343
|
clearTimeout(timeoutId);
|
|
1342
|
-
})
|
|
1344
|
+
});
|
|
1343
1345
|
};
|
|
1344
1346
|
|
|
1345
1347
|
const fetchWithWorker = async (fetchUrl, audience, scope, fetchOptions, timeout, worker, useFormData, useMrrt) => sendMessage({
|
|
@@ -1461,10 +1463,10 @@ const injectDefaultScopes = function injectDefaultScopes(authScopes, openIdScope
|
|
|
1461
1463
|
let requestedScopes = {
|
|
1462
1464
|
[DEFAULT_AUDIENCE]: getUniqueScopes(openIdScope, ...extraScopes)
|
|
1463
1465
|
};
|
|
1464
|
-
Object.keys(authScopes).forEach(
|
|
1466
|
+
Object.keys(authScopes).forEach(key => {
|
|
1465
1467
|
const audienceScopes = authScopes[key];
|
|
1466
1468
|
requestedScopes[key] = getUniqueScopes(openIdScope, audienceScopes, ...extraScopes);
|
|
1467
|
-
})
|
|
1469
|
+
});
|
|
1468
1470
|
return requestedScopes;
|
|
1469
1471
|
};
|
|
1470
1472
|
|
|
@@ -1532,7 +1534,7 @@ class LocalStorageCache {
|
|
|
1532
1534
|
localStorage.removeItem(key);
|
|
1533
1535
|
}
|
|
1534
1536
|
allKeys() {
|
|
1535
|
-
return Object.keys(window.localStorage).filter(
|
|
1537
|
+
return Object.keys(window.localStorage).filter(key => key.startsWith(CACHE_KEY_PREFIX));
|
|
1536
1538
|
}
|
|
1537
1539
|
}
|
|
1538
1540
|
|
|
@@ -1670,10 +1672,10 @@ class CacheManager {
|
|
|
1670
1672
|
var _a;
|
|
1671
1673
|
const keys = await this.getCacheKeys();
|
|
1672
1674
|
if (!keys) return;
|
|
1673
|
-
await keys.filter(
|
|
1675
|
+
await keys.filter(key => clientId ? key.includes(clientId) : true).reduce(async (memo, key) => {
|
|
1674
1676
|
await memo;
|
|
1675
1677
|
await this.cache.remove(key);
|
|
1676
|
-
}
|
|
1678
|
+
}, Promise.resolve());
|
|
1677
1679
|
await ((_a = this.keyManifest) === null || _a === void 0 ? void 0 : _a.clear());
|
|
1678
1680
|
}
|
|
1679
1681
|
async wrapCacheEntry(entry) {
|
|
@@ -1698,14 +1700,14 @@ class CacheManager {
|
|
|
1698
1700
|
}, CACHE_KEY_PREFIX, CACHE_KEY_ID_TOKEN_SUFFIX).toKey();
|
|
1699
1701
|
}
|
|
1700
1702
|
matchExistingCacheKey(keyToMatch, allKeys) {
|
|
1701
|
-
return allKeys.filter(
|
|
1703
|
+
return allKeys.filter(key => {
|
|
1702
1704
|
var _a;
|
|
1703
1705
|
const cacheKey = CacheKey.fromKey(key);
|
|
1704
1706
|
const scopeSet = new Set(cacheKey.scope && cacheKey.scope.split(" "));
|
|
1705
1707
|
const scopesToMatch = ((_a = keyToMatch.scope) === null || _a === void 0 ? void 0 : _a.split(" ")) || [];
|
|
1706
|
-
const hasAllScopes = cacheKey.scope && scopesToMatch.reduce((
|
|
1708
|
+
const hasAllScopes = cacheKey.scope && scopesToMatch.reduce((acc, current) => acc && scopeSet.has(current), true);
|
|
1707
1709
|
return cacheKey.prefix === CACHE_KEY_PREFIX && cacheKey.clientId === keyToMatch.clientId && cacheKey.audience === keyToMatch.audience && hasAllScopes;
|
|
1708
|
-
})
|
|
1710
|
+
})[0];
|
|
1709
1711
|
}
|
|
1710
1712
|
async getEntryWithRefreshToken(keyToMatch, allKeys) {
|
|
1711
1713
|
var _a;
|
|
@@ -1774,12 +1776,12 @@ const decode$1 = token => {
|
|
|
1774
1776
|
__raw: token
|
|
1775
1777
|
};
|
|
1776
1778
|
const user = {};
|
|
1777
|
-
Object.keys(payloadJSON).forEach(
|
|
1779
|
+
Object.keys(payloadJSON).forEach(k => {
|
|
1778
1780
|
claims[k] = payloadJSON[k];
|
|
1779
1781
|
if (!idTokendecoded.includes(k)) {
|
|
1780
1782
|
user[k] = payloadJSON[k];
|
|
1781
1783
|
}
|
|
1782
|
-
})
|
|
1784
|
+
});
|
|
1783
1785
|
return {
|
|
1784
1786
|
encoded: {
|
|
1785
1787
|
header: header,
|
|
@@ -2095,17 +2097,17 @@ function createBase64WorkerFactory(base64, sourcemapArg, enableUnicodeArg) {
|
|
|
2095
2097
|
};
|
|
2096
2098
|
}
|
|
2097
2099
|
|
|
2098
|
-
var WorkerFactory = createBase64WorkerFactory("Lyogcm9sbHVwLXBsdWdpbi13ZWItd29ya2VyLWxvYWRlciAqLwooZnVuY3Rpb24oKSB7CiAgICAidXNlIHN0cmljdCI7CiAgICBjbGFzcyBHZW5lcmljRXJyb3IgZXh0ZW5kcyBFcnJvciB7CiAgICAgICAgY29uc3RydWN0b3IoZXJyb3IsIGVycm9yX2Rlc2NyaXB0aW9uKSB7CiAgICAgICAgICAgIHN1cGVyKGVycm9yX2Rlc2NyaXB0aW9uKTsKICAgICAgICAgICAgdGhpcy5lcnJvciA9IGVycm9yOwogICAgICAgICAgICB0aGlzLmVycm9yX2Rlc2NyaXB0aW9uID0gZXJyb3JfZGVzY3JpcHRpb247CiAgICAgICAgICAgIE9iamVjdC5zZXRQcm90b3R5cGVPZih0aGlzLCBHZW5lcmljRXJyb3IucHJvdG90eXBlKTsKICAgICAgICB9CiAgICAgICAgc3RhdGljIGZyb21QYXlsb2FkKF9yZWYpIHsKICAgICAgICAgICAgbGV0IHtlcnJvcjogZXJyb3IsIGVycm9yX2Rlc2NyaXB0aW9uOiBlcnJvcl9kZXNjcmlwdGlvbn0gPSBfcmVmOwogICAgICAgICAgICByZXR1cm4gbmV3I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Hwge307CiAgICAgICAgdHJ5IHsKICAgICAgICAgICAgY29uc3QgYm9keSA9IHVzZUZvcm1EYXRhID8gZm9ybURhdGFUb09iamVjdChmZXRjaE9wdGlvbnMuYm9keSkgOiBKU09OLnBhcnNlKGZldGNoT3B0aW9ucy5ib2R5KTsKICAgICAgICAgICAgaWYgKCFib2R5LnJlZnJlc2hfdG9rZW4gJiYgYm9keS5ncmFudF90eXBlID09PSAicmVmcmVzaF90b2tlbiIpIHsKICAgICAgICAgICAgICAgIHJlZnJlc2hUb2tlbiA9IGdldFJlZnJlc2hUb2tlbihhdWRpZW5jZSwgc2NvcGUpOwogICAgICAgICAgICAgICAgaWYgKCFyZWZyZXNoVG9rZW4gJiYgdXNlTXJydCkgewogICAgICAgICAgICAgICAgICAgIGNvbnN0IGxhdGVzdFJlZnJlc2hUb2tlbiA9IHJlZnJlc2hUb2tlbnNbImxhdGVzdF9yZWZyZXNoX3Rva2VuIl07CiAgICAgICAgICAgICAgICAgICAgY29uc3QgaXNEb3duc2NvcGluZyA9IGNoZWNrRG93bnNjb3Bpbmcoc2NvcGUsIGF1ZGllbmNlKTsKICAgICAgICAgICAgICAgICAgICBpZiAobGF0ZXN0UmVmcmVzaFRva2VuICYmICFpc0Rvd25zY29waW5nKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHJlZnJlc2hUb2tlbiA9IGxhdGVzdFJlZnJlc2hUb2tlbjsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoIXJlZnJlc2hUb2tlbikgewogICAgICAgICAgICAgICAgICAgIHRocm93IG5ldyBNaXNzaW5nUmVmcmVzaFRva2VuRXJyb3IoYXVkaWVuY2UsIHNjb3BlKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGZldGNoT3B0aW9ucy5ib2R5ID0gdXNlRm9ybURhdGEgPyBjcmVhdGVRdWVyeVBhcmFtcyhPYmplY3QuYXNzaWduKE9iamVjdC5hc3NpZ24oe30sIGJvZHkpLCB7CiAgICAgICAgICAgICAgICAgICAgcmVmcmVzaF90b2tlbjogcmVmcmVzaFRva2VuCiAgICAgICAgICAgICAgICB9KSkgOiBKU09OLnN0cmluZ2lmeShPYmplY3QuYXNzaWduKE9iamVjdC5hc3NpZ24oe30sIGJvZHkpLCB7CiAgICAgICAgICAgICAgICAgICAgcmVmcmVzaF90b2tlbjogcmVmcmVzaFRva2VuCiAgICAgICAgICAgICAgICB9KSk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgbGV0IGFib3J0Q29udHJvbGxlcjsKICAgICAgICAgICAgaWYgKHR5cGVvZiBBYm9ydENvbnRyb2xsZXIgPT09ICJmdW5jdGlvbiIpIHsKICAgICAgICAgICAgICAgIGFib3J0Q29udHJvbGxlciA9IG5ldyBBYm9ydENvbnRyb2xsZXI7CiAgICAgICAgICAgICAgICBmZXRjaE9wdGlvbnMuc2lnbmFsID0gYWJvcnRDb250cm9sbGVyLnNpZ25hbDsKICAgICAgICAgICAgfQogICAgICAgICAgICBsZXQgcmVzcG9uc2U7CiAgICAgICAgICAgIHRyeSB7CiAgICAgICAgICAgICAgICByZXNwb25zZSA9IGF3YWl0IFByb21pc2UucmFjZShbIHdhaXQodGltZW91dCksIGZldGNoKGZldGNoVXJsLCBPYmplY3QuYXNzaWduKHt9LCBmZXRjaE9wdGlvbnMpKSBdKTsKICAgICAgICAgICAgfSBjYXRjaCAoZXJyb3IpIHsKICAgICAgICAgICAgICAgIHBvcnQucG9zdE1lc3NhZ2UoewogICAgICAgICAgICAgICAgICAgIGVycm9yOiBlcnJvci5tZXNzYWdlCiAgICAgICAgICAgICAgICB9KTsKICAgICAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoIXJlc3BvbnNlKSB7CiAgICAgICAgICAgICAgICBpZiAoYWJvcnRDb250cm9sbGVyKSBhYm9ydENvbnRyb2xsZXIuYWJvcnQoKTsKICAgICAgICAgICAgICAgIHBvcnQucG9zdE1lc3NhZ2UoewogICAgICAgICAgICAgICAgICAgIGVycm9yOiAiVGltZW91dCB3aGVuIGV4ZWN1dGluZyAnZmV0Y2gnIgogICAgICAgICAgICAgICAgfSk7CiAgICAgICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaGVhZGVycyA9IGZyb21FbnRyaWVzKHJlc3BvbnNlLmhlYWRlcnMpOwogICAgICAgICAgICBqc29uID0gYXdhaXQgcmVzcG9uc2UuanNvbigpOwogICAgICAgICAgICBpZiAoanNvbi5yZWZyZXNoX3Rva2VuKSB7CiAgICAgICAgICAgICAgICBpZiAodXNlTXJydCkgewogICAgICAgICAgICAgICAgICAgIHJlZnJlc2hUb2tlbnNbImxhdGVzdF9yZWZyZXNoX3Rva2VuIl0gPSBqc29uLnJlZnJlc2hfdG9rZW47CiAgICAgICAgICAgICAgICAgICAgdXBkYXRlUmVmcmVzaFRva2VucyhyZWZyZXNoVG9rZW4sIGpzb24ucmVmcmVzaF90b2tlbik7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzZXRSZWZyZXNoVG9rZW4oanNvbi5yZWZyZXNoX3Rva2VuLCBhdWRpZW5jZSwgc2NvcGUpOwogICAgICAgICAgICAgICAgZGVsZXRlIGpzb24ucmVmcmVzaF90b2tlbjsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIGRlbGV0ZVJlZnJlc2hUb2tlbihhdWRpZW5jZSwgc2NvcGUpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHBvcnQucG9zdE1lc3NhZ2UoewogICAgICAgICAgICAgICAgb2s6IHJlc3BvbnNlLm9rLAogICAgICAgICAgICAgICAganNvbjoganNvbiwKICAgICAgICAgICAgICAgIGhlYWRlcnM6IGhlYWRlcnMKICAgICAgICAgICAgfSk7CiAgICAgICAgfSBjYXRjaCAoZXJyb3IpIHsKICAgICAgICAgICAgcG9ydC5wb3N0TWVzc2FnZSh7CiAgICAgICAgICAgICAgICBvazogZmFsc2UsCiAgICAgICAgICAgICAgICBqc29uOiB7CiAgICAgICAgICAgICAgICAgICAgZXJyb3I6IGVycm9yLmVycm9yLAogICAgICAgICAgICAgICAgICAgIGVycm9yX2Rlc2NyaXB0aW9uOiBlcnJvci5tZXNzYWdlCiAgICAgICAgICAgICAgICB9LAogICAgICAgICAgICAgICAgaGVhZGVyczogaGVhZGVycwogICAgICAgICAgICB9KTsKICAgICAgICB9CiAgICB9OwogICAgewogICAgICAgIGFkZEV2ZW50TGlzdGVuZXIoIm1lc3NhZ2UiLCBtZXNzYWdlSGFuZGxlcik7CiAgICB9Cn0pKCk7Cgo=", null, false);
|
|
2100
|
+
var WorkerFactory = createBase64WorkerFactory("Lyogcm9sbHVwLXBsdWdpbi13ZWItd29ya2VyLWxvYWRlciAqLwooZnVuY3Rpb24oKSB7CiAgICAidXNlIHN0cmljdCI7CiAgICBjbGFzcyBHZW5lcmljRXJyb3IgZXh0ZW5kcyBFcnJvciB7CiAgICAgICAgY29uc3RydWN0b3IoZXJyb3IsIGVycm9yX2Rlc2NyaXB0aW9uKSB7CiAgICAgICAgICAgIHN1cGVyKGVycm9yX2Rlc2NyaXB0aW9uKTsKICAgICAgICAgICAgdGhpcy5lcnJvciA9IGVycm9yOwogICAgICAgICAgICB0aGlzLmVycm9yX2Rlc2NyaXB0aW9uID0gZXJyb3JfZGVzY3JpcHRpb247CiAgICAgICAgICAgIE9iamVjdC5zZXRQcm90b3R5cGVPZih0aGlzLCBHZW5lcmljRXJyb3IucHJvdG90eXBlKTsKICAgICAgICB9CiAgICAgICAgc3RhdGljIGZyb21QYXlsb2FkKF9yZWYpIHsKICAgICAgICAgICAgbGV0IHtlcnJvcjogZXJyb3IsIGVycm9yX2Rlc2NyaXB0aW9uOiBlcnJvcl9kZXNjcmlwdGlvbn0gPSBfcmVmOwogICAgICAgICAgICByZXR1cm4gbmV3IEdlbmVyaWNFcnJvcihlcnJvciwgZXJyb3JfZGVzY3JpcHRp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oYXVkaWVuY2UsIHNjb3BlKV07CiAgICBjb25zdCB3YWl0ID0gdGltZSA9PiBuZXcgUHJvbWlzZShyZXNvbHZlID0+IHNldFRpbWVvdXQocmVzb2x2ZSwgdGltZSkpOwogICAgY29uc3QgZm9ybURhdGFUb09iamVjdCA9IGZvcm1EYXRhID0+IHsKICAgICAgICBjb25zdCBxdWVyeVBhcmFtcyA9IG5ldyBVUkxTZWFyY2hQYXJhbXMoZm9ybURhdGEpOwogICAgICAgIGNvbnN0IHBhcnNlZFF1ZXJ5ID0ge307CiAgICAgICAgcXVlcnlQYXJhbXMuZm9yRWFjaCgodmFsLCBrZXkpID0+IHsKICAgICAgICAgICAgcGFyc2VkUXVlcnlba2V5XSA9IHZhbDsKICAgICAgICB9KTsKICAgICAgICByZXR1cm4gcGFyc2VkUXVlcnk7CiAgICB9OwogICAgY29uc3QgdXBkYXRlUmVmcmVzaFRva2VucyA9IChvbGRSZWZyZXNoVG9rZW4sIG5ld1JlZnJlc2hUb2tlbikgPT4gewogICAgICAgIE9iamVjdC5lbnRyaWVzKHJlZnJlc2hUb2tlbnMpLmZvckVhY2goX3JlZiA9PiB7CiAgICAgICAgICAgIGxldCBba2V5LCB0b2tlbl0gPSBfcmVmOwogICAgICAgICAgICBpZiAodG9rZW4gPT09IG9sZFJlZnJlc2hUb2tlbikgewogICAgICAgICAgICAgICAgcmVmcmVzaFRva2Vuc1trZXldID0gbmV3UmVmcmVzaFRva2VuOwogICAgICAgICAgICB9CiAgICAgICAgfSk7CiAgICB9OwogICAgY29uc3QgY2hlY2tEb3duc2NvcGluZyA9IChzY29wZSwgYXVkaWVuY2UpID0+IHsKICAgICAgICBjb25zdCBmaW5kQ29pbmNpZGVuY2UgPSBPYmplY3Qua2V5cyhyZWZyZXNoVG9rZW5zKS5maW5kKGtleSA9PiB7CiAgICAgICAgICAgIGlmIChrZXkgIT09ICJsYXRlc3RfcmVmcmVzaF90b2tlbiIpIHsKICAgICAgICAgICAgICAgIGNvbnN0IGl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0aW9ucy5ib2R5KSA6IEpTT04ucGFyc2UoZmV0Y2hPcHRpb25zLmJvZHkpOwogICAgICAgICAgICBpZiAoIWJvZHkucmVmcmVzaF90b2tlbiAmJiBib2R5LmdyYW50X3R5cGUgPT09ICJyZWZyZXNoX3Rva2VuIikgewogICAgICAgICAgICAgICAgcmVmcmVzaFRva2VuID0gZ2V0UmVmcmVzaFRva2VuKGF1ZGllbmNlLCBzY29wZSk7CiAgICAgICAgICAgICAgICBpZiAoIXJlZnJlc2hUb2tlbiAmJiB1c2VNcnJ0KSB7CiAgICAgICAgICAgICAgICAgICAgY29uc3QgbGF0ZXN0UmVmcmVzaFRva2VuID0gcmVmcmVzaFRva2Vuc1sibGF0ZXN0X3JlZnJlc2hfdG9rZW4iXTsKICAgICAgICAgICAgICAgICAgICBjb25zdCBpc0Rvd25zY29waW5nID0gY2hlY2tEb3duc2NvcGluZyhzY29wZSwgYXVkaWVuY2UpOwogICAgICAgICAgICAgICAgICAgIGlmIChsYXRlc3RSZWZyZXNoVG9rZW4gJiYgIWlzRG93bnNjb3BpbmcpIHsKICAgICAgICAgICAgICAgICAgICAgICAgcmVmcmVzaFRva2VuID0gbGF0ZXN0UmVmcmVzaFRva2VuOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmICghcmVmcmVzaFRva2VuKSB7CiAgICAgICAgICAgICAgICAgICAgdGhyb3cgbmV3IE1pc3NpbmdSZWZyZXNoVG9rZW5FcnJvcihhdWRpZW5jZSwgc2NvcGUpOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgZmV0Y2hPcHRpb25zLmJvZHkgPSB1c2VGb3JtRGF0YSA/IGNyZWF0ZVF1ZXJ5UGFyYW1zKE9iamVjdC5hc3NpZ24oT2JqZWN0LmFzc2lnbih7fSwgYm9keSksIHsKICAgICAgICAgICAgICAgICAgICByZWZyZXNoX3Rva2VuOiByZWZyZXNoVG9rZW4KICAgICAgICAgICAgICAgIH0pKSA6IEpTT04uc3RyaW5naWZ5KE9iamVjdC5hc3NpZ24oT2JqZWN0LmFzc2lnbih7fSwgYm9keSksIHsKICAgICAgICAgICAgICAgICAgICByZWZyZXNoX3Rva2VuOiByZWZyZXNoVG9rZW4KICAgICAgICAgICAgICAgIH0pKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBsZXQgYWJvcnRDb250cm9sbGVyOwogICAgICAgICAgICBpZiAodHlwZW9mIEFib3J0Q29udHJvbGxlciA9PT0gImZ1bmN0aW9uIikgewogICAgICAgICAgICAgICAgYWJvcnRDb250cm9sbGVyID0gbmV3IEFib3J0Q29udHJvbGxlcjsKICAgICAgICAgICAgICAgIGZldGNoT3B0aW9ucy5zaWduYWwgPSBhYm9ydENvbnRyb2xsZXIuc2lnbmFsOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGxldCByZXNwb25zZTsKICAgICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgICAgIHJlc3BvbnNlID0gYXdhaXQgUHJvbWlzZS5yYWNlKFsgd2FpdCh0aW1lb3V0KSwgZmV0Y2goZmV0Y2hVcmwsIE9iamVjdC5hc3NpZ24oe30sIGZldGNoT3B0aW9ucykpIF0pOwogICAgICAgICAgICB9IGNhdGNoIChlcnJvcikgewogICAgICAgICAgICAgICAgcG9ydC5wb3N0TWVzc2FnZSh7CiAgICAgICAgICAgICAgICAgICAgZXJyb3I6IGVycm9yLm1lc3NhZ2UKICAgICAgICAgICAgICAgIH0pOwogICAgICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmICghcmVzcG9uc2UpIHsKICAgICAgICAgICAgICAgIGlmIChhYm9ydENvbnRyb2xsZXIpIGFib3J0Q29udHJvbGxlci5hYm9ydCgpOwogICAgICAgICAgICAgICAgcG9ydC5wb3N0TWVzc2FnZSh7CiAgICAgICAgICAgICAgICAgICAgZXJyb3I6ICJUaW1lb3V0IHdoZW4gZXhlY3V0aW5nICdmZXRjaCciCiAgICAgICAgICAgICAgICB9KTsKICAgICAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgICAgfQogICAgICAgICAgICBoZWFkZXJzID0gZnJvbUVudHJpZXMocmVzcG9uc2UuaGVhZGVycyk7CiAgICAgICAgICAgIGpzb24gPSBhd2FpdCByZXNwb25zZS5qc29uKCk7CiAgICAgICAgICAgIGlmIChqc29uLnJlZnJlc2hfdG9rZW4pIHsKICAgICAgICAgICAgICAgIGlmICh1c2VNcnJ0KSB7CiAgICAgICAgICAgICAgICAgICAgcmVmcmVzaFRva2Vuc1sibGF0ZXN0X3JlZnJlc2hfdG9rZW4iXSA9IGpzb24ucmVmcmVzaF90b2tlbjsKICAgICAgICAgICAgICAgICAgICB1cGRhdGVSZWZyZXNoVG9rZW5zKHJlZnJlc2hUb2tlbiwganNvbi5yZWZyZXNoX3Rva2VuKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHNldFJlZnJlc2hUb2tlbihqc29uLnJlZnJlc2hfdG9rZW4sIGF1ZGllbmNlLCBzY29wZSk7CiAgICAgICAgICAgICAgICBkZWxldGUganNvbi5yZWZyZXNoX3Rva2VuOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgZGVsZXRlUmVmcmVzaFRva2VuKGF1ZGllbmNlLCBzY29wZSk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgcG9ydC5wb3N0TWVzc2FnZSh7CiAgICAgICAgICAgICAgICBvazogcmVzcG9uc2Uub2ssCiAgICAgICAgICAgICAgICBqc29uOiBqc29uLAogICAgICAgICAgICAgICAgaGVhZGVyczogaGVhZGVycwogICAgICAgICAgICB9KTsKICAgICAgICB9IGNhdGNoIChlcnJvcikgewogICAgICAgICAgICBwb3J0LnBvc3RNZXNzYWdlKHsKICAgICAgICAgICAgICAgIG9rOiBmYWxzZSwKICAgICAgICAgICAgICAgIGpzb246IHsKICAgICAgICAgICAgICAgICAgICBlcnJvcjogZXJyb3IuZXJyb3IsCiAgICAgICAgICAgICAgICAgICAgZXJyb3JfZGVzY3JpcHRpb246IGVycm9yLm1lc3NhZ2UKICAgICAgICAgICAgICAgIH0sCiAgICAgICAgICAgICAgICBoZWFkZXJzOiBoZWFkZXJzCiAgICAgICAgICAgIH0pOwogICAgICAgIH0KICAgIH07CiAgICB7CiAgICAgICAgYWRkRXZlbnRMaXN0ZW5lcigibWVzc2FnZSIsIG1lc3NhZ2VIYW5kbGVyKTsKICAgIH0KfSkoKTsKCg==", null, false);
|
|
2099
2101
|
|
|
2100
2102
|
const singlePromiseMap = {};
|
|
2101
2103
|
|
|
2102
2104
|
const singlePromise = (cb, key) => {
|
|
2103
2105
|
let promise = singlePromiseMap[key];
|
|
2104
2106
|
if (!promise) {
|
|
2105
|
-
promise = cb().finally((
|
|
2107
|
+
promise = cb().finally(() => {
|
|
2106
2108
|
delete singlePromiseMap[key];
|
|
2107
2109
|
promise = null;
|
|
2108
|
-
})
|
|
2110
|
+
});
|
|
2109
2111
|
singlePromiseMap[key] = promise;
|
|
2110
2112
|
}
|
|
2111
2113
|
return promise;
|
|
@@ -2195,13 +2197,13 @@ const patchOpenUrlWithOnRedirect = options => {
|
|
|
2195
2197
|
const allScopesAreIncluded = (scopeToInclude, scopes) => {
|
|
2196
2198
|
const scopeGroup = (scopes === null || scopes === void 0 ? void 0 : scopes.split(" ")) || [];
|
|
2197
2199
|
const scopesToInclude = (scopeToInclude === null || scopeToInclude === void 0 ? void 0 : scopeToInclude.split(" ")) || [];
|
|
2198
|
-
return scopesToInclude.every(
|
|
2200
|
+
return scopesToInclude.every(key => scopeGroup.includes(key));
|
|
2199
2201
|
};
|
|
2200
2202
|
|
|
2201
2203
|
const getMissingScopes = (requestedScope, respondedScope) => {
|
|
2202
2204
|
const requestedScopes = (requestedScope === null || requestedScope === void 0 ? void 0 : requestedScope.split(" ")) || [];
|
|
2203
2205
|
const respondedScopes = (respondedScope === null || respondedScope === void 0 ? void 0 : respondedScope.split(" ")) || [];
|
|
2204
|
-
const missingScopes = requestedScopes.filter(
|
|
2206
|
+
const missingScopes = requestedScopes.filter(scope => respondedScopes.indexOf(scope) == -1);
|
|
2205
2207
|
return missingScopes.join(",");
|
|
2206
2208
|
};
|
|
2207
2209
|
|
|
@@ -2213,7 +2215,7 @@ const getScopeToRequest = (useMrrt, authorizationParams, cachedAudience, cachedS
|
|
|
2213
2215
|
}
|
|
2214
2216
|
const cachedScopes = cachedScope.split(" ");
|
|
2215
2217
|
const newScopes = ((_a = authorizationParams.scope) === null || _a === void 0 ? void 0 : _a.split(" ")) || [];
|
|
2216
|
-
const newScopesAreIncluded = newScopes.every(
|
|
2218
|
+
const newScopesAreIncluded = newScopes.every(scope => cachedScopes.includes(scope));
|
|
2217
2219
|
return cachedScopes.length >= newScopes.length && newScopesAreIncluded ? cachedScope : authorizationParams.scope;
|
|
2218
2220
|
}
|
|
2219
2221
|
return authorizationParams.scope;
|
|
@@ -2246,11 +2248,11 @@ class DpopStorage {
|
|
|
2246
2248
|
}
|
|
2247
2249
|
createDbHandle() {
|
|
2248
2250
|
const req = window.indexedDB.open(NAME, this.getVersion());
|
|
2249
|
-
return new Promise((
|
|
2250
|
-
req.onupgradeneeded = () => Object.values(TABLES).forEach(
|
|
2251
|
+
return new Promise((resolve, reject) => {
|
|
2252
|
+
req.onupgradeneeded = () => Object.values(TABLES).forEach(t => req.result.createObjectStore(t));
|
|
2251
2253
|
req.onerror = () => reject(req.error);
|
|
2252
2254
|
req.onsuccess = () => resolve(req.result);
|
|
2253
|
-
})
|
|
2255
|
+
});
|
|
2254
2256
|
}
|
|
2255
2257
|
async getDbHandle() {
|
|
2256
2258
|
if (!this.dbHandle) {
|
|
@@ -2263,10 +2265,10 @@ class DpopStorage {
|
|
|
2263
2265
|
const txn = db.transaction(table, mode);
|
|
2264
2266
|
const store = txn.objectStore(table);
|
|
2265
2267
|
const request = requestFactory(store);
|
|
2266
|
-
return new Promise((
|
|
2268
|
+
return new Promise((resolve, reject) => {
|
|
2267
2269
|
request.onsuccess = () => resolve(request.result);
|
|
2268
2270
|
request.onerror = () => reject(request.error);
|
|
2269
|
-
})
|
|
2271
|
+
});
|
|
2270
2272
|
}
|
|
2271
2273
|
buildKey(id) {
|
|
2272
2274
|
const finalId = id ? "_".concat(id) : AUTH0_NONCE_ID;
|
|
@@ -2279,7 +2281,7 @@ class DpopStorage {
|
|
|
2279
2281
|
return this.save(TABLES.KEYPAIR, this.buildKey(), keyPair);
|
|
2280
2282
|
}
|
|
2281
2283
|
async save(table, key, obj) {
|
|
2282
|
-
return void await this.executeDbRequest(table, "readwrite",
|
|
2284
|
+
return void await this.executeDbRequest(table, "readwrite", table => table.put(obj, key));
|
|
2283
2285
|
}
|
|
2284
2286
|
findNonce(id) {
|
|
2285
2287
|
return this.find(TABLES.NONCE, this.buildKey(id));
|
|
@@ -2288,14 +2290,14 @@ class DpopStorage {
|
|
|
2288
2290
|
return this.find(TABLES.KEYPAIR, this.buildKey());
|
|
2289
2291
|
}
|
|
2290
2292
|
find(table, key) {
|
|
2291
|
-
return this.executeDbRequest(table, "readonly",
|
|
2293
|
+
return this.executeDbRequest(table, "readonly", table => table.get(key));
|
|
2292
2294
|
}
|
|
2293
2295
|
async deleteBy(table, predicate) {
|
|
2294
|
-
const allKeys = await this.executeDbRequest(table, "readonly",
|
|
2295
|
-
allKeys === null || allKeys === void 0 ? void 0 : allKeys.filter(predicate).map(
|
|
2296
|
+
const allKeys = await this.executeDbRequest(table, "readonly", table => table.getAllKeys());
|
|
2297
|
+
allKeys === null || allKeys === void 0 ? void 0 : allKeys.filter(predicate).map(k => this.executeDbRequest(table, "readwrite", table => table.delete(k)));
|
|
2296
2298
|
}
|
|
2297
2299
|
deleteByClientId(table, clientId) {
|
|
2298
|
-
return this.deleteBy(table,
|
|
2300
|
+
return this.deleteBy(table, k => typeof k === "string" && k.startsWith("".concat(clientId, "::")));
|
|
2299
2301
|
}
|
|
2300
2302
|
clearNonces() {
|
|
2301
2303
|
return this.deleteByClientId(TABLES.NONCE, this.clientId);
|
|
@@ -2625,9 +2627,9 @@ function ownKeys(e, r) {
|
|
|
2625
2627
|
var t = Object.keys(e);
|
|
2626
2628
|
if (Object.getOwnPropertySymbols) {
|
|
2627
2629
|
var o = Object.getOwnPropertySymbols(e);
|
|
2628
|
-
r && (o = o.filter(
|
|
2630
|
+
r && (o = o.filter(function(r) {
|
|
2629
2631
|
return Object.getOwnPropertyDescriptor(e, r).enumerable;
|
|
2630
|
-
}))
|
|
2632
|
+
})), t.push.apply(t, o);
|
|
2631
2633
|
}
|
|
2632
2634
|
return t;
|
|
2633
2635
|
}
|
|
@@ -2635,11 +2637,11 @@ function ownKeys(e, r) {
|
|
|
2635
2637
|
function _objectSpread2(e) {
|
|
2636
2638
|
for (var r = 1; r < arguments.length; r++) {
|
|
2637
2639
|
var t = null != arguments[r] ? arguments[r] : {};
|
|
2638
|
-
r % 2 ? ownKeys(Object(t), !0).forEach(
|
|
2640
|
+
r % 2 ? ownKeys(Object(t), !0).forEach(function(r) {
|
|
2639
2641
|
_defineProperty(e, r, t[r]);
|
|
2640
|
-
})
|
|
2642
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r) {
|
|
2641
2643
|
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
|
|
2642
|
-
})
|
|
2644
|
+
});
|
|
2643
2645
|
}
|
|
2644
2646
|
return e;
|
|
2645
2647
|
}
|
|
@@ -2691,16 +2693,16 @@ function AsyncGenerator(e) {
|
|
|
2691
2693
|
function resume(r, t) {
|
|
2692
2694
|
try {
|
|
2693
2695
|
var n = e[r](t), o = n.value, u = o instanceof _OverloadYield;
|
|
2694
|
-
Promise.resolve(u ? o.v : o).then(
|
|
2696
|
+
Promise.resolve(u ? o.v : o).then(function(t) {
|
|
2695
2697
|
if (u) {
|
|
2696
2698
|
var i = "return" === r ? "return" : "next";
|
|
2697
2699
|
if (!o.k || t.done) return resume(i, t);
|
|
2698
2700
|
t = e[i](t).value;
|
|
2699
2701
|
}
|
|
2700
2702
|
settle(n.done ? "return" : "normal", t);
|
|
2701
|
-
}
|
|
2703
|
+
}, function(e) {
|
|
2702
2704
|
resume("throw", e);
|
|
2703
|
-
})
|
|
2705
|
+
});
|
|
2704
2706
|
} catch (e) {
|
|
2705
2707
|
settle("throw", e);
|
|
2706
2708
|
}
|
|
@@ -2727,7 +2729,7 @@ function AsyncGenerator(e) {
|
|
|
2727
2729
|
(r = r.next) ? resume(r.key, r.arg) : t = null;
|
|
2728
2730
|
}
|
|
2729
2731
|
this._invoke = function(e, n) {
|
|
2730
|
-
return new Promise(
|
|
2732
|
+
return new Promise(function(o, u) {
|
|
2731
2733
|
var i = {
|
|
2732
2734
|
key: e,
|
|
2733
2735
|
arg: n,
|
|
@@ -2736,7 +2738,7 @@ function AsyncGenerator(e) {
|
|
|
2736
2738
|
next: null
|
|
2737
2739
|
};
|
|
2738
2740
|
t ? t = t.next = i : (r = t = i, resume(e, n));
|
|
2739
|
-
})
|
|
2741
|
+
});
|
|
2740
2742
|
}, "function" != typeof e.return && (this.return = void 0);
|
|
2741
2743
|
}
|
|
2742
2744
|
|
|
@@ -2756,7 +2758,7 @@ let USER_AGENT$2;
|
|
|
2756
2758
|
|
|
2757
2759
|
if (typeof navigator === "undefined" || !((_navigator$userAgent$2 = navigator.userAgent) !== null && _navigator$userAgent$2 !== void 0 && (_navigator$userAgent$$2 = _navigator$userAgent$2.startsWith) !== null && _navigator$userAgent$$2 !== void 0 && _navigator$userAgent$$2.call(_navigator$userAgent$2, "Mozilla/5.0 "))) {
|
|
2758
2760
|
const NAME = "oauth4webapi";
|
|
2759
|
-
const VERSION = "v3.8.
|
|
2761
|
+
const VERSION = "v3.8.5";
|
|
2760
2762
|
USER_AGENT$2 = "".concat(NAME, "/").concat(VERSION);
|
|
2761
2763
|
}
|
|
2762
2764
|
|
|
@@ -2986,7 +2988,7 @@ async function performDiscovery$1(input, urlName, transform, options) {
|
|
|
2986
2988
|
}
|
|
2987
2989
|
|
|
2988
2990
|
async function discoveryRequest(issuerIdentifier, options) {
|
|
2989
|
-
return performDiscovery$1(issuerIdentifier, "issuerIdentifier",
|
|
2991
|
+
return performDiscovery$1(issuerIdentifier, "issuerIdentifier", url => {
|
|
2990
2992
|
switch (options === null || options === void 0 ? void 0 : options.algorithm) {
|
|
2991
2993
|
case undefined:
|
|
2992
2994
|
case "oidc":
|
|
@@ -3001,7 +3003,7 @@ async function discoveryRequest(issuerIdentifier, options) {
|
|
|
3001
3003
|
throw CodedTypeError$1('"options.algorithm" must be "oidc" (default), or "oauth2"', ERR_INVALID_ARG_VALUE$1);
|
|
3002
3004
|
}
|
|
3003
3005
|
return url;
|
|
3004
|
-
}
|
|
3006
|
+
}, options);
|
|
3005
3007
|
}
|
|
3006
3008
|
|
|
3007
3009
|
function assertNumber(input, allow0, it, code, cause) {
|
|
@@ -4349,10 +4351,10 @@ function concat() {
|
|
|
4349
4351
|
for (var _len = arguments.length, buffers = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
4350
4352
|
buffers[_key] = arguments[_key];
|
|
4351
4353
|
}
|
|
4352
|
-
const size = buffers.reduce((
|
|
4354
|
+
const size = buffers.reduce((acc, _ref) => {
|
|
4353
4355
|
let {length: length} = _ref;
|
|
4354
4356
|
return acc + length;
|
|
4355
|
-
}
|
|
4357
|
+
}, 0);
|
|
4356
4358
|
const buf = new Uint8Array(size);
|
|
4357
4359
|
let i = 0;
|
|
4358
4360
|
for (const buffer of buffers) {
|
|
@@ -4404,6 +4406,145 @@ function decode(input) {
|
|
|
4404
4406
|
}
|
|
4405
4407
|
}
|
|
4406
4408
|
|
|
4409
|
+
const unusable = function unusable(name) {
|
|
4410
|
+
let prop = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "algorithm.name";
|
|
4411
|
+
return new TypeError("CryptoKey does not support this operation, its ".concat(prop, " must be ").concat(name));
|
|
4412
|
+
};
|
|
4413
|
+
|
|
4414
|
+
const isAlgorithm = (algorithm, name) => algorithm.name === name;
|
|
4415
|
+
|
|
4416
|
+
function getHashLength(hash) {
|
|
4417
|
+
return parseInt(hash.name.slice(4), 10);
|
|
4418
|
+
}
|
|
4419
|
+
|
|
4420
|
+
function checkHashLength(algorithm, expected) {
|
|
4421
|
+
const actual = getHashLength(algorithm.hash);
|
|
4422
|
+
if (actual !== expected) throw unusable("SHA-".concat(expected), "algorithm.hash");
|
|
4423
|
+
}
|
|
4424
|
+
|
|
4425
|
+
function getNamedCurve(alg) {
|
|
4426
|
+
switch (alg) {
|
|
4427
|
+
case "ES256":
|
|
4428
|
+
return "P-256";
|
|
4429
|
+
|
|
4430
|
+
case "ES384":
|
|
4431
|
+
return "P-384";
|
|
4432
|
+
|
|
4433
|
+
case "ES512":
|
|
4434
|
+
return "P-521";
|
|
4435
|
+
|
|
4436
|
+
default:
|
|
4437
|
+
throw new Error("unreachable");
|
|
4438
|
+
}
|
|
4439
|
+
}
|
|
4440
|
+
|
|
4441
|
+
function checkUsage(key, usage) {
|
|
4442
|
+
if (usage && !key.usages.includes(usage)) {
|
|
4443
|
+
throw new TypeError("CryptoKey does not support this operation, its usages must include ".concat(usage, "."));
|
|
4444
|
+
}
|
|
4445
|
+
}
|
|
4446
|
+
|
|
4447
|
+
function checkSigCryptoKey(key, alg, usage) {
|
|
4448
|
+
switch (alg) {
|
|
4449
|
+
case "HS256":
|
|
4450
|
+
case "HS384":
|
|
4451
|
+
case "HS512":
|
|
4452
|
+
{
|
|
4453
|
+
if (!isAlgorithm(key.algorithm, "HMAC")) throw unusable("HMAC");
|
|
4454
|
+
checkHashLength(key.algorithm, parseInt(alg.slice(2), 10));
|
|
4455
|
+
break;
|
|
4456
|
+
}
|
|
4457
|
+
|
|
4458
|
+
case "RS256":
|
|
4459
|
+
case "RS384":
|
|
4460
|
+
case "RS512":
|
|
4461
|
+
{
|
|
4462
|
+
if (!isAlgorithm(key.algorithm, "RSASSA-PKCS1-v1_5")) throw unusable("RSASSA-PKCS1-v1_5");
|
|
4463
|
+
checkHashLength(key.algorithm, parseInt(alg.slice(2), 10));
|
|
4464
|
+
break;
|
|
4465
|
+
}
|
|
4466
|
+
|
|
4467
|
+
case "PS256":
|
|
4468
|
+
case "PS384":
|
|
4469
|
+
case "PS512":
|
|
4470
|
+
{
|
|
4471
|
+
if (!isAlgorithm(key.algorithm, "RSA-PSS")) throw unusable("RSA-PSS");
|
|
4472
|
+
checkHashLength(key.algorithm, parseInt(alg.slice(2), 10));
|
|
4473
|
+
break;
|
|
4474
|
+
}
|
|
4475
|
+
|
|
4476
|
+
case "Ed25519":
|
|
4477
|
+
case "EdDSA":
|
|
4478
|
+
{
|
|
4479
|
+
if (!isAlgorithm(key.algorithm, "Ed25519")) throw unusable("Ed25519");
|
|
4480
|
+
break;
|
|
4481
|
+
}
|
|
4482
|
+
|
|
4483
|
+
case "ML-DSA-44":
|
|
4484
|
+
case "ML-DSA-65":
|
|
4485
|
+
case "ML-DSA-87":
|
|
4486
|
+
{
|
|
4487
|
+
if (!isAlgorithm(key.algorithm, alg)) throw unusable(alg);
|
|
4488
|
+
break;
|
|
4489
|
+
}
|
|
4490
|
+
|
|
4491
|
+
case "ES256":
|
|
4492
|
+
case "ES384":
|
|
4493
|
+
case "ES512":
|
|
4494
|
+
{
|
|
4495
|
+
if (!isAlgorithm(key.algorithm, "ECDSA")) throw unusable("ECDSA");
|
|
4496
|
+
const expected = getNamedCurve(alg);
|
|
4497
|
+
const actual = key.algorithm.namedCurve;
|
|
4498
|
+
if (actual !== expected) throw unusable(expected, "algorithm.namedCurve");
|
|
4499
|
+
break;
|
|
4500
|
+
}
|
|
4501
|
+
|
|
4502
|
+
default:
|
|
4503
|
+
throw new TypeError("CryptoKey does not support this operation");
|
|
4504
|
+
}
|
|
4505
|
+
checkUsage(key, usage);
|
|
4506
|
+
}
|
|
4507
|
+
|
|
4508
|
+
function message(msg, actual) {
|
|
4509
|
+
for (var _len = arguments.length, types = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
|
|
4510
|
+
types[_key - 2] = arguments[_key];
|
|
4511
|
+
}
|
|
4512
|
+
types = types.filter(Boolean);
|
|
4513
|
+
if (types.length > 2) {
|
|
4514
|
+
const last = types.pop();
|
|
4515
|
+
msg += "one of type ".concat(types.join(", "), ", or ").concat(last, ".");
|
|
4516
|
+
} else if (types.length === 2) {
|
|
4517
|
+
msg += "one of type ".concat(types[0], " or ").concat(types[1], ".");
|
|
4518
|
+
} else {
|
|
4519
|
+
msg += "of type ".concat(types[0], ".");
|
|
4520
|
+
}
|
|
4521
|
+
if (actual == null) {
|
|
4522
|
+
msg += " Received ".concat(actual);
|
|
4523
|
+
} else if (typeof actual === "function" && actual.name) {
|
|
4524
|
+
msg += " Received function ".concat(actual.name);
|
|
4525
|
+
} else if (typeof actual === "object" && actual != null) {
|
|
4526
|
+
var _actual$constructor;
|
|
4527
|
+
if ((_actual$constructor = actual.constructor) !== null && _actual$constructor !== void 0 && _actual$constructor.name) {
|
|
4528
|
+
msg += " Received an instance of ".concat(actual.constructor.name);
|
|
4529
|
+
}
|
|
4530
|
+
}
|
|
4531
|
+
return msg;
|
|
4532
|
+
}
|
|
4533
|
+
|
|
4534
|
+
const invalidKeyInput = function invalidKeyInput(actual) {
|
|
4535
|
+
for (var _len2 = arguments.length, types = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
4536
|
+
types[_key2 - 1] = arguments[_key2];
|
|
4537
|
+
}
|
|
4538
|
+
return message("Key must be ", actual, ...types);
|
|
4539
|
+
};
|
|
4540
|
+
|
|
4541
|
+
const withAlg = function withAlg(alg, actual) {
|
|
4542
|
+
for (var _len3 = arguments.length, types = new Array(_len3 > 2 ? _len3 - 2 : 0), _key3 = 2; _key3 < _len3; _key3++) {
|
|
4543
|
+
types[_key3 - 2] = arguments[_key3];
|
|
4544
|
+
}
|
|
4545
|
+
return message("Key for the ".concat(alg, " algorithm must be "), actual, ...types);
|
|
4546
|
+
};
|
|
4547
|
+
|
|
4407
4548
|
class JOSEError extends Error {
|
|
4408
4549
|
constructor(message, options) {
|
|
4409
4550
|
var _Error$captureStackTr;
|
|
@@ -4581,207 +4722,486 @@ class JWSSignatureVerificationFailed extends JOSEError {
|
|
|
4581
4722
|
|
|
4582
4723
|
_defineProperty(JWSSignatureVerificationFailed, "code", "ERR_JWS_SIGNATURE_VERIFICATION_FAILED");
|
|
4583
4724
|
|
|
4584
|
-
const
|
|
4585
|
-
|
|
4586
|
-
|
|
4725
|
+
const isCryptoKey = key => {
|
|
4726
|
+
if ((key === null || key === void 0 ? void 0 : key[Symbol.toStringTag]) === "CryptoKey") return true;
|
|
4727
|
+
try {
|
|
4728
|
+
return key instanceof CryptoKey;
|
|
4729
|
+
} catch (_unused) {
|
|
4730
|
+
return false;
|
|
4731
|
+
}
|
|
4587
4732
|
};
|
|
4588
4733
|
|
|
4589
|
-
const
|
|
4590
|
-
|
|
4591
|
-
function getHashLength(hash) {
|
|
4592
|
-
return parseInt(hash.name.slice(4), 10);
|
|
4593
|
-
}
|
|
4734
|
+
const isKeyObject = key => (key === null || key === void 0 ? void 0 : key[Symbol.toStringTag]) === "KeyObject";
|
|
4594
4735
|
|
|
4595
|
-
|
|
4596
|
-
switch (alg) {
|
|
4597
|
-
case "ES256":
|
|
4598
|
-
return "P-256";
|
|
4736
|
+
const isKeyLike = key => isCryptoKey(key) || isKeyObject(key);
|
|
4599
4737
|
|
|
4600
|
-
|
|
4601
|
-
|
|
4738
|
+
function decodeBase64url(value, label, ErrorClass) {
|
|
4739
|
+
try {
|
|
4740
|
+
return decode(value);
|
|
4741
|
+
} catch (_unused) {
|
|
4742
|
+
throw new ErrorClass("Failed to base64url decode the ".concat(label));
|
|
4743
|
+
}
|
|
4744
|
+
}
|
|
4602
4745
|
|
|
4603
|
-
|
|
4604
|
-
return "P-521";
|
|
4746
|
+
const isObjectLike = value => typeof value === "object" && value !== null;
|
|
4605
4747
|
|
|
4606
|
-
|
|
4607
|
-
|
|
4748
|
+
function isObject(input) {
|
|
4749
|
+
if (!isObjectLike(input) || Object.prototype.toString.call(input) !== "[object Object]") {
|
|
4750
|
+
return false;
|
|
4608
4751
|
}
|
|
4752
|
+
if (Object.getPrototypeOf(input) === null) {
|
|
4753
|
+
return true;
|
|
4754
|
+
}
|
|
4755
|
+
let proto = input;
|
|
4756
|
+
while (Object.getPrototypeOf(proto) !== null) {
|
|
4757
|
+
proto = Object.getPrototypeOf(proto);
|
|
4758
|
+
}
|
|
4759
|
+
return Object.getPrototypeOf(input) === proto;
|
|
4609
4760
|
}
|
|
4610
4761
|
|
|
4611
|
-
function
|
|
4612
|
-
|
|
4613
|
-
|
|
4762
|
+
function isDisjoint() {
|
|
4763
|
+
for (var _len = arguments.length, headers = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
4764
|
+
headers[_key] = arguments[_key];
|
|
4765
|
+
}
|
|
4766
|
+
const sources = headers.filter(Boolean);
|
|
4767
|
+
if (sources.length === 0 || sources.length === 1) {
|
|
4768
|
+
return true;
|
|
4769
|
+
}
|
|
4770
|
+
let acc;
|
|
4771
|
+
for (const header of sources) {
|
|
4772
|
+
const parameters = Object.keys(header);
|
|
4773
|
+
if (!acc || acc.size === 0) {
|
|
4774
|
+
acc = new Set(parameters);
|
|
4775
|
+
continue;
|
|
4776
|
+
}
|
|
4777
|
+
for (const parameter of parameters) {
|
|
4778
|
+
if (acc.has(parameter)) {
|
|
4779
|
+
return false;
|
|
4780
|
+
}
|
|
4781
|
+
acc.add(parameter);
|
|
4782
|
+
}
|
|
4783
|
+
}
|
|
4784
|
+
return true;
|
|
4785
|
+
}
|
|
4786
|
+
|
|
4787
|
+
const isJWK = key => isObject(key) && typeof key.kty === "string";
|
|
4788
|
+
|
|
4789
|
+
const isPrivateJWK = key => key.kty !== "oct" && (key.kty === "AKP" && typeof key.priv === "string" || typeof key.d === "string");
|
|
4790
|
+
|
|
4791
|
+
const isPublicJWK = key => key.kty !== "oct" && key.d === undefined && key.priv === undefined;
|
|
4792
|
+
|
|
4793
|
+
const isSecretJWK = key => key.kty === "oct" && typeof key.k === "string";
|
|
4794
|
+
|
|
4795
|
+
function checkKeyLength(alg, key) {
|
|
4796
|
+
if (alg.startsWith("RS") || alg.startsWith("PS")) {
|
|
4797
|
+
const {modulusLength: modulusLength} = key.algorithm;
|
|
4798
|
+
if (typeof modulusLength !== "number" || modulusLength < 2048) {
|
|
4799
|
+
throw new TypeError("".concat(alg, " requires key modulusLength to be 2048 bits or larger"));
|
|
4800
|
+
}
|
|
4614
4801
|
}
|
|
4615
4802
|
}
|
|
4616
4803
|
|
|
4617
|
-
function
|
|
4804
|
+
function subtleAlgorithm(alg, algorithm) {
|
|
4805
|
+
const hash = "SHA-".concat(alg.slice(-3));
|
|
4618
4806
|
switch (alg) {
|
|
4619
4807
|
case "HS256":
|
|
4620
4808
|
case "HS384":
|
|
4621
4809
|
case "HS512":
|
|
4622
|
-
{
|
|
4623
|
-
|
|
4624
|
-
|
|
4625
|
-
|
|
4626
|
-
|
|
4627
|
-
|
|
4628
|
-
|
|
4810
|
+
return {
|
|
4811
|
+
hash: hash,
|
|
4812
|
+
name: "HMAC"
|
|
4813
|
+
};
|
|
4814
|
+
|
|
4815
|
+
case "PS256":
|
|
4816
|
+
case "PS384":
|
|
4817
|
+
case "PS512":
|
|
4818
|
+
return {
|
|
4819
|
+
hash: hash,
|
|
4820
|
+
name: "RSA-PSS",
|
|
4821
|
+
saltLength: parseInt(alg.slice(-3), 10) >> 3
|
|
4822
|
+
};
|
|
4629
4823
|
|
|
4630
4824
|
case "RS256":
|
|
4631
4825
|
case "RS384":
|
|
4632
4826
|
case "RS512":
|
|
4633
|
-
{
|
|
4634
|
-
|
|
4635
|
-
|
|
4636
|
-
|
|
4637
|
-
|
|
4638
|
-
|
|
4827
|
+
return {
|
|
4828
|
+
hash: hash,
|
|
4829
|
+
name: "RSASSA-PKCS1-v1_5"
|
|
4830
|
+
};
|
|
4831
|
+
|
|
4832
|
+
case "ES256":
|
|
4833
|
+
case "ES384":
|
|
4834
|
+
case "ES512":
|
|
4835
|
+
return {
|
|
4836
|
+
hash: hash,
|
|
4837
|
+
name: "ECDSA",
|
|
4838
|
+
namedCurve: algorithm.namedCurve
|
|
4839
|
+
};
|
|
4840
|
+
|
|
4841
|
+
case "Ed25519":
|
|
4842
|
+
case "EdDSA":
|
|
4843
|
+
return {
|
|
4844
|
+
name: "Ed25519"
|
|
4845
|
+
};
|
|
4846
|
+
|
|
4847
|
+
case "ML-DSA-44":
|
|
4848
|
+
case "ML-DSA-65":
|
|
4849
|
+
case "ML-DSA-87":
|
|
4850
|
+
return {
|
|
4851
|
+
name: alg
|
|
4852
|
+
};
|
|
4853
|
+
|
|
4854
|
+
default:
|
|
4855
|
+
throw new JOSENotSupported("alg ".concat(alg, " is not supported either by JOSE or your javascript runtime"));
|
|
4856
|
+
}
|
|
4857
|
+
}
|
|
4858
|
+
|
|
4859
|
+
async function getSigKey(alg, key, usage) {
|
|
4860
|
+
if (key instanceof Uint8Array) {
|
|
4861
|
+
if (!alg.startsWith("HS")) {
|
|
4862
|
+
throw new TypeError(invalidKeyInput(key, "CryptoKey", "KeyObject", "JSON Web Key"));
|
|
4639
4863
|
}
|
|
4864
|
+
return crypto.subtle.importKey("raw", key, {
|
|
4865
|
+
hash: "SHA-".concat(alg.slice(-3)),
|
|
4866
|
+
name: "HMAC"
|
|
4867
|
+
}, false, [ usage ]);
|
|
4868
|
+
}
|
|
4869
|
+
checkSigCryptoKey(key, alg, usage);
|
|
4870
|
+
return key;
|
|
4871
|
+
}
|
|
4640
4872
|
|
|
4641
|
-
|
|
4642
|
-
|
|
4643
|
-
|
|
4873
|
+
async function verify(alg, key, signature, data) {
|
|
4874
|
+
const cryptoKey = await getSigKey(alg, key, "verify");
|
|
4875
|
+
checkKeyLength(alg, cryptoKey);
|
|
4876
|
+
const algorithm = subtleAlgorithm(alg, cryptoKey.algorithm);
|
|
4877
|
+
try {
|
|
4878
|
+
return await crypto.subtle.verify(algorithm, cryptoKey, signature, data);
|
|
4879
|
+
} catch (_unused) {
|
|
4880
|
+
return false;
|
|
4881
|
+
}
|
|
4882
|
+
}
|
|
4883
|
+
|
|
4884
|
+
const unsupportedAlg = 'Invalid or unsupported JWK "alg" (Algorithm) Parameter value';
|
|
4885
|
+
|
|
4886
|
+
function subtleMapping(jwk) {
|
|
4887
|
+
let algorithm;
|
|
4888
|
+
let keyUsages;
|
|
4889
|
+
switch (jwk.kty) {
|
|
4890
|
+
case "AKP":
|
|
4644
4891
|
{
|
|
4645
|
-
|
|
4646
|
-
|
|
4647
|
-
|
|
4648
|
-
|
|
4892
|
+
switch (jwk.alg) {
|
|
4893
|
+
case "ML-DSA-44":
|
|
4894
|
+
case "ML-DSA-65":
|
|
4895
|
+
case "ML-DSA-87":
|
|
4896
|
+
algorithm = {
|
|
4897
|
+
name: jwk.alg
|
|
4898
|
+
};
|
|
4899
|
+
keyUsages = jwk.priv ? [ "sign" ] : [ "verify" ];
|
|
4900
|
+
break;
|
|
4901
|
+
|
|
4902
|
+
default:
|
|
4903
|
+
throw new JOSENotSupported(unsupportedAlg);
|
|
4904
|
+
}
|
|
4649
4905
|
break;
|
|
4650
4906
|
}
|
|
4651
4907
|
|
|
4652
|
-
case "
|
|
4653
|
-
case "EdDSA":
|
|
4908
|
+
case "RSA":
|
|
4654
4909
|
{
|
|
4655
|
-
|
|
4910
|
+
switch (jwk.alg) {
|
|
4911
|
+
case "PS256":
|
|
4912
|
+
case "PS384":
|
|
4913
|
+
case "PS512":
|
|
4914
|
+
algorithm = {
|
|
4915
|
+
name: "RSA-PSS",
|
|
4916
|
+
hash: "SHA-".concat(jwk.alg.slice(-3))
|
|
4917
|
+
};
|
|
4918
|
+
keyUsages = jwk.d ? [ "sign" ] : [ "verify" ];
|
|
4919
|
+
break;
|
|
4920
|
+
|
|
4921
|
+
case "RS256":
|
|
4922
|
+
case "RS384":
|
|
4923
|
+
case "RS512":
|
|
4924
|
+
algorithm = {
|
|
4925
|
+
name: "RSASSA-PKCS1-v1_5",
|
|
4926
|
+
hash: "SHA-".concat(jwk.alg.slice(-3))
|
|
4927
|
+
};
|
|
4928
|
+
keyUsages = jwk.d ? [ "sign" ] : [ "verify" ];
|
|
4929
|
+
break;
|
|
4930
|
+
|
|
4931
|
+
case "RSA-OAEP":
|
|
4932
|
+
case "RSA-OAEP-256":
|
|
4933
|
+
case "RSA-OAEP-384":
|
|
4934
|
+
case "RSA-OAEP-512":
|
|
4935
|
+
algorithm = {
|
|
4936
|
+
name: "RSA-OAEP",
|
|
4937
|
+
hash: "SHA-".concat(parseInt(jwk.alg.slice(-3), 10) || 1)
|
|
4938
|
+
};
|
|
4939
|
+
keyUsages = jwk.d ? [ "decrypt", "unwrapKey" ] : [ "encrypt", "wrapKey" ];
|
|
4940
|
+
break;
|
|
4941
|
+
|
|
4942
|
+
default:
|
|
4943
|
+
throw new JOSENotSupported(unsupportedAlg);
|
|
4944
|
+
}
|
|
4656
4945
|
break;
|
|
4657
4946
|
}
|
|
4658
4947
|
|
|
4659
|
-
case "
|
|
4660
|
-
case "ML-DSA-65":
|
|
4661
|
-
case "ML-DSA-87":
|
|
4948
|
+
case "EC":
|
|
4662
4949
|
{
|
|
4663
|
-
|
|
4950
|
+
switch (jwk.alg) {
|
|
4951
|
+
case "ES256":
|
|
4952
|
+
case "ES384":
|
|
4953
|
+
case "ES512":
|
|
4954
|
+
algorithm = {
|
|
4955
|
+
name: "ECDSA",
|
|
4956
|
+
namedCurve: {
|
|
4957
|
+
ES256: "P-256",
|
|
4958
|
+
ES384: "P-384",
|
|
4959
|
+
ES512: "P-521"
|
|
4960
|
+
}[jwk.alg]
|
|
4961
|
+
};
|
|
4962
|
+
keyUsages = jwk.d ? [ "sign" ] : [ "verify" ];
|
|
4963
|
+
break;
|
|
4964
|
+
|
|
4965
|
+
case "ECDH-ES":
|
|
4966
|
+
case "ECDH-ES+A128KW":
|
|
4967
|
+
case "ECDH-ES+A192KW":
|
|
4968
|
+
case "ECDH-ES+A256KW":
|
|
4969
|
+
algorithm = {
|
|
4970
|
+
name: "ECDH",
|
|
4971
|
+
namedCurve: jwk.crv
|
|
4972
|
+
};
|
|
4973
|
+
keyUsages = jwk.d ? [ "deriveBits" ] : [];
|
|
4974
|
+
break;
|
|
4975
|
+
|
|
4976
|
+
default:
|
|
4977
|
+
throw new JOSENotSupported(unsupportedAlg);
|
|
4978
|
+
}
|
|
4664
4979
|
break;
|
|
4665
4980
|
}
|
|
4666
4981
|
|
|
4667
|
-
case "
|
|
4668
|
-
case "ES384":
|
|
4669
|
-
case "ES512":
|
|
4982
|
+
case "OKP":
|
|
4670
4983
|
{
|
|
4671
|
-
|
|
4672
|
-
|
|
4673
|
-
|
|
4674
|
-
|
|
4984
|
+
switch (jwk.alg) {
|
|
4985
|
+
case "Ed25519":
|
|
4986
|
+
case "EdDSA":
|
|
4987
|
+
algorithm = {
|
|
4988
|
+
name: "Ed25519"
|
|
4989
|
+
};
|
|
4990
|
+
keyUsages = jwk.d ? [ "sign" ] : [ "verify" ];
|
|
4991
|
+
break;
|
|
4992
|
+
|
|
4993
|
+
case "ECDH-ES":
|
|
4994
|
+
case "ECDH-ES+A128KW":
|
|
4995
|
+
case "ECDH-ES+A192KW":
|
|
4996
|
+
case "ECDH-ES+A256KW":
|
|
4997
|
+
algorithm = {
|
|
4998
|
+
name: jwk.crv
|
|
4999
|
+
};
|
|
5000
|
+
keyUsages = jwk.d ? [ "deriveBits" ] : [];
|
|
5001
|
+
break;
|
|
5002
|
+
|
|
5003
|
+
default:
|
|
5004
|
+
throw new JOSENotSupported(unsupportedAlg);
|
|
5005
|
+
}
|
|
4675
5006
|
break;
|
|
4676
5007
|
}
|
|
4677
5008
|
|
|
4678
5009
|
default:
|
|
4679
|
-
throw new
|
|
5010
|
+
throw new JOSENotSupported('Invalid or unsupported JWK "kty" (Key Type) Parameter value');
|
|
4680
5011
|
}
|
|
4681
|
-
|
|
5012
|
+
return {
|
|
5013
|
+
algorithm: algorithm,
|
|
5014
|
+
keyUsages: keyUsages
|
|
5015
|
+
};
|
|
4682
5016
|
}
|
|
4683
5017
|
|
|
4684
|
-
function
|
|
4685
|
-
|
|
4686
|
-
|
|
4687
|
-
|
|
4688
|
-
types = types.filter(Boolean);
|
|
4689
|
-
if (types.length > 2) {
|
|
4690
|
-
const last = types.pop();
|
|
4691
|
-
msg += "one of type ".concat(types.join(", "), ", or ").concat(last, ".");
|
|
4692
|
-
} else if (types.length === 2) {
|
|
4693
|
-
msg += "one of type ".concat(types[0], " or ").concat(types[1], ".");
|
|
4694
|
-
} else {
|
|
4695
|
-
msg += "of type ".concat(types[0], ".");
|
|
5018
|
+
async function jwkToKey(jwk) {
|
|
5019
|
+
var _jwk$ext, _jwk$key_ops;
|
|
5020
|
+
if (!jwk.alg) {
|
|
5021
|
+
throw new TypeError('"alg" argument is required when "jwk.alg" is not present');
|
|
4696
5022
|
}
|
|
4697
|
-
|
|
4698
|
-
|
|
4699
|
-
|
|
4700
|
-
|
|
4701
|
-
} else if (typeof actual === "object" && actual != null) {
|
|
4702
|
-
var _actual$constructor;
|
|
4703
|
-
if ((_actual$constructor = actual.constructor) !== null && _actual$constructor !== void 0 && _actual$constructor.name) {
|
|
4704
|
-
msg += " Received an instance of ".concat(actual.constructor.name);
|
|
4705
|
-
}
|
|
5023
|
+
const {algorithm: algorithm, keyUsages: keyUsages} = subtleMapping(jwk);
|
|
5024
|
+
const keyData = _objectSpread2({}, jwk);
|
|
5025
|
+
if (keyData.kty !== "AKP") {
|
|
5026
|
+
delete keyData.alg;
|
|
4706
5027
|
}
|
|
4707
|
-
|
|
5028
|
+
delete keyData.use;
|
|
5029
|
+
return crypto.subtle.importKey("jwk", keyData, algorithm, (_jwk$ext = jwk.ext) !== null && _jwk$ext !== void 0 ? _jwk$ext : jwk.d || jwk.priv ? false : true, (_jwk$key_ops = jwk.key_ops) !== null && _jwk$key_ops !== void 0 ? _jwk$key_ops : keyUsages);
|
|
4708
5030
|
}
|
|
4709
5031
|
|
|
4710
|
-
const
|
|
4711
|
-
|
|
4712
|
-
|
|
5032
|
+
const unusableForAlg = "given KeyObject instance cannot be used for this algorithm";
|
|
5033
|
+
|
|
5034
|
+
let cache;
|
|
5035
|
+
|
|
5036
|
+
const handleJWK = async function handleJWK(key, jwk, alg) {
|
|
5037
|
+
let freeze = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
5038
|
+
cache || (cache = new WeakMap);
|
|
5039
|
+
let cached = cache.get(key);
|
|
5040
|
+
if (cached !== null && cached !== void 0 && cached[alg]) {
|
|
5041
|
+
return cached[alg];
|
|
4713
5042
|
}
|
|
4714
|
-
|
|
5043
|
+
const cryptoKey = await jwkToKey(_objectSpread2(_objectSpread2({}, jwk), {}, {
|
|
5044
|
+
alg: alg
|
|
5045
|
+
}));
|
|
5046
|
+
if (freeze) Object.freeze(key);
|
|
5047
|
+
if (!cached) {
|
|
5048
|
+
cache.set(key, {
|
|
5049
|
+
[alg]: cryptoKey
|
|
5050
|
+
});
|
|
5051
|
+
} else {
|
|
5052
|
+
cached[alg] = cryptoKey;
|
|
5053
|
+
}
|
|
5054
|
+
return cryptoKey;
|
|
4715
5055
|
};
|
|
4716
5056
|
|
|
4717
|
-
const
|
|
4718
|
-
|
|
4719
|
-
|
|
5057
|
+
const handleKeyObject = (keyObject, alg) => {
|
|
5058
|
+
cache || (cache = new WeakMap);
|
|
5059
|
+
let cached = cache.get(keyObject);
|
|
5060
|
+
if (cached !== null && cached !== void 0 && cached[alg]) {
|
|
5061
|
+
return cached[alg];
|
|
4720
5062
|
}
|
|
4721
|
-
|
|
4722
|
-
|
|
5063
|
+
const isPublic = keyObject.type === "public";
|
|
5064
|
+
const extractable = isPublic ? true : false;
|
|
5065
|
+
let cryptoKey;
|
|
5066
|
+
if (keyObject.asymmetricKeyType === "x25519") {
|
|
5067
|
+
switch (alg) {
|
|
5068
|
+
case "ECDH-ES":
|
|
5069
|
+
case "ECDH-ES+A128KW":
|
|
5070
|
+
case "ECDH-ES+A192KW":
|
|
5071
|
+
case "ECDH-ES+A256KW":
|
|
5072
|
+
break;
|
|
4723
5073
|
|
|
4724
|
-
|
|
4725
|
-
|
|
4726
|
-
|
|
4727
|
-
|
|
4728
|
-
}
|
|
4729
|
-
|
|
5074
|
+
default:
|
|
5075
|
+
throw new TypeError(unusableForAlg);
|
|
5076
|
+
}
|
|
5077
|
+
cryptoKey = keyObject.toCryptoKey(keyObject.asymmetricKeyType, extractable, isPublic ? [] : [ "deriveBits" ]);
|
|
5078
|
+
}
|
|
5079
|
+
if (keyObject.asymmetricKeyType === "ed25519") {
|
|
5080
|
+
if (alg !== "EdDSA" && alg !== "Ed25519") {
|
|
5081
|
+
throw new TypeError(unusableForAlg);
|
|
5082
|
+
}
|
|
5083
|
+
cryptoKey = keyObject.toCryptoKey(keyObject.asymmetricKeyType, extractable, [ isPublic ? "verify" : "sign" ]);
|
|
5084
|
+
}
|
|
5085
|
+
switch (keyObject.asymmetricKeyType) {
|
|
5086
|
+
case "ml-dsa-44":
|
|
5087
|
+
case "ml-dsa-65":
|
|
5088
|
+
case "ml-dsa-87":
|
|
5089
|
+
{
|
|
5090
|
+
if (alg !== keyObject.asymmetricKeyType.toUpperCase()) {
|
|
5091
|
+
throw new TypeError(unusableForAlg);
|
|
5092
|
+
}
|
|
5093
|
+
cryptoKey = keyObject.toCryptoKey(keyObject.asymmetricKeyType, extractable, [ isPublic ? "verify" : "sign" ]);
|
|
5094
|
+
}
|
|
5095
|
+
}
|
|
5096
|
+
if (keyObject.asymmetricKeyType === "rsa") {
|
|
5097
|
+
let hash;
|
|
5098
|
+
switch (alg) {
|
|
5099
|
+
case "RSA-OAEP":
|
|
5100
|
+
hash = "SHA-1";
|
|
5101
|
+
break;
|
|
5102
|
+
|
|
5103
|
+
case "RS256":
|
|
5104
|
+
case "PS256":
|
|
5105
|
+
case "RSA-OAEP-256":
|
|
5106
|
+
hash = "SHA-256";
|
|
5107
|
+
break;
|
|
5108
|
+
|
|
5109
|
+
case "RS384":
|
|
5110
|
+
case "PS384":
|
|
5111
|
+
case "RSA-OAEP-384":
|
|
5112
|
+
hash = "SHA-384";
|
|
5113
|
+
break;
|
|
5114
|
+
|
|
5115
|
+
case "RS512":
|
|
5116
|
+
case "PS512":
|
|
5117
|
+
case "RSA-OAEP-512":
|
|
5118
|
+
hash = "SHA-512";
|
|
5119
|
+
break;
|
|
5120
|
+
|
|
5121
|
+
default:
|
|
5122
|
+
throw new TypeError(unusableForAlg);
|
|
5123
|
+
}
|
|
5124
|
+
if (alg.startsWith("RSA-OAEP")) {
|
|
5125
|
+
return keyObject.toCryptoKey({
|
|
5126
|
+
name: "RSA-OAEP",
|
|
5127
|
+
hash: hash
|
|
5128
|
+
}, extractable, isPublic ? [ "encrypt" ] : [ "decrypt" ]);
|
|
5129
|
+
}
|
|
5130
|
+
cryptoKey = keyObject.toCryptoKey({
|
|
5131
|
+
name: alg.startsWith("PS") ? "RSA-PSS" : "RSASSA-PKCS1-v1_5",
|
|
5132
|
+
hash: hash
|
|
5133
|
+
}, extractable, [ isPublic ? "verify" : "sign" ]);
|
|
5134
|
+
}
|
|
5135
|
+
if (keyObject.asymmetricKeyType === "ec") {
|
|
5136
|
+
var _keyObject$asymmetric;
|
|
5137
|
+
const nist = new Map([ [ "prime256v1", "P-256" ], [ "secp384r1", "P-384" ], [ "secp521r1", "P-521" ] ]);
|
|
5138
|
+
const namedCurve = nist.get((_keyObject$asymmetric = keyObject.asymmetricKeyDetails) === null || _keyObject$asymmetric === void 0 ? void 0 : _keyObject$asymmetric.namedCurve);
|
|
5139
|
+
if (!namedCurve) {
|
|
5140
|
+
throw new TypeError(unusableForAlg);
|
|
5141
|
+
}
|
|
5142
|
+
const expectedCurve = {
|
|
5143
|
+
ES256: "P-256",
|
|
5144
|
+
ES384: "P-384",
|
|
5145
|
+
ES512: "P-521"
|
|
5146
|
+
};
|
|
5147
|
+
if (expectedCurve[alg] && namedCurve === expectedCurve[alg]) {
|
|
5148
|
+
cryptoKey = keyObject.toCryptoKey({
|
|
5149
|
+
name: "ECDSA",
|
|
5150
|
+
namedCurve: namedCurve
|
|
5151
|
+
}, extractable, [ isPublic ? "verify" : "sign" ]);
|
|
5152
|
+
}
|
|
5153
|
+
if (alg.startsWith("ECDH-ES")) {
|
|
5154
|
+
cryptoKey = keyObject.toCryptoKey({
|
|
5155
|
+
name: "ECDH",
|
|
5156
|
+
namedCurve: namedCurve
|
|
5157
|
+
}, extractable, isPublic ? [] : [ "deriveBits" ]);
|
|
5158
|
+
}
|
|
5159
|
+
}
|
|
5160
|
+
if (!cryptoKey) {
|
|
5161
|
+
throw new TypeError(unusableForAlg);
|
|
5162
|
+
}
|
|
5163
|
+
if (!cached) {
|
|
5164
|
+
cache.set(keyObject, {
|
|
5165
|
+
[alg]: cryptoKey
|
|
5166
|
+
});
|
|
5167
|
+
} else {
|
|
5168
|
+
cached[alg] = cryptoKey;
|
|
4730
5169
|
}
|
|
5170
|
+
return cryptoKey;
|
|
4731
5171
|
};
|
|
4732
5172
|
|
|
4733
|
-
|
|
4734
|
-
|
|
4735
|
-
|
|
4736
|
-
|
|
4737
|
-
function isDisjoint() {
|
|
4738
|
-
for (var _len = arguments.length, headers = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
4739
|
-
headers[_key] = arguments[_key];
|
|
5173
|
+
async function normalizeKey(key, alg) {
|
|
5174
|
+
if (key instanceof Uint8Array) {
|
|
5175
|
+
return key;
|
|
4740
5176
|
}
|
|
4741
|
-
|
|
4742
|
-
|
|
4743
|
-
return true;
|
|
5177
|
+
if (isCryptoKey(key)) {
|
|
5178
|
+
return key;
|
|
4744
5179
|
}
|
|
4745
|
-
|
|
4746
|
-
|
|
4747
|
-
|
|
4748
|
-
if (!acc || acc.size === 0) {
|
|
4749
|
-
acc = new Set(parameters);
|
|
4750
|
-
continue;
|
|
5180
|
+
if (isKeyObject(key)) {
|
|
5181
|
+
if (key.type === "secret") {
|
|
5182
|
+
return key.export();
|
|
4751
5183
|
}
|
|
4752
|
-
|
|
4753
|
-
|
|
4754
|
-
return
|
|
5184
|
+
if ("toCryptoKey" in key && typeof key.toCryptoKey === "function") {
|
|
5185
|
+
try {
|
|
5186
|
+
return handleKeyObject(key, alg);
|
|
5187
|
+
} catch (err) {
|
|
5188
|
+
if (err instanceof TypeError) {
|
|
5189
|
+
throw err;
|
|
5190
|
+
}
|
|
4755
5191
|
}
|
|
4756
|
-
acc.add(parameter);
|
|
4757
5192
|
}
|
|
5193
|
+
let jwk = key.export({
|
|
5194
|
+
format: "jwk"
|
|
5195
|
+
});
|
|
5196
|
+
return handleJWK(key, jwk, alg);
|
|
4758
5197
|
}
|
|
4759
|
-
|
|
4760
|
-
|
|
4761
|
-
|
|
4762
|
-
const isObjectLike = value => typeof value === "object" && value !== null;
|
|
4763
|
-
|
|
4764
|
-
function isObject(input) {
|
|
4765
|
-
if (!isObjectLike(input) || Object.prototype.toString.call(input) !== "[object Object]") {
|
|
4766
|
-
return false;
|
|
4767
|
-
}
|
|
4768
|
-
if (Object.getPrototypeOf(input) === null) {
|
|
4769
|
-
return true;
|
|
4770
|
-
}
|
|
4771
|
-
let proto = input;
|
|
4772
|
-
while (Object.getPrototypeOf(proto) !== null) {
|
|
4773
|
-
proto = Object.getPrototypeOf(proto);
|
|
4774
|
-
}
|
|
4775
|
-
return Object.getPrototypeOf(input) === proto;
|
|
4776
|
-
}
|
|
4777
|
-
|
|
4778
|
-
function checkKeyLength(alg, key) {
|
|
4779
|
-
if (alg.startsWith("RS") || alg.startsWith("PS")) {
|
|
4780
|
-
const {modulusLength: modulusLength} = key.algorithm;
|
|
4781
|
-
if (typeof modulusLength !== "number" || modulusLength < 2048) {
|
|
4782
|
-
throw new TypeError("".concat(alg, " requires key modulusLength to be 2048 bits or larger"));
|
|
5198
|
+
if (isJWK(key)) {
|
|
5199
|
+
if (key.k) {
|
|
5200
|
+
return decode(key.k);
|
|
4783
5201
|
}
|
|
5202
|
+
return handleJWK(key, key, alg, true);
|
|
4784
5203
|
}
|
|
5204
|
+
throw new Error("unreachable");
|
|
4785
5205
|
}
|
|
4786
5206
|
|
|
4787
5207
|
const bytesEqual = (a, b) => {
|
|
@@ -4931,217 +5351,61 @@ const genericImport = async (keyFormat, keyData, alg, options) => {
|
|
|
4931
5351
|
case "ECDH-ES+A128KW":
|
|
4932
5352
|
case "ECDH-ES+A192KW":
|
|
4933
5353
|
case "ECDH-ES+A256KW":
|
|
4934
|
-
{
|
|
4935
|
-
try {
|
|
4936
|
-
const namedCurve = options.getNamedCurve(keyData);
|
|
4937
|
-
algorithm = namedCurve === "X25519" ? {
|
|
4938
|
-
name: "X25519"
|
|
4939
|
-
} : {
|
|
4940
|
-
name: "ECDH",
|
|
4941
|
-
namedCurve: namedCurve
|
|
4942
|
-
};
|
|
4943
|
-
} catch (cause) {
|
|
4944
|
-
throw new JOSENotSupported("Invalid or unsupported key format");
|
|
4945
|
-
}
|
|
4946
|
-
keyUsages = isPublic ? [] : [ "deriveBits" ];
|
|
4947
|
-
break;
|
|
4948
|
-
}
|
|
4949
|
-
|
|
4950
|
-
case "Ed25519":
|
|
4951
|
-
case "EdDSA":
|
|
4952
|
-
algorithm = {
|
|
4953
|
-
name: "Ed25519"
|
|
4954
|
-
};
|
|
4955
|
-
keyUsages = getSigUsages();
|
|
4956
|
-
break;
|
|
4957
|
-
|
|
4958
|
-
case "ML-DSA-44":
|
|
4959
|
-
case "ML-DSA-65":
|
|
4960
|
-
case "ML-DSA-87":
|
|
4961
|
-
algorithm = {
|
|
4962
|
-
name: alg
|
|
4963
|
-
};
|
|
4964
|
-
keyUsages = getSigUsages();
|
|
4965
|
-
break;
|
|
4966
|
-
|
|
4967
|
-
default:
|
|
4968
|
-
throw new JOSENotSupported('Invalid or unsupported "alg" (Algorithm) value');
|
|
4969
|
-
}
|
|
4970
|
-
return crypto.subtle.importKey(keyFormat, keyData, algorithm, (_options$extractable = options === null || options === void 0 ? void 0 : options.extractable) !== null && _options$extractable !== void 0 ? _options$extractable : isPublic ? true : false, keyUsages);
|
|
4971
|
-
};
|
|
4972
|
-
|
|
4973
|
-
const processPEMData = (pem, pattern) => decodeBase64(pem.replace(pattern, ""));
|
|
4974
|
-
|
|
4975
|
-
const fromPKCS8 = (pem, alg, options) => {
|
|
4976
|
-
var _alg$startsWith;
|
|
4977
|
-
const keyData = processPEMData(pem, /(?:-----(?:BEGIN|END) PRIVATE KEY-----|\s)/g);
|
|
4978
|
-
let opts = options;
|
|
4979
|
-
if (alg !== null && alg !== void 0 && (_alg$startsWith = alg.startsWith) !== null && _alg$startsWith !== void 0 && _alg$startsWith.call(alg, "ECDH-ES")) {
|
|
4980
|
-
opts || (opts = {});
|
|
4981
|
-
opts.getNamedCurve = keyData => {
|
|
4982
|
-
const state = createASN1State(keyData);
|
|
4983
|
-
parsePKCS8Header(state);
|
|
4984
|
-
return parseECAlgorithmIdentifier(state);
|
|
4985
|
-
};
|
|
4986
|
-
}
|
|
4987
|
-
return genericImport("pkcs8", keyData, alg, opts);
|
|
4988
|
-
};
|
|
4989
|
-
|
|
4990
|
-
function subtleMapping(jwk) {
|
|
4991
|
-
let algorithm;
|
|
4992
|
-
let keyUsages;
|
|
4993
|
-
switch (jwk.kty) {
|
|
4994
|
-
case "AKP":
|
|
4995
|
-
{
|
|
4996
|
-
switch (jwk.alg) {
|
|
4997
|
-
case "ML-DSA-44":
|
|
4998
|
-
case "ML-DSA-65":
|
|
4999
|
-
case "ML-DSA-87":
|
|
5000
|
-
algorithm = {
|
|
5001
|
-
name: jwk.alg
|
|
5002
|
-
};
|
|
5003
|
-
keyUsages = jwk.priv ? [ "sign" ] : [ "verify" ];
|
|
5004
|
-
break;
|
|
5005
|
-
|
|
5006
|
-
default:
|
|
5007
|
-
throw new JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
|
|
5008
|
-
}
|
|
5009
|
-
break;
|
|
5010
|
-
}
|
|
5011
|
-
|
|
5012
|
-
case "RSA":
|
|
5013
|
-
{
|
|
5014
|
-
switch (jwk.alg) {
|
|
5015
|
-
case "PS256":
|
|
5016
|
-
case "PS384":
|
|
5017
|
-
case "PS512":
|
|
5018
|
-
algorithm = {
|
|
5019
|
-
name: "RSA-PSS",
|
|
5020
|
-
hash: "SHA-".concat(jwk.alg.slice(-3))
|
|
5021
|
-
};
|
|
5022
|
-
keyUsages = jwk.d ? [ "sign" ] : [ "verify" ];
|
|
5023
|
-
break;
|
|
5024
|
-
|
|
5025
|
-
case "RS256":
|
|
5026
|
-
case "RS384":
|
|
5027
|
-
case "RS512":
|
|
5028
|
-
algorithm = {
|
|
5029
|
-
name: "RSASSA-PKCS1-v1_5",
|
|
5030
|
-
hash: "SHA-".concat(jwk.alg.slice(-3))
|
|
5031
|
-
};
|
|
5032
|
-
keyUsages = jwk.d ? [ "sign" ] : [ "verify" ];
|
|
5033
|
-
break;
|
|
5034
|
-
|
|
5035
|
-
case "RSA-OAEP":
|
|
5036
|
-
case "RSA-OAEP-256":
|
|
5037
|
-
case "RSA-OAEP-384":
|
|
5038
|
-
case "RSA-OAEP-512":
|
|
5039
|
-
algorithm = {
|
|
5040
|
-
name: "RSA-OAEP",
|
|
5041
|
-
hash: "SHA-".concat(parseInt(jwk.alg.slice(-3), 10) || 1)
|
|
5042
|
-
};
|
|
5043
|
-
keyUsages = jwk.d ? [ "decrypt", "unwrapKey" ] : [ "encrypt", "wrapKey" ];
|
|
5044
|
-
break;
|
|
5045
|
-
|
|
5046
|
-
default:
|
|
5047
|
-
throw new JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
|
|
5048
|
-
}
|
|
5049
|
-
break;
|
|
5050
|
-
}
|
|
5051
|
-
|
|
5052
|
-
case "EC":
|
|
5053
|
-
{
|
|
5054
|
-
switch (jwk.alg) {
|
|
5055
|
-
case "ES256":
|
|
5056
|
-
algorithm = {
|
|
5057
|
-
name: "ECDSA",
|
|
5058
|
-
namedCurve: "P-256"
|
|
5059
|
-
};
|
|
5060
|
-
keyUsages = jwk.d ? [ "sign" ] : [ "verify" ];
|
|
5061
|
-
break;
|
|
5062
|
-
|
|
5063
|
-
case "ES384":
|
|
5064
|
-
algorithm = {
|
|
5065
|
-
name: "ECDSA",
|
|
5066
|
-
namedCurve: "P-384"
|
|
5067
|
-
};
|
|
5068
|
-
keyUsages = jwk.d ? [ "sign" ] : [ "verify" ];
|
|
5069
|
-
break;
|
|
5070
|
-
|
|
5071
|
-
case "ES512":
|
|
5072
|
-
algorithm = {
|
|
5073
|
-
name: "ECDSA",
|
|
5074
|
-
namedCurve: "P-521"
|
|
5075
|
-
};
|
|
5076
|
-
keyUsages = jwk.d ? [ "sign" ] : [ "verify" ];
|
|
5077
|
-
break;
|
|
5078
|
-
|
|
5079
|
-
case "ECDH-ES":
|
|
5080
|
-
case "ECDH-ES+A128KW":
|
|
5081
|
-
case "ECDH-ES+A192KW":
|
|
5082
|
-
case "ECDH-ES+A256KW":
|
|
5083
|
-
algorithm = {
|
|
5084
|
-
name: "ECDH",
|
|
5085
|
-
namedCurve: jwk.crv
|
|
5086
|
-
};
|
|
5087
|
-
keyUsages = jwk.d ? [ "deriveBits" ] : [];
|
|
5088
|
-
break;
|
|
5089
|
-
|
|
5090
|
-
default:
|
|
5091
|
-
throw new JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
|
|
5092
|
-
}
|
|
5093
|
-
break;
|
|
5094
|
-
}
|
|
5095
|
-
|
|
5096
|
-
case "OKP":
|
|
5097
|
-
{
|
|
5098
|
-
switch (jwk.alg) {
|
|
5099
|
-
case "Ed25519":
|
|
5100
|
-
case "EdDSA":
|
|
5101
|
-
algorithm = {
|
|
5102
|
-
name: "Ed25519"
|
|
5103
|
-
};
|
|
5104
|
-
keyUsages = jwk.d ? [ "sign" ] : [ "verify" ];
|
|
5105
|
-
break;
|
|
5106
|
-
|
|
5107
|
-
case "ECDH-ES":
|
|
5108
|
-
case "ECDH-ES+A128KW":
|
|
5109
|
-
case "ECDH-ES+A192KW":
|
|
5110
|
-
case "ECDH-ES+A256KW":
|
|
5111
|
-
algorithm = {
|
|
5112
|
-
name: jwk.crv
|
|
5354
|
+
{
|
|
5355
|
+
try {
|
|
5356
|
+
const namedCurve = options.getNamedCurve(keyData);
|
|
5357
|
+
algorithm = namedCurve === "X25519" ? {
|
|
5358
|
+
name: "X25519"
|
|
5359
|
+
} : {
|
|
5360
|
+
name: "ECDH",
|
|
5361
|
+
namedCurve: namedCurve
|
|
5113
5362
|
};
|
|
5114
|
-
|
|
5115
|
-
|
|
5116
|
-
|
|
5117
|
-
default:
|
|
5118
|
-
throw new JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
|
|
5363
|
+
} catch (cause) {
|
|
5364
|
+
throw new JOSENotSupported("Invalid or unsupported key format");
|
|
5119
5365
|
}
|
|
5366
|
+
keyUsages = isPublic ? [] : [ "deriveBits" ];
|
|
5120
5367
|
break;
|
|
5121
5368
|
}
|
|
5122
5369
|
|
|
5370
|
+
case "Ed25519":
|
|
5371
|
+
case "EdDSA":
|
|
5372
|
+
algorithm = {
|
|
5373
|
+
name: "Ed25519"
|
|
5374
|
+
};
|
|
5375
|
+
keyUsages = getSigUsages();
|
|
5376
|
+
break;
|
|
5377
|
+
|
|
5378
|
+
case "ML-DSA-44":
|
|
5379
|
+
case "ML-DSA-65":
|
|
5380
|
+
case "ML-DSA-87":
|
|
5381
|
+
algorithm = {
|
|
5382
|
+
name: alg
|
|
5383
|
+
};
|
|
5384
|
+
keyUsages = getSigUsages();
|
|
5385
|
+
break;
|
|
5386
|
+
|
|
5123
5387
|
default:
|
|
5124
|
-
throw new JOSENotSupported('Invalid or unsupported
|
|
5388
|
+
throw new JOSENotSupported('Invalid or unsupported "alg" (Algorithm) value');
|
|
5125
5389
|
}
|
|
5126
|
-
return
|
|
5127
|
-
|
|
5128
|
-
keyUsages: keyUsages
|
|
5129
|
-
};
|
|
5130
|
-
}
|
|
5390
|
+
return crypto.subtle.importKey(keyFormat, keyData, algorithm, (_options$extractable = options === null || options === void 0 ? void 0 : options.extractable) !== null && _options$extractable !== void 0 ? _options$extractable : isPublic ? true : false, keyUsages);
|
|
5391
|
+
};
|
|
5131
5392
|
|
|
5132
|
-
|
|
5133
|
-
|
|
5134
|
-
|
|
5135
|
-
|
|
5136
|
-
|
|
5137
|
-
|
|
5138
|
-
|
|
5139
|
-
|
|
5140
|
-
|
|
5393
|
+
const processPEMData = (pem, pattern) => decodeBase64(pem.replace(pattern, ""));
|
|
5394
|
+
|
|
5395
|
+
const fromPKCS8 = (pem, alg, options) => {
|
|
5396
|
+
var _alg$startsWith;
|
|
5397
|
+
const keyData = processPEMData(pem, /(?:-----(?:BEGIN|END) PRIVATE KEY-----|\s)/g);
|
|
5398
|
+
let opts = options;
|
|
5399
|
+
if (alg !== null && alg !== void 0 && (_alg$startsWith = alg.startsWith) !== null && _alg$startsWith !== void 0 && _alg$startsWith.call(alg, "ECDH-ES")) {
|
|
5400
|
+
opts || (opts = {});
|
|
5401
|
+
opts.getNamedCurve = keyData => {
|
|
5402
|
+
const state = createASN1State(keyData);
|
|
5403
|
+
parsePKCS8Header(state);
|
|
5404
|
+
return parseECAlgorithmIdentifier(state);
|
|
5405
|
+
};
|
|
5141
5406
|
}
|
|
5142
|
-
|
|
5143
|
-
|
|
5144
|
-
}
|
|
5407
|
+
return genericImport("pkcs8", keyData, alg, opts);
|
|
5408
|
+
};
|
|
5145
5409
|
|
|
5146
5410
|
async function importPKCS8(pkcs8, alg, options) {
|
|
5147
5411
|
if (typeof pkcs8 !== "string" || pkcs8.indexOf("-----BEGIN PRIVATE KEY-----") !== 0) {
|
|
@@ -5190,241 +5454,53 @@ async function importJWK(jwk, alg, options) {
|
|
|
5190
5454
|
case "EC":
|
|
5191
5455
|
case "OKP":
|
|
5192
5456
|
return jwkToKey(_objectSpread2(_objectSpread2({}, jwk), {}, {
|
|
5193
|
-
alg: alg,
|
|
5194
|
-
ext: ext
|
|
5195
|
-
}));
|
|
5196
|
-
|
|
5197
|
-
default:
|
|
5198
|
-
throw new JOSENotSupported('Unsupported "kty" (Key Type) Parameter value');
|
|
5199
|
-
}
|
|
5200
|
-
}
|
|
5201
|
-
|
|
5202
|
-
function validateCrit(Err, recognizedDefault, recognizedOption, protectedHeader, joseHeader) {
|
|
5203
|
-
if (joseHeader.crit !== undefined && (protectedHeader === null || protectedHeader === void 0 ? void 0 : protectedHeader.crit) === undefined) {
|
|
5204
|
-
throw new Err('"crit" (Critical) Header Parameter MUST be integrity protected');
|
|
5205
|
-
}
|
|
5206
|
-
if (!protectedHeader || protectedHeader.crit === undefined) {
|
|
5207
|
-
return new Set;
|
|
5208
|
-
}
|
|
5209
|
-
if (!Array.isArray(protectedHeader.crit) || protectedHeader.crit.length === 0 || protectedHeader.crit.some((input => typeof input !== "string" || input.length === 0))) {
|
|
5210
|
-
throw new Err('"crit" (Critical) Header Parameter MUST be an array of non-empty strings when present');
|
|
5211
|
-
}
|
|
5212
|
-
let recognized;
|
|
5213
|
-
if (recognizedOption !== undefined) {
|
|
5214
|
-
recognized = new Map([ ...Object.entries(recognizedOption), ...recognizedDefault.entries() ]);
|
|
5215
|
-
} else {
|
|
5216
|
-
recognized = recognizedDefault;
|
|
5217
|
-
}
|
|
5218
|
-
for (const parameter of protectedHeader.crit) {
|
|
5219
|
-
if (!recognized.has(parameter)) {
|
|
5220
|
-
throw new JOSENotSupported('Extension Header Parameter "'.concat(parameter, '" is not recognized'));
|
|
5221
|
-
}
|
|
5222
|
-
if (joseHeader[parameter] === undefined) {
|
|
5223
|
-
throw new Err('Extension Header Parameter "'.concat(parameter, '" is missing'));
|
|
5224
|
-
}
|
|
5225
|
-
if (recognized.get(parameter) && protectedHeader[parameter] === undefined) {
|
|
5226
|
-
throw new Err('Extension Header Parameter "'.concat(parameter, '" MUST be integrity protected'));
|
|
5227
|
-
}
|
|
5228
|
-
}
|
|
5229
|
-
return new Set(protectedHeader.crit);
|
|
5230
|
-
}
|
|
5231
|
-
|
|
5232
|
-
function validateAlgorithms(option, algorithms) {
|
|
5233
|
-
if (algorithms !== undefined && (!Array.isArray(algorithms) || algorithms.some((s => typeof s !== "string")))) {
|
|
5234
|
-
throw new TypeError('"'.concat(option, '" option must be an array of strings'));
|
|
5235
|
-
}
|
|
5236
|
-
if (!algorithms) {
|
|
5237
|
-
return undefined;
|
|
5238
|
-
}
|
|
5239
|
-
return new Set(algorithms);
|
|
5240
|
-
}
|
|
5241
|
-
|
|
5242
|
-
const isJWK = key => isObject(key) && typeof key.kty === "string";
|
|
5243
|
-
|
|
5244
|
-
const isPrivateJWK = key => key.kty !== "oct" && (key.kty === "AKP" && typeof key.priv === "string" || typeof key.d === "string");
|
|
5245
|
-
|
|
5246
|
-
const isPublicJWK = key => key.kty !== "oct" && key.d === undefined && key.priv === undefined;
|
|
5247
|
-
|
|
5248
|
-
const isSecretJWK = key => key.kty === "oct" && typeof key.k === "string";
|
|
5249
|
-
|
|
5250
|
-
let cache;
|
|
5251
|
-
|
|
5252
|
-
const handleJWK = async function handleJWK(key, jwk, alg) {
|
|
5253
|
-
let freeze = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
5254
|
-
cache || (cache = new WeakMap);
|
|
5255
|
-
let cached = cache.get(key);
|
|
5256
|
-
if (cached !== null && cached !== void 0 && cached[alg]) {
|
|
5257
|
-
return cached[alg];
|
|
5258
|
-
}
|
|
5259
|
-
const cryptoKey = await jwkToKey(_objectSpread2(_objectSpread2({}, jwk), {}, {
|
|
5260
|
-
alg: alg
|
|
5261
|
-
}));
|
|
5262
|
-
if (freeze) Object.freeze(key);
|
|
5263
|
-
if (!cached) {
|
|
5264
|
-
cache.set(key, {
|
|
5265
|
-
[alg]: cryptoKey
|
|
5266
|
-
});
|
|
5267
|
-
} else {
|
|
5268
|
-
cached[alg] = cryptoKey;
|
|
5269
|
-
}
|
|
5270
|
-
return cryptoKey;
|
|
5271
|
-
};
|
|
5272
|
-
|
|
5273
|
-
const handleKeyObject = (keyObject, alg) => {
|
|
5274
|
-
cache || (cache = new WeakMap);
|
|
5275
|
-
let cached = cache.get(keyObject);
|
|
5276
|
-
if (cached !== null && cached !== void 0 && cached[alg]) {
|
|
5277
|
-
return cached[alg];
|
|
5278
|
-
}
|
|
5279
|
-
const isPublic = keyObject.type === "public";
|
|
5280
|
-
const extractable = isPublic ? true : false;
|
|
5281
|
-
let cryptoKey;
|
|
5282
|
-
if (keyObject.asymmetricKeyType === "x25519") {
|
|
5283
|
-
switch (alg) {
|
|
5284
|
-
case "ECDH-ES":
|
|
5285
|
-
case "ECDH-ES+A128KW":
|
|
5286
|
-
case "ECDH-ES+A192KW":
|
|
5287
|
-
case "ECDH-ES+A256KW":
|
|
5288
|
-
break;
|
|
5289
|
-
|
|
5290
|
-
default:
|
|
5291
|
-
throw new TypeError("given KeyObject instance cannot be used for this algorithm");
|
|
5292
|
-
}
|
|
5293
|
-
cryptoKey = keyObject.toCryptoKey(keyObject.asymmetricKeyType, extractable, isPublic ? [] : [ "deriveBits" ]);
|
|
5294
|
-
}
|
|
5295
|
-
if (keyObject.asymmetricKeyType === "ed25519") {
|
|
5296
|
-
if (alg !== "EdDSA" && alg !== "Ed25519") {
|
|
5297
|
-
throw new TypeError("given KeyObject instance cannot be used for this algorithm");
|
|
5298
|
-
}
|
|
5299
|
-
cryptoKey = keyObject.toCryptoKey(keyObject.asymmetricKeyType, extractable, [ isPublic ? "verify" : "sign" ]);
|
|
5300
|
-
}
|
|
5301
|
-
switch (keyObject.asymmetricKeyType) {
|
|
5302
|
-
case "ml-dsa-44":
|
|
5303
|
-
case "ml-dsa-65":
|
|
5304
|
-
case "ml-dsa-87":
|
|
5305
|
-
{
|
|
5306
|
-
if (alg !== keyObject.asymmetricKeyType.toUpperCase()) {
|
|
5307
|
-
throw new TypeError("given KeyObject instance cannot be used for this algorithm");
|
|
5308
|
-
}
|
|
5309
|
-
cryptoKey = keyObject.toCryptoKey(keyObject.asymmetricKeyType, extractable, [ isPublic ? "verify" : "sign" ]);
|
|
5310
|
-
}
|
|
5311
|
-
}
|
|
5312
|
-
if (keyObject.asymmetricKeyType === "rsa") {
|
|
5313
|
-
let hash;
|
|
5314
|
-
switch (alg) {
|
|
5315
|
-
case "RSA-OAEP":
|
|
5316
|
-
hash = "SHA-1";
|
|
5317
|
-
break;
|
|
5318
|
-
|
|
5319
|
-
case "RS256":
|
|
5320
|
-
case "PS256":
|
|
5321
|
-
case "RSA-OAEP-256":
|
|
5322
|
-
hash = "SHA-256";
|
|
5323
|
-
break;
|
|
5324
|
-
|
|
5325
|
-
case "RS384":
|
|
5326
|
-
case "PS384":
|
|
5327
|
-
case "RSA-OAEP-384":
|
|
5328
|
-
hash = "SHA-384";
|
|
5329
|
-
break;
|
|
5330
|
-
|
|
5331
|
-
case "RS512":
|
|
5332
|
-
case "PS512":
|
|
5333
|
-
case "RSA-OAEP-512":
|
|
5334
|
-
hash = "SHA-512";
|
|
5335
|
-
break;
|
|
5336
|
-
|
|
5337
|
-
default:
|
|
5338
|
-
throw new TypeError("given KeyObject instance cannot be used for this algorithm");
|
|
5339
|
-
}
|
|
5340
|
-
if (alg.startsWith("RSA-OAEP")) {
|
|
5341
|
-
return keyObject.toCryptoKey({
|
|
5342
|
-
name: "RSA-OAEP",
|
|
5343
|
-
hash: hash
|
|
5344
|
-
}, extractable, isPublic ? [ "encrypt" ] : [ "decrypt" ]);
|
|
5345
|
-
}
|
|
5346
|
-
cryptoKey = keyObject.toCryptoKey({
|
|
5347
|
-
name: alg.startsWith("PS") ? "RSA-PSS" : "RSASSA-PKCS1-v1_5",
|
|
5348
|
-
hash: hash
|
|
5349
|
-
}, extractable, [ isPublic ? "verify" : "sign" ]);
|
|
5350
|
-
}
|
|
5351
|
-
if (keyObject.asymmetricKeyType === "ec") {
|
|
5352
|
-
var _keyObject$asymmetric;
|
|
5353
|
-
const nist = new Map([ [ "prime256v1", "P-256" ], [ "secp384r1", "P-384" ], [ "secp521r1", "P-521" ] ]);
|
|
5354
|
-
const namedCurve = nist.get((_keyObject$asymmetric = keyObject.asymmetricKeyDetails) === null || _keyObject$asymmetric === void 0 ? void 0 : _keyObject$asymmetric.namedCurve);
|
|
5355
|
-
if (!namedCurve) {
|
|
5356
|
-
throw new TypeError("given KeyObject instance cannot be used for this algorithm");
|
|
5357
|
-
}
|
|
5358
|
-
if (alg === "ES256" && namedCurve === "P-256") {
|
|
5359
|
-
cryptoKey = keyObject.toCryptoKey({
|
|
5360
|
-
name: "ECDSA",
|
|
5361
|
-
namedCurve: namedCurve
|
|
5362
|
-
}, extractable, [ isPublic ? "verify" : "sign" ]);
|
|
5363
|
-
}
|
|
5364
|
-
if (alg === "ES384" && namedCurve === "P-384") {
|
|
5365
|
-
cryptoKey = keyObject.toCryptoKey({
|
|
5366
|
-
name: "ECDSA",
|
|
5367
|
-
namedCurve: namedCurve
|
|
5368
|
-
}, extractable, [ isPublic ? "verify" : "sign" ]);
|
|
5369
|
-
}
|
|
5370
|
-
if (alg === "ES512" && namedCurve === "P-521") {
|
|
5371
|
-
cryptoKey = keyObject.toCryptoKey({
|
|
5372
|
-
name: "ECDSA",
|
|
5373
|
-
namedCurve: namedCurve
|
|
5374
|
-
}, extractable, [ isPublic ? "verify" : "sign" ]);
|
|
5375
|
-
}
|
|
5376
|
-
if (alg.startsWith("ECDH-ES")) {
|
|
5377
|
-
cryptoKey = keyObject.toCryptoKey({
|
|
5378
|
-
name: "ECDH",
|
|
5379
|
-
namedCurve: namedCurve
|
|
5380
|
-
}, extractable, isPublic ? [] : [ "deriveBits" ]);
|
|
5381
|
-
}
|
|
5382
|
-
}
|
|
5383
|
-
if (!cryptoKey) {
|
|
5384
|
-
throw new TypeError("given KeyObject instance cannot be used for this algorithm");
|
|
5385
|
-
}
|
|
5386
|
-
if (!cached) {
|
|
5387
|
-
cache.set(keyObject, {
|
|
5388
|
-
[alg]: cryptoKey
|
|
5389
|
-
});
|
|
5390
|
-
} else {
|
|
5391
|
-
cached[alg] = cryptoKey;
|
|
5457
|
+
alg: alg,
|
|
5458
|
+
ext: ext
|
|
5459
|
+
}));
|
|
5460
|
+
|
|
5461
|
+
default:
|
|
5462
|
+
throw new JOSENotSupported('Unsupported "kty" (Key Type) Parameter value');
|
|
5392
5463
|
}
|
|
5393
|
-
|
|
5394
|
-
};
|
|
5464
|
+
}
|
|
5395
5465
|
|
|
5396
|
-
|
|
5397
|
-
if (
|
|
5398
|
-
|
|
5466
|
+
function validateCrit(Err, recognizedDefault, recognizedOption, protectedHeader, joseHeader) {
|
|
5467
|
+
if (joseHeader.crit !== undefined && (protectedHeader === null || protectedHeader === void 0 ? void 0 : protectedHeader.crit) === undefined) {
|
|
5468
|
+
throw new Err('"crit" (Critical) Header Parameter MUST be integrity protected');
|
|
5399
5469
|
}
|
|
5400
|
-
if (
|
|
5401
|
-
return
|
|
5470
|
+
if (!protectedHeader || protectedHeader.crit === undefined) {
|
|
5471
|
+
return new Set;
|
|
5402
5472
|
}
|
|
5403
|
-
if (
|
|
5404
|
-
|
|
5405
|
-
|
|
5473
|
+
if (!Array.isArray(protectedHeader.crit) || protectedHeader.crit.length === 0 || protectedHeader.crit.some(input => typeof input !== "string" || input.length === 0)) {
|
|
5474
|
+
throw new Err('"crit" (Critical) Header Parameter MUST be an array of non-empty strings when present');
|
|
5475
|
+
}
|
|
5476
|
+
let recognized;
|
|
5477
|
+
if (recognizedOption !== undefined) {
|
|
5478
|
+
recognized = new Map([ ...Object.entries(recognizedOption), ...recognizedDefault.entries() ]);
|
|
5479
|
+
} else {
|
|
5480
|
+
recognized = recognizedDefault;
|
|
5481
|
+
}
|
|
5482
|
+
for (const parameter of protectedHeader.crit) {
|
|
5483
|
+
if (!recognized.has(parameter)) {
|
|
5484
|
+
throw new JOSENotSupported('Extension Header Parameter "'.concat(parameter, '" is not recognized'));
|
|
5406
5485
|
}
|
|
5407
|
-
if (
|
|
5408
|
-
|
|
5409
|
-
return handleKeyObject(key, alg);
|
|
5410
|
-
} catch (err) {
|
|
5411
|
-
if (err instanceof TypeError) {
|
|
5412
|
-
throw err;
|
|
5413
|
-
}
|
|
5414
|
-
}
|
|
5486
|
+
if (joseHeader[parameter] === undefined) {
|
|
5487
|
+
throw new Err('Extension Header Parameter "'.concat(parameter, '" is missing'));
|
|
5415
5488
|
}
|
|
5416
|
-
|
|
5417
|
-
|
|
5418
|
-
});
|
|
5419
|
-
return handleJWK(key, jwk, alg);
|
|
5420
|
-
}
|
|
5421
|
-
if (isJWK(key)) {
|
|
5422
|
-
if (key.k) {
|
|
5423
|
-
return decode(key.k);
|
|
5489
|
+
if (recognized.get(parameter) && protectedHeader[parameter] === undefined) {
|
|
5490
|
+
throw new Err('Extension Header Parameter "'.concat(parameter, '" MUST be integrity protected'));
|
|
5424
5491
|
}
|
|
5425
|
-
return handleJWK(key, key, alg, true);
|
|
5426
5492
|
}
|
|
5427
|
-
|
|
5493
|
+
return new Set(protectedHeader.crit);
|
|
5494
|
+
}
|
|
5495
|
+
|
|
5496
|
+
function validateAlgorithms(option, algorithms) {
|
|
5497
|
+
if (algorithms !== undefined && (!Array.isArray(algorithms) || algorithms.some(s => typeof s !== "string"))) {
|
|
5498
|
+
throw new TypeError('"'.concat(option, '" option must be an array of strings'));
|
|
5499
|
+
}
|
|
5500
|
+
if (!algorithms) {
|
|
5501
|
+
return undefined;
|
|
5502
|
+
}
|
|
5503
|
+
return new Set(algorithms);
|
|
5428
5504
|
}
|
|
5429
5505
|
|
|
5430
5506
|
const tag = key => key === null || key === void 0 ? void 0 : key[Symbol.toStringTag];
|
|
@@ -5564,7 +5640,7 @@ let USER_AGENT$1;
|
|
|
5564
5640
|
|
|
5565
5641
|
if (typeof navigator === "undefined" || !((_navigator$userAgent$1 = navigator.userAgent) !== null && _navigator$userAgent$1 !== void 0 && (_navigator$userAgent$$1 = _navigator$userAgent$1.startsWith) !== null && _navigator$userAgent$$1 !== void 0 && _navigator$userAgent$$1.call(_navigator$userAgent$1, "Mozilla/5.0 "))) {
|
|
5566
5642
|
const NAME = "openid-client";
|
|
5567
|
-
const VERSION = "v6.8.
|
|
5643
|
+
const VERSION = "v6.8.2";
|
|
5568
5644
|
USER_AGENT$1 = "".concat(NAME, "/").concat(VERSION);
|
|
5569
5645
|
headers = {
|
|
5570
5646
|
"user-agent": USER_AGENT$1
|
|
@@ -5776,7 +5852,7 @@ async function performDiscovery(server, options) {
|
|
|
5776
5852
|
method: "GET",
|
|
5777
5853
|
redirect: "manual",
|
|
5778
5854
|
signal: signal
|
|
5779
|
-
})).then(
|
|
5855
|
+
})).then(response => processDiscoveryResponse(_nodiscoverycheck, response)).catch(errorHandler);
|
|
5780
5856
|
if (resolve && new URL(as.issuer).href !== server.href) {
|
|
5781
5857
|
handleEntraId(server, as, options) || handleB2Clogin(server, options) || (() => {
|
|
5782
5858
|
throw new ClientError("discovered metadata issuer does not match the expected issuer", {
|
|
@@ -5951,7 +6027,7 @@ async function handleRetryAfter(response, currentInterval, signal) {
|
|
|
5951
6027
|
}
|
|
5952
6028
|
|
|
5953
6029
|
function wait(duration, signal) {
|
|
5954
|
-
return new Promise((
|
|
6030
|
+
return new Promise((resolve, reject) => {
|
|
5955
6031
|
const waitStep = remaining => {
|
|
5956
6032
|
try {
|
|
5957
6033
|
signal.throwIfAborted();
|
|
@@ -5964,10 +6040,10 @@ function wait(duration, signal) {
|
|
|
5964
6040
|
return;
|
|
5965
6041
|
}
|
|
5966
6042
|
const currentWait = Math.min(remaining, 5);
|
|
5967
|
-
setTimeout((
|
|
6043
|
+
setTimeout(() => waitStep(remaining - currentWait), currentWait * 1e3);
|
|
5968
6044
|
};
|
|
5969
6045
|
waitStep(duration);
|
|
5970
|
-
})
|
|
6046
|
+
});
|
|
5971
6047
|
}
|
|
5972
6048
|
|
|
5973
6049
|
async function initiateBackchannelAuthentication(config, parameters) {
|
|
@@ -5978,7 +6054,7 @@ async function initiateBackchannelAuthentication(config, parameters) {
|
|
|
5978
6054
|
[allowInsecureRequests$1]: !tlsOnly,
|
|
5979
6055
|
headers: new Headers(headers),
|
|
5980
6056
|
signal: signal(timeout)
|
|
5981
|
-
}).then(
|
|
6057
|
+
}).then(response => processBackchannelAuthenticationResponse(as, c, response)).catch(errorHandler);
|
|
5982
6058
|
}
|
|
5983
6059
|
|
|
5984
6060
|
async function pollBackchannelAuthenticationGrant(config, backchannelAuthenticationResponse, parameters, options) {
|
|
@@ -6305,7 +6381,7 @@ async function genericGrantRequest(config, grantType, parameters, options) {
|
|
|
6305
6381
|
DPoP: options === null || options === void 0 ? void 0 : options.DPoP,
|
|
6306
6382
|
headers: new Headers(headers),
|
|
6307
6383
|
signal: signal(timeout)
|
|
6308
|
-
}).then(
|
|
6384
|
+
}).then(response => {
|
|
6309
6385
|
let recognizedTokenTypes;
|
|
6310
6386
|
if (grantType === "urn:ietf:params:oauth:grant-type:token-exchange") {
|
|
6311
6387
|
recognizedTokenTypes = {
|
|
@@ -6316,91 +6392,11 @@ async function genericGrantRequest(config, grantType, parameters, options) {
|
|
|
6316
6392
|
[jweDecrypt]: decrypt,
|
|
6317
6393
|
recognizedTokenTypes: recognizedTokenTypes
|
|
6318
6394
|
});
|
|
6319
|
-
})
|
|
6395
|
+
}).catch(errorHandler);
|
|
6320
6396
|
addHelpers(result);
|
|
6321
6397
|
return result;
|
|
6322
6398
|
}
|
|
6323
6399
|
|
|
6324
|
-
function subtleAlgorithm(alg, algorithm) {
|
|
6325
|
-
const hash = "SHA-".concat(alg.slice(-3));
|
|
6326
|
-
switch (alg) {
|
|
6327
|
-
case "HS256":
|
|
6328
|
-
case "HS384":
|
|
6329
|
-
case "HS512":
|
|
6330
|
-
return {
|
|
6331
|
-
hash: hash,
|
|
6332
|
-
name: "HMAC"
|
|
6333
|
-
};
|
|
6334
|
-
|
|
6335
|
-
case "PS256":
|
|
6336
|
-
case "PS384":
|
|
6337
|
-
case "PS512":
|
|
6338
|
-
return {
|
|
6339
|
-
hash: hash,
|
|
6340
|
-
name: "RSA-PSS",
|
|
6341
|
-
saltLength: parseInt(alg.slice(-3), 10) >> 3
|
|
6342
|
-
};
|
|
6343
|
-
|
|
6344
|
-
case "RS256":
|
|
6345
|
-
case "RS384":
|
|
6346
|
-
case "RS512":
|
|
6347
|
-
return {
|
|
6348
|
-
hash: hash,
|
|
6349
|
-
name: "RSASSA-PKCS1-v1_5"
|
|
6350
|
-
};
|
|
6351
|
-
|
|
6352
|
-
case "ES256":
|
|
6353
|
-
case "ES384":
|
|
6354
|
-
case "ES512":
|
|
6355
|
-
return {
|
|
6356
|
-
hash: hash,
|
|
6357
|
-
name: "ECDSA",
|
|
6358
|
-
namedCurve: algorithm.namedCurve
|
|
6359
|
-
};
|
|
6360
|
-
|
|
6361
|
-
case "Ed25519":
|
|
6362
|
-
case "EdDSA":
|
|
6363
|
-
return {
|
|
6364
|
-
name: "Ed25519"
|
|
6365
|
-
};
|
|
6366
|
-
|
|
6367
|
-
case "ML-DSA-44":
|
|
6368
|
-
case "ML-DSA-65":
|
|
6369
|
-
case "ML-DSA-87":
|
|
6370
|
-
return {
|
|
6371
|
-
name: alg
|
|
6372
|
-
};
|
|
6373
|
-
|
|
6374
|
-
default:
|
|
6375
|
-
throw new JOSENotSupported("alg ".concat(alg, " is not supported either by JOSE or your javascript runtime"));
|
|
6376
|
-
}
|
|
6377
|
-
}
|
|
6378
|
-
|
|
6379
|
-
async function getSigKey(alg, key, usage) {
|
|
6380
|
-
if (key instanceof Uint8Array) {
|
|
6381
|
-
if (!alg.startsWith("HS")) {
|
|
6382
|
-
throw new TypeError(invalidKeyInput(key, "CryptoKey", "KeyObject", "JSON Web Key"));
|
|
6383
|
-
}
|
|
6384
|
-
return crypto.subtle.importKey("raw", key, {
|
|
6385
|
-
hash: "SHA-".concat(alg.slice(-3)),
|
|
6386
|
-
name: "HMAC"
|
|
6387
|
-
}, false, [ usage ]);
|
|
6388
|
-
}
|
|
6389
|
-
checkSigCryptoKey(key, alg, usage);
|
|
6390
|
-
return key;
|
|
6391
|
-
}
|
|
6392
|
-
|
|
6393
|
-
async function verify(alg, key, signature, data) {
|
|
6394
|
-
const cryptoKey = await getSigKey(alg, key, "verify");
|
|
6395
|
-
checkKeyLength(alg, cryptoKey);
|
|
6396
|
-
const algorithm = subtleAlgorithm(alg, cryptoKey.algorithm);
|
|
6397
|
-
try {
|
|
6398
|
-
return await crypto.subtle.verify(algorithm, cryptoKey, signature, data);
|
|
6399
|
-
} catch (_unused) {
|
|
6400
|
-
return false;
|
|
6401
|
-
}
|
|
6402
|
-
}
|
|
6403
|
-
|
|
6404
6400
|
async function flattenedVerify(jws, key, options) {
|
|
6405
6401
|
if (!isObject(jws)) {
|
|
6406
6402
|
throw new JWSInvalid("Flattened JWS must be an object");
|
|
@@ -6463,12 +6459,7 @@ async function flattenedVerify(jws, key, options) {
|
|
|
6463
6459
|
}
|
|
6464
6460
|
checkKeyType(alg, key, "verify");
|
|
6465
6461
|
const data = concat(jws.protected !== undefined ? encode(jws.protected) : new Uint8Array, encode("."), typeof jws.payload === "string" ? b64 ? encode(jws.payload) : encoder.encode(jws.payload) : jws.payload);
|
|
6466
|
-
|
|
6467
|
-
try {
|
|
6468
|
-
signature = decode(jws.signature);
|
|
6469
|
-
} catch (_unused2) {
|
|
6470
|
-
throw new JWSInvalid("Failed to base64url decode the signature");
|
|
6471
|
-
}
|
|
6462
|
+
const signature = decodeBase64url(jws.signature, "signature", JWSInvalid);
|
|
6472
6463
|
const k = await normalizeKey(key, alg);
|
|
6473
6464
|
const verified = await verify(alg, k, signature, data);
|
|
6474
6465
|
if (!verified) {
|
|
@@ -6476,11 +6467,7 @@ async function flattenedVerify(jws, key, options) {
|
|
|
6476
6467
|
}
|
|
6477
6468
|
let payload;
|
|
6478
6469
|
if (b64) {
|
|
6479
|
-
|
|
6480
|
-
payload = decode(jws.payload);
|
|
6481
|
-
} catch (_unused3) {
|
|
6482
|
-
throw new JWSInvalid("Failed to base64url decode the payload");
|
|
6483
|
-
}
|
|
6470
|
+
payload = decodeBase64url(jws.payload, "payload", JWSInvalid);
|
|
6484
6471
|
} else if (typeof jws.payload === "string") {
|
|
6485
6472
|
payload = encoder.encode(jws.payload);
|
|
6486
6473
|
} else {
|
|
@@ -6767,7 +6754,7 @@ class LocalJWKSet {
|
|
|
6767
6754
|
async getKey(protectedHeader, token) {
|
|
6768
6755
|
const {alg: alg, kid: kid} = _objectSpread2(_objectSpread2({}, protectedHeader), token === null || token === void 0 ? void 0 : token.header);
|
|
6769
6756
|
const kty = getKtyFromAlg(alg);
|
|
6770
|
-
const candidates = _classPrivateFieldGet2(_jwks$1, this).keys.filter(
|
|
6757
|
+
const candidates = _classPrivateFieldGet2(_jwks$1, this).keys.filter(jwk => {
|
|
6771
6758
|
let candidate = kty === jwk.kty;
|
|
6772
6759
|
if (candidate && typeof kid === "string") {
|
|
6773
6760
|
candidate = kid === jwk.kid;
|
|
@@ -6802,7 +6789,7 @@ class LocalJWKSet {
|
|
|
6802
6789
|
}
|
|
6803
6790
|
}
|
|
6804
6791
|
return candidate;
|
|
6805
|
-
})
|
|
6792
|
+
});
|
|
6806
6793
|
const {0: jwk, length: length} = candidates;
|
|
6807
6794
|
if (length === 0) {
|
|
6808
6795
|
throw new JWKSNoMatchingKey;
|
|
@@ -6810,13 +6797,13 @@ class LocalJWKSet {
|
|
|
6810
6797
|
if (length !== 1) {
|
|
6811
6798
|
const error = new JWKSMultipleMatchingKeys;
|
|
6812
6799
|
const _cached = _classPrivateFieldGet2(_cached2, this);
|
|
6813
|
-
error[Symbol.asyncIterator] = _wrapAsyncGenerator(
|
|
6800
|
+
error[Symbol.asyncIterator] = _wrapAsyncGenerator(function*() {
|
|
6814
6801
|
for (const jwk of candidates) {
|
|
6815
6802
|
try {
|
|
6816
6803
|
yield yield _awaitAsyncGenerator(importWithAlgCache(_cached, jwk, alg));
|
|
6817
6804
|
} catch (_unused) {}
|
|
6818
6805
|
}
|
|
6819
|
-
})
|
|
6806
|
+
});
|
|
6820
6807
|
throw error;
|
|
6821
6808
|
}
|
|
6822
6809
|
return importWithAlgCache(_classPrivateFieldGet2(_cached2, this), jwk, alg);
|
|
@@ -6861,7 +6848,7 @@ let USER_AGENT;
|
|
|
6861
6848
|
|
|
6862
6849
|
if (typeof navigator === "undefined" || !((_navigator$userAgent = navigator.userAgent) !== null && _navigator$userAgent !== void 0 && (_navigator$userAgent$ = _navigator$userAgent.startsWith) !== null && _navigator$userAgent$ !== void 0 && _navigator$userAgent$.call(_navigator$userAgent, "Mozilla/5.0 "))) {
|
|
6863
6850
|
const NAME = "jose";
|
|
6864
|
-
const VERSION = "v6.1
|
|
6851
|
+
const VERSION = "v6.2.1";
|
|
6865
6852
|
USER_AGENT = "".concat(NAME, "/").concat(VERSION);
|
|
6866
6853
|
}
|
|
6867
6854
|
|
|
@@ -6874,12 +6861,12 @@ async function fetchJwks(url, headers, signal) {
|
|
|
6874
6861
|
signal: signal,
|
|
6875
6862
|
redirect: "manual",
|
|
6876
6863
|
headers: headers
|
|
6877
|
-
}).catch(
|
|
6864
|
+
}).catch(err => {
|
|
6878
6865
|
if (err.name === "TimeoutError") {
|
|
6879
6866
|
throw new JWKSTimeout;
|
|
6880
6867
|
}
|
|
6881
6868
|
throw err;
|
|
6882
|
-
})
|
|
6869
|
+
});
|
|
6883
6870
|
if (response.status !== 200) {
|
|
6884
6871
|
throw new JOSEError("Expected 200 OK from the JSON Web Key Set HTTP response");
|
|
6885
6872
|
}
|
|
@@ -6994,7 +6981,7 @@ class RemoteJWKSet {
|
|
|
6994
6981
|
if (_classPrivateFieldGet2(_pendingFetch, this) && isCloudflareWorkers()) {
|
|
6995
6982
|
_classPrivateFieldSet2(_pendingFetch, this, undefined);
|
|
6996
6983
|
}
|
|
6997
|
-
_classPrivateFieldGet2(_pendingFetch, this) || _classPrivateFieldSet2(_pendingFetch, this, fetchJwks(_classPrivateFieldGet2(_url, this).href, _classPrivateFieldGet2(_headers, this), AbortSignal.timeout(_classPrivateFieldGet2(_timeoutDuration, this)), _classPrivateFieldGet2(_customFetch$1, this)).then(
|
|
6984
|
+
_classPrivateFieldGet2(_pendingFetch, this) || _classPrivateFieldSet2(_pendingFetch, this, fetchJwks(_classPrivateFieldGet2(_url, this).href, _classPrivateFieldGet2(_headers, this), AbortSignal.timeout(_classPrivateFieldGet2(_timeoutDuration, this)), _classPrivateFieldGet2(_customFetch$1, this)).then(json => {
|
|
6998
6985
|
_classPrivateFieldSet2(_local, this, createLocalJWKSet(json));
|
|
6999
6986
|
if (_classPrivateFieldGet2(_cache, this)) {
|
|
7000
6987
|
_classPrivateFieldGet2(_cache, this).uat = Date.now();
|
|
@@ -7002,10 +6989,10 @@ class RemoteJWKSet {
|
|
|
7002
6989
|
}
|
|
7003
6990
|
_classPrivateFieldSet2(_jwksTimestamp, this, Date.now());
|
|
7004
6991
|
_classPrivateFieldSet2(_pendingFetch, this, undefined);
|
|
7005
|
-
})
|
|
6992
|
+
}).catch(err => {
|
|
7006
6993
|
_classPrivateFieldSet2(_pendingFetch, this, undefined);
|
|
7007
6994
|
throw err;
|
|
7008
|
-
}))
|
|
6995
|
+
}));
|
|
7009
6996
|
await _classPrivateFieldGet2(_pendingFetch, this);
|
|
7010
6997
|
}
|
|
7011
6998
|
}
|
|
@@ -7047,7 +7034,7 @@ function createRemoteJWKSet(url, options) {
|
|
|
7047
7034
|
|
|
7048
7035
|
const _excluded = [ "mfaToken" ], _excluded2 = [ "mfaToken" ];
|
|
7049
7036
|
|
|
7050
|
-
var _baseUrl, _clientId, _customFetch, _configuration, _serverMetadata, _options, _jwks,
|
|
7037
|
+
var _baseUrl, _clientId, _customFetch, _entries, _ttlMs, _maxEntries, _configuration, _serverMetadata, _clientAuthPromise, _options, _customFetch2, _jwks, _discoveryCache, _inFlightDiscovery, _jwksCache, _Class9_brand;
|
|
7051
7038
|
|
|
7052
7039
|
var NotSupportedError = class NotSupportedError extends Error {
|
|
7053
7040
|
constructor(code, message) {
|
|
@@ -7153,12 +7140,12 @@ var MissingClientAuthError = class MissingClientAuthError extends Error {
|
|
|
7153
7140
|
};
|
|
7154
7141
|
|
|
7155
7142
|
function stripUndefinedProperties(value) {
|
|
7156
|
-
return Object.entries(value).filter(
|
|
7143
|
+
return Object.entries(value).filter(_ref => {
|
|
7157
7144
|
let [, value2] = _ref;
|
|
7158
7145
|
return typeof value2 !== "undefined";
|
|
7159
|
-
})
|
|
7146
|
+
}).reduce((acc, curr) => _objectSpread2(_objectSpread2({}, acc), {}, {
|
|
7160
7147
|
[curr[0]]: curr[1]
|
|
7161
|
-
})
|
|
7148
|
+
}), {});
|
|
7162
7149
|
}
|
|
7163
7150
|
|
|
7164
7151
|
var MfaError$1 = class MfaError extends Error {
|
|
@@ -7230,7 +7217,9 @@ function transformEnrollmentResponse(api) {
|
|
|
7230
7217
|
oobChannel: api.oob_channel,
|
|
7231
7218
|
oobCode: api.oob_code,
|
|
7232
7219
|
bindingMethod: api.binding_method,
|
|
7233
|
-
id: api.id
|
|
7220
|
+
id: api.id,
|
|
7221
|
+
barcodeUri: api.barcode_uri,
|
|
7222
|
+
recoveryCodes: api.recovery_codes
|
|
7234
7223
|
};
|
|
7235
7224
|
}
|
|
7236
7225
|
throw new Error("Unexpected authenticator type: ".concat(api.authenticator_type));
|
|
@@ -7351,6 +7340,42 @@ class MfaClient {
|
|
|
7351
7340
|
}
|
|
7352
7341
|
});
|
|
7353
7342
|
|
|
7343
|
+
function createTelemetryFetch(baseFetch, config) {
|
|
7344
|
+
if (config.enabled === false) {
|
|
7345
|
+
return baseFetch;
|
|
7346
|
+
}
|
|
7347
|
+
const telemetryData = {
|
|
7348
|
+
name: config.name,
|
|
7349
|
+
version: config.version
|
|
7350
|
+
};
|
|
7351
|
+
const headerValue = btoa(JSON.stringify(telemetryData));
|
|
7352
|
+
return async (input, init) => {
|
|
7353
|
+
const headers = input instanceof Request ? new Headers(input.headers) : new Headers;
|
|
7354
|
+
if (init !== null && init !== void 0 && init.headers) {
|
|
7355
|
+
const initHeaders = new Headers(init.headers);
|
|
7356
|
+
initHeaders.forEach((value, key) => {
|
|
7357
|
+
headers.set(key, value);
|
|
7358
|
+
});
|
|
7359
|
+
}
|
|
7360
|
+
headers.set("Auth0-Client", headerValue);
|
|
7361
|
+
return baseFetch(input, _objectSpread2(_objectSpread2({}, init), {}, {
|
|
7362
|
+
headers: headers
|
|
7363
|
+
}));
|
|
7364
|
+
};
|
|
7365
|
+
}
|
|
7366
|
+
|
|
7367
|
+
function getTelemetryConfig(config) {
|
|
7368
|
+
var _config$name, _config$version;
|
|
7369
|
+
if ((config === null || config === void 0 ? void 0 : config.enabled) === false) {
|
|
7370
|
+
return config;
|
|
7371
|
+
}
|
|
7372
|
+
return {
|
|
7373
|
+
enabled: true,
|
|
7374
|
+
name: (_config$name = config === null || config === void 0 ? void 0 : config.name) !== null && _config$name !== void 0 ? _config$name : "@auth0/auth0-auth-js",
|
|
7375
|
+
version: (_config$version = config === null || config === void 0 ? void 0 : config.version) !== null && _config$version !== void 0 ? _config$version : "1.5.0"
|
|
7376
|
+
};
|
|
7377
|
+
}
|
|
7378
|
+
|
|
7354
7379
|
var TokenResponse = class _TokenResponse {
|
|
7355
7380
|
constructor(accessToken, expiresAt, idToken, refreshToken, scope, claims, authorizationDetails) {
|
|
7356
7381
|
_defineProperty(this, "accessToken", void 0);
|
|
@@ -7379,6 +7404,81 @@ var TokenResponse = class _TokenResponse {
|
|
|
7379
7404
|
}
|
|
7380
7405
|
};
|
|
7381
7406
|
|
|
7407
|
+
var LruCache = (_entries = new WeakMap, _ttlMs = new WeakMap, _maxEntries = new WeakMap,
|
|
7408
|
+
class LruCache {
|
|
7409
|
+
constructor(maxEntries, ttlMs) {
|
|
7410
|
+
_classPrivateFieldInitSpec(this, _entries, new Map);
|
|
7411
|
+
_classPrivateFieldInitSpec(this, _ttlMs, void 0);
|
|
7412
|
+
_classPrivateFieldInitSpec(this, _maxEntries, void 0);
|
|
7413
|
+
_classPrivateFieldSet2(_maxEntries, this, Math.max(1, Math.floor(maxEntries)));
|
|
7414
|
+
_classPrivateFieldSet2(_ttlMs, this, Math.max(0, Math.floor(ttlMs)));
|
|
7415
|
+
}
|
|
7416
|
+
get(key) {
|
|
7417
|
+
const entry = _classPrivateFieldGet2(_entries, this).get(key);
|
|
7418
|
+
if (!entry) {
|
|
7419
|
+
return;
|
|
7420
|
+
}
|
|
7421
|
+
if (Date.now() >= entry.expiresAt) {
|
|
7422
|
+
_classPrivateFieldGet2(_entries, this).delete(key);
|
|
7423
|
+
return;
|
|
7424
|
+
}
|
|
7425
|
+
_classPrivateFieldGet2(_entries, this).delete(key);
|
|
7426
|
+
_classPrivateFieldGet2(_entries, this).set(key, entry);
|
|
7427
|
+
return entry.value;
|
|
7428
|
+
}
|
|
7429
|
+
set(key, value) {
|
|
7430
|
+
if (_classPrivateFieldGet2(_entries, this).has(key)) {
|
|
7431
|
+
_classPrivateFieldGet2(_entries, this).delete(key);
|
|
7432
|
+
}
|
|
7433
|
+
_classPrivateFieldGet2(_entries, this).set(key, {
|
|
7434
|
+
value: value,
|
|
7435
|
+
expiresAt: Date.now() + _classPrivateFieldGet2(_ttlMs, this)
|
|
7436
|
+
});
|
|
7437
|
+
while (_classPrivateFieldGet2(_entries, this).size > _classPrivateFieldGet2(_maxEntries, this)) {
|
|
7438
|
+
const oldestKey = _classPrivateFieldGet2(_entries, this).keys().next().value;
|
|
7439
|
+
if (oldestKey === void 0) {
|
|
7440
|
+
break;
|
|
7441
|
+
}
|
|
7442
|
+
_classPrivateFieldGet2(_entries, this).delete(oldestKey);
|
|
7443
|
+
}
|
|
7444
|
+
}
|
|
7445
|
+
});
|
|
7446
|
+
|
|
7447
|
+
var globalCaches = new Map;
|
|
7448
|
+
|
|
7449
|
+
function getGlobalCache(key) {
|
|
7450
|
+
return globalCaches.get(key);
|
|
7451
|
+
}
|
|
7452
|
+
|
|
7453
|
+
function getGlobalCacheKey(maxEntries, ttlMs) {
|
|
7454
|
+
return "".concat(maxEntries, ":").concat(ttlMs);
|
|
7455
|
+
}
|
|
7456
|
+
|
|
7457
|
+
function resolveCacheConfig(options) {
|
|
7458
|
+
const ttlSeconds = typeof (options === null || options === void 0 ? void 0 : options.ttl) === "number" ? options.ttl : 600;
|
|
7459
|
+
const maxEntries = typeof (options === null || options === void 0 ? void 0 : options.maxEntries) === "number" && options.maxEntries > 0 ? options.maxEntries : 100;
|
|
7460
|
+
const ttlMs = ttlSeconds * 1e3;
|
|
7461
|
+
return {
|
|
7462
|
+
ttlMs: ttlMs,
|
|
7463
|
+
maxEntries: maxEntries
|
|
7464
|
+
};
|
|
7465
|
+
}
|
|
7466
|
+
|
|
7467
|
+
var DiscoveryCacheFactory = class {
|
|
7468
|
+
static createDiscoveryCache(config) {
|
|
7469
|
+
const cacheKey = getGlobalCacheKey(config.maxEntries, config.ttlMs);
|
|
7470
|
+
let cache = getGlobalCache(cacheKey);
|
|
7471
|
+
if (!cache) {
|
|
7472
|
+
cache = new LruCache(config.maxEntries, config.ttlMs);
|
|
7473
|
+
globalCaches.set(cacheKey, cache);
|
|
7474
|
+
}
|
|
7475
|
+
return cache;
|
|
7476
|
+
}
|
|
7477
|
+
static createJwksCache() {
|
|
7478
|
+
return {};
|
|
7479
|
+
}
|
|
7480
|
+
};
|
|
7481
|
+
|
|
7382
7482
|
var DEFAULT_SCOPES = "openid profile email offline_access";
|
|
7383
7483
|
|
|
7384
7484
|
var MAX_ARRAY_VALUES_PER_KEY = 20;
|
|
@@ -7411,9 +7511,9 @@ function appendExtraParams(params, extra) {
|
|
|
7411
7511
|
if (parameterValue.length > MAX_ARRAY_VALUES_PER_KEY) {
|
|
7412
7512
|
throw new TokenExchangeError("Parameter '".concat(parameterKey, "' exceeds maximum array size of ").concat(MAX_ARRAY_VALUES_PER_KEY));
|
|
7413
7513
|
}
|
|
7414
|
-
parameterValue.forEach(
|
|
7514
|
+
parameterValue.forEach(arrayItem => {
|
|
7415
7515
|
params.append(parameterKey, arrayItem);
|
|
7416
|
-
})
|
|
7516
|
+
});
|
|
7417
7517
|
} else {
|
|
7418
7518
|
params.append(parameterKey, parameterValue);
|
|
7419
7519
|
}
|
|
@@ -7430,39 +7530,58 @@ var SUBJECT_TYPE_ACCESS_TOKEN = "urn:ietf:params:oauth:token-type:access_token";
|
|
|
7430
7530
|
|
|
7431
7531
|
var REQUESTED_TOKEN_TYPE_FEDERATED_CONNECTION_ACCESS_TOKEN = "http://auth0.com/oauth/token-type/federated-connection-access-token";
|
|
7432
7532
|
|
|
7433
|
-
var AuthClient = (_configuration = new WeakMap, _serverMetadata = new WeakMap,
|
|
7434
|
-
|
|
7533
|
+
var AuthClient = (_configuration = new WeakMap, _serverMetadata = new WeakMap, _clientAuthPromise = new WeakMap,
|
|
7534
|
+
_options = new WeakMap, _customFetch2 = new WeakMap, _jwks = new WeakMap, _discoveryCache = new WeakMap,
|
|
7535
|
+
_inFlightDiscovery = new WeakMap, _jwksCache = new WeakMap, _Class9_brand = new WeakSet,
|
|
7536
|
+
class AuthClient {
|
|
7435
7537
|
constructor(_options2) {
|
|
7436
|
-
|
|
7538
|
+
var _options2$customFetch;
|
|
7539
|
+
_classPrivateMethodInitSpec(this, _Class9_brand);
|
|
7437
7540
|
_classPrivateFieldInitSpec(this, _configuration, void 0);
|
|
7438
7541
|
_classPrivateFieldInitSpec(this, _serverMetadata, void 0);
|
|
7542
|
+
_classPrivateFieldInitSpec(this, _clientAuthPromise, void 0);
|
|
7439
7543
|
_classPrivateFieldInitSpec(this, _options, void 0);
|
|
7544
|
+
_classPrivateFieldInitSpec(this, _customFetch2, void 0);
|
|
7440
7545
|
_classPrivateFieldInitSpec(this, _jwks, void 0);
|
|
7546
|
+
_classPrivateFieldInitSpec(this, _discoveryCache, void 0);
|
|
7547
|
+
_classPrivateFieldInitSpec(this, _inFlightDiscovery, void 0);
|
|
7548
|
+
_classPrivateFieldInitSpec(this, _jwksCache, void 0);
|
|
7441
7549
|
_defineProperty(this, "mfa", void 0);
|
|
7442
7550
|
_classPrivateFieldSet2(_options, this, _options2);
|
|
7443
7551
|
if (_options2.useMtls && !_options2.customFetch) {
|
|
7444
7552
|
throw new NotSupportedError("mtls_without_custom_fetch_not_supported", "Using mTLS without a custom fetch implementation is not supported");
|
|
7445
7553
|
}
|
|
7554
|
+
_classPrivateFieldSet2(_customFetch2, this, createTelemetryFetch((_options2$customFetch = _options2.customFetch) !== null && _options2$customFetch !== void 0 ? _options2$customFetch : function() {
|
|
7555
|
+
return fetch(...arguments);
|
|
7556
|
+
}, getTelemetryConfig(_options2.telemetry)));
|
|
7557
|
+
const cacheConfig = resolveCacheConfig(_options2.discoveryCache);
|
|
7558
|
+
_classPrivateFieldSet2(_discoveryCache, this, DiscoveryCacheFactory.createDiscoveryCache(cacheConfig));
|
|
7559
|
+
_classPrivateFieldSet2(_inFlightDiscovery, this, new Map);
|
|
7560
|
+
_classPrivateFieldSet2(_jwksCache, this, DiscoveryCacheFactory.createJwksCache());
|
|
7446
7561
|
this.mfa = new MfaClient({
|
|
7447
7562
|
domain: _classPrivateFieldGet2(_options, this).domain,
|
|
7448
7563
|
clientId: _classPrivateFieldGet2(_options, this).clientId,
|
|
7449
|
-
customFetch: _classPrivateFieldGet2(
|
|
7564
|
+
customFetch: _classPrivateFieldGet2(_customFetch2, this)
|
|
7450
7565
|
});
|
|
7451
7566
|
}
|
|
7567
|
+
async getServerMetadata() {
|
|
7568
|
+
const {serverMetadata: serverMetadata} = await _assertClassBrand(_Class9_brand, this, _discover).call(this);
|
|
7569
|
+
return serverMetadata;
|
|
7570
|
+
}
|
|
7452
7571
|
async buildAuthorizationUrl(options) {
|
|
7453
|
-
const {serverMetadata: serverMetadata} = await _assertClassBrand(
|
|
7572
|
+
const {serverMetadata: serverMetadata} = await _assertClassBrand(_Class9_brand, this, _discover).call(this);
|
|
7454
7573
|
if (options !== null && options !== void 0 && options.pushedAuthorizationRequests && !serverMetadata.pushed_authorization_request_endpoint) {
|
|
7455
7574
|
throw new NotSupportedError("par_not_supported_error", "The Auth0 tenant does not have pushed authorization requests enabled. Learn how to enable it here: https://auth0.com/docs/get-started/applications/configure-par");
|
|
7456
7575
|
}
|
|
7457
7576
|
try {
|
|
7458
|
-
return await _assertClassBrand(
|
|
7577
|
+
return await _assertClassBrand(_Class9_brand, this, _buildAuthorizationUrl).call(this, options);
|
|
7459
7578
|
} catch (e) {
|
|
7460
7579
|
throw new BuildAuthorizationUrlError(e);
|
|
7461
7580
|
}
|
|
7462
7581
|
}
|
|
7463
7582
|
async buildLinkUserUrl(options) {
|
|
7464
7583
|
try {
|
|
7465
|
-
const result = await _assertClassBrand(
|
|
7584
|
+
const result = await _assertClassBrand(_Class9_brand, this, _buildAuthorizationUrl).call(this, {
|
|
7466
7585
|
authorizationParams: _objectSpread2(_objectSpread2({}, options.authorizationParams), {}, {
|
|
7467
7586
|
requested_connection: options.connection,
|
|
7468
7587
|
requested_connection_scope: options.connectionScope,
|
|
@@ -7480,7 +7599,7 @@ _jwks = new WeakMap, _Class8_brand = new WeakSet, class AuthClient {
|
|
|
7480
7599
|
}
|
|
7481
7600
|
async buildUnlinkUserUrl(options) {
|
|
7482
7601
|
try {
|
|
7483
|
-
const result = await _assertClassBrand(
|
|
7602
|
+
const result = await _assertClassBrand(_Class9_brand, this, _buildAuthorizationUrl).call(this, {
|
|
7484
7603
|
authorizationParams: _objectSpread2(_objectSpread2({}, options.authorizationParams), {}, {
|
|
7485
7604
|
requested_connection: options.connection,
|
|
7486
7605
|
scope: "openid unlink_account",
|
|
@@ -7496,7 +7615,7 @@ _jwks = new WeakMap, _Class8_brand = new WeakSet, class AuthClient {
|
|
|
7496
7615
|
}
|
|
7497
7616
|
}
|
|
7498
7617
|
async backchannelAuthentication(options) {
|
|
7499
|
-
const {configuration: configuration, serverMetadata: serverMetadata} = await _assertClassBrand(
|
|
7618
|
+
const {configuration: configuration, serverMetadata: serverMetadata} = await _assertClassBrand(_Class9_brand, this, _discover).call(this);
|
|
7500
7619
|
const additionalParams = stripUndefinedProperties(_objectSpread2(_objectSpread2({}, _classPrivateFieldGet2(_options, this).authorizationParams), options === null || options === void 0 ? void 0 : options.authorizationParams));
|
|
7501
7620
|
const params = new URLSearchParams(_objectSpread2(_objectSpread2({
|
|
7502
7621
|
scope: DEFAULT_SCOPES
|
|
@@ -7524,7 +7643,7 @@ _jwks = new WeakMap, _Class8_brand = new WeakSet, class AuthClient {
|
|
|
7524
7643
|
}
|
|
7525
7644
|
}
|
|
7526
7645
|
async initiateBackchannelAuthentication(options) {
|
|
7527
|
-
const {configuration: configuration, serverMetadata: serverMetadata} = await _assertClassBrand(
|
|
7646
|
+
const {configuration: configuration, serverMetadata: serverMetadata} = await _assertClassBrand(_Class9_brand, this, _discover).call(this);
|
|
7528
7647
|
const additionalParams = stripUndefinedProperties(_objectSpread2(_objectSpread2({}, _classPrivateFieldGet2(_options, this).authorizationParams), options === null || options === void 0 ? void 0 : options.authorizationParams));
|
|
7529
7648
|
const params = new URLSearchParams(_objectSpread2(_objectSpread2({
|
|
7530
7649
|
scope: DEFAULT_SCOPES
|
|
@@ -7556,7 +7675,7 @@ _jwks = new WeakMap, _Class8_brand = new WeakSet, class AuthClient {
|
|
|
7556
7675
|
}
|
|
7557
7676
|
async backchannelAuthenticationGrant(_ref2) {
|
|
7558
7677
|
let {authReqId: authReqId} = _ref2;
|
|
7559
|
-
const {configuration: configuration} = await _assertClassBrand(
|
|
7678
|
+
const {configuration: configuration} = await _assertClassBrand(_Class9_brand, this, _discover).call(this);
|
|
7560
7679
|
const params = new URLSearchParams({
|
|
7561
7680
|
auth_req_id: authReqId
|
|
7562
7681
|
});
|
|
@@ -7591,10 +7710,10 @@ _jwks = new WeakMap, _Class8_brand = new WeakSet, class AuthClient {
|
|
|
7591
7710
|
}
|
|
7592
7711
|
}
|
|
7593
7712
|
async exchangeToken(options) {
|
|
7594
|
-
return "connection" in options ? _assertClassBrand(
|
|
7713
|
+
return "connection" in options ? _assertClassBrand(_Class9_brand, this, _exchangeTokenVaultToken).call(this, options) : _assertClassBrand(_Class9_brand, this, _exchangeProfileToken).call(this, options);
|
|
7595
7714
|
}
|
|
7596
7715
|
async getTokenByCode(url, options) {
|
|
7597
|
-
const {configuration: configuration} = await _assertClassBrand(
|
|
7716
|
+
const {configuration: configuration} = await _assertClassBrand(_Class9_brand, this, _discover).call(this);
|
|
7598
7717
|
try {
|
|
7599
7718
|
const tokenEndpointResponse = await authorizationCodeGrant(configuration, url, {
|
|
7600
7719
|
pkceCodeVerifier: options.codeVerifier
|
|
@@ -7605,16 +7724,23 @@ _jwks = new WeakMap, _Class8_brand = new WeakSet, class AuthClient {
|
|
|
7605
7724
|
}
|
|
7606
7725
|
}
|
|
7607
7726
|
async getTokenByRefreshToken(options) {
|
|
7608
|
-
const {configuration: configuration} = await _assertClassBrand(
|
|
7727
|
+
const {configuration: configuration} = await _assertClassBrand(_Class9_brand, this, _discover).call(this);
|
|
7728
|
+
const additionalParameters = new URLSearchParams;
|
|
7729
|
+
if (options.audience) {
|
|
7730
|
+
additionalParameters.append("audience", options.audience);
|
|
7731
|
+
}
|
|
7732
|
+
if (options.scope) {
|
|
7733
|
+
additionalParameters.append("scope", options.scope);
|
|
7734
|
+
}
|
|
7609
7735
|
try {
|
|
7610
|
-
const tokenEndpointResponse = await refreshTokenGrant(configuration, options.refreshToken);
|
|
7736
|
+
const tokenEndpointResponse = await refreshTokenGrant(configuration, options.refreshToken, additionalParameters);
|
|
7611
7737
|
return TokenResponse.fromTokenEndpointResponse(tokenEndpointResponse);
|
|
7612
7738
|
} catch (e) {
|
|
7613
7739
|
throw new TokenByRefreshTokenError("The access token has expired and there was an error while trying to refresh it.", e);
|
|
7614
7740
|
}
|
|
7615
7741
|
}
|
|
7616
7742
|
async getTokenByClientCredentials(options) {
|
|
7617
|
-
const {configuration: configuration} = await _assertClassBrand(
|
|
7743
|
+
const {configuration: configuration} = await _assertClassBrand(_Class9_brand, this, _discover).call(this);
|
|
7618
7744
|
try {
|
|
7619
7745
|
const params = new URLSearchParams({
|
|
7620
7746
|
audience: options.audience
|
|
@@ -7629,7 +7755,7 @@ _jwks = new WeakMap, _Class8_brand = new WeakSet, class AuthClient {
|
|
|
7629
7755
|
}
|
|
7630
7756
|
}
|
|
7631
7757
|
async buildLogoutUrl(options) {
|
|
7632
|
-
const {configuration: configuration, serverMetadata: serverMetadata} = await _assertClassBrand(
|
|
7758
|
+
const {configuration: configuration, serverMetadata: serverMetadata} = await _assertClassBrand(_Class9_brand, this, _discover).call(this);
|
|
7633
7759
|
if (!serverMetadata.end_session_endpoint) {
|
|
7634
7760
|
const url = new URL("https://".concat(_classPrivateFieldGet2(_options, this).domain, "/v2/logout"));
|
|
7635
7761
|
url.searchParams.set("returnTo", options.returnTo);
|
|
@@ -7641,9 +7767,13 @@ _jwks = new WeakMap, _Class8_brand = new WeakSet, class AuthClient {
|
|
|
7641
7767
|
});
|
|
7642
7768
|
}
|
|
7643
7769
|
async verifyLogoutToken(options) {
|
|
7644
|
-
const {serverMetadata: serverMetadata} = await _assertClassBrand(
|
|
7645
|
-
|
|
7646
|
-
|
|
7770
|
+
const {serverMetadata: serverMetadata} = await _assertClassBrand(_Class9_brand, this, _discover).call(this);
|
|
7771
|
+
const cacheConfig = resolveCacheConfig(_classPrivateFieldGet2(_options, this).discoveryCache);
|
|
7772
|
+
const jwksUri = serverMetadata.jwks_uri;
|
|
7773
|
+
_classPrivateFieldGet2(_jwks, this) || _classPrivateFieldSet2(_jwks, this, createRemoteJWKSet(new URL(jwksUri), {
|
|
7774
|
+
cacheMaxAge: cacheConfig.ttlMs,
|
|
7775
|
+
[customFetch]: _classPrivateFieldGet2(_customFetch2, this),
|
|
7776
|
+
[jwksCache]: _classPrivateFieldGet2(_jwksCache, this)
|
|
7647
7777
|
}));
|
|
7648
7778
|
const {payload: payload} = await jwtVerify(options.logoutToken, _classPrivateFieldGet2(_jwks, this), {
|
|
7649
7779
|
issuer: serverMetadata.issuer,
|
|
@@ -7682,6 +7812,18 @@ _jwks = new WeakMap, _Class8_brand = new WeakSet, class AuthClient {
|
|
|
7682
7812
|
}
|
|
7683
7813
|
});
|
|
7684
7814
|
|
|
7815
|
+
function _getDiscoveryCacheKey() {
|
|
7816
|
+
const domain = _classPrivateFieldGet2(_options, this).domain.toLowerCase();
|
|
7817
|
+
return "".concat(domain, "|mtls:").concat(_classPrivateFieldGet2(_options, this).useMtls ? "1" : "0");
|
|
7818
|
+
}
|
|
7819
|
+
|
|
7820
|
+
async function _createConfiguration(serverMetadata) {
|
|
7821
|
+
const clientAuth = await _assertClassBrand(_Class9_brand, this, _getClientAuth).call(this);
|
|
7822
|
+
const configuration = new Configuration(serverMetadata, _classPrivateFieldGet2(_options, this).clientId, _classPrivateFieldGet2(_options, this).clientSecret, clientAuth);
|
|
7823
|
+
configuration[customFetch$1] = _classPrivateFieldGet2(_customFetch2, this);
|
|
7824
|
+
return configuration;
|
|
7825
|
+
}
|
|
7826
|
+
|
|
7685
7827
|
async function _discover() {
|
|
7686
7828
|
if (_classPrivateFieldGet2(_configuration, this) && _classPrivateFieldGet2(_serverMetadata, this)) {
|
|
7687
7829
|
return {
|
|
@@ -7689,14 +7831,58 @@ async function _discover() {
|
|
|
7689
7831
|
serverMetadata: _classPrivateFieldGet2(_serverMetadata, this)
|
|
7690
7832
|
};
|
|
7691
7833
|
}
|
|
7692
|
-
const
|
|
7693
|
-
|
|
7694
|
-
|
|
7695
|
-
|
|
7696
|
-
|
|
7697
|
-
|
|
7698
|
-
|
|
7699
|
-
|
|
7834
|
+
const cacheKey = _assertClassBrand(_Class9_brand, this, _getDiscoveryCacheKey).call(this);
|
|
7835
|
+
const cached = _classPrivateFieldGet2(_discoveryCache, this).get(cacheKey);
|
|
7836
|
+
if (cached) {
|
|
7837
|
+
_classPrivateFieldSet2(_serverMetadata, this, cached.serverMetadata);
|
|
7838
|
+
_classPrivateFieldSet2(_configuration, this, await _assertClassBrand(_Class9_brand, this, _createConfiguration).call(this, cached.serverMetadata));
|
|
7839
|
+
return {
|
|
7840
|
+
configuration: _classPrivateFieldGet2(_configuration, this),
|
|
7841
|
+
serverMetadata: _classPrivateFieldGet2(_serverMetadata, this)
|
|
7842
|
+
};
|
|
7843
|
+
}
|
|
7844
|
+
const inFlight = _classPrivateFieldGet2(_inFlightDiscovery, this).get(cacheKey);
|
|
7845
|
+
if (inFlight) {
|
|
7846
|
+
const entry = await inFlight;
|
|
7847
|
+
_classPrivateFieldSet2(_serverMetadata, this, entry.serverMetadata);
|
|
7848
|
+
_classPrivateFieldSet2(_configuration, this, await _assertClassBrand(_Class9_brand, this, _createConfiguration).call(this, entry.serverMetadata));
|
|
7849
|
+
return {
|
|
7850
|
+
configuration: _classPrivateFieldGet2(_configuration, this),
|
|
7851
|
+
serverMetadata: _classPrivateFieldGet2(_serverMetadata, this)
|
|
7852
|
+
};
|
|
7853
|
+
}
|
|
7854
|
+
const discoveryPromise = (async () => {
|
|
7855
|
+
const clientAuth = await _assertClassBrand(_Class9_brand, this, _getClientAuth).call(this);
|
|
7856
|
+
const configuration = await discovery(new URL("https://".concat(_classPrivateFieldGet2(_options, this).domain)), _classPrivateFieldGet2(_options, this).clientId, {
|
|
7857
|
+
use_mtls_endpoint_aliases: _classPrivateFieldGet2(_options, this).useMtls
|
|
7858
|
+
}, clientAuth, {
|
|
7859
|
+
[customFetch$1]: _classPrivateFieldGet2(_customFetch2, this)
|
|
7860
|
+
});
|
|
7861
|
+
const serverMetadata = configuration.serverMetadata();
|
|
7862
|
+
_classPrivateFieldGet2(_discoveryCache, this).set(cacheKey, {
|
|
7863
|
+
serverMetadata: serverMetadata
|
|
7864
|
+
});
|
|
7865
|
+
return {
|
|
7866
|
+
configuration: configuration,
|
|
7867
|
+
serverMetadata: serverMetadata
|
|
7868
|
+
};
|
|
7869
|
+
})();
|
|
7870
|
+
const inFlightEntry = discoveryPromise.then(_ref3 => {
|
|
7871
|
+
let {serverMetadata: serverMetadata} = _ref3;
|
|
7872
|
+
return {
|
|
7873
|
+
serverMetadata: serverMetadata
|
|
7874
|
+
};
|
|
7875
|
+
});
|
|
7876
|
+
void inFlightEntry.catch(() => void 0);
|
|
7877
|
+
_classPrivateFieldGet2(_inFlightDiscovery, this).set(cacheKey, inFlightEntry);
|
|
7878
|
+
try {
|
|
7879
|
+
const {configuration: configuration, serverMetadata: serverMetadata} = await discoveryPromise;
|
|
7880
|
+
_classPrivateFieldSet2(_configuration, this, configuration);
|
|
7881
|
+
_classPrivateFieldSet2(_serverMetadata, this, serverMetadata);
|
|
7882
|
+
_classPrivateFieldGet2(_configuration, this)[customFetch$1] = _classPrivateFieldGet2(_customFetch2, this);
|
|
7883
|
+
} finally {
|
|
7884
|
+
_classPrivateFieldGet2(_inFlightDiscovery, this).delete(cacheKey);
|
|
7885
|
+
}
|
|
7700
7886
|
return {
|
|
7701
7887
|
configuration: _classPrivateFieldGet2(_configuration, this),
|
|
7702
7888
|
serverMetadata: _classPrivateFieldGet2(_serverMetadata, this)
|
|
@@ -7705,7 +7891,7 @@ async function _discover() {
|
|
|
7705
7891
|
|
|
7706
7892
|
async function _exchangeTokenVaultToken(options) {
|
|
7707
7893
|
var _options$subjectToken, _options$requestedTok;
|
|
7708
|
-
const {configuration: configuration} = await _assertClassBrand(
|
|
7894
|
+
const {configuration: configuration} = await _assertClassBrand(_Class9_brand, this, _discover).call(this);
|
|
7709
7895
|
if ("audience" in options || "resource" in options) {
|
|
7710
7896
|
throw new TokenExchangeError("audience and resource parameters are not supported for Token Vault exchanges");
|
|
7711
7897
|
}
|
|
@@ -7732,7 +7918,7 @@ async function _exchangeTokenVaultToken(options) {
|
|
|
7732
7918
|
}
|
|
7733
7919
|
|
|
7734
7920
|
async function _exchangeProfileToken(options) {
|
|
7735
|
-
const {configuration: configuration} = await _assertClassBrand(
|
|
7921
|
+
const {configuration: configuration} = await _assertClassBrand(_Class9_brand, this, _discover).call(this);
|
|
7736
7922
|
validateSubjectToken(options.subjectToken);
|
|
7737
7923
|
const tokenRequestParams = new URLSearchParams({
|
|
7738
7924
|
subject_token_type: options.subjectTokenType,
|
|
@@ -7760,21 +7946,29 @@ async function _exchangeProfileToken(options) {
|
|
|
7760
7946
|
}
|
|
7761
7947
|
|
|
7762
7948
|
async function _getClientAuth() {
|
|
7763
|
-
if (!_classPrivateFieldGet2(
|
|
7764
|
-
|
|
7765
|
-
|
|
7766
|
-
|
|
7767
|
-
|
|
7768
|
-
|
|
7769
|
-
|
|
7770
|
-
|
|
7771
|
-
|
|
7949
|
+
if (!_classPrivateFieldGet2(_clientAuthPromise, this)) {
|
|
7950
|
+
_classPrivateFieldSet2(_clientAuthPromise, this, (async () => {
|
|
7951
|
+
if (!_classPrivateFieldGet2(_options, this).clientSecret && !_classPrivateFieldGet2(_options, this).clientAssertionSigningKey && !_classPrivateFieldGet2(_options, this).useMtls) {
|
|
7952
|
+
throw new MissingClientAuthError;
|
|
7953
|
+
}
|
|
7954
|
+
if (_classPrivateFieldGet2(_options, this).useMtls) {
|
|
7955
|
+
return TlsClientAuth();
|
|
7956
|
+
}
|
|
7957
|
+
let clientPrivateKey = _classPrivateFieldGet2(_options, this).clientAssertionSigningKey;
|
|
7958
|
+
if (clientPrivateKey && !(clientPrivateKey instanceof CryptoKey)) {
|
|
7959
|
+
clientPrivateKey = await importPKCS8(clientPrivateKey, _classPrivateFieldGet2(_options, this).clientAssertionSigningAlg || "RS256");
|
|
7960
|
+
}
|
|
7961
|
+
return clientPrivateKey ? PrivateKeyJwt(clientPrivateKey) : ClientSecretPost(_classPrivateFieldGet2(_options, this).clientSecret);
|
|
7962
|
+
})().catch(error => {
|
|
7963
|
+
_classPrivateFieldSet2(_clientAuthPromise, this, void 0);
|
|
7964
|
+
throw error;
|
|
7965
|
+
}));
|
|
7772
7966
|
}
|
|
7773
|
-
return
|
|
7967
|
+
return _classPrivateFieldGet2(_clientAuthPromise, this);
|
|
7774
7968
|
}
|
|
7775
7969
|
|
|
7776
7970
|
async function _buildAuthorizationUrl(options) {
|
|
7777
|
-
const {configuration: configuration} = await _assertClassBrand(
|
|
7971
|
+
const {configuration: configuration} = await _assertClassBrand(_Class9_brand, this, _discover).call(this);
|
|
7778
7972
|
const codeChallengeMethod = "S256";
|
|
7779
7973
|
const codeVerifier = randomPKCECodeVerifier();
|
|
7780
7974
|
const codeChallenge = await calculatePKCECodeChallenge(codeVerifier);
|
|
@@ -7899,15 +8093,15 @@ class MfaApiClient {
|
|
|
7899
8093
|
if (!((_a = context === null || context === void 0 ? void 0 : context.mfaRequirements) === null || _a === void 0 ? void 0 : _a.challenge) || context.mfaRequirements.challenge.length === 0) {
|
|
7900
8094
|
throw new MfaListAuthenticatorsError("invalid_request", "challengeType is required and must contain at least one challenge type, please check mfa_required error payload");
|
|
7901
8095
|
}
|
|
7902
|
-
const challengeTypes = context.mfaRequirements.challenge.map(
|
|
8096
|
+
const challengeTypes = context.mfaRequirements.challenge.map(c => c.type);
|
|
7903
8097
|
try {
|
|
7904
8098
|
const allAuthenticators = await this.authJsMfaClient.listAuthenticators({
|
|
7905
8099
|
mfaToken: mfaToken
|
|
7906
8100
|
});
|
|
7907
|
-
return allAuthenticators.filter(
|
|
8101
|
+
return allAuthenticators.filter(auth => {
|
|
7908
8102
|
if (!auth.type) return false;
|
|
7909
8103
|
return challengeTypes.includes(auth.type);
|
|
7910
|
-
})
|
|
8104
|
+
});
|
|
7911
8105
|
} catch (error) {
|
|
7912
8106
|
if (error instanceof MfaListAuthenticatorsError$1) {
|
|
7913
8107
|
throw new MfaListAuthenticatorsError((_b = error.cause) === null || _b === void 0 ? void 0 : _b.error, error.message);
|
|
@@ -8273,7 +8467,7 @@ class Auth0Client {
|
|
|
8273
8467
|
scope: scopesToRequest(this.scope, (_a = options.authorizationParams) === null || _a === void 0 ? void 0 : _a.scope, ((_b = options.authorizationParams) === null || _b === void 0 ? void 0 : _b.audience) || this.options.authorizationParams.audience)
|
|
8274
8468
|
})
|
|
8275
8469
|
});
|
|
8276
|
-
const result = await singlePromise((
|
|
8470
|
+
const result = await singlePromise(() => this._getTokenSilently(localOptions), "".concat(this.options.clientId, "::").concat(localOptions.authorizationParams.audience, "::").concat(localOptions.authorizationParams.scope));
|
|
8277
8471
|
return options.detailedResponse ? result : result === null || result === void 0 ? void 0 : result.access_token;
|
|
8278
8472
|
}
|
|
8279
8473
|
async _getTokenSilently(options) {
|
|
@@ -8294,7 +8488,7 @@ class Auth0Client {
|
|
|
8294
8488
|
}
|
|
8295
8489
|
const lockKey = buildGetTokenSilentlyLockKey(this.options.clientId, getTokenOptions.authorizationParams.audience || "default");
|
|
8296
8490
|
try {
|
|
8297
|
-
return await this.lockManager.runWithLock(lockKey, 5e3,
|
|
8491
|
+
return await this.lockManager.runWithLock(lockKey, 5e3, async () => {
|
|
8298
8492
|
if (cacheMode !== "off") {
|
|
8299
8493
|
const entry = await this._getEntryFromCache({
|
|
8300
8494
|
scope: getTokenOptions.authorizationParams.scope,
|
|
@@ -8316,7 +8510,7 @@ class Auth0Client {
|
|
|
8316
8510
|
} : null), {
|
|
8317
8511
|
expires_in: expires_in
|
|
8318
8512
|
});
|
|
8319
|
-
})
|
|
8513
|
+
});
|
|
8320
8514
|
} catch (error) {
|
|
8321
8515
|
if (this._isInteractiveError(error) && this.options.interactiveErrorHandler === "popup") {
|
|
8322
8516
|
return await this._handleInteractiveErrorWithPopup(getTokenOptions);
|
|
@@ -8325,7 +8519,10 @@ class Auth0Client {
|
|
|
8325
8519
|
}
|
|
8326
8520
|
}
|
|
8327
8521
|
_isInteractiveError(error) {
|
|
8328
|
-
return error instanceof MfaRequiredError;
|
|
8522
|
+
return error instanceof MfaRequiredError || error instanceof GenericError && this._isIframeMfaError(error);
|
|
8523
|
+
}
|
|
8524
|
+
_isIframeMfaError(error) {
|
|
8525
|
+
return error.error === "login_required" && error.error_description === MFA_STEP_UP_ERROR_DESCRIPTION;
|
|
8329
8526
|
}
|
|
8330
8527
|
async _handleInteractiveErrorWithPopup(options) {
|
|
8331
8528
|
try {
|
|
@@ -8407,7 +8604,7 @@ class Auth0Client {
|
|
|
8407
8604
|
async _getTokenFromIFrame(options) {
|
|
8408
8605
|
const iframeLockKey = buildIframeLockKey(this.options.clientId);
|
|
8409
8606
|
try {
|
|
8410
|
-
return await this.lockManager.runWithLock(iframeLockKey, 5e3,
|
|
8607
|
+
return await this.lockManager.runWithLock(iframeLockKey, 5e3, async () => {
|
|
8411
8608
|
const params = Object.assign(Object.assign({}, options.authorizationParams), {
|
|
8412
8609
|
prompt: "none"
|
|
8413
8610
|
});
|
|
@@ -8447,12 +8644,15 @@ class Auth0Client {
|
|
|
8447
8644
|
oauthTokenScope: tokenResult.scope,
|
|
8448
8645
|
audience: audience
|
|
8449
8646
|
});
|
|
8450
|
-
})
|
|
8647
|
+
});
|
|
8451
8648
|
} catch (e) {
|
|
8452
8649
|
if (e.error === "login_required") {
|
|
8453
|
-
this.
|
|
8454
|
-
|
|
8455
|
-
|
|
8650
|
+
const shouldSkipLogoutForMfaStepUp = e instanceof GenericError && this._isIframeMfaError(e) && this.options.interactiveErrorHandler === "popup";
|
|
8651
|
+
if (!shouldSkipLogoutForMfaStepUp) {
|
|
8652
|
+
this.logout({
|
|
8653
|
+
openUrl: false
|
|
8654
|
+
});
|
|
8655
|
+
}
|
|
8456
8656
|
}
|
|
8457
8657
|
throw e;
|
|
8458
8658
|
}
|