@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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
(function(global, factory) {
|
|
2
2
|
typeof exports === "object" && typeof module !== "undefined" ? factory(exports) : typeof define === "function" && define.amd ? define([ "exports" ], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self,
|
|
3
3
|
factory(global.auth0 = {}));
|
|
4
|
-
})(this,
|
|
4
|
+
})(this, function(exports) {
|
|
5
5
|
"use strict";
|
|
6
6
|
function __rest(s, e) {
|
|
7
7
|
var t = {};
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
var e = new Error(message);
|
|
16
16
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
17
17
|
};
|
|
18
|
-
var version = "2.
|
|
18
|
+
var version = "2.17.1";
|
|
19
19
|
const DEFAULT_AUTHORIZE_TIMEOUT_IN_SECONDS = 60;
|
|
20
20
|
const DEFAULT_POPUP_CONFIG_OPTIONS = {
|
|
21
21
|
timeoutInSeconds: DEFAULT_AUTHORIZE_TIMEOUT_IN_SECONDS
|
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
const MISSING_REFRESH_TOKEN_ERROR_MESSAGE = "Missing Refresh Token";
|
|
28
28
|
const INVALID_REFRESH_TOKEN_ERROR_MESSAGE = "invalid refresh token";
|
|
29
29
|
const USER_BLOCKED_ERROR_MESSAGE = "user is blocked";
|
|
30
|
+
const MFA_STEP_UP_ERROR_DESCRIPTION = "Multifactor authentication required";
|
|
30
31
|
const DEFAULT_SCOPE = "openid profile email";
|
|
31
32
|
const DEFAULT_SESSION_CHECK_EXPIRY_DAYS = 1;
|
|
32
33
|
const DEFAULT_AUTH0_CLIENT = {
|
|
@@ -142,7 +143,7 @@
|
|
|
142
143
|
};
|
|
143
144
|
const runIframe = function runIframe(authorizeUrl, eventOrigin) {
|
|
144
145
|
let timeoutInSeconds = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : DEFAULT_AUTHORIZE_TIMEOUT_IN_SECONDS;
|
|
145
|
-
return new Promise((
|
|
146
|
+
return new Promise((res, rej) => {
|
|
146
147
|
const iframe = window.document.createElement("iframe");
|
|
147
148
|
iframe.setAttribute("width", "0");
|
|
148
149
|
iframe.setAttribute("height", "0");
|
|
@@ -154,10 +155,10 @@
|
|
|
154
155
|
}
|
|
155
156
|
};
|
|
156
157
|
let _iframeEventHandler;
|
|
157
|
-
const timeoutSetTimeoutId = setTimeout((
|
|
158
|
+
const timeoutSetTimeoutId = setTimeout(() => {
|
|
158
159
|
rej(new TimeoutError);
|
|
159
160
|
removeIframe();
|
|
160
|
-
}
|
|
161
|
+
}, timeoutInSeconds * 1e3);
|
|
161
162
|
_iframeEventHandler = function iframeEventHandler(e) {
|
|
162
163
|
if (e.origin != eventOrigin) return;
|
|
163
164
|
if (!e.data || e.data.type !== "authorization_response") return;
|
|
@@ -173,7 +174,7 @@
|
|
|
173
174
|
window.addEventListener("message", _iframeEventHandler, false);
|
|
174
175
|
window.document.body.appendChild(iframe);
|
|
175
176
|
iframe.setAttribute("src", authorizeUrl);
|
|
176
|
-
})
|
|
177
|
+
});
|
|
177
178
|
};
|
|
178
179
|
const openPopup = url => {
|
|
179
180
|
const width = 400;
|
|
@@ -182,21 +183,21 @@
|
|
|
182
183
|
const top = window.screenY + (window.innerHeight - height) / 2;
|
|
183
184
|
return window.open(url, "auth0:authorize:popup", "left=".concat(left, ",top=").concat(top, ",width=").concat(width, ",height=").concat(height, ",resizable,scrollbars=yes,status=1"));
|
|
184
185
|
};
|
|
185
|
-
const runPopup = config => new Promise((
|
|
186
|
+
const runPopup = config => new Promise((resolve, reject) => {
|
|
186
187
|
let _popupEventListener;
|
|
187
|
-
const popupTimer = setInterval((
|
|
188
|
+
const popupTimer = setInterval(() => {
|
|
188
189
|
if (config.popup && config.popup.closed) {
|
|
189
190
|
clearInterval(popupTimer);
|
|
190
191
|
clearTimeout(timeoutId);
|
|
191
192
|
window.removeEventListener("message", _popupEventListener, false);
|
|
192
193
|
reject(new PopupCancelledError(config.popup));
|
|
193
194
|
}
|
|
194
|
-
}
|
|
195
|
-
const timeoutId = setTimeout((
|
|
195
|
+
}, 1e3);
|
|
196
|
+
const timeoutId = setTimeout(() => {
|
|
196
197
|
clearInterval(popupTimer);
|
|
197
198
|
reject(new PopupTimeoutError(config.popup));
|
|
198
199
|
window.removeEventListener("message", _popupEventListener, false);
|
|
199
|
-
}
|
|
200
|
+
}, (config.timeoutInSeconds || DEFAULT_AUTHORIZE_TIMEOUT_IN_SECONDS) * 1e3);
|
|
200
201
|
_popupEventListener = function popupEventListener(e) {
|
|
201
202
|
if (!e.data || e.data.type !== "authorization_response") {
|
|
202
203
|
return;
|
|
@@ -213,19 +214,19 @@
|
|
|
213
214
|
resolve(e.data.response);
|
|
214
215
|
};
|
|
215
216
|
window.addEventListener("message", _popupEventListener);
|
|
216
|
-
})
|
|
217
|
+
});
|
|
217
218
|
const getCrypto = () => window.crypto;
|
|
218
219
|
const createRandomString = () => {
|
|
219
220
|
const charset = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_~.";
|
|
220
221
|
let random = "";
|
|
221
222
|
const randomValues = Array.from(getCrypto().getRandomValues(new Uint8Array(43)));
|
|
222
|
-
randomValues.forEach(
|
|
223
|
+
randomValues.forEach(v => random += charset[v % charset.length]);
|
|
223
224
|
return random;
|
|
224
225
|
};
|
|
225
226
|
const encode$2 = value => btoa(value);
|
|
226
|
-
const stripUndefined = params => Object.keys(params).filter(
|
|
227
|
+
const stripUndefined = params => Object.keys(params).filter(k => typeof params[k] !== "undefined").reduce((acc, key) => Object.assign(Object.assign({}, acc), {
|
|
227
228
|
[key]: params[key]
|
|
228
|
-
})
|
|
229
|
+
}), {});
|
|
229
230
|
const ALLOWED_AUTH0CLIENT_PROPERTIES = [ {
|
|
230
231
|
key: "name",
|
|
231
232
|
type: [ "string" ]
|
|
@@ -238,16 +239,16 @@
|
|
|
238
239
|
} ];
|
|
239
240
|
const stripAuth0Client = function stripAuth0Client(auth0Client) {
|
|
240
241
|
let excludeEnv = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
241
|
-
return Object.keys(auth0Client).reduce((
|
|
242
|
+
return Object.keys(auth0Client).reduce((acc, key) => {
|
|
242
243
|
if (excludeEnv && key === "env") {
|
|
243
244
|
return acc;
|
|
244
245
|
}
|
|
245
|
-
const allowedProperty = ALLOWED_AUTH0CLIENT_PROPERTIES.find(
|
|
246
|
+
const allowedProperty = ALLOWED_AUTH0CLIENT_PROPERTIES.find(p => p.key === key);
|
|
246
247
|
if (allowedProperty && allowedProperty.type.includes(typeof auth0Client[key])) {
|
|
247
248
|
acc[key] = auth0Client[key];
|
|
248
249
|
}
|
|
249
250
|
return acc;
|
|
250
|
-
}
|
|
251
|
+
}, {});
|
|
251
252
|
};
|
|
252
253
|
const createQueryParams = _a => {
|
|
253
254
|
var {clientId: client_id} = _a, params = __rest(_a, [ "clientId" ]);
|
|
@@ -267,9 +268,9 @@
|
|
|
267
268
|
"/": "_",
|
|
268
269
|
"=": ""
|
|
269
270
|
};
|
|
270
|
-
return input.replace(/[+/=]/g,
|
|
271
|
+
return input.replace(/[+/=]/g, m => b64Chars[m]);
|
|
271
272
|
};
|
|
272
|
-
const decodeB64 = input => decodeURIComponent(atob(input).split("").map(
|
|
273
|
+
const decodeB64 = input => decodeURIComponent(atob(input).split("").map(c => "%" + ("00" + c.charCodeAt(0).toString(16)).slice(-2)).join(""));
|
|
273
274
|
const urlDecodeB64 = input => decodeB64(input.replace(/_/g, "/").replace(/-/g, "+"));
|
|
274
275
|
const bufferToBase64UrlEncoded = input => {
|
|
275
276
|
const ie11SafeInput = new Uint8Array(input);
|
|
@@ -301,11 +302,11 @@
|
|
|
301
302
|
}
|
|
302
303
|
return parseInt(value, 10) || undefined;
|
|
303
304
|
};
|
|
304
|
-
const fromEntries = iterable => [ ...iterable ].reduce((
|
|
305
|
+
const fromEntries = iterable => [ ...iterable ].reduce((obj, _ref) => {
|
|
305
306
|
let [key, val] = _ref;
|
|
306
307
|
obj[key] = val;
|
|
307
308
|
return obj;
|
|
308
|
-
}
|
|
309
|
+
}, {});
|
|
309
310
|
var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
|
|
310
311
|
var browserTabsLock = {};
|
|
311
312
|
var processLock = {};
|
|
@@ -335,14 +336,14 @@
|
|
|
335
336
|
return _this.locked.has(key);
|
|
336
337
|
};
|
|
337
338
|
this.lock = function(key) {
|
|
338
|
-
return new Promise(
|
|
339
|
+
return new Promise(function(resolve, reject) {
|
|
339
340
|
if (_this.isLocked(key)) {
|
|
340
341
|
_this.addToLocked(key, resolve);
|
|
341
342
|
} else {
|
|
342
343
|
_this.addToLocked(key);
|
|
343
344
|
resolve();
|
|
344
345
|
}
|
|
345
|
-
})
|
|
346
|
+
});
|
|
346
347
|
};
|
|
347
348
|
this.unlock = function(key) {
|
|
348
349
|
var callbacks = _this.locked.get(key);
|
|
@@ -370,7 +371,7 @@
|
|
|
370
371
|
}
|
|
371
372
|
processLock.default = getLock;
|
|
372
373
|
var __awaiter = commonjsGlobal && commonjsGlobal.__awaiter || function(thisArg, _arguments, P, generator) {
|
|
373
|
-
return new (P || (P = Promise))(
|
|
374
|
+
return new (P || (P = Promise))(function(resolve, reject) {
|
|
374
375
|
function fulfilled(value) {
|
|
375
376
|
try {
|
|
376
377
|
step(generator.next(value));
|
|
@@ -386,12 +387,12 @@
|
|
|
386
387
|
}
|
|
387
388
|
}
|
|
388
389
|
function step(result) {
|
|
389
|
-
result.done ? resolve(result.value) : new P(
|
|
390
|
+
result.done ? resolve(result.value) : new P(function(resolve) {
|
|
390
391
|
resolve(result.value);
|
|
391
|
-
})
|
|
392
|
+
}).then(fulfilled, rejected);
|
|
392
393
|
}
|
|
393
394
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
394
|
-
})
|
|
395
|
+
});
|
|
395
396
|
};
|
|
396
397
|
var __generator = commonjsGlobal && commonjsGlobal.__generator || function(thisArg, body) {
|
|
397
398
|
var _ = {
|
|
@@ -490,39 +491,39 @@
|
|
|
490
491
|
var LOCK_STORAGE_KEY = "browser-tabs-lock-key";
|
|
491
492
|
var DEFAULT_STORAGE_HANDLER = {
|
|
492
493
|
key: function(index) {
|
|
493
|
-
return __awaiter(_this, void 0, void 0,
|
|
494
|
-
return __generator(this,
|
|
494
|
+
return __awaiter(_this, void 0, void 0, function() {
|
|
495
|
+
return __generator(this, function(_a) {
|
|
495
496
|
throw new Error("Unsupported");
|
|
496
|
-
})
|
|
497
|
-
})
|
|
497
|
+
});
|
|
498
|
+
});
|
|
498
499
|
},
|
|
499
500
|
getItem: function(key) {
|
|
500
|
-
return __awaiter(_this, void 0, void 0,
|
|
501
|
-
return __generator(this,
|
|
501
|
+
return __awaiter(_this, void 0, void 0, function() {
|
|
502
|
+
return __generator(this, function(_a) {
|
|
502
503
|
throw new Error("Unsupported");
|
|
503
|
-
})
|
|
504
|
-
})
|
|
504
|
+
});
|
|
505
|
+
});
|
|
505
506
|
},
|
|
506
507
|
clear: function() {
|
|
507
|
-
return __awaiter(_this, void 0, void 0,
|
|
508
|
-
return __generator(this,
|
|
508
|
+
return __awaiter(_this, void 0, void 0, function() {
|
|
509
|
+
return __generator(this, function(_a) {
|
|
509
510
|
return [ 2, window.localStorage.clear() ];
|
|
510
|
-
})
|
|
511
|
-
})
|
|
511
|
+
});
|
|
512
|
+
});
|
|
512
513
|
},
|
|
513
514
|
removeItem: function(key) {
|
|
514
|
-
return __awaiter(_this, void 0, void 0,
|
|
515
|
-
return __generator(this,
|
|
515
|
+
return __awaiter(_this, void 0, void 0, function() {
|
|
516
|
+
return __generator(this, function(_a) {
|
|
516
517
|
throw new Error("Unsupported");
|
|
517
|
-
})
|
|
518
|
-
})
|
|
518
|
+
});
|
|
519
|
+
});
|
|
519
520
|
},
|
|
520
521
|
setItem: function(key, value) {
|
|
521
|
-
return __awaiter(_this, void 0, void 0,
|
|
522
|
-
return __generator(this,
|
|
522
|
+
return __awaiter(_this, void 0, void 0, function() {
|
|
523
|
+
return __generator(this, function(_a) {
|
|
523
524
|
throw new Error("Unsupported");
|
|
524
|
-
})
|
|
525
|
-
})
|
|
525
|
+
});
|
|
526
|
+
});
|
|
526
527
|
},
|
|
527
528
|
keySync: function(index) {
|
|
528
529
|
return window.localStorage.key(index);
|
|
@@ -541,9 +542,9 @@
|
|
|
541
542
|
}
|
|
542
543
|
};
|
|
543
544
|
function delay(milliseconds) {
|
|
544
|
-
return new Promise(
|
|
545
|
+
return new Promise(function(resolve) {
|
|
545
546
|
return setTimeout(resolve, milliseconds);
|
|
546
|
-
})
|
|
547
|
+
});
|
|
547
548
|
}
|
|
548
549
|
function generateRandomString(length) {
|
|
549
550
|
var CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
|
|
@@ -576,9 +577,9 @@
|
|
|
576
577
|
if (timeout === void 0) {
|
|
577
578
|
timeout = 5e3;
|
|
578
579
|
}
|
|
579
|
-
return __awaiter(this, void 0, void 0,
|
|
580
|
+
return __awaiter(this, void 0, void 0, function() {
|
|
580
581
|
var iat, MAX_TIME, STORAGE_KEY, STORAGE, lockObj, TIMEOUT_KEY, lockObjPostDelay, parsedLockObjPostDelay;
|
|
581
|
-
return __generator(this,
|
|
582
|
+
return __generator(this, function(_a) {
|
|
582
583
|
switch (_a.label) {
|
|
583
584
|
case 0:
|
|
584
585
|
iat = Date.now() + generateRandomString(4);
|
|
@@ -637,17 +638,17 @@
|
|
|
637
638
|
case 8:
|
|
638
639
|
return [ 2, false ];
|
|
639
640
|
}
|
|
640
|
-
})
|
|
641
|
-
})
|
|
641
|
+
});
|
|
642
|
+
});
|
|
642
643
|
};
|
|
643
644
|
SuperTokensLock.prototype.refreshLockWhileAcquired = function(storageKey, iat) {
|
|
644
|
-
return __awaiter(this, void 0, void 0,
|
|
645
|
+
return __awaiter(this, void 0, void 0, function() {
|
|
645
646
|
var _this = this;
|
|
646
|
-
return __generator(this,
|
|
647
|
-
setTimeout(
|
|
648
|
-
return __awaiter(_this, void 0, void 0,
|
|
647
|
+
return __generator(this, function(_a) {
|
|
648
|
+
setTimeout(function() {
|
|
649
|
+
return __awaiter(_this, void 0, void 0, function() {
|
|
649
650
|
var STORAGE, lockObj, parsedLockObj;
|
|
650
|
-
return __generator(this,
|
|
651
|
+
return __generator(this, function(_a) {
|
|
651
652
|
switch (_a.label) {
|
|
652
653
|
case 0:
|
|
653
654
|
return [ 4, processLock_1.default().lock(iat) ];
|
|
@@ -672,19 +673,19 @@
|
|
|
672
673
|
this.refreshLockWhileAcquired(storageKey, iat);
|
|
673
674
|
return [ 2 ];
|
|
674
675
|
}
|
|
675
|
-
})
|
|
676
|
-
})
|
|
677
|
-
}
|
|
676
|
+
});
|
|
677
|
+
});
|
|
678
|
+
}, 1e3);
|
|
678
679
|
return [ 2 ];
|
|
679
|
-
})
|
|
680
|
-
})
|
|
680
|
+
});
|
|
681
|
+
});
|
|
681
682
|
};
|
|
682
683
|
SuperTokensLock.prototype.waitForSomethingToChange = function(MAX_TIME) {
|
|
683
|
-
return __awaiter(this, void 0, void 0,
|
|
684
|
-
return __generator(this,
|
|
684
|
+
return __awaiter(this, void 0, void 0, function() {
|
|
685
|
+
return __generator(this, function(_a) {
|
|
685
686
|
switch (_a.label) {
|
|
686
687
|
case 0:
|
|
687
|
-
return [ 4, new Promise(
|
|
688
|
+
return [ 4, new Promise(function(resolve) {
|
|
688
689
|
var resolvedCalled = false;
|
|
689
690
|
var startedAt = Date.now();
|
|
690
691
|
var MIN_TIME_TO_WAIT = 50;
|
|
@@ -709,14 +710,14 @@
|
|
|
709
710
|
window.addEventListener("storage", stopWaiting);
|
|
710
711
|
SuperTokensLock.addToWaiting(stopWaiting);
|
|
711
712
|
var timeOutId = setTimeout(stopWaiting, Math.max(0, MAX_TIME - Date.now()));
|
|
712
|
-
})
|
|
713
|
+
}) ];
|
|
713
714
|
|
|
714
715
|
case 1:
|
|
715
716
|
_a.sent();
|
|
716
717
|
return [ 2 ];
|
|
717
718
|
}
|
|
718
|
-
})
|
|
719
|
-
})
|
|
719
|
+
});
|
|
720
|
+
});
|
|
720
721
|
};
|
|
721
722
|
SuperTokensLock.addToWaiting = function(func) {
|
|
722
723
|
this.removeFromWaiting(func);
|
|
@@ -729,22 +730,22 @@
|
|
|
729
730
|
if (SuperTokensLock.waiters === undefined) {
|
|
730
731
|
return;
|
|
731
732
|
}
|
|
732
|
-
SuperTokensLock.waiters = SuperTokensLock.waiters.filter(
|
|
733
|
+
SuperTokensLock.waiters = SuperTokensLock.waiters.filter(function(i) {
|
|
733
734
|
return i !== func;
|
|
734
|
-
})
|
|
735
|
+
});
|
|
735
736
|
};
|
|
736
737
|
SuperTokensLock.notifyWaiters = function() {
|
|
737
738
|
if (SuperTokensLock.waiters === undefined) {
|
|
738
739
|
return;
|
|
739
740
|
}
|
|
740
741
|
var waiters = SuperTokensLock.waiters.slice();
|
|
741
|
-
waiters.forEach(
|
|
742
|
+
waiters.forEach(function(i) {
|
|
742
743
|
return i();
|
|
743
|
-
})
|
|
744
|
+
});
|
|
744
745
|
};
|
|
745
746
|
SuperTokensLock.prototype.releaseLock = function(lockKey) {
|
|
746
|
-
return __awaiter(this, void 0, void 0,
|
|
747
|
-
return __generator(this,
|
|
747
|
+
return __awaiter(this, void 0, void 0, function() {
|
|
748
|
+
return __generator(this, function(_a) {
|
|
748
749
|
switch (_a.label) {
|
|
749
750
|
case 0:
|
|
750
751
|
return [ 4, this.releaseLock__private__(lockKey) ];
|
|
@@ -752,13 +753,13 @@
|
|
|
752
753
|
case 1:
|
|
753
754
|
return [ 2, _a.sent() ];
|
|
754
755
|
}
|
|
755
|
-
})
|
|
756
|
-
})
|
|
756
|
+
});
|
|
757
|
+
});
|
|
757
758
|
};
|
|
758
759
|
SuperTokensLock.prototype.releaseLock__private__ = function(lockKey) {
|
|
759
|
-
return __awaiter(this, void 0, void 0,
|
|
760
|
+
return __awaiter(this, void 0, void 0, function() {
|
|
760
761
|
var STORAGE, STORAGE_KEY, lockObj, parsedlockObj;
|
|
761
|
-
return __generator(this,
|
|
762
|
+
return __generator(this, function(_a) {
|
|
762
763
|
switch (_a.label) {
|
|
763
764
|
case 0:
|
|
764
765
|
STORAGE = this.storageHandler === undefined ? DEFAULT_STORAGE_HANDLER : this.storageHandler;
|
|
@@ -782,8 +783,8 @@
|
|
|
782
783
|
case 2:
|
|
783
784
|
return [ 2 ];
|
|
784
785
|
}
|
|
785
|
-
})
|
|
786
|
-
})
|
|
786
|
+
});
|
|
787
|
+
});
|
|
787
788
|
};
|
|
788
789
|
SuperTokensLock.lockCorrector = function(storageHandler) {
|
|
789
790
|
var MIN_ALLOWED_TIME = Date.now() - 5e3;
|
|
@@ -823,16 +824,16 @@
|
|
|
823
824
|
class WebLocksApiManager {
|
|
824
825
|
async runWithLock(key, timeout, callback) {
|
|
825
826
|
const controller = new AbortController;
|
|
826
|
-
const timeoutId = setTimeout((
|
|
827
|
+
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
827
828
|
try {
|
|
828
829
|
return await navigator.locks.request(key, {
|
|
829
830
|
mode: "exclusive",
|
|
830
831
|
signal: controller.signal
|
|
831
|
-
},
|
|
832
|
+
}, async lock => {
|
|
832
833
|
clearTimeout(timeoutId);
|
|
833
834
|
if (!lock) throw new Error("Lock not available");
|
|
834
835
|
return await callback();
|
|
835
|
-
})
|
|
836
|
+
});
|
|
836
837
|
} catch (error) {
|
|
837
838
|
clearTimeout(timeoutId);
|
|
838
839
|
if ((error === null || error === void 0 ? void 0 : error.name) === "AbortError") throw new TimeoutError;
|
|
@@ -845,7 +846,7 @@
|
|
|
845
846
|
this.activeLocks = new Set;
|
|
846
847
|
this.lock = new _default;
|
|
847
848
|
this.pagehideHandler = () => {
|
|
848
|
-
this.activeLocks.forEach(
|
|
849
|
+
this.activeLocks.forEach(key => this.lock.releaseLock(key));
|
|
849
850
|
this.activeLocks.clear();
|
|
850
851
|
};
|
|
851
852
|
}
|
|
@@ -1197,7 +1198,7 @@
|
|
|
1197
1198
|
function isGrantTypeSupported(grantType) {
|
|
1198
1199
|
return SUPPORTED_GRANT_TYPES.includes(grantType);
|
|
1199
1200
|
}
|
|
1200
|
-
const sendMessage = (message, to) => new Promise(
|
|
1201
|
+
const sendMessage = (message, to) => new Promise(function(resolve, reject) {
|
|
1201
1202
|
const messageChannel = new MessageChannel;
|
|
1202
1203
|
messageChannel.port1.onmessage = function(event) {
|
|
1203
1204
|
if (event.data.error) {
|
|
@@ -1208,7 +1209,7 @@
|
|
|
1208
1209
|
messageChannel.port1.close();
|
|
1209
1210
|
};
|
|
1210
1211
|
to.postMessage(message, [ messageChannel.port2 ]);
|
|
1211
|
-
})
|
|
1212
|
+
});
|
|
1212
1213
|
const createAbortController = () => new AbortController;
|
|
1213
1214
|
const dofetch = async (fetchUrl, fetchOptions) => {
|
|
1214
1215
|
const response = await fetch(fetchUrl, fetchOptions);
|
|
@@ -1222,14 +1223,14 @@
|
|
|
1222
1223
|
const controller = createAbortController();
|
|
1223
1224
|
fetchOptions.signal = controller.signal;
|
|
1224
1225
|
let timeoutId;
|
|
1225
|
-
return Promise.race([ dofetch(fetchUrl, fetchOptions), new Promise((
|
|
1226
|
-
timeoutId = setTimeout((
|
|
1226
|
+
return Promise.race([ dofetch(fetchUrl, fetchOptions), new Promise((_, reject) => {
|
|
1227
|
+
timeoutId = setTimeout(() => {
|
|
1227
1228
|
controller.abort();
|
|
1228
1229
|
reject(new Error("Timeout when executing 'fetch'"));
|
|
1229
|
-
}
|
|
1230
|
-
})
|
|
1230
|
+
}, timeout);
|
|
1231
|
+
}) ]).finally(() => {
|
|
1231
1232
|
clearTimeout(timeoutId);
|
|
1232
|
-
})
|
|
1233
|
+
});
|
|
1233
1234
|
};
|
|
1234
1235
|
const fetchWithWorker = async (fetchUrl, audience, scope, fetchOptions, timeout, worker, useFormData, useMrrt) => sendMessage({
|
|
1235
1236
|
auth: {
|
|
@@ -1344,10 +1345,10 @@
|
|
|
1344
1345
|
let requestedScopes = {
|
|
1345
1346
|
[DEFAULT_AUDIENCE]: getUniqueScopes(openIdScope, ...extraScopes)
|
|
1346
1347
|
};
|
|
1347
|
-
Object.keys(authScopes).forEach(
|
|
1348
|
+
Object.keys(authScopes).forEach(key => {
|
|
1348
1349
|
const audienceScopes = authScopes[key];
|
|
1349
1350
|
requestedScopes[key] = getUniqueScopes(openIdScope, audienceScopes, ...extraScopes);
|
|
1350
|
-
})
|
|
1351
|
+
});
|
|
1351
1352
|
return requestedScopes;
|
|
1352
1353
|
};
|
|
1353
1354
|
const scopesToRequest = (authScopes, methodScopes, audience) => {
|
|
@@ -1410,7 +1411,7 @@
|
|
|
1410
1411
|
localStorage.removeItem(key);
|
|
1411
1412
|
}
|
|
1412
1413
|
allKeys() {
|
|
1413
|
-
return Object.keys(window.localStorage).filter(
|
|
1414
|
+
return Object.keys(window.localStorage).filter(key => key.startsWith(CACHE_KEY_PREFIX));
|
|
1414
1415
|
}
|
|
1415
1416
|
}
|
|
1416
1417
|
class InMemoryCache {
|
|
@@ -1545,10 +1546,10 @@
|
|
|
1545
1546
|
var _a;
|
|
1546
1547
|
const keys = await this.getCacheKeys();
|
|
1547
1548
|
if (!keys) return;
|
|
1548
|
-
await keys.filter(
|
|
1549
|
+
await keys.filter(key => clientId ? key.includes(clientId) : true).reduce(async (memo, key) => {
|
|
1549
1550
|
await memo;
|
|
1550
1551
|
await this.cache.remove(key);
|
|
1551
|
-
}
|
|
1552
|
+
}, Promise.resolve());
|
|
1552
1553
|
await ((_a = this.keyManifest) === null || _a === void 0 ? void 0 : _a.clear());
|
|
1553
1554
|
}
|
|
1554
1555
|
async wrapCacheEntry(entry) {
|
|
@@ -1573,14 +1574,14 @@
|
|
|
1573
1574
|
}, CACHE_KEY_PREFIX, CACHE_KEY_ID_TOKEN_SUFFIX).toKey();
|
|
1574
1575
|
}
|
|
1575
1576
|
matchExistingCacheKey(keyToMatch, allKeys) {
|
|
1576
|
-
return allKeys.filter(
|
|
1577
|
+
return allKeys.filter(key => {
|
|
1577
1578
|
var _a;
|
|
1578
1579
|
const cacheKey = CacheKey.fromKey(key);
|
|
1579
1580
|
const scopeSet = new Set(cacheKey.scope && cacheKey.scope.split(" "));
|
|
1580
1581
|
const scopesToMatch = ((_a = keyToMatch.scope) === null || _a === void 0 ? void 0 : _a.split(" ")) || [];
|
|
1581
|
-
const hasAllScopes = cacheKey.scope && scopesToMatch.reduce((
|
|
1582
|
+
const hasAllScopes = cacheKey.scope && scopesToMatch.reduce((acc, current) => acc && scopeSet.has(current), true);
|
|
1582
1583
|
return cacheKey.prefix === CACHE_KEY_PREFIX && cacheKey.clientId === keyToMatch.clientId && cacheKey.audience === keyToMatch.audience && hasAllScopes;
|
|
1583
|
-
})
|
|
1584
|
+
})[0];
|
|
1584
1585
|
}
|
|
1585
1586
|
async getEntryWithRefreshToken(keyToMatch, allKeys) {
|
|
1586
1587
|
var _a;
|
|
@@ -1644,12 +1645,12 @@
|
|
|
1644
1645
|
__raw: token
|
|
1645
1646
|
};
|
|
1646
1647
|
const user = {};
|
|
1647
|
-
Object.keys(payloadJSON).forEach(
|
|
1648
|
+
Object.keys(payloadJSON).forEach(k => {
|
|
1648
1649
|
claims[k] = payloadJSON[k];
|
|
1649
1650
|
if (!idTokendecoded.includes(k)) {
|
|
1650
1651
|
user[k] = payloadJSON[k];
|
|
1651
1652
|
}
|
|
1652
|
-
})
|
|
1653
|
+
});
|
|
1653
1654
|
return {
|
|
1654
1655
|
encoded: {
|
|
1655
1656
|
header: header,
|
|
@@ -1941,15 +1942,15 @@
|
|
|
1941
1942
|
return new Worker(url, options);
|
|
1942
1943
|
};
|
|
1943
1944
|
}
|
|
1944
|
-
var WorkerFactory = createBase64WorkerFactory("Lyogcm9sbHVwLXBsdWdpbi13ZWItd29ya2VyLWxvYWRlciAqLwooZnVuY3Rpb24oKSB7CiAgICAidXNlIHN0cmljdCI7CiAgICBjbGFzcyBHZW5lcmljRXJyb3IgZXh0ZW5kcyBFcnJvciB7CiAgICAgICAgY29uc3RydWN0b3IoZXJyb3IsIGVycm9yX2Rlc2NyaXB0aW9uKSB7CiAgICAgICAgICAgIHN1cGVyKGVycm9yX2Rlc2NyaXB0aW9uKTsKICAgICAgICAgICAgdGhpcy5lcnJvciA9IGVycm9yOwogICAgICAgICAgICB0aGlzLmVycm9yX2Rlc2NyaXB0aW9uID0gZXJyb3JfZGVzY3JpcHRpb247CiAgICAgICAgICAgIE9iamVjdC5zZXRQcm90b3R5cGVPZih0aGlzLCBHZW5lcmljRXJyb3IucHJvdG90eXBlKTsKICAgICAgICB9CiAgICAgICAgc3RhdGljIGZyb21QYXlsb2FkKF9yZWYpIHsKICAgICAgICAgICAgbGV0IHtlcnJvcjogZXJyb3IsIGVycm9yX2Rlc2NyaXB0aW9uOiBlcn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qge2F1ZGllbmNlOiBhdWRpZW5jZSwgc2NvcGU6IHNjb3BlfSA9IGF1dGggfHwge307CiAgICAgICAgdHJ5IHsKICAgICAgICAgICAgY29uc3QgYm9keSA9IHVzZUZvcm1EYXRhID8gZm9ybURhdGFUb09iamVjdChmZXRjaE9wdGlvbnMuYm9keSkgOiBKU09OLnBhcnNlKGZldGNoT3B0aW9ucy5ib2R5KTsKICAgICAgICAgICAgaWYgKCFib2R5LnJlZnJlc2hfdG9rZW4gJiYgYm9keS5ncmFudF90eXBlID09PSAicmVmcmVzaF90b2tlbiIpIHsKICAgICAgICAgICAgICAgIHJlZnJlc2hUb2tlbiA9IGdldFJlZnJlc2hUb2tlbihhdWRpZW5jZSwgc2NvcGUpOwogICAgICAgICAgICAgICAgaWYgKCFyZWZyZXNoVG9rZW4gJiYgdXNlTXJydCkgewogICAgICAgICAgICAgICAgICAgIGNvbnN0IGxhdGVzdFJlZnJlc2hUb2tlbiA9IHJlZnJlc2hUb2tlbnNbImxhdGVzdF9yZWZyZXNoX3Rva2VuIl07CiAgICAgICAgICAgICAgICAgICAgY29uc3QgaXNEb3duc2NvcGluZyA9IGNoZWNrRG93bnNjb3Bpbmcoc2NvcGUsIGF1ZGllbmNlKTsKICAgICAgICAgICAgICAgICAgICBpZiAobGF0ZXN0UmVmcmVzaFRva2VuICYmICFpc0Rvd25zY29waW5nKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHJlZnJlc2hUb2tlbiA9IGxhdGVzdFJlZnJlc2hUb2tlbjsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoIXJlZnJlc2hUb2tlbikgewogICAgICAgICAgICAgICAgICAgIHRocm93IG5ldyBNaXNzaW5nUmVmcmVzaFRva2VuRXJyb3IoYXVkaWVuY2UsIHNjb3BlKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGZldGNoT3B0aW9ucy5ib2R5ID0gdXNlRm9ybURhdGEgPyBjcmVhdGVRdWVyeVBhcmFtcyhPYmplY3QuYXNzaWduKE9iamVjdC5hc3NpZ24oe30sIGJvZHkpLCB7CiAgICAgICAgICAgICAgICAgICAgcmVmcmVzaF90b2tlbjogcmVmcmVzaFRva2VuCiAgICAgICAgICAgICAgICB9KSkgOiBKU09OLnN0cmluZ2lmeShPYmplY3QuYXNzaWduKE9iamVjdC5hc3NpZ24oe30sIGJvZHkpLCB7CiAgICAgICAgICAgICAgICAgICAgcmVmcmVzaF90b2tlbjogcmVmcmVzaFRva2VuCiAgICAgICAgICAgICAgICB9KSk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgbGV0IGFib3J0Q29udHJvbGxlcjsKICAgICAgICAgICAgaWYgKHR5cGVvZiBBYm9ydENvbnRyb2xsZXIgPT09ICJmdW5jdGlvbiIpIHsKICAgICAgICAgICAgICAgIGFib3J0Q29udHJvbGxlciA9IG5ldyBBYm9ydENvbnRyb2xsZXI7CiAgICAgICAgICAgICAgICBmZXRjaE9wdGlvbnMuc2lnbmFsID0gYWJvcnRDb250cm9sbGVyLnNpZ25hbDsKICAgICAgICAgICAgfQogICAgICAgICAgICBsZXQgcmVzcG9uc2U7CiAgICAgICAgICAgIHRyeSB7CiAgICAgICAgICAgICAgICByZXNwb25zZSA9IGF3YWl0IFByb21pc2UucmFjZShbIHdhaXQodGltZW91dCksIGZldGNoKGZldGNoVXJsLCBPYmplY3QuYXNzaWduKHt9LCBmZXRjaE9wdGlvbnMpKSBdKTsKICAgICAgICAgICAgfSBjYXRjaCAoZXJyb3IpIHsKICAgICAgICAgICAgICAgIHBvcnQucG9zdE1lc3NhZ2UoewogICAgICAgICAgICAgICAgICAgIGVycm9yOiBlcnJvci5tZXNzYWdlCiAgICAgICAgICAgICAgICB9KTsKICAgICAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoIXJlc3BvbnNlKSB7CiAgICAgICAgICAgICAgICBpZiAoYWJvcnRDb250cm9sbGVyKSBhYm9ydENvbnRyb2xsZXIuYWJvcnQoKTsKICAgICAgICAgICAgICAgIHBvcnQucG9zdE1lc3NhZ2UoewogICAgICAgICAgICAgICAgICAgIGVycm9yOiAiVGltZW91dCB3aGVuIGV4ZWN1dGluZyAnZmV0Y2gnIgogICAgICAgICAgICAgICAgfSk7CiAgICAgICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaGVhZGVycyA9IGZyb21FbnRyaWVzKHJlc3BvbnNlLmhlYWRlcnMpOwogICAgICAgICAgICBqc29uID0gYXdhaXQgcmVzcG9uc2UuanNvbigpOwogICAgICAgICAgICBpZiAoanNvbi5yZWZyZXNoX3Rva2VuKSB7CiAgICAgICAgICAgICAgICBpZiAodXNlTXJydCkgewogICAgICAgICAgICAgICAgICAgIHJlZnJlc2hUb2tlbnNbImxhdGVzdF9yZWZyZXNoX3Rva2VuIl0gPSBqc29uLnJlZnJlc2hfdG9rZW47CiAgICAgICAgICAgICAgICAgICAgdXBkYXRlUmVmcmVzaFRva2VucyhyZWZyZXNoVG9rZW4sIGpzb24ucmVmcmVzaF90b2tlbik7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzZXRSZWZyZXNoVG9rZW4oanNvbi5yZWZyZXNoX3Rva2VuLCBhdWRpZW5jZSwgc2NvcGUpOwogICAgICAgICAgICAgICAgZGVsZXRlIGpzb24ucmVmcmVzaF90b2tlbjsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIGRlbGV0ZVJlZnJlc2hUb2tlbihhdWRpZW5jZSwgc2NvcGUpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHBvcnQucG9zdE1lc3NhZ2UoewogICAgICAgICAgICAgICAgb2s6IHJlc3BvbnNlLm9rLAogICAgICAgICAgICAgICAganNvbjoganNvbiwKICAgICAgICAgICAgICAgIGhlYWRlcnM6IGhlYWRlcnMKICAgICAgICAgICAgfSk7CiAgICAgICAgfSBjYXRjaCAoZXJyb3IpIHsKICAgICAgICAgICAgcG9ydC5wb3N0TWVzc2FnZSh7CiAgICAgICAgICAgICAgICBvazogZmFsc2UsCiAgICAgICAgICAgICAgICBqc29uOiB7CiAgICAgICAgICAgICAgICAgICAgZXJyb3I6IGVycm9yLmVycm9yLAogICAgICAgICAgICAgICAgICAgIGVycm9yX2Rlc2NyaXB0aW9uOiBlcnJvci5tZXNzYWdlCiAgICAgICAgICAgICAgICB9LAogICAgICAgICAgICAgICAgaGVhZGVyczogaGVhZGVycwogICAgICAgICAgICB9KTsKICAgICAgICB9CiAgICB9OwogICAgewogICAgICAgIGFkZEV2ZW50TGlzdGVuZXIoIm1lc3NhZ2UiLCBtZXNzYWdlSGFuZGxlcik7CiAgICB9Cn0pKCk7Cgo=", null, false);
|
|
1945
|
+
var WorkerFactory = createBase64WorkerFactory("Lyogcm9sbHVwLXBsdWdpbi13ZWItd29ya2VyLWxvYWRlciAqLwooZnVuY3Rpb24oKSB7CiAgICAidXNlIHN0cmljdCI7CiAgICBjbGFzcyBHZW5lcmljRXJyb3IgZXh0ZW5kcyBFcnJvciB7CiAgICAgICAgY29uc3RydWN0b3IoZXJyb3IsIGVycm9yX2Rlc2NyaXB0aW9uKSB7CiAgICAgICAgICAgIHN1cGVyKGVycm9yX2Rlc2NyaXB0aW9uKTsKICAgICAgICAgICAgdGhpcy5lcnJvciA9IGVycm9yOwogICAgICAgICAgICB0aGlzLmVycm9yX2Rlc2NyaXB0aW9uID0gZXJyb3JfZGVzY3JpcHRpb247CiAgICAgICAgICAgIE9iamVjdC5zZXRQcm90b3R5cGVPZih0aGlzLCBHZW5lcmljRXJyb3IucHJvdG90eXBlKTsKICAgICAgICB9CiAgICAgICAgc3RhdGljIGZyb21QYXlsb2FkKF9yZWYpIHsKICAgICAgICAgICAgbGV0IHtlcnJvcjogZXJyb3IsIGVycm9yX2Rlc2NyaXB0aW9uOiBlcnJvcl9kZXNjcmlwdGlvbn0gPSBfcmVmOwogICAgICAgICAgICByZ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mNlLCBzY29wZSkgPT4gZGVsZXRlIHJlZnJlc2hUb2tlbnNbY2FjaGVLZXkoYXVkaWVuY2UsIHNjb3BlKV07CiAgICBjb25zdCB3YWl0ID0gdGltZSA9PiBuZXcgUHJvbWlzZShyZXNvbHZlID0+IHNldFRpbWVvdXQocmVzb2x2ZSwgdGltZSkpOwogICAgY29uc3QgZm9ybURhdGFUb09iamVjdCA9IGZvcm1EYXRhID0+IHsKICAgICAgICBjb25zdCBxdWVyeVBhcmFtcyA9IG5ldyBVUkxTZWFyY2hQYXJhbXMoZm9ybURhdGEpOwogICAgICAgIGNvbnN0IHBhcnNlZFF1ZXJ5ID0ge307CiAgICAgICAgcXVlcnlQYXJhbXMuZm9yRWFjaCgodmFsLCBrZXkpID0+IHsKICAgICAgICAgICAgcGFyc2VkUXVlcnlba2V5XSA9IHZhbDsKICAgICAgICB9KTsKICAgICAgICByZXR1cm4gcGFyc2VkUXVlcnk7CiAgICB9OwogICAgY29uc3QgdXBkYXRlUmVmcmVzaFRva2VucyA9IChvbGRSZWZyZXNoVG9rZW4sIG5ld1JlZnJlc2hUb2tlbikgPT4gewogICAgICAgIE9iamVjdC5lbnRyaWVzKHJlZnJlc2hUb2tlbnMpLmZvckVhY2goX3JlZiA9PiB7CiAgICAgICAgICAgIGxldCBba2V5LCB0b2tlbl0gPSBfcmVmOwogICAgICAgICAgICBpZiAodG9rZW4gPT09IG9sZFJlZnJlc2hUb2tlbikgewogICAgICAgICAgICAgICAgcmVmcmVzaFRva2Vuc1trZXldID0gbmV3UmVmcmVzaFRva2VuOwogICAgICAgICAgICB9CiAgICAgICAgfSk7CiAgICB9OwogICAgY29uc3QgY2hlY2tEb3duc2NvcGluZyA9IChzY29wZSwgYXVkaWVuY2UpID0+IHsKICAgICAgICBjb25zdCBmaW5kQ29pbmNpZGVuY2UgPSBPYmplY3Qua2V5cyhyZWZyZXNoVG9rZW5zKS5maW5kKGtleSA9PiB7CiAgICAgICAgICAgIGlmIChrZXkgIT09ICJs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ib2R5ID0gdXNlRm9ybURhdGEgPyBmb3JtRGF0YVRvT2JqZWN0KGZldGNoT3B0aW9ucy5ib2R5KSA6IEpTT04ucGFyc2UoZmV0Y2hPcHRpb25zLmJvZHkpOwogICAgICAgICAgICBpZiAoIWJvZHkucmVmcmVzaF90b2tlbiAmJiBib2R5LmdyYW50X3R5cGUgPT09ICJyZWZyZXNoX3Rva2VuIikgewogICAgICAgICAgICAgICAgcmVmcmVzaFRva2VuID0gZ2V0UmVmcmVzaFRva2VuKGF1ZGllbmNlLCBzY29wZSk7CiAgICAgICAgICAgICAgICBpZiAoIXJlZnJlc2hUb2tlbiAmJiB1c2VNcnJ0KSB7CiAgICAgICAgICAgICAgICAgICAgY29uc3QgbGF0ZXN0UmVmcmVzaFRva2VuID0gcmVmcmVzaFRva2Vuc1sibGF0ZXN0X3JlZnJlc2hfdG9rZW4iXTsKICAgICAgICAgICAgICAgICAgICBjb25zdCBpc0Rvd25zY29waW5nID0gY2hlY2tEb3duc2NvcGluZyhzY29wZSwgYXVkaWVuY2UpOwogICAgICAgICAgICAgICAgICAgIGlmIChsYXRlc3RSZWZyZXNoVG9rZW4gJiYgIWlzRG93bnNjb3BpbmcpIHsKICAgICAgICAgICAgICAgICAgICAgICAgcmVmcmVzaFRva2VuID0gbGF0ZXN0UmVmcmVzaFRva2VuOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmICghcmVmcmVzaFRva2VuKSB7CiAgICAgICAgICAgICAgICAgICAgdGhyb3cgbmV3IE1pc3NpbmdSZWZyZXNoVG9rZW5FcnJvcihhdWRpZW5jZSwgc2NvcGUpOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgZmV0Y2hPcHRpb25zLmJvZHkgPSB1c2VGb3JtRGF0YSA/IGNyZWF0ZVF1ZXJ5UGFyYW1zKE9iamVjdC5hc3NpZ24oT2JqZWN0LmFzc2lnbih7fSwgYm9keSksIHsKICAgICAgICAgICAgICAgICAgICByZWZyZXNoX3Rva2VuOiByZWZyZXNoVG9rZW4KICAgICAgICAgICAgICAgIH0pKSA6IEpTT04uc3RyaW5naWZ5KE9iamVjdC5hc3NpZ24oT2JqZWN0LmFzc2lnbih7fSwgYm9keSksIHsKICAgICAgICAgICAgICAgICAgICByZWZyZXNoX3Rva2VuOiByZWZyZXNoVG9rZW4KICAgICAgICAgICAgICAgIH0pKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBsZXQgYWJvcnRDb250cm9sbGVyOwogICAgICAgICAgICBpZiAodHlwZW9mIEFib3J0Q29udHJvbGxlciA9PT0gImZ1bmN0aW9uIikgewogICAgICAgICAgICAgICAgYWJvcnRDb250cm9sbGVyID0gbmV3IEFib3J0Q29udHJvbGxlcjsKICAgICAgICAgICAgICAgIGZldGNoT3B0aW9ucy5zaWduYWwgPSBhYm9ydENvbnRyb2xsZXIuc2lnbmFsOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGxldCByZXNwb25zZTsKICAgICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgICAgIHJlc3BvbnNlID0gYXdhaXQgUHJvbWlzZS5yYWNlKFsgd2FpdCh0aW1lb3V0KSwgZmV0Y2goZmV0Y2hVcmwsIE9iamVjdC5hc3NpZ24oe30sIGZldGNoT3B0aW9ucykpIF0pOwogICAgICAgICAgICB9IGNhdGNoIChlcnJvcikgewogICAgICAgICAgICAgICAgcG9ydC5wb3N0TWVzc2FnZSh7CiAgICAgICAgICAgICAgICAgICAgZXJyb3I6IGVycm9yLm1lc3NhZ2UKICAgICAgICAgICAgICAgIH0pOwogICAgICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmICghcmVzcG9uc2UpIHsKICAgICAgICAgICAgICAgIGlmIChhYm9ydENvbnRyb2xsZXIpIGFib3J0Q29udHJvbGxlci5hYm9ydCgpOwogICAgICAgICAgICAgICAgcG9ydC5wb3N0TWVzc2FnZSh7CiAgICAgICAgICAgICAgICAgICAgZXJyb3I6ICJUaW1lb3V0IHdoZW4gZXhlY3V0aW5nICdmZXRjaCciCiAgICAgICAgICAgICAgICB9KTsKICAgICAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgICAgfQogICAgICAgICAgICBoZWFkZXJzID0gZnJvbUVudHJpZXMocmVzcG9uc2UuaGVhZGVycyk7CiAgICAgICAgICAgIGpzb24gPSBhd2FpdCByZXNwb25zZS5qc29uKCk7CiAgICAgICAgICAgIGlmIChqc29uLnJlZnJlc2hfdG9rZW4pIHsKICAgICAgICAgICAgICAgIGlmICh1c2VNcnJ0KSB7CiAgICAgICAgICAgICAgICAgICAgcmVmcmVzaFRva2Vuc1sibGF0ZXN0X3JlZnJlc2hfdG9rZW4iXSA9IGpzb24ucmVmcmVzaF90b2tlbjsKICAgICAgICAgICAgICAgICAgICB1cGRhdGVSZWZyZXNoVG9rZW5zKHJlZnJlc2hUb2tlbiwganNvbi5yZWZyZXNoX3Rva2VuKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHNldFJlZnJlc2hUb2tlbihqc29uLnJlZnJlc2hfdG9rZW4sIGF1ZGllbmNlLCBzY29wZSk7CiAgICAgICAgICAgICAgICBkZWxldGUganNvbi5yZWZyZXNoX3Rva2VuOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgZGVsZXRlUmVmcmVzaFRva2VuKGF1ZGllbmNlLCBzY29wZSk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgcG9ydC5wb3N0TWVzc2FnZSh7CiAgICAgICAgICAgICAgICBvazogcmVzcG9uc2Uub2ssCiAgICAgICAgICAgICAgICBqc29uOiBqc29uLAogICAgICAgICAgICAgICAgaGVhZGVyczogaGVhZGVycwogICAgICAgICAgICB9KTsKICAgICAgICB9IGNhdGNoIChlcnJvcikgewogICAgICAgICAgICBwb3J0LnBvc3RNZXNzYWdlKHsKICAgICAgICAgICAgICAgIG9rOiBmYWxzZSwKICAgICAgICAgICAgICAgIGpzb246IHsKICAgICAgICAgICAgICAgICAgICBlcnJvcjogZXJyb3IuZXJyb3IsCiAgICAgICAgICAgICAgICAgICAgZXJyb3JfZGVzY3JpcHRpb246IGVycm9yLm1lc3NhZ2UKICAgICAgICAgICAgICAgIH0sCiAgICAgICAgICAgICAgICBoZWFkZXJzOiBoZWFkZXJzCiAgICAgICAgICAgIH0pOwogICAgICAgIH0KICAgIH07CiAgICB7CiAgICAgICAgYWRkRXZlbnRMaXN0ZW5lcigibWVzc2FnZSIsIG1lc3NhZ2VIYW5kbGVyKTsKICAgIH0KfSkoKTsKCg==", null, false);
|
|
1945
1946
|
const singlePromiseMap = {};
|
|
1946
1947
|
const singlePromise = (cb, key) => {
|
|
1947
1948
|
let promise = singlePromiseMap[key];
|
|
1948
1949
|
if (!promise) {
|
|
1949
|
-
promise = cb().finally((
|
|
1950
|
+
promise = cb().finally(() => {
|
|
1950
1951
|
delete singlePromiseMap[key];
|
|
1951
1952
|
promise = null;
|
|
1952
|
-
})
|
|
1953
|
+
});
|
|
1953
1954
|
singlePromiseMap[key] = promise;
|
|
1954
1955
|
}
|
|
1955
1956
|
return promise;
|
|
@@ -2026,12 +2027,12 @@
|
|
|
2026
2027
|
const allScopesAreIncluded = (scopeToInclude, scopes) => {
|
|
2027
2028
|
const scopeGroup = (scopes === null || scopes === void 0 ? void 0 : scopes.split(" ")) || [];
|
|
2028
2029
|
const scopesToInclude = (scopeToInclude === null || scopeToInclude === void 0 ? void 0 : scopeToInclude.split(" ")) || [];
|
|
2029
|
-
return scopesToInclude.every(
|
|
2030
|
+
return scopesToInclude.every(key => scopeGroup.includes(key));
|
|
2030
2031
|
};
|
|
2031
2032
|
const getMissingScopes = (requestedScope, respondedScope) => {
|
|
2032
2033
|
const requestedScopes = (requestedScope === null || requestedScope === void 0 ? void 0 : requestedScope.split(" ")) || [];
|
|
2033
2034
|
const respondedScopes = (respondedScope === null || respondedScope === void 0 ? void 0 : respondedScope.split(" ")) || [];
|
|
2034
|
-
const missingScopes = requestedScopes.filter(
|
|
2035
|
+
const missingScopes = requestedScopes.filter(scope => respondedScopes.indexOf(scope) == -1);
|
|
2035
2036
|
return missingScopes.join(",");
|
|
2036
2037
|
};
|
|
2037
2038
|
const getScopeToRequest = (useMrrt, authorizationParams, cachedAudience, cachedScope) => {
|
|
@@ -2042,7 +2043,7 @@
|
|
|
2042
2043
|
}
|
|
2043
2044
|
const cachedScopes = cachedScope.split(" ");
|
|
2044
2045
|
const newScopes = ((_a = authorizationParams.scope) === null || _a === void 0 ? void 0 : _a.split(" ")) || [];
|
|
2045
|
-
const newScopesAreIncluded = newScopes.every(
|
|
2046
|
+
const newScopesAreIncluded = newScopes.every(scope => cachedScopes.includes(scope));
|
|
2046
2047
|
return cachedScopes.length >= newScopes.length && newScopesAreIncluded ? cachedScope : authorizationParams.scope;
|
|
2047
2048
|
}
|
|
2048
2049
|
return authorizationParams.scope;
|
|
@@ -2069,11 +2070,11 @@
|
|
|
2069
2070
|
}
|
|
2070
2071
|
createDbHandle() {
|
|
2071
2072
|
const req = window.indexedDB.open(NAME, this.getVersion());
|
|
2072
|
-
return new Promise((
|
|
2073
|
-
req.onupgradeneeded = () => Object.values(TABLES).forEach(
|
|
2073
|
+
return new Promise((resolve, reject) => {
|
|
2074
|
+
req.onupgradeneeded = () => Object.values(TABLES).forEach(t => req.result.createObjectStore(t));
|
|
2074
2075
|
req.onerror = () => reject(req.error);
|
|
2075
2076
|
req.onsuccess = () => resolve(req.result);
|
|
2076
|
-
})
|
|
2077
|
+
});
|
|
2077
2078
|
}
|
|
2078
2079
|
async getDbHandle() {
|
|
2079
2080
|
if (!this.dbHandle) {
|
|
@@ -2086,10 +2087,10 @@
|
|
|
2086
2087
|
const txn = db.transaction(table, mode);
|
|
2087
2088
|
const store = txn.objectStore(table);
|
|
2088
2089
|
const request = requestFactory(store);
|
|
2089
|
-
return new Promise((
|
|
2090
|
+
return new Promise((resolve, reject) => {
|
|
2090
2091
|
request.onsuccess = () => resolve(request.result);
|
|
2091
2092
|
request.onerror = () => reject(request.error);
|
|
2092
|
-
})
|
|
2093
|
+
});
|
|
2093
2094
|
}
|
|
2094
2095
|
buildKey(id) {
|
|
2095
2096
|
const finalId = id ? "_".concat(id) : AUTH0_NONCE_ID;
|
|
@@ -2102,7 +2103,7 @@
|
|
|
2102
2103
|
return this.save(TABLES.KEYPAIR, this.buildKey(), keyPair);
|
|
2103
2104
|
}
|
|
2104
2105
|
async save(table, key, obj) {
|
|
2105
|
-
return void await this.executeDbRequest(table, "readwrite",
|
|
2106
|
+
return void await this.executeDbRequest(table, "readwrite", table => table.put(obj, key));
|
|
2106
2107
|
}
|
|
2107
2108
|
findNonce(id) {
|
|
2108
2109
|
return this.find(TABLES.NONCE, this.buildKey(id));
|
|
@@ -2111,14 +2112,14 @@
|
|
|
2111
2112
|
return this.find(TABLES.KEYPAIR, this.buildKey());
|
|
2112
2113
|
}
|
|
2113
2114
|
find(table, key) {
|
|
2114
|
-
return this.executeDbRequest(table, "readonly",
|
|
2115
|
+
return this.executeDbRequest(table, "readonly", table => table.get(key));
|
|
2115
2116
|
}
|
|
2116
2117
|
async deleteBy(table, predicate) {
|
|
2117
|
-
const allKeys = await this.executeDbRequest(table, "readonly",
|
|
2118
|
-
allKeys === null || allKeys === void 0 ? void 0 : allKeys.filter(predicate).map(
|
|
2118
|
+
const allKeys = await this.executeDbRequest(table, "readonly", table => table.getAllKeys());
|
|
2119
|
+
allKeys === null || allKeys === void 0 ? void 0 : allKeys.filter(predicate).map(k => this.executeDbRequest(table, "readwrite", table => table.delete(k)));
|
|
2119
2120
|
}
|
|
2120
2121
|
deleteByClientId(table, clientId) {
|
|
2121
|
-
return this.deleteBy(table,
|
|
2122
|
+
return this.deleteBy(table, k => typeof k === "string" && k.startsWith("".concat(clientId, "::")));
|
|
2122
2123
|
}
|
|
2123
2124
|
clearNonces() {
|
|
2124
2125
|
return this.deleteByClientId(TABLES.NONCE, this.clientId);
|
|
@@ -2428,20 +2429,20 @@
|
|
|
2428
2429
|
var t = Object.keys(e);
|
|
2429
2430
|
if (Object.getOwnPropertySymbols) {
|
|
2430
2431
|
var o = Object.getOwnPropertySymbols(e);
|
|
2431
|
-
r && (o = o.filter(
|
|
2432
|
+
r && (o = o.filter(function(r) {
|
|
2432
2433
|
return Object.getOwnPropertyDescriptor(e, r).enumerable;
|
|
2433
|
-
}))
|
|
2434
|
+
})), t.push.apply(t, o);
|
|
2434
2435
|
}
|
|
2435
2436
|
return t;
|
|
2436
2437
|
}
|
|
2437
2438
|
function _objectSpread2(e) {
|
|
2438
2439
|
for (var r = 1; r < arguments.length; r++) {
|
|
2439
2440
|
var t = null != arguments[r] ? arguments[r] : {};
|
|
2440
|
-
r % 2 ? ownKeys(Object(t), !0).forEach(
|
|
2441
|
+
r % 2 ? ownKeys(Object(t), !0).forEach(function(r) {
|
|
2441
2442
|
_defineProperty(e, r, t[r]);
|
|
2442
|
-
})
|
|
2443
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r) {
|
|
2443
2444
|
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
|
|
2444
|
-
})
|
|
2445
|
+
});
|
|
2445
2446
|
}
|
|
2446
2447
|
return e;
|
|
2447
2448
|
}
|
|
@@ -2487,16 +2488,16 @@
|
|
|
2487
2488
|
function resume(r, t) {
|
|
2488
2489
|
try {
|
|
2489
2490
|
var n = e[r](t), o = n.value, u = o instanceof _OverloadYield;
|
|
2490
|
-
Promise.resolve(u ? o.v : o).then(
|
|
2491
|
+
Promise.resolve(u ? o.v : o).then(function(t) {
|
|
2491
2492
|
if (u) {
|
|
2492
2493
|
var i = "return" === r ? "return" : "next";
|
|
2493
2494
|
if (!o.k || t.done) return resume(i, t);
|
|
2494
2495
|
t = e[i](t).value;
|
|
2495
2496
|
}
|
|
2496
2497
|
settle(n.done ? "return" : "normal", t);
|
|
2497
|
-
}
|
|
2498
|
+
}, function(e) {
|
|
2498
2499
|
resume("throw", e);
|
|
2499
|
-
})
|
|
2500
|
+
});
|
|
2500
2501
|
} catch (e) {
|
|
2501
2502
|
settle("throw", e);
|
|
2502
2503
|
}
|
|
@@ -2523,7 +2524,7 @@
|
|
|
2523
2524
|
(r = r.next) ? resume(r.key, r.arg) : t = null;
|
|
2524
2525
|
}
|
|
2525
2526
|
this._invoke = function(e, n) {
|
|
2526
|
-
return new Promise(
|
|
2527
|
+
return new Promise(function(o, u) {
|
|
2527
2528
|
var i = {
|
|
2528
2529
|
key: e,
|
|
2529
2530
|
arg: n,
|
|
@@ -2532,7 +2533,7 @@
|
|
|
2532
2533
|
next: null
|
|
2533
2534
|
};
|
|
2534
2535
|
t ? t = t.next = i : (r = t = i, resume(e, n));
|
|
2535
|
-
})
|
|
2536
|
+
});
|
|
2536
2537
|
}, "function" != typeof e.return && (this.return = void 0);
|
|
2537
2538
|
}
|
|
2538
2539
|
AsyncGenerator.prototype["function" == typeof Symbol && Symbol.asyncIterator || "@@asyncIterator"] = function() {
|
|
@@ -2548,7 +2549,7 @@
|
|
|
2548
2549
|
let USER_AGENT$2;
|
|
2549
2550
|
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 "))) {
|
|
2550
2551
|
const NAME = "oauth4webapi";
|
|
2551
|
-
const VERSION = "v3.8.
|
|
2552
|
+
const VERSION = "v3.8.5";
|
|
2552
2553
|
USER_AGENT$2 = "".concat(NAME, "/").concat(VERSION);
|
|
2553
2554
|
}
|
|
2554
2555
|
function looseInstanceOf(input, expected) {
|
|
@@ -2747,7 +2748,7 @@
|
|
|
2747
2748
|
});
|
|
2748
2749
|
}
|
|
2749
2750
|
async function discoveryRequest(issuerIdentifier, options) {
|
|
2750
|
-
return performDiscovery$1(issuerIdentifier, "issuerIdentifier",
|
|
2751
|
+
return performDiscovery$1(issuerIdentifier, "issuerIdentifier", url => {
|
|
2751
2752
|
switch (options === null || options === void 0 ? void 0 : options.algorithm) {
|
|
2752
2753
|
case undefined:
|
|
2753
2754
|
case "oidc":
|
|
@@ -2762,7 +2763,7 @@
|
|
|
2762
2763
|
throw CodedTypeError$1('"options.algorithm" must be "oidc" (default), or "oauth2"', ERR_INVALID_ARG_VALUE$1);
|
|
2763
2764
|
}
|
|
2764
2765
|
return url;
|
|
2765
|
-
}
|
|
2766
|
+
}, options);
|
|
2766
2767
|
}
|
|
2767
2768
|
function assertNumber(input, allow0, it, code, cause) {
|
|
2768
2769
|
try {
|
|
@@ -3998,10 +3999,10 @@
|
|
|
3998
3999
|
for (var _len = arguments.length, buffers = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
3999
4000
|
buffers[_key] = arguments[_key];
|
|
4000
4001
|
}
|
|
4001
|
-
const size = buffers.reduce((
|
|
4002
|
+
const size = buffers.reduce((acc, _ref) => {
|
|
4002
4003
|
let {length: length} = _ref;
|
|
4003
4004
|
return acc + length;
|
|
4004
|
-
}
|
|
4005
|
+
}, 0);
|
|
4005
4006
|
const buf = new Uint8Array(size);
|
|
4006
4007
|
let i = 0;
|
|
4007
4008
|
for (const buffer of buffers) {
|
|
@@ -4049,6 +4050,135 @@
|
|
|
4049
4050
|
throw new TypeError("The input to be decoded is not correctly encoded.");
|
|
4050
4051
|
}
|
|
4051
4052
|
}
|
|
4053
|
+
const unusable = function unusable(name) {
|
|
4054
|
+
let prop = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "algorithm.name";
|
|
4055
|
+
return new TypeError("CryptoKey does not support this operation, its ".concat(prop, " must be ").concat(name));
|
|
4056
|
+
};
|
|
4057
|
+
const isAlgorithm = (algorithm, name) => algorithm.name === name;
|
|
4058
|
+
function getHashLength(hash) {
|
|
4059
|
+
return parseInt(hash.name.slice(4), 10);
|
|
4060
|
+
}
|
|
4061
|
+
function checkHashLength(algorithm, expected) {
|
|
4062
|
+
const actual = getHashLength(algorithm.hash);
|
|
4063
|
+
if (actual !== expected) throw unusable("SHA-".concat(expected), "algorithm.hash");
|
|
4064
|
+
}
|
|
4065
|
+
function getNamedCurve(alg) {
|
|
4066
|
+
switch (alg) {
|
|
4067
|
+
case "ES256":
|
|
4068
|
+
return "P-256";
|
|
4069
|
+
|
|
4070
|
+
case "ES384":
|
|
4071
|
+
return "P-384";
|
|
4072
|
+
|
|
4073
|
+
case "ES512":
|
|
4074
|
+
return "P-521";
|
|
4075
|
+
|
|
4076
|
+
default:
|
|
4077
|
+
throw new Error("unreachable");
|
|
4078
|
+
}
|
|
4079
|
+
}
|
|
4080
|
+
function checkUsage(key, usage) {
|
|
4081
|
+
if (usage && !key.usages.includes(usage)) {
|
|
4082
|
+
throw new TypeError("CryptoKey does not support this operation, its usages must include ".concat(usage, "."));
|
|
4083
|
+
}
|
|
4084
|
+
}
|
|
4085
|
+
function checkSigCryptoKey(key, alg, usage) {
|
|
4086
|
+
switch (alg) {
|
|
4087
|
+
case "HS256":
|
|
4088
|
+
case "HS384":
|
|
4089
|
+
case "HS512":
|
|
4090
|
+
{
|
|
4091
|
+
if (!isAlgorithm(key.algorithm, "HMAC")) throw unusable("HMAC");
|
|
4092
|
+
checkHashLength(key.algorithm, parseInt(alg.slice(2), 10));
|
|
4093
|
+
break;
|
|
4094
|
+
}
|
|
4095
|
+
|
|
4096
|
+
case "RS256":
|
|
4097
|
+
case "RS384":
|
|
4098
|
+
case "RS512":
|
|
4099
|
+
{
|
|
4100
|
+
if (!isAlgorithm(key.algorithm, "RSASSA-PKCS1-v1_5")) throw unusable("RSASSA-PKCS1-v1_5");
|
|
4101
|
+
checkHashLength(key.algorithm, parseInt(alg.slice(2), 10));
|
|
4102
|
+
break;
|
|
4103
|
+
}
|
|
4104
|
+
|
|
4105
|
+
case "PS256":
|
|
4106
|
+
case "PS384":
|
|
4107
|
+
case "PS512":
|
|
4108
|
+
{
|
|
4109
|
+
if (!isAlgorithm(key.algorithm, "RSA-PSS")) throw unusable("RSA-PSS");
|
|
4110
|
+
checkHashLength(key.algorithm, parseInt(alg.slice(2), 10));
|
|
4111
|
+
break;
|
|
4112
|
+
}
|
|
4113
|
+
|
|
4114
|
+
case "Ed25519":
|
|
4115
|
+
case "EdDSA":
|
|
4116
|
+
{
|
|
4117
|
+
if (!isAlgorithm(key.algorithm, "Ed25519")) throw unusable("Ed25519");
|
|
4118
|
+
break;
|
|
4119
|
+
}
|
|
4120
|
+
|
|
4121
|
+
case "ML-DSA-44":
|
|
4122
|
+
case "ML-DSA-65":
|
|
4123
|
+
case "ML-DSA-87":
|
|
4124
|
+
{
|
|
4125
|
+
if (!isAlgorithm(key.algorithm, alg)) throw unusable(alg);
|
|
4126
|
+
break;
|
|
4127
|
+
}
|
|
4128
|
+
|
|
4129
|
+
case "ES256":
|
|
4130
|
+
case "ES384":
|
|
4131
|
+
case "ES512":
|
|
4132
|
+
{
|
|
4133
|
+
if (!isAlgorithm(key.algorithm, "ECDSA")) throw unusable("ECDSA");
|
|
4134
|
+
const expected = getNamedCurve(alg);
|
|
4135
|
+
const actual = key.algorithm.namedCurve;
|
|
4136
|
+
if (actual !== expected) throw unusable(expected, "algorithm.namedCurve");
|
|
4137
|
+
break;
|
|
4138
|
+
}
|
|
4139
|
+
|
|
4140
|
+
default:
|
|
4141
|
+
throw new TypeError("CryptoKey does not support this operation");
|
|
4142
|
+
}
|
|
4143
|
+
checkUsage(key, usage);
|
|
4144
|
+
}
|
|
4145
|
+
function message(msg, actual) {
|
|
4146
|
+
for (var _len = arguments.length, types = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
|
|
4147
|
+
types[_key - 2] = arguments[_key];
|
|
4148
|
+
}
|
|
4149
|
+
types = types.filter(Boolean);
|
|
4150
|
+
if (types.length > 2) {
|
|
4151
|
+
const last = types.pop();
|
|
4152
|
+
msg += "one of type ".concat(types.join(", "), ", or ").concat(last, ".");
|
|
4153
|
+
} else if (types.length === 2) {
|
|
4154
|
+
msg += "one of type ".concat(types[0], " or ").concat(types[1], ".");
|
|
4155
|
+
} else {
|
|
4156
|
+
msg += "of type ".concat(types[0], ".");
|
|
4157
|
+
}
|
|
4158
|
+
if (actual == null) {
|
|
4159
|
+
msg += " Received ".concat(actual);
|
|
4160
|
+
} else if (typeof actual === "function" && actual.name) {
|
|
4161
|
+
msg += " Received function ".concat(actual.name);
|
|
4162
|
+
} else if (typeof actual === "object" && actual != null) {
|
|
4163
|
+
var _actual$constructor;
|
|
4164
|
+
if ((_actual$constructor = actual.constructor) !== null && _actual$constructor !== void 0 && _actual$constructor.name) {
|
|
4165
|
+
msg += " Received an instance of ".concat(actual.constructor.name);
|
|
4166
|
+
}
|
|
4167
|
+
}
|
|
4168
|
+
return msg;
|
|
4169
|
+
}
|
|
4170
|
+
const invalidKeyInput = function invalidKeyInput(actual) {
|
|
4171
|
+
for (var _len2 = arguments.length, types = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
4172
|
+
types[_key2 - 1] = arguments[_key2];
|
|
4173
|
+
}
|
|
4174
|
+
return message("Key must be ", actual, ...types);
|
|
4175
|
+
};
|
|
4176
|
+
const withAlg = function withAlg(alg, actual) {
|
|
4177
|
+
for (var _len3 = arguments.length, types = new Array(_len3 > 2 ? _len3 - 2 : 0), _key3 = 2; _key3 < _len3; _key3++) {
|
|
4178
|
+
types[_key3 - 2] = arguments[_key3];
|
|
4179
|
+
}
|
|
4180
|
+
return message("Key for the ".concat(alg, " algorithm must be "), actual, ...types);
|
|
4181
|
+
};
|
|
4052
4182
|
class JOSEError extends Error {
|
|
4053
4183
|
constructor(message, options) {
|
|
4054
4184
|
var _Error$captureStackTr;
|
|
@@ -4196,147 +4326,37 @@
|
|
|
4196
4326
|
}
|
|
4197
4327
|
}
|
|
4198
4328
|
_defineProperty(JWSSignatureVerificationFailed, "code", "ERR_JWS_SIGNATURE_VERIFICATION_FAILED");
|
|
4199
|
-
const
|
|
4200
|
-
|
|
4201
|
-
|
|
4329
|
+
const isCryptoKey = key => {
|
|
4330
|
+
if ((key === null || key === void 0 ? void 0 : key[Symbol.toStringTag]) === "CryptoKey") return true;
|
|
4331
|
+
try {
|
|
4332
|
+
return key instanceof CryptoKey;
|
|
4333
|
+
} catch (_unused) {
|
|
4334
|
+
return false;
|
|
4335
|
+
}
|
|
4202
4336
|
};
|
|
4203
|
-
const
|
|
4204
|
-
|
|
4205
|
-
|
|
4206
|
-
|
|
4207
|
-
|
|
4208
|
-
|
|
4209
|
-
|
|
4210
|
-
return "P-256";
|
|
4211
|
-
|
|
4212
|
-
case "ES384":
|
|
4213
|
-
return "P-384";
|
|
4214
|
-
|
|
4215
|
-
case "ES512":
|
|
4216
|
-
return "P-521";
|
|
4217
|
-
|
|
4218
|
-
default:
|
|
4219
|
-
throw new Error("unreachable");
|
|
4337
|
+
const isKeyObject = key => (key === null || key === void 0 ? void 0 : key[Symbol.toStringTag]) === "KeyObject";
|
|
4338
|
+
const isKeyLike = key => isCryptoKey(key) || isKeyObject(key);
|
|
4339
|
+
function decodeBase64url(value, label, ErrorClass) {
|
|
4340
|
+
try {
|
|
4341
|
+
return decode(value);
|
|
4342
|
+
} catch (_unused) {
|
|
4343
|
+
throw new ErrorClass("Failed to base64url decode the ".concat(label));
|
|
4220
4344
|
}
|
|
4221
4345
|
}
|
|
4222
|
-
|
|
4223
|
-
|
|
4224
|
-
|
|
4346
|
+
const isObjectLike = value => typeof value === "object" && value !== null;
|
|
4347
|
+
function isObject(input) {
|
|
4348
|
+
if (!isObjectLike(input) || Object.prototype.toString.call(input) !== "[object Object]") {
|
|
4349
|
+
return false;
|
|
4225
4350
|
}
|
|
4351
|
+
if (Object.getPrototypeOf(input) === null) {
|
|
4352
|
+
return true;
|
|
4353
|
+
}
|
|
4354
|
+
let proto = input;
|
|
4355
|
+
while (Object.getPrototypeOf(proto) !== null) {
|
|
4356
|
+
proto = Object.getPrototypeOf(proto);
|
|
4357
|
+
}
|
|
4358
|
+
return Object.getPrototypeOf(input) === proto;
|
|
4226
4359
|
}
|
|
4227
|
-
function checkSigCryptoKey(key, alg, usage) {
|
|
4228
|
-
switch (alg) {
|
|
4229
|
-
case "HS256":
|
|
4230
|
-
case "HS384":
|
|
4231
|
-
case "HS512":
|
|
4232
|
-
{
|
|
4233
|
-
if (!isAlgorithm(key.algorithm, "HMAC")) throw unusable("HMAC");
|
|
4234
|
-
const expected = parseInt(alg.slice(2), 10);
|
|
4235
|
-
const actual = getHashLength(key.algorithm.hash);
|
|
4236
|
-
if (actual !== expected) throw unusable("SHA-".concat(expected), "algorithm.hash");
|
|
4237
|
-
break;
|
|
4238
|
-
}
|
|
4239
|
-
|
|
4240
|
-
case "RS256":
|
|
4241
|
-
case "RS384":
|
|
4242
|
-
case "RS512":
|
|
4243
|
-
{
|
|
4244
|
-
if (!isAlgorithm(key.algorithm, "RSASSA-PKCS1-v1_5")) throw unusable("RSASSA-PKCS1-v1_5");
|
|
4245
|
-
const expected = parseInt(alg.slice(2), 10);
|
|
4246
|
-
const actual = getHashLength(key.algorithm.hash);
|
|
4247
|
-
if (actual !== expected) throw unusable("SHA-".concat(expected), "algorithm.hash");
|
|
4248
|
-
break;
|
|
4249
|
-
}
|
|
4250
|
-
|
|
4251
|
-
case "PS256":
|
|
4252
|
-
case "PS384":
|
|
4253
|
-
case "PS512":
|
|
4254
|
-
{
|
|
4255
|
-
if (!isAlgorithm(key.algorithm, "RSA-PSS")) throw unusable("RSA-PSS");
|
|
4256
|
-
const expected = parseInt(alg.slice(2), 10);
|
|
4257
|
-
const actual = getHashLength(key.algorithm.hash);
|
|
4258
|
-
if (actual !== expected) throw unusable("SHA-".concat(expected), "algorithm.hash");
|
|
4259
|
-
break;
|
|
4260
|
-
}
|
|
4261
|
-
|
|
4262
|
-
case "Ed25519":
|
|
4263
|
-
case "EdDSA":
|
|
4264
|
-
{
|
|
4265
|
-
if (!isAlgorithm(key.algorithm, "Ed25519")) throw unusable("Ed25519");
|
|
4266
|
-
break;
|
|
4267
|
-
}
|
|
4268
|
-
|
|
4269
|
-
case "ML-DSA-44":
|
|
4270
|
-
case "ML-DSA-65":
|
|
4271
|
-
case "ML-DSA-87":
|
|
4272
|
-
{
|
|
4273
|
-
if (!isAlgorithm(key.algorithm, alg)) throw unusable(alg);
|
|
4274
|
-
break;
|
|
4275
|
-
}
|
|
4276
|
-
|
|
4277
|
-
case "ES256":
|
|
4278
|
-
case "ES384":
|
|
4279
|
-
case "ES512":
|
|
4280
|
-
{
|
|
4281
|
-
if (!isAlgorithm(key.algorithm, "ECDSA")) throw unusable("ECDSA");
|
|
4282
|
-
const expected = getNamedCurve(alg);
|
|
4283
|
-
const actual = key.algorithm.namedCurve;
|
|
4284
|
-
if (actual !== expected) throw unusable(expected, "algorithm.namedCurve");
|
|
4285
|
-
break;
|
|
4286
|
-
}
|
|
4287
|
-
|
|
4288
|
-
default:
|
|
4289
|
-
throw new TypeError("CryptoKey does not support this operation");
|
|
4290
|
-
}
|
|
4291
|
-
checkUsage(key, usage);
|
|
4292
|
-
}
|
|
4293
|
-
function message(msg, actual) {
|
|
4294
|
-
for (var _len = arguments.length, types = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
|
|
4295
|
-
types[_key - 2] = arguments[_key];
|
|
4296
|
-
}
|
|
4297
|
-
types = types.filter(Boolean);
|
|
4298
|
-
if (types.length > 2) {
|
|
4299
|
-
const last = types.pop();
|
|
4300
|
-
msg += "one of type ".concat(types.join(", "), ", or ").concat(last, ".");
|
|
4301
|
-
} else if (types.length === 2) {
|
|
4302
|
-
msg += "one of type ".concat(types[0], " or ").concat(types[1], ".");
|
|
4303
|
-
} else {
|
|
4304
|
-
msg += "of type ".concat(types[0], ".");
|
|
4305
|
-
}
|
|
4306
|
-
if (actual == null) {
|
|
4307
|
-
msg += " Received ".concat(actual);
|
|
4308
|
-
} else if (typeof actual === "function" && actual.name) {
|
|
4309
|
-
msg += " Received function ".concat(actual.name);
|
|
4310
|
-
} else if (typeof actual === "object" && actual != null) {
|
|
4311
|
-
var _actual$constructor;
|
|
4312
|
-
if ((_actual$constructor = actual.constructor) !== null && _actual$constructor !== void 0 && _actual$constructor.name) {
|
|
4313
|
-
msg += " Received an instance of ".concat(actual.constructor.name);
|
|
4314
|
-
}
|
|
4315
|
-
}
|
|
4316
|
-
return msg;
|
|
4317
|
-
}
|
|
4318
|
-
const invalidKeyInput = function invalidKeyInput(actual) {
|
|
4319
|
-
for (var _len2 = arguments.length, types = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
4320
|
-
types[_key2 - 1] = arguments[_key2];
|
|
4321
|
-
}
|
|
4322
|
-
return message("Key must be ", actual, ...types);
|
|
4323
|
-
};
|
|
4324
|
-
const withAlg = function withAlg(alg, actual) {
|
|
4325
|
-
for (var _len3 = arguments.length, types = new Array(_len3 > 2 ? _len3 - 2 : 0), _key3 = 2; _key3 < _len3; _key3++) {
|
|
4326
|
-
types[_key3 - 2] = arguments[_key3];
|
|
4327
|
-
}
|
|
4328
|
-
return message("Key for the ".concat(alg, " algorithm must be "), actual, ...types);
|
|
4329
|
-
};
|
|
4330
|
-
const isCryptoKey = key => {
|
|
4331
|
-
if ((key === null || key === void 0 ? void 0 : key[Symbol.toStringTag]) === "CryptoKey") return true;
|
|
4332
|
-
try {
|
|
4333
|
-
return key instanceof CryptoKey;
|
|
4334
|
-
} catch (_unused) {
|
|
4335
|
-
return false;
|
|
4336
|
-
}
|
|
4337
|
-
};
|
|
4338
|
-
const isKeyObject = key => (key === null || key === void 0 ? void 0 : key[Symbol.toStringTag]) === "KeyObject";
|
|
4339
|
-
const isKeyLike = key => isCryptoKey(key) || isKeyObject(key);
|
|
4340
4360
|
function isDisjoint() {
|
|
4341
4361
|
for (var _len = arguments.length, headers = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
4342
4362
|
headers[_key] = arguments[_key];
|
|
@@ -4361,20 +4381,10 @@
|
|
|
4361
4381
|
}
|
|
4362
4382
|
return true;
|
|
4363
4383
|
}
|
|
4364
|
-
const
|
|
4365
|
-
|
|
4366
|
-
|
|
4367
|
-
|
|
4368
|
-
}
|
|
4369
|
-
if (Object.getPrototypeOf(input) === null) {
|
|
4370
|
-
return true;
|
|
4371
|
-
}
|
|
4372
|
-
let proto = input;
|
|
4373
|
-
while (Object.getPrototypeOf(proto) !== null) {
|
|
4374
|
-
proto = Object.getPrototypeOf(proto);
|
|
4375
|
-
}
|
|
4376
|
-
return Object.getPrototypeOf(input) === proto;
|
|
4377
|
-
}
|
|
4384
|
+
const isJWK = key => isObject(key) && typeof key.kty === "string";
|
|
4385
|
+
const isPrivateJWK = key => key.kty !== "oct" && (key.kty === "AKP" && typeof key.priv === "string" || typeof key.d === "string");
|
|
4386
|
+
const isPublicJWK = key => key.kty !== "oct" && key.d === undefined && key.priv === undefined;
|
|
4387
|
+
const isSecretJWK = key => key.kty === "oct" && typeof key.k === "string";
|
|
4378
4388
|
function checkKeyLength(alg, key) {
|
|
4379
4389
|
if (alg.startsWith("RS") || alg.startsWith("PS")) {
|
|
4380
4390
|
const {modulusLength: modulusLength} = key.algorithm;
|
|
@@ -4383,198 +4393,84 @@
|
|
|
4383
4393
|
}
|
|
4384
4394
|
}
|
|
4385
4395
|
}
|
|
4386
|
-
|
|
4387
|
-
|
|
4388
|
-
for (let i = 0; i < a.byteLength; i++) {
|
|
4389
|
-
if (a[i] !== b[i]) return false;
|
|
4390
|
-
}
|
|
4391
|
-
return true;
|
|
4392
|
-
};
|
|
4393
|
-
const createASN1State = data => ({
|
|
4394
|
-
data: data,
|
|
4395
|
-
pos: 0
|
|
4396
|
-
});
|
|
4397
|
-
const parseLength = state => {
|
|
4398
|
-
const first = state.data[state.pos++];
|
|
4399
|
-
if (first & 128) {
|
|
4400
|
-
const lengthOfLen = first & 127;
|
|
4401
|
-
let length = 0;
|
|
4402
|
-
for (let i = 0; i < lengthOfLen; i++) {
|
|
4403
|
-
length = length << 8 | state.data[state.pos++];
|
|
4404
|
-
}
|
|
4405
|
-
return length;
|
|
4406
|
-
}
|
|
4407
|
-
return first;
|
|
4408
|
-
};
|
|
4409
|
-
const expectTag = (state, expectedTag, errorMessage) => {
|
|
4410
|
-
if (state.data[state.pos++] !== expectedTag) {
|
|
4411
|
-
throw new Error(errorMessage);
|
|
4412
|
-
}
|
|
4413
|
-
};
|
|
4414
|
-
const getSubarray = (state, length) => {
|
|
4415
|
-
const result = state.data.subarray(state.pos, state.pos + length);
|
|
4416
|
-
state.pos += length;
|
|
4417
|
-
return result;
|
|
4418
|
-
};
|
|
4419
|
-
const parseAlgorithmOID = state => {
|
|
4420
|
-
expectTag(state, 6, "Expected algorithm OID");
|
|
4421
|
-
const oidLen = parseLength(state);
|
|
4422
|
-
return getSubarray(state, oidLen);
|
|
4423
|
-
};
|
|
4424
|
-
function parsePKCS8Header(state) {
|
|
4425
|
-
expectTag(state, 48, "Invalid PKCS#8 structure");
|
|
4426
|
-
parseLength(state);
|
|
4427
|
-
expectTag(state, 2, "Expected version field");
|
|
4428
|
-
const verLen = parseLength(state);
|
|
4429
|
-
state.pos += verLen;
|
|
4430
|
-
expectTag(state, 48, "Expected algorithm identifier");
|
|
4431
|
-
const algIdLen = parseLength(state);
|
|
4432
|
-
const algIdStart = state.pos;
|
|
4433
|
-
return {
|
|
4434
|
-
algIdStart: algIdStart,
|
|
4435
|
-
algIdLength: algIdLen
|
|
4436
|
-
};
|
|
4437
|
-
}
|
|
4438
|
-
const parseECAlgorithmIdentifier = state => {
|
|
4439
|
-
const algOid = parseAlgorithmOID(state);
|
|
4440
|
-
if (bytesEqual(algOid, [ 43, 101, 110 ])) {
|
|
4441
|
-
return "X25519";
|
|
4442
|
-
}
|
|
4443
|
-
if (!bytesEqual(algOid, [ 42, 134, 72, 206, 61, 2, 1 ])) {
|
|
4444
|
-
throw new Error("Unsupported key algorithm");
|
|
4445
|
-
}
|
|
4446
|
-
expectTag(state, 6, "Expected curve OID");
|
|
4447
|
-
const curveOidLen = parseLength(state);
|
|
4448
|
-
const curveOid = getSubarray(state, curveOidLen);
|
|
4449
|
-
for (const {name: name, oid: oid} of [ {
|
|
4450
|
-
name: "P-256",
|
|
4451
|
-
oid: [ 42, 134, 72, 206, 61, 3, 1, 7 ]
|
|
4452
|
-
}, {
|
|
4453
|
-
name: "P-384",
|
|
4454
|
-
oid: [ 43, 129, 4, 0, 34 ]
|
|
4455
|
-
}, {
|
|
4456
|
-
name: "P-521",
|
|
4457
|
-
oid: [ 43, 129, 4, 0, 35 ]
|
|
4458
|
-
} ]) {
|
|
4459
|
-
if (bytesEqual(curveOid, oid)) {
|
|
4460
|
-
return name;
|
|
4461
|
-
}
|
|
4462
|
-
}
|
|
4463
|
-
throw new Error("Unsupported named curve");
|
|
4464
|
-
};
|
|
4465
|
-
const genericImport = async (keyFormat, keyData, alg, options) => {
|
|
4466
|
-
var _options$extractable;
|
|
4467
|
-
let algorithm;
|
|
4468
|
-
let keyUsages;
|
|
4469
|
-
const isPublic = keyFormat === "spki";
|
|
4470
|
-
const getSigUsages = () => isPublic ? [ "verify" ] : [ "sign" ];
|
|
4471
|
-
const getEncUsages = () => isPublic ? [ "encrypt", "wrapKey" ] : [ "decrypt", "unwrapKey" ];
|
|
4396
|
+
function subtleAlgorithm(alg, algorithm) {
|
|
4397
|
+
const hash = "SHA-".concat(alg.slice(-3));
|
|
4472
4398
|
switch (alg) {
|
|
4399
|
+
case "HS256":
|
|
4400
|
+
case "HS384":
|
|
4401
|
+
case "HS512":
|
|
4402
|
+
return {
|
|
4403
|
+
hash: hash,
|
|
4404
|
+
name: "HMAC"
|
|
4405
|
+
};
|
|
4406
|
+
|
|
4473
4407
|
case "PS256":
|
|
4474
4408
|
case "PS384":
|
|
4475
4409
|
case "PS512":
|
|
4476
|
-
|
|
4410
|
+
return {
|
|
4411
|
+
hash: hash,
|
|
4477
4412
|
name: "RSA-PSS",
|
|
4478
|
-
|
|
4413
|
+
saltLength: parseInt(alg.slice(-3), 10) >> 3
|
|
4479
4414
|
};
|
|
4480
|
-
keyUsages = getSigUsages();
|
|
4481
|
-
break;
|
|
4482
4415
|
|
|
4483
4416
|
case "RS256":
|
|
4484
4417
|
case "RS384":
|
|
4485
4418
|
case "RS512":
|
|
4486
|
-
|
|
4487
|
-
|
|
4488
|
-
|
|
4489
|
-
};
|
|
4490
|
-
keyUsages = getSigUsages();
|
|
4491
|
-
break;
|
|
4492
|
-
|
|
4493
|
-
case "RSA-OAEP":
|
|
4494
|
-
case "RSA-OAEP-256":
|
|
4495
|
-
case "RSA-OAEP-384":
|
|
4496
|
-
case "RSA-OAEP-512":
|
|
4497
|
-
algorithm = {
|
|
4498
|
-
name: "RSA-OAEP",
|
|
4499
|
-
hash: "SHA-".concat(parseInt(alg.slice(-3), 10) || 1)
|
|
4419
|
+
return {
|
|
4420
|
+
hash: hash,
|
|
4421
|
+
name: "RSASSA-PKCS1-v1_5"
|
|
4500
4422
|
};
|
|
4501
|
-
keyUsages = getEncUsages();
|
|
4502
|
-
break;
|
|
4503
4423
|
|
|
4504
4424
|
case "ES256":
|
|
4505
4425
|
case "ES384":
|
|
4506
4426
|
case "ES512":
|
|
4507
|
-
{
|
|
4508
|
-
|
|
4509
|
-
|
|
4510
|
-
|
|
4511
|
-
|
|
4512
|
-
};
|
|
4513
|
-
algorithm = {
|
|
4514
|
-
name: "ECDSA",
|
|
4515
|
-
namedCurve: curveMap[alg]
|
|
4516
|
-
};
|
|
4517
|
-
keyUsages = getSigUsages();
|
|
4518
|
-
break;
|
|
4519
|
-
}
|
|
4520
|
-
|
|
4521
|
-
case "ECDH-ES":
|
|
4522
|
-
case "ECDH-ES+A128KW":
|
|
4523
|
-
case "ECDH-ES+A192KW":
|
|
4524
|
-
case "ECDH-ES+A256KW":
|
|
4525
|
-
{
|
|
4526
|
-
try {
|
|
4527
|
-
const namedCurve = options.getNamedCurve(keyData);
|
|
4528
|
-
algorithm = namedCurve === "X25519" ? {
|
|
4529
|
-
name: "X25519"
|
|
4530
|
-
} : {
|
|
4531
|
-
name: "ECDH",
|
|
4532
|
-
namedCurve: namedCurve
|
|
4533
|
-
};
|
|
4534
|
-
} catch (cause) {
|
|
4535
|
-
throw new JOSENotSupported("Invalid or unsupported key format");
|
|
4536
|
-
}
|
|
4537
|
-
keyUsages = isPublic ? [] : [ "deriveBits" ];
|
|
4538
|
-
break;
|
|
4539
|
-
}
|
|
4427
|
+
return {
|
|
4428
|
+
hash: hash,
|
|
4429
|
+
name: "ECDSA",
|
|
4430
|
+
namedCurve: algorithm.namedCurve
|
|
4431
|
+
};
|
|
4540
4432
|
|
|
4541
4433
|
case "Ed25519":
|
|
4542
4434
|
case "EdDSA":
|
|
4543
|
-
|
|
4435
|
+
return {
|
|
4544
4436
|
name: "Ed25519"
|
|
4545
4437
|
};
|
|
4546
|
-
keyUsages = getSigUsages();
|
|
4547
|
-
break;
|
|
4548
4438
|
|
|
4549
4439
|
case "ML-DSA-44":
|
|
4550
4440
|
case "ML-DSA-65":
|
|
4551
4441
|
case "ML-DSA-87":
|
|
4552
|
-
|
|
4442
|
+
return {
|
|
4553
4443
|
name: alg
|
|
4554
4444
|
};
|
|
4555
|
-
keyUsages = getSigUsages();
|
|
4556
|
-
break;
|
|
4557
4445
|
|
|
4558
4446
|
default:
|
|
4559
|
-
throw new JOSENotSupported(
|
|
4447
|
+
throw new JOSENotSupported("alg ".concat(alg, " is not supported either by JOSE or your javascript runtime"));
|
|
4560
4448
|
}
|
|
4561
|
-
|
|
4562
|
-
|
|
4563
|
-
|
|
4564
|
-
|
|
4565
|
-
|
|
4566
|
-
|
|
4567
|
-
|
|
4568
|
-
|
|
4569
|
-
|
|
4570
|
-
|
|
4571
|
-
const state = createASN1State(keyData);
|
|
4572
|
-
parsePKCS8Header(state);
|
|
4573
|
-
return parseECAlgorithmIdentifier(state);
|
|
4574
|
-
};
|
|
4449
|
+
}
|
|
4450
|
+
async function getSigKey(alg, key, usage) {
|
|
4451
|
+
if (key instanceof Uint8Array) {
|
|
4452
|
+
if (!alg.startsWith("HS")) {
|
|
4453
|
+
throw new TypeError(invalidKeyInput(key, "CryptoKey", "KeyObject", "JSON Web Key"));
|
|
4454
|
+
}
|
|
4455
|
+
return crypto.subtle.importKey("raw", key, {
|
|
4456
|
+
hash: "SHA-".concat(alg.slice(-3)),
|
|
4457
|
+
name: "HMAC"
|
|
4458
|
+
}, false, [ usage ]);
|
|
4575
4459
|
}
|
|
4576
|
-
|
|
4577
|
-
|
|
4460
|
+
checkSigCryptoKey(key, alg, usage);
|
|
4461
|
+
return key;
|
|
4462
|
+
}
|
|
4463
|
+
async function verify(alg, key, signature, data) {
|
|
4464
|
+
const cryptoKey = await getSigKey(alg, key, "verify");
|
|
4465
|
+
checkKeyLength(alg, cryptoKey);
|
|
4466
|
+
const algorithm = subtleAlgorithm(alg, cryptoKey.algorithm);
|
|
4467
|
+
try {
|
|
4468
|
+
return await crypto.subtle.verify(algorithm, cryptoKey, signature, data);
|
|
4469
|
+
} catch (_unused) {
|
|
4470
|
+
return false;
|
|
4471
|
+
}
|
|
4472
|
+
}
|
|
4473
|
+
const unsupportedAlg = 'Invalid or unsupported JWK "alg" (Algorithm) Parameter value';
|
|
4578
4474
|
function subtleMapping(jwk) {
|
|
4579
4475
|
let algorithm;
|
|
4580
4476
|
let keyUsages;
|
|
@@ -4592,7 +4488,7 @@
|
|
|
4592
4488
|
break;
|
|
4593
4489
|
|
|
4594
4490
|
default:
|
|
4595
|
-
throw new JOSENotSupported(
|
|
4491
|
+
throw new JOSENotSupported(unsupportedAlg);
|
|
4596
4492
|
}
|
|
4597
4493
|
break;
|
|
4598
4494
|
}
|
|
@@ -4632,7 +4528,7 @@
|
|
|
4632
4528
|
break;
|
|
4633
4529
|
|
|
4634
4530
|
default:
|
|
4635
|
-
throw new JOSENotSupported(
|
|
4531
|
+
throw new JOSENotSupported(unsupportedAlg);
|
|
4636
4532
|
}
|
|
4637
4533
|
break;
|
|
4638
4534
|
}
|
|
@@ -4641,25 +4537,15 @@
|
|
|
4641
4537
|
{
|
|
4642
4538
|
switch (jwk.alg) {
|
|
4643
4539
|
case "ES256":
|
|
4644
|
-
algorithm = {
|
|
4645
|
-
name: "ECDSA",
|
|
4646
|
-
namedCurve: "P-256"
|
|
4647
|
-
};
|
|
4648
|
-
keyUsages = jwk.d ? [ "sign" ] : [ "verify" ];
|
|
4649
|
-
break;
|
|
4650
|
-
|
|
4651
4540
|
case "ES384":
|
|
4652
|
-
algorithm = {
|
|
4653
|
-
name: "ECDSA",
|
|
4654
|
-
namedCurve: "P-384"
|
|
4655
|
-
};
|
|
4656
|
-
keyUsages = jwk.d ? [ "sign" ] : [ "verify" ];
|
|
4657
|
-
break;
|
|
4658
|
-
|
|
4659
4541
|
case "ES512":
|
|
4660
4542
|
algorithm = {
|
|
4661
4543
|
name: "ECDSA",
|
|
4662
|
-
namedCurve:
|
|
4544
|
+
namedCurve: {
|
|
4545
|
+
ES256: "P-256",
|
|
4546
|
+
ES384: "P-384",
|
|
4547
|
+
ES512: "P-521"
|
|
4548
|
+
}[jwk.alg]
|
|
4663
4549
|
};
|
|
4664
4550
|
keyUsages = jwk.d ? [ "sign" ] : [ "verify" ];
|
|
4665
4551
|
break;
|
|
@@ -4676,7 +4562,7 @@
|
|
|
4676
4562
|
break;
|
|
4677
4563
|
|
|
4678
4564
|
default:
|
|
4679
|
-
throw new JOSENotSupported(
|
|
4565
|
+
throw new JOSENotSupported(unsupportedAlg);
|
|
4680
4566
|
}
|
|
4681
4567
|
break;
|
|
4682
4568
|
}
|
|
@@ -4703,7 +4589,7 @@
|
|
|
4703
4589
|
break;
|
|
4704
4590
|
|
|
4705
4591
|
default:
|
|
4706
|
-
throw new JOSENotSupported(
|
|
4592
|
+
throw new JOSENotSupported(unsupportedAlg);
|
|
4707
4593
|
}
|
|
4708
4594
|
break;
|
|
4709
4595
|
}
|
|
@@ -4729,102 +4615,7 @@
|
|
|
4729
4615
|
delete keyData.use;
|
|
4730
4616
|
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);
|
|
4731
4617
|
}
|
|
4732
|
-
|
|
4733
|
-
if (typeof pkcs8 !== "string" || pkcs8.indexOf("-----BEGIN PRIVATE KEY-----") !== 0) {
|
|
4734
|
-
throw new TypeError('"pkcs8" must be PKCS#8 formatted string');
|
|
4735
|
-
}
|
|
4736
|
-
return fromPKCS8(pkcs8, alg, options);
|
|
4737
|
-
}
|
|
4738
|
-
async function importJWK(jwk, alg, options) {
|
|
4739
|
-
var _options$extractable;
|
|
4740
|
-
if (!isObject(jwk)) {
|
|
4741
|
-
throw new TypeError("JWK must be an object");
|
|
4742
|
-
}
|
|
4743
|
-
let ext;
|
|
4744
|
-
alg !== null && alg !== void 0 ? alg : alg = jwk.alg;
|
|
4745
|
-
ext !== null && ext !== void 0 ? ext : ext = (_options$extractable = options === null || options === void 0 ? void 0 : options.extractable) !== null && _options$extractable !== void 0 ? _options$extractable : jwk.ext;
|
|
4746
|
-
switch (jwk.kty) {
|
|
4747
|
-
case "oct":
|
|
4748
|
-
if (typeof jwk.k !== "string" || !jwk.k) {
|
|
4749
|
-
throw new TypeError('missing "k" (Key Value) Parameter value');
|
|
4750
|
-
}
|
|
4751
|
-
return decode(jwk.k);
|
|
4752
|
-
|
|
4753
|
-
case "RSA":
|
|
4754
|
-
if ("oth" in jwk && jwk.oth !== undefined) {
|
|
4755
|
-
throw new JOSENotSupported('RSA JWK "oth" (Other Primes Info) Parameter value is not supported');
|
|
4756
|
-
}
|
|
4757
|
-
return jwkToKey(_objectSpread2(_objectSpread2({}, jwk), {}, {
|
|
4758
|
-
alg: alg,
|
|
4759
|
-
ext: ext
|
|
4760
|
-
}));
|
|
4761
|
-
|
|
4762
|
-
case "AKP":
|
|
4763
|
-
{
|
|
4764
|
-
if (typeof jwk.alg !== "string" || !jwk.alg) {
|
|
4765
|
-
throw new TypeError('missing "alg" (Algorithm) Parameter value');
|
|
4766
|
-
}
|
|
4767
|
-
if (alg !== undefined && alg !== jwk.alg) {
|
|
4768
|
-
throw new TypeError("JWK alg and alg option value mismatch");
|
|
4769
|
-
}
|
|
4770
|
-
return jwkToKey(_objectSpread2(_objectSpread2({}, jwk), {}, {
|
|
4771
|
-
ext: ext
|
|
4772
|
-
}));
|
|
4773
|
-
}
|
|
4774
|
-
|
|
4775
|
-
case "EC":
|
|
4776
|
-
case "OKP":
|
|
4777
|
-
return jwkToKey(_objectSpread2(_objectSpread2({}, jwk), {}, {
|
|
4778
|
-
alg: alg,
|
|
4779
|
-
ext: ext
|
|
4780
|
-
}));
|
|
4781
|
-
|
|
4782
|
-
default:
|
|
4783
|
-
throw new JOSENotSupported('Unsupported "kty" (Key Type) Parameter value');
|
|
4784
|
-
}
|
|
4785
|
-
}
|
|
4786
|
-
function validateCrit(Err, recognizedDefault, recognizedOption, protectedHeader, joseHeader) {
|
|
4787
|
-
if (joseHeader.crit !== undefined && (protectedHeader === null || protectedHeader === void 0 ? void 0 : protectedHeader.crit) === undefined) {
|
|
4788
|
-
throw new Err('"crit" (Critical) Header Parameter MUST be integrity protected');
|
|
4789
|
-
}
|
|
4790
|
-
if (!protectedHeader || protectedHeader.crit === undefined) {
|
|
4791
|
-
return new Set;
|
|
4792
|
-
}
|
|
4793
|
-
if (!Array.isArray(protectedHeader.crit) || protectedHeader.crit.length === 0 || protectedHeader.crit.some((input => typeof input !== "string" || input.length === 0))) {
|
|
4794
|
-
throw new Err('"crit" (Critical) Header Parameter MUST be an array of non-empty strings when present');
|
|
4795
|
-
}
|
|
4796
|
-
let recognized;
|
|
4797
|
-
if (recognizedOption !== undefined) {
|
|
4798
|
-
recognized = new Map([ ...Object.entries(recognizedOption), ...recognizedDefault.entries() ]);
|
|
4799
|
-
} else {
|
|
4800
|
-
recognized = recognizedDefault;
|
|
4801
|
-
}
|
|
4802
|
-
for (const parameter of protectedHeader.crit) {
|
|
4803
|
-
if (!recognized.has(parameter)) {
|
|
4804
|
-
throw new JOSENotSupported('Extension Header Parameter "'.concat(parameter, '" is not recognized'));
|
|
4805
|
-
}
|
|
4806
|
-
if (joseHeader[parameter] === undefined) {
|
|
4807
|
-
throw new Err('Extension Header Parameter "'.concat(parameter, '" is missing'));
|
|
4808
|
-
}
|
|
4809
|
-
if (recognized.get(parameter) && protectedHeader[parameter] === undefined) {
|
|
4810
|
-
throw new Err('Extension Header Parameter "'.concat(parameter, '" MUST be integrity protected'));
|
|
4811
|
-
}
|
|
4812
|
-
}
|
|
4813
|
-
return new Set(protectedHeader.crit);
|
|
4814
|
-
}
|
|
4815
|
-
function validateAlgorithms(option, algorithms) {
|
|
4816
|
-
if (algorithms !== undefined && (!Array.isArray(algorithms) || algorithms.some((s => typeof s !== "string")))) {
|
|
4817
|
-
throw new TypeError('"'.concat(option, '" option must be an array of strings'));
|
|
4818
|
-
}
|
|
4819
|
-
if (!algorithms) {
|
|
4820
|
-
return undefined;
|
|
4821
|
-
}
|
|
4822
|
-
return new Set(algorithms);
|
|
4823
|
-
}
|
|
4824
|
-
const isJWK = key => isObject(key) && typeof key.kty === "string";
|
|
4825
|
-
const isPrivateJWK = key => key.kty !== "oct" && (key.kty === "AKP" && typeof key.priv === "string" || typeof key.d === "string");
|
|
4826
|
-
const isPublicJWK = key => key.kty !== "oct" && key.d === undefined && key.priv === undefined;
|
|
4827
|
-
const isSecretJWK = key => key.kty === "oct" && typeof key.k === "string";
|
|
4618
|
+
const unusableForAlg = "given KeyObject instance cannot be used for this algorithm";
|
|
4828
4619
|
let cache;
|
|
4829
4620
|
const handleJWK = async function handleJWK(key, jwk, alg) {
|
|
4830
4621
|
let freeze = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
@@ -4864,13 +4655,13 @@
|
|
|
4864
4655
|
break;
|
|
4865
4656
|
|
|
4866
4657
|
default:
|
|
4867
|
-
throw new TypeError(
|
|
4658
|
+
throw new TypeError(unusableForAlg);
|
|
4868
4659
|
}
|
|
4869
4660
|
cryptoKey = keyObject.toCryptoKey(keyObject.asymmetricKeyType, extractable, isPublic ? [] : [ "deriveBits" ]);
|
|
4870
4661
|
}
|
|
4871
4662
|
if (keyObject.asymmetricKeyType === "ed25519") {
|
|
4872
4663
|
if (alg !== "EdDSA" && alg !== "Ed25519") {
|
|
4873
|
-
throw new TypeError(
|
|
4664
|
+
throw new TypeError(unusableForAlg);
|
|
4874
4665
|
}
|
|
4875
4666
|
cryptoKey = keyObject.toCryptoKey(keyObject.asymmetricKeyType, extractable, [ isPublic ? "verify" : "sign" ]);
|
|
4876
4667
|
}
|
|
@@ -4880,7 +4671,7 @@
|
|
|
4880
4671
|
case "ml-dsa-87":
|
|
4881
4672
|
{
|
|
4882
4673
|
if (alg !== keyObject.asymmetricKeyType.toUpperCase()) {
|
|
4883
|
-
throw new TypeError(
|
|
4674
|
+
throw new TypeError(unusableForAlg);
|
|
4884
4675
|
}
|
|
4885
4676
|
cryptoKey = keyObject.toCryptoKey(keyObject.asymmetricKeyType, extractable, [ isPublic ? "verify" : "sign" ]);
|
|
4886
4677
|
}
|
|
@@ -4911,7 +4702,7 @@
|
|
|
4911
4702
|
break;
|
|
4912
4703
|
|
|
4913
4704
|
default:
|
|
4914
|
-
throw new TypeError(
|
|
4705
|
+
throw new TypeError(unusableForAlg);
|
|
4915
4706
|
}
|
|
4916
4707
|
if (alg.startsWith("RSA-OAEP")) {
|
|
4917
4708
|
return keyObject.toCryptoKey({
|
|
@@ -4929,21 +4720,14 @@
|
|
|
4929
4720
|
const nist = new Map([ [ "prime256v1", "P-256" ], [ "secp384r1", "P-384" ], [ "secp521r1", "P-521" ] ]);
|
|
4930
4721
|
const namedCurve = nist.get((_keyObject$asymmetric = keyObject.asymmetricKeyDetails) === null || _keyObject$asymmetric === void 0 ? void 0 : _keyObject$asymmetric.namedCurve);
|
|
4931
4722
|
if (!namedCurve) {
|
|
4932
|
-
throw new TypeError(
|
|
4933
|
-
}
|
|
4934
|
-
if (alg === "ES256" && namedCurve === "P-256") {
|
|
4935
|
-
cryptoKey = keyObject.toCryptoKey({
|
|
4936
|
-
name: "ECDSA",
|
|
4937
|
-
namedCurve: namedCurve
|
|
4938
|
-
}, extractable, [ isPublic ? "verify" : "sign" ]);
|
|
4723
|
+
throw new TypeError(unusableForAlg);
|
|
4939
4724
|
}
|
|
4940
|
-
|
|
4941
|
-
|
|
4942
|
-
|
|
4943
|
-
|
|
4944
|
-
|
|
4945
|
-
|
|
4946
|
-
if (alg === "ES512" && namedCurve === "P-521") {
|
|
4725
|
+
const expectedCurve = {
|
|
4726
|
+
ES256: "P-256",
|
|
4727
|
+
ES384: "P-384",
|
|
4728
|
+
ES512: "P-521"
|
|
4729
|
+
};
|
|
4730
|
+
if (expectedCurve[alg] && namedCurve === expectedCurve[alg]) {
|
|
4947
4731
|
cryptoKey = keyObject.toCryptoKey({
|
|
4948
4732
|
name: "ECDSA",
|
|
4949
4733
|
namedCurve: namedCurve
|
|
@@ -4956,50 +4740,334 @@
|
|
|
4956
4740
|
}, extractable, isPublic ? [] : [ "deriveBits" ]);
|
|
4957
4741
|
}
|
|
4958
4742
|
}
|
|
4959
|
-
if (!cryptoKey) {
|
|
4960
|
-
throw new TypeError(
|
|
4743
|
+
if (!cryptoKey) {
|
|
4744
|
+
throw new TypeError(unusableForAlg);
|
|
4745
|
+
}
|
|
4746
|
+
if (!cached) {
|
|
4747
|
+
cache.set(keyObject, {
|
|
4748
|
+
[alg]: cryptoKey
|
|
4749
|
+
});
|
|
4750
|
+
} else {
|
|
4751
|
+
cached[alg] = cryptoKey;
|
|
4752
|
+
}
|
|
4753
|
+
return cryptoKey;
|
|
4754
|
+
};
|
|
4755
|
+
async function normalizeKey(key, alg) {
|
|
4756
|
+
if (key instanceof Uint8Array) {
|
|
4757
|
+
return key;
|
|
4758
|
+
}
|
|
4759
|
+
if (isCryptoKey(key)) {
|
|
4760
|
+
return key;
|
|
4761
|
+
}
|
|
4762
|
+
if (isKeyObject(key)) {
|
|
4763
|
+
if (key.type === "secret") {
|
|
4764
|
+
return key.export();
|
|
4765
|
+
}
|
|
4766
|
+
if ("toCryptoKey" in key && typeof key.toCryptoKey === "function") {
|
|
4767
|
+
try {
|
|
4768
|
+
return handleKeyObject(key, alg);
|
|
4769
|
+
} catch (err) {
|
|
4770
|
+
if (err instanceof TypeError) {
|
|
4771
|
+
throw err;
|
|
4772
|
+
}
|
|
4773
|
+
}
|
|
4774
|
+
}
|
|
4775
|
+
let jwk = key.export({
|
|
4776
|
+
format: "jwk"
|
|
4777
|
+
});
|
|
4778
|
+
return handleJWK(key, jwk, alg);
|
|
4779
|
+
}
|
|
4780
|
+
if (isJWK(key)) {
|
|
4781
|
+
if (key.k) {
|
|
4782
|
+
return decode(key.k);
|
|
4783
|
+
}
|
|
4784
|
+
return handleJWK(key, key, alg, true);
|
|
4785
|
+
}
|
|
4786
|
+
throw new Error("unreachable");
|
|
4787
|
+
}
|
|
4788
|
+
const bytesEqual = (a, b) => {
|
|
4789
|
+
if (a.byteLength !== b.length) return false;
|
|
4790
|
+
for (let i = 0; i < a.byteLength; i++) {
|
|
4791
|
+
if (a[i] !== b[i]) return false;
|
|
4792
|
+
}
|
|
4793
|
+
return true;
|
|
4794
|
+
};
|
|
4795
|
+
const createASN1State = data => ({
|
|
4796
|
+
data: data,
|
|
4797
|
+
pos: 0
|
|
4798
|
+
});
|
|
4799
|
+
const parseLength = state => {
|
|
4800
|
+
const first = state.data[state.pos++];
|
|
4801
|
+
if (first & 128) {
|
|
4802
|
+
const lengthOfLen = first & 127;
|
|
4803
|
+
let length = 0;
|
|
4804
|
+
for (let i = 0; i < lengthOfLen; i++) {
|
|
4805
|
+
length = length << 8 | state.data[state.pos++];
|
|
4806
|
+
}
|
|
4807
|
+
return length;
|
|
4808
|
+
}
|
|
4809
|
+
return first;
|
|
4810
|
+
};
|
|
4811
|
+
const expectTag = (state, expectedTag, errorMessage) => {
|
|
4812
|
+
if (state.data[state.pos++] !== expectedTag) {
|
|
4813
|
+
throw new Error(errorMessage);
|
|
4814
|
+
}
|
|
4815
|
+
};
|
|
4816
|
+
const getSubarray = (state, length) => {
|
|
4817
|
+
const result = state.data.subarray(state.pos, state.pos + length);
|
|
4818
|
+
state.pos += length;
|
|
4819
|
+
return result;
|
|
4820
|
+
};
|
|
4821
|
+
const parseAlgorithmOID = state => {
|
|
4822
|
+
expectTag(state, 6, "Expected algorithm OID");
|
|
4823
|
+
const oidLen = parseLength(state);
|
|
4824
|
+
return getSubarray(state, oidLen);
|
|
4825
|
+
};
|
|
4826
|
+
function parsePKCS8Header(state) {
|
|
4827
|
+
expectTag(state, 48, "Invalid PKCS#8 structure");
|
|
4828
|
+
parseLength(state);
|
|
4829
|
+
expectTag(state, 2, "Expected version field");
|
|
4830
|
+
const verLen = parseLength(state);
|
|
4831
|
+
state.pos += verLen;
|
|
4832
|
+
expectTag(state, 48, "Expected algorithm identifier");
|
|
4833
|
+
const algIdLen = parseLength(state);
|
|
4834
|
+
const algIdStart = state.pos;
|
|
4835
|
+
return {
|
|
4836
|
+
algIdStart: algIdStart,
|
|
4837
|
+
algIdLength: algIdLen
|
|
4838
|
+
};
|
|
4839
|
+
}
|
|
4840
|
+
const parseECAlgorithmIdentifier = state => {
|
|
4841
|
+
const algOid = parseAlgorithmOID(state);
|
|
4842
|
+
if (bytesEqual(algOid, [ 43, 101, 110 ])) {
|
|
4843
|
+
return "X25519";
|
|
4844
|
+
}
|
|
4845
|
+
if (!bytesEqual(algOid, [ 42, 134, 72, 206, 61, 2, 1 ])) {
|
|
4846
|
+
throw new Error("Unsupported key algorithm");
|
|
4847
|
+
}
|
|
4848
|
+
expectTag(state, 6, "Expected curve OID");
|
|
4849
|
+
const curveOidLen = parseLength(state);
|
|
4850
|
+
const curveOid = getSubarray(state, curveOidLen);
|
|
4851
|
+
for (const {name: name, oid: oid} of [ {
|
|
4852
|
+
name: "P-256",
|
|
4853
|
+
oid: [ 42, 134, 72, 206, 61, 3, 1, 7 ]
|
|
4854
|
+
}, {
|
|
4855
|
+
name: "P-384",
|
|
4856
|
+
oid: [ 43, 129, 4, 0, 34 ]
|
|
4857
|
+
}, {
|
|
4858
|
+
name: "P-521",
|
|
4859
|
+
oid: [ 43, 129, 4, 0, 35 ]
|
|
4860
|
+
} ]) {
|
|
4861
|
+
if (bytesEqual(curveOid, oid)) {
|
|
4862
|
+
return name;
|
|
4863
|
+
}
|
|
4864
|
+
}
|
|
4865
|
+
throw new Error("Unsupported named curve");
|
|
4866
|
+
};
|
|
4867
|
+
const genericImport = async (keyFormat, keyData, alg, options) => {
|
|
4868
|
+
var _options$extractable;
|
|
4869
|
+
let algorithm;
|
|
4870
|
+
let keyUsages;
|
|
4871
|
+
const isPublic = keyFormat === "spki";
|
|
4872
|
+
const getSigUsages = () => isPublic ? [ "verify" ] : [ "sign" ];
|
|
4873
|
+
const getEncUsages = () => isPublic ? [ "encrypt", "wrapKey" ] : [ "decrypt", "unwrapKey" ];
|
|
4874
|
+
switch (alg) {
|
|
4875
|
+
case "PS256":
|
|
4876
|
+
case "PS384":
|
|
4877
|
+
case "PS512":
|
|
4878
|
+
algorithm = {
|
|
4879
|
+
name: "RSA-PSS",
|
|
4880
|
+
hash: "SHA-".concat(alg.slice(-3))
|
|
4881
|
+
};
|
|
4882
|
+
keyUsages = getSigUsages();
|
|
4883
|
+
break;
|
|
4884
|
+
|
|
4885
|
+
case "RS256":
|
|
4886
|
+
case "RS384":
|
|
4887
|
+
case "RS512":
|
|
4888
|
+
algorithm = {
|
|
4889
|
+
name: "RSASSA-PKCS1-v1_5",
|
|
4890
|
+
hash: "SHA-".concat(alg.slice(-3))
|
|
4891
|
+
};
|
|
4892
|
+
keyUsages = getSigUsages();
|
|
4893
|
+
break;
|
|
4894
|
+
|
|
4895
|
+
case "RSA-OAEP":
|
|
4896
|
+
case "RSA-OAEP-256":
|
|
4897
|
+
case "RSA-OAEP-384":
|
|
4898
|
+
case "RSA-OAEP-512":
|
|
4899
|
+
algorithm = {
|
|
4900
|
+
name: "RSA-OAEP",
|
|
4901
|
+
hash: "SHA-".concat(parseInt(alg.slice(-3), 10) || 1)
|
|
4902
|
+
};
|
|
4903
|
+
keyUsages = getEncUsages();
|
|
4904
|
+
break;
|
|
4905
|
+
|
|
4906
|
+
case "ES256":
|
|
4907
|
+
case "ES384":
|
|
4908
|
+
case "ES512":
|
|
4909
|
+
{
|
|
4910
|
+
const curveMap = {
|
|
4911
|
+
ES256: "P-256",
|
|
4912
|
+
ES384: "P-384",
|
|
4913
|
+
ES512: "P-521"
|
|
4914
|
+
};
|
|
4915
|
+
algorithm = {
|
|
4916
|
+
name: "ECDSA",
|
|
4917
|
+
namedCurve: curveMap[alg]
|
|
4918
|
+
};
|
|
4919
|
+
keyUsages = getSigUsages();
|
|
4920
|
+
break;
|
|
4921
|
+
}
|
|
4922
|
+
|
|
4923
|
+
case "ECDH-ES":
|
|
4924
|
+
case "ECDH-ES+A128KW":
|
|
4925
|
+
case "ECDH-ES+A192KW":
|
|
4926
|
+
case "ECDH-ES+A256KW":
|
|
4927
|
+
{
|
|
4928
|
+
try {
|
|
4929
|
+
const namedCurve = options.getNamedCurve(keyData);
|
|
4930
|
+
algorithm = namedCurve === "X25519" ? {
|
|
4931
|
+
name: "X25519"
|
|
4932
|
+
} : {
|
|
4933
|
+
name: "ECDH",
|
|
4934
|
+
namedCurve: namedCurve
|
|
4935
|
+
};
|
|
4936
|
+
} catch (cause) {
|
|
4937
|
+
throw new JOSENotSupported("Invalid or unsupported key format");
|
|
4938
|
+
}
|
|
4939
|
+
keyUsages = isPublic ? [] : [ "deriveBits" ];
|
|
4940
|
+
break;
|
|
4941
|
+
}
|
|
4942
|
+
|
|
4943
|
+
case "Ed25519":
|
|
4944
|
+
case "EdDSA":
|
|
4945
|
+
algorithm = {
|
|
4946
|
+
name: "Ed25519"
|
|
4947
|
+
};
|
|
4948
|
+
keyUsages = getSigUsages();
|
|
4949
|
+
break;
|
|
4950
|
+
|
|
4951
|
+
case "ML-DSA-44":
|
|
4952
|
+
case "ML-DSA-65":
|
|
4953
|
+
case "ML-DSA-87":
|
|
4954
|
+
algorithm = {
|
|
4955
|
+
name: alg
|
|
4956
|
+
};
|
|
4957
|
+
keyUsages = getSigUsages();
|
|
4958
|
+
break;
|
|
4959
|
+
|
|
4960
|
+
default:
|
|
4961
|
+
throw new JOSENotSupported('Invalid or unsupported "alg" (Algorithm) value');
|
|
4962
|
+
}
|
|
4963
|
+
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);
|
|
4964
|
+
};
|
|
4965
|
+
const processPEMData = (pem, pattern) => decodeBase64(pem.replace(pattern, ""));
|
|
4966
|
+
const fromPKCS8 = (pem, alg, options) => {
|
|
4967
|
+
var _alg$startsWith;
|
|
4968
|
+
const keyData = processPEMData(pem, /(?:-----(?:BEGIN|END) PRIVATE KEY-----|\s)/g);
|
|
4969
|
+
let opts = options;
|
|
4970
|
+
if (alg !== null && alg !== void 0 && (_alg$startsWith = alg.startsWith) !== null && _alg$startsWith !== void 0 && _alg$startsWith.call(alg, "ECDH-ES")) {
|
|
4971
|
+
opts || (opts = {});
|
|
4972
|
+
opts.getNamedCurve = keyData => {
|
|
4973
|
+
const state = createASN1State(keyData);
|
|
4974
|
+
parsePKCS8Header(state);
|
|
4975
|
+
return parseECAlgorithmIdentifier(state);
|
|
4976
|
+
};
|
|
4977
|
+
}
|
|
4978
|
+
return genericImport("pkcs8", keyData, alg, opts);
|
|
4979
|
+
};
|
|
4980
|
+
async function importPKCS8(pkcs8, alg, options) {
|
|
4981
|
+
if (typeof pkcs8 !== "string" || pkcs8.indexOf("-----BEGIN PRIVATE KEY-----") !== 0) {
|
|
4982
|
+
throw new TypeError('"pkcs8" must be PKCS#8 formatted string');
|
|
4983
|
+
}
|
|
4984
|
+
return fromPKCS8(pkcs8, alg, options);
|
|
4985
|
+
}
|
|
4986
|
+
async function importJWK(jwk, alg, options) {
|
|
4987
|
+
var _options$extractable;
|
|
4988
|
+
if (!isObject(jwk)) {
|
|
4989
|
+
throw new TypeError("JWK must be an object");
|
|
4990
|
+
}
|
|
4991
|
+
let ext;
|
|
4992
|
+
alg !== null && alg !== void 0 ? alg : alg = jwk.alg;
|
|
4993
|
+
ext !== null && ext !== void 0 ? ext : ext = (_options$extractable = options === null || options === void 0 ? void 0 : options.extractable) !== null && _options$extractable !== void 0 ? _options$extractable : jwk.ext;
|
|
4994
|
+
switch (jwk.kty) {
|
|
4995
|
+
case "oct":
|
|
4996
|
+
if (typeof jwk.k !== "string" || !jwk.k) {
|
|
4997
|
+
throw new TypeError('missing "k" (Key Value) Parameter value');
|
|
4998
|
+
}
|
|
4999
|
+
return decode(jwk.k);
|
|
5000
|
+
|
|
5001
|
+
case "RSA":
|
|
5002
|
+
if ("oth" in jwk && jwk.oth !== undefined) {
|
|
5003
|
+
throw new JOSENotSupported('RSA JWK "oth" (Other Primes Info) Parameter value is not supported');
|
|
5004
|
+
}
|
|
5005
|
+
return jwkToKey(_objectSpread2(_objectSpread2({}, jwk), {}, {
|
|
5006
|
+
alg: alg,
|
|
5007
|
+
ext: ext
|
|
5008
|
+
}));
|
|
5009
|
+
|
|
5010
|
+
case "AKP":
|
|
5011
|
+
{
|
|
5012
|
+
if (typeof jwk.alg !== "string" || !jwk.alg) {
|
|
5013
|
+
throw new TypeError('missing "alg" (Algorithm) Parameter value');
|
|
5014
|
+
}
|
|
5015
|
+
if (alg !== undefined && alg !== jwk.alg) {
|
|
5016
|
+
throw new TypeError("JWK alg and alg option value mismatch");
|
|
5017
|
+
}
|
|
5018
|
+
return jwkToKey(_objectSpread2(_objectSpread2({}, jwk), {}, {
|
|
5019
|
+
ext: ext
|
|
5020
|
+
}));
|
|
5021
|
+
}
|
|
5022
|
+
|
|
5023
|
+
case "EC":
|
|
5024
|
+
case "OKP":
|
|
5025
|
+
return jwkToKey(_objectSpread2(_objectSpread2({}, jwk), {}, {
|
|
5026
|
+
alg: alg,
|
|
5027
|
+
ext: ext
|
|
5028
|
+
}));
|
|
5029
|
+
|
|
5030
|
+
default:
|
|
5031
|
+
throw new JOSENotSupported('Unsupported "kty" (Key Type) Parameter value');
|
|
5032
|
+
}
|
|
5033
|
+
}
|
|
5034
|
+
function validateCrit(Err, recognizedDefault, recognizedOption, protectedHeader, joseHeader) {
|
|
5035
|
+
if (joseHeader.crit !== undefined && (protectedHeader === null || protectedHeader === void 0 ? void 0 : protectedHeader.crit) === undefined) {
|
|
5036
|
+
throw new Err('"crit" (Critical) Header Parameter MUST be integrity protected');
|
|
4961
5037
|
}
|
|
4962
|
-
if (!
|
|
4963
|
-
|
|
4964
|
-
[alg]: cryptoKey
|
|
4965
|
-
});
|
|
4966
|
-
} else {
|
|
4967
|
-
cached[alg] = cryptoKey;
|
|
5038
|
+
if (!protectedHeader || protectedHeader.crit === undefined) {
|
|
5039
|
+
return new Set;
|
|
4968
5040
|
}
|
|
4969
|
-
|
|
4970
|
-
|
|
4971
|
-
async function normalizeKey(key, alg) {
|
|
4972
|
-
if (key instanceof Uint8Array) {
|
|
4973
|
-
return key;
|
|
5041
|
+
if (!Array.isArray(protectedHeader.crit) || protectedHeader.crit.length === 0 || protectedHeader.crit.some(input => typeof input !== "string" || input.length === 0)) {
|
|
5042
|
+
throw new Err('"crit" (Critical) Header Parameter MUST be an array of non-empty strings when present');
|
|
4974
5043
|
}
|
|
4975
|
-
|
|
4976
|
-
|
|
5044
|
+
let recognized;
|
|
5045
|
+
if (recognizedOption !== undefined) {
|
|
5046
|
+
recognized = new Map([ ...Object.entries(recognizedOption), ...recognizedDefault.entries() ]);
|
|
5047
|
+
} else {
|
|
5048
|
+
recognized = recognizedDefault;
|
|
4977
5049
|
}
|
|
4978
|
-
|
|
4979
|
-
if (
|
|
4980
|
-
|
|
5050
|
+
for (const parameter of protectedHeader.crit) {
|
|
5051
|
+
if (!recognized.has(parameter)) {
|
|
5052
|
+
throw new JOSENotSupported('Extension Header Parameter "'.concat(parameter, '" is not recognized'));
|
|
4981
5053
|
}
|
|
4982
|
-
if (
|
|
4983
|
-
|
|
4984
|
-
return handleKeyObject(key, alg);
|
|
4985
|
-
} catch (err) {
|
|
4986
|
-
if (err instanceof TypeError) {
|
|
4987
|
-
throw err;
|
|
4988
|
-
}
|
|
4989
|
-
}
|
|
5054
|
+
if (joseHeader[parameter] === undefined) {
|
|
5055
|
+
throw new Err('Extension Header Parameter "'.concat(parameter, '" is missing'));
|
|
4990
5056
|
}
|
|
4991
|
-
|
|
4992
|
-
|
|
4993
|
-
});
|
|
4994
|
-
return handleJWK(key, jwk, alg);
|
|
4995
|
-
}
|
|
4996
|
-
if (isJWK(key)) {
|
|
4997
|
-
if (key.k) {
|
|
4998
|
-
return decode(key.k);
|
|
5057
|
+
if (recognized.get(parameter) && protectedHeader[parameter] === undefined) {
|
|
5058
|
+
throw new Err('Extension Header Parameter "'.concat(parameter, '" MUST be integrity protected'));
|
|
4999
5059
|
}
|
|
5000
|
-
return handleJWK(key, key, alg, true);
|
|
5001
5060
|
}
|
|
5002
|
-
|
|
5061
|
+
return new Set(protectedHeader.crit);
|
|
5062
|
+
}
|
|
5063
|
+
function validateAlgorithms(option, algorithms) {
|
|
5064
|
+
if (algorithms !== undefined && (!Array.isArray(algorithms) || algorithms.some(s => typeof s !== "string"))) {
|
|
5065
|
+
throw new TypeError('"'.concat(option, '" option must be an array of strings'));
|
|
5066
|
+
}
|
|
5067
|
+
if (!algorithms) {
|
|
5068
|
+
return undefined;
|
|
5069
|
+
}
|
|
5070
|
+
return new Set(algorithms);
|
|
5003
5071
|
}
|
|
5004
5072
|
const tag = key => key === null || key === void 0 ? void 0 : key[Symbol.toStringTag];
|
|
5005
5073
|
const jwkMatchesOp = (alg, key, usage) => {
|
|
@@ -5130,7 +5198,7 @@
|
|
|
5130
5198
|
let USER_AGENT$1;
|
|
5131
5199
|
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 "))) {
|
|
5132
5200
|
const NAME = "openid-client";
|
|
5133
|
-
const VERSION = "v6.8.
|
|
5201
|
+
const VERSION = "v6.8.2";
|
|
5134
5202
|
USER_AGENT$1 = "".concat(NAME, "/").concat(VERSION);
|
|
5135
5203
|
headers = {
|
|
5136
5204
|
"user-agent": USER_AGENT$1
|
|
@@ -5320,7 +5388,7 @@
|
|
|
5320
5388
|
method: "GET",
|
|
5321
5389
|
redirect: "manual",
|
|
5322
5390
|
signal: signal
|
|
5323
|
-
})).then(
|
|
5391
|
+
})).then(response => processDiscoveryResponse(_nodiscoverycheck, response)).catch(errorHandler);
|
|
5324
5392
|
if (resolve && new URL(as.issuer).href !== server.href) {
|
|
5325
5393
|
handleEntraId(server, as, options) || handleB2Clogin(server, options) || (() => {
|
|
5326
5394
|
throw new ClientError("discovered metadata issuer does not match the expected issuer", {
|
|
@@ -5486,7 +5554,7 @@
|
|
|
5486
5554
|
}
|
|
5487
5555
|
}
|
|
5488
5556
|
function wait(duration, signal) {
|
|
5489
|
-
return new Promise((
|
|
5557
|
+
return new Promise((resolve, reject) => {
|
|
5490
5558
|
const waitStep = remaining => {
|
|
5491
5559
|
try {
|
|
5492
5560
|
signal.throwIfAborted();
|
|
@@ -5499,10 +5567,10 @@
|
|
|
5499
5567
|
return;
|
|
5500
5568
|
}
|
|
5501
5569
|
const currentWait = Math.min(remaining, 5);
|
|
5502
|
-
setTimeout((
|
|
5570
|
+
setTimeout(() => waitStep(remaining - currentWait), currentWait * 1e3);
|
|
5503
5571
|
};
|
|
5504
5572
|
waitStep(duration);
|
|
5505
|
-
})
|
|
5573
|
+
});
|
|
5506
5574
|
}
|
|
5507
5575
|
async function initiateBackchannelAuthentication(config, parameters) {
|
|
5508
5576
|
checkConfig(config);
|
|
@@ -5512,7 +5580,7 @@
|
|
|
5512
5580
|
[allowInsecureRequests$1]: !tlsOnly,
|
|
5513
5581
|
headers: new Headers(headers),
|
|
5514
5582
|
signal: signal(timeout)
|
|
5515
|
-
}).then(
|
|
5583
|
+
}).then(response => processBackchannelAuthenticationResponse(as, c, response)).catch(errorHandler);
|
|
5516
5584
|
}
|
|
5517
5585
|
async function pollBackchannelAuthenticationGrant(config, backchannelAuthenticationResponse, parameters, options) {
|
|
5518
5586
|
var _backchannelAuthentic, _options$signal2;
|
|
@@ -5824,7 +5892,7 @@
|
|
|
5824
5892
|
DPoP: options === null || options === void 0 ? void 0 : options.DPoP,
|
|
5825
5893
|
headers: new Headers(headers),
|
|
5826
5894
|
signal: signal(timeout)
|
|
5827
|
-
}).then(
|
|
5895
|
+
}).then(response => {
|
|
5828
5896
|
let recognizedTokenTypes;
|
|
5829
5897
|
if (grantType === "urn:ietf:params:oauth:grant-type:token-exchange") {
|
|
5830
5898
|
recognizedTokenTypes = {
|
|
@@ -5835,87 +5903,10 @@
|
|
|
5835
5903
|
[jweDecrypt]: decrypt,
|
|
5836
5904
|
recognizedTokenTypes: recognizedTokenTypes
|
|
5837
5905
|
});
|
|
5838
|
-
})
|
|
5906
|
+
}).catch(errorHandler);
|
|
5839
5907
|
addHelpers(result);
|
|
5840
5908
|
return result;
|
|
5841
5909
|
}
|
|
5842
|
-
function subtleAlgorithm(alg, algorithm) {
|
|
5843
|
-
const hash = "SHA-".concat(alg.slice(-3));
|
|
5844
|
-
switch (alg) {
|
|
5845
|
-
case "HS256":
|
|
5846
|
-
case "HS384":
|
|
5847
|
-
case "HS512":
|
|
5848
|
-
return {
|
|
5849
|
-
hash: hash,
|
|
5850
|
-
name: "HMAC"
|
|
5851
|
-
};
|
|
5852
|
-
|
|
5853
|
-
case "PS256":
|
|
5854
|
-
case "PS384":
|
|
5855
|
-
case "PS512":
|
|
5856
|
-
return {
|
|
5857
|
-
hash: hash,
|
|
5858
|
-
name: "RSA-PSS",
|
|
5859
|
-
saltLength: parseInt(alg.slice(-3), 10) >> 3
|
|
5860
|
-
};
|
|
5861
|
-
|
|
5862
|
-
case "RS256":
|
|
5863
|
-
case "RS384":
|
|
5864
|
-
case "RS512":
|
|
5865
|
-
return {
|
|
5866
|
-
hash: hash,
|
|
5867
|
-
name: "RSASSA-PKCS1-v1_5"
|
|
5868
|
-
};
|
|
5869
|
-
|
|
5870
|
-
case "ES256":
|
|
5871
|
-
case "ES384":
|
|
5872
|
-
case "ES512":
|
|
5873
|
-
return {
|
|
5874
|
-
hash: hash,
|
|
5875
|
-
name: "ECDSA",
|
|
5876
|
-
namedCurve: algorithm.namedCurve
|
|
5877
|
-
};
|
|
5878
|
-
|
|
5879
|
-
case "Ed25519":
|
|
5880
|
-
case "EdDSA":
|
|
5881
|
-
return {
|
|
5882
|
-
name: "Ed25519"
|
|
5883
|
-
};
|
|
5884
|
-
|
|
5885
|
-
case "ML-DSA-44":
|
|
5886
|
-
case "ML-DSA-65":
|
|
5887
|
-
case "ML-DSA-87":
|
|
5888
|
-
return {
|
|
5889
|
-
name: alg
|
|
5890
|
-
};
|
|
5891
|
-
|
|
5892
|
-
default:
|
|
5893
|
-
throw new JOSENotSupported("alg ".concat(alg, " is not supported either by JOSE or your javascript runtime"));
|
|
5894
|
-
}
|
|
5895
|
-
}
|
|
5896
|
-
async function getSigKey(alg, key, usage) {
|
|
5897
|
-
if (key instanceof Uint8Array) {
|
|
5898
|
-
if (!alg.startsWith("HS")) {
|
|
5899
|
-
throw new TypeError(invalidKeyInput(key, "CryptoKey", "KeyObject", "JSON Web Key"));
|
|
5900
|
-
}
|
|
5901
|
-
return crypto.subtle.importKey("raw", key, {
|
|
5902
|
-
hash: "SHA-".concat(alg.slice(-3)),
|
|
5903
|
-
name: "HMAC"
|
|
5904
|
-
}, false, [ usage ]);
|
|
5905
|
-
}
|
|
5906
|
-
checkSigCryptoKey(key, alg, usage);
|
|
5907
|
-
return key;
|
|
5908
|
-
}
|
|
5909
|
-
async function verify(alg, key, signature, data) {
|
|
5910
|
-
const cryptoKey = await getSigKey(alg, key, "verify");
|
|
5911
|
-
checkKeyLength(alg, cryptoKey);
|
|
5912
|
-
const algorithm = subtleAlgorithm(alg, cryptoKey.algorithm);
|
|
5913
|
-
try {
|
|
5914
|
-
return await crypto.subtle.verify(algorithm, cryptoKey, signature, data);
|
|
5915
|
-
} catch (_unused) {
|
|
5916
|
-
return false;
|
|
5917
|
-
}
|
|
5918
|
-
}
|
|
5919
5910
|
async function flattenedVerify(jws, key, options) {
|
|
5920
5911
|
if (!isObject(jws)) {
|
|
5921
5912
|
throw new JWSInvalid("Flattened JWS must be an object");
|
|
@@ -5978,12 +5969,7 @@
|
|
|
5978
5969
|
}
|
|
5979
5970
|
checkKeyType(alg, key, "verify");
|
|
5980
5971
|
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);
|
|
5981
|
-
|
|
5982
|
-
try {
|
|
5983
|
-
signature = decode(jws.signature);
|
|
5984
|
-
} catch (_unused2) {
|
|
5985
|
-
throw new JWSInvalid("Failed to base64url decode the signature");
|
|
5986
|
-
}
|
|
5972
|
+
const signature = decodeBase64url(jws.signature, "signature", JWSInvalid);
|
|
5987
5973
|
const k = await normalizeKey(key, alg);
|
|
5988
5974
|
const verified = await verify(alg, k, signature, data);
|
|
5989
5975
|
if (!verified) {
|
|
@@ -5991,11 +5977,7 @@
|
|
|
5991
5977
|
}
|
|
5992
5978
|
let payload;
|
|
5993
5979
|
if (b64) {
|
|
5994
|
-
|
|
5995
|
-
payload = decode(jws.payload);
|
|
5996
|
-
} catch (_unused3) {
|
|
5997
|
-
throw new JWSInvalid("Failed to base64url decode the payload");
|
|
5998
|
-
}
|
|
5980
|
+
payload = decodeBase64url(jws.payload, "payload", JWSInvalid);
|
|
5999
5981
|
} else if (typeof jws.payload === "string") {
|
|
6000
5982
|
payload = encoder.encode(jws.payload);
|
|
6001
5983
|
} else {
|
|
@@ -6263,7 +6245,7 @@
|
|
|
6263
6245
|
async getKey(protectedHeader, token) {
|
|
6264
6246
|
const {alg: alg, kid: kid} = _objectSpread2(_objectSpread2({}, protectedHeader), token === null || token === void 0 ? void 0 : token.header);
|
|
6265
6247
|
const kty = getKtyFromAlg(alg);
|
|
6266
|
-
const candidates = _classPrivateFieldGet2(_jwks$1, this).keys.filter(
|
|
6248
|
+
const candidates = _classPrivateFieldGet2(_jwks$1, this).keys.filter(jwk => {
|
|
6267
6249
|
let candidate = kty === jwk.kty;
|
|
6268
6250
|
if (candidate && typeof kid === "string") {
|
|
6269
6251
|
candidate = kid === jwk.kid;
|
|
@@ -6298,7 +6280,7 @@
|
|
|
6298
6280
|
}
|
|
6299
6281
|
}
|
|
6300
6282
|
return candidate;
|
|
6301
|
-
})
|
|
6283
|
+
});
|
|
6302
6284
|
const {0: jwk, length: length} = candidates;
|
|
6303
6285
|
if (length === 0) {
|
|
6304
6286
|
throw new JWKSNoMatchingKey;
|
|
@@ -6306,13 +6288,13 @@
|
|
|
6306
6288
|
if (length !== 1) {
|
|
6307
6289
|
const error = new JWKSMultipleMatchingKeys;
|
|
6308
6290
|
const _cached = _classPrivateFieldGet2(_cached2, this);
|
|
6309
|
-
error[Symbol.asyncIterator] = _wrapAsyncGenerator(
|
|
6291
|
+
error[Symbol.asyncIterator] = _wrapAsyncGenerator(function*() {
|
|
6310
6292
|
for (const jwk of candidates) {
|
|
6311
6293
|
try {
|
|
6312
6294
|
yield yield _awaitAsyncGenerator(importWithAlgCache(_cached, jwk, alg));
|
|
6313
6295
|
} catch (_unused) {}
|
|
6314
6296
|
}
|
|
6315
|
-
})
|
|
6297
|
+
});
|
|
6316
6298
|
throw error;
|
|
6317
6299
|
}
|
|
6318
6300
|
return importWithAlgCache(_classPrivateFieldGet2(_cached2, this), jwk, alg);
|
|
@@ -6351,7 +6333,7 @@
|
|
|
6351
6333
|
let USER_AGENT;
|
|
6352
6334
|
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 "))) {
|
|
6353
6335
|
const NAME = "jose";
|
|
6354
|
-
const VERSION = "v6.1
|
|
6336
|
+
const VERSION = "v6.2.1";
|
|
6355
6337
|
USER_AGENT = "".concat(NAME, "/").concat(VERSION);
|
|
6356
6338
|
}
|
|
6357
6339
|
const customFetch = Symbol();
|
|
@@ -6362,12 +6344,12 @@
|
|
|
6362
6344
|
signal: signal,
|
|
6363
6345
|
redirect: "manual",
|
|
6364
6346
|
headers: headers
|
|
6365
|
-
}).catch(
|
|
6347
|
+
}).catch(err => {
|
|
6366
6348
|
if (err.name === "TimeoutError") {
|
|
6367
6349
|
throw new JWKSTimeout;
|
|
6368
6350
|
}
|
|
6369
6351
|
throw err;
|
|
6370
|
-
})
|
|
6352
|
+
});
|
|
6371
6353
|
if (response.status !== 200) {
|
|
6372
6354
|
throw new JOSEError("Expected 200 OK from the JSON Web Key Set HTTP response");
|
|
6373
6355
|
}
|
|
@@ -6469,7 +6451,7 @@
|
|
|
6469
6451
|
if (_classPrivateFieldGet2(_pendingFetch, this) && isCloudflareWorkers()) {
|
|
6470
6452
|
_classPrivateFieldSet2(_pendingFetch, this, undefined);
|
|
6471
6453
|
}
|
|
6472
|
-
_classPrivateFieldGet2(_pendingFetch, this) || _classPrivateFieldSet2(_pendingFetch, this, fetchJwks(_classPrivateFieldGet2(_url, this).href, _classPrivateFieldGet2(_headers, this), AbortSignal.timeout(_classPrivateFieldGet2(_timeoutDuration, this)), _classPrivateFieldGet2(_customFetch$1, this)).then(
|
|
6454
|
+
_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 => {
|
|
6473
6455
|
_classPrivateFieldSet2(_local, this, createLocalJWKSet(json));
|
|
6474
6456
|
if (_classPrivateFieldGet2(_cache, this)) {
|
|
6475
6457
|
_classPrivateFieldGet2(_cache, this).uat = Date.now();
|
|
@@ -6477,10 +6459,10 @@
|
|
|
6477
6459
|
}
|
|
6478
6460
|
_classPrivateFieldSet2(_jwksTimestamp, this, Date.now());
|
|
6479
6461
|
_classPrivateFieldSet2(_pendingFetch, this, undefined);
|
|
6480
|
-
})
|
|
6462
|
+
}).catch(err => {
|
|
6481
6463
|
_classPrivateFieldSet2(_pendingFetch, this, undefined);
|
|
6482
6464
|
throw err;
|
|
6483
|
-
}))
|
|
6465
|
+
}));
|
|
6484
6466
|
await _classPrivateFieldGet2(_pendingFetch, this);
|
|
6485
6467
|
}
|
|
6486
6468
|
}
|
|
@@ -6519,7 +6501,7 @@
|
|
|
6519
6501
|
return remoteJWKSet;
|
|
6520
6502
|
}
|
|
6521
6503
|
const _excluded = [ "mfaToken" ], _excluded2 = [ "mfaToken" ];
|
|
6522
|
-
var _baseUrl, _clientId, _customFetch, _configuration, _serverMetadata, _options, _jwks,
|
|
6504
|
+
var _baseUrl, _clientId, _customFetch, _entries, _ttlMs, _maxEntries, _configuration, _serverMetadata, _clientAuthPromise, _options, _customFetch2, _jwks, _discoveryCache, _inFlightDiscovery, _jwksCache, _Class9_brand;
|
|
6523
6505
|
var NotSupportedError = class NotSupportedError extends Error {
|
|
6524
6506
|
constructor(code, message) {
|
|
6525
6507
|
super(message);
|
|
@@ -6611,12 +6593,12 @@
|
|
|
6611
6593
|
}
|
|
6612
6594
|
};
|
|
6613
6595
|
function stripUndefinedProperties(value) {
|
|
6614
|
-
return Object.entries(value).filter(
|
|
6596
|
+
return Object.entries(value).filter(_ref => {
|
|
6615
6597
|
let [, value2] = _ref;
|
|
6616
6598
|
return typeof value2 !== "undefined";
|
|
6617
|
-
})
|
|
6599
|
+
}).reduce((acc, curr) => _objectSpread2(_objectSpread2({}, acc), {}, {
|
|
6618
6600
|
[curr[0]]: curr[1]
|
|
6619
|
-
})
|
|
6601
|
+
}), {});
|
|
6620
6602
|
}
|
|
6621
6603
|
var MfaError$1 = class MfaError extends Error {
|
|
6622
6604
|
constructor(code, message, cause) {
|
|
@@ -6681,7 +6663,9 @@
|
|
|
6681
6663
|
oobChannel: api.oob_channel,
|
|
6682
6664
|
oobCode: api.oob_code,
|
|
6683
6665
|
bindingMethod: api.binding_method,
|
|
6684
|
-
id: api.id
|
|
6666
|
+
id: api.id,
|
|
6667
|
+
barcodeUri: api.barcode_uri,
|
|
6668
|
+
recoveryCodes: api.recovery_codes
|
|
6685
6669
|
};
|
|
6686
6670
|
}
|
|
6687
6671
|
throw new Error("Unexpected authenticator type: ".concat(api.authenticator_type));
|
|
@@ -6799,6 +6783,40 @@
|
|
|
6799
6783
|
return transformChallengeResponse(apiResponse);
|
|
6800
6784
|
}
|
|
6801
6785
|
});
|
|
6786
|
+
function createTelemetryFetch(baseFetch, config) {
|
|
6787
|
+
if (config.enabled === false) {
|
|
6788
|
+
return baseFetch;
|
|
6789
|
+
}
|
|
6790
|
+
const telemetryData = {
|
|
6791
|
+
name: config.name,
|
|
6792
|
+
version: config.version
|
|
6793
|
+
};
|
|
6794
|
+
const headerValue = btoa(JSON.stringify(telemetryData));
|
|
6795
|
+
return async (input, init) => {
|
|
6796
|
+
const headers = input instanceof Request ? new Headers(input.headers) : new Headers;
|
|
6797
|
+
if (init !== null && init !== void 0 && init.headers) {
|
|
6798
|
+
const initHeaders = new Headers(init.headers);
|
|
6799
|
+
initHeaders.forEach((value, key) => {
|
|
6800
|
+
headers.set(key, value);
|
|
6801
|
+
});
|
|
6802
|
+
}
|
|
6803
|
+
headers.set("Auth0-Client", headerValue);
|
|
6804
|
+
return baseFetch(input, _objectSpread2(_objectSpread2({}, init), {}, {
|
|
6805
|
+
headers: headers
|
|
6806
|
+
}));
|
|
6807
|
+
};
|
|
6808
|
+
}
|
|
6809
|
+
function getTelemetryConfig(config) {
|
|
6810
|
+
var _config$name, _config$version;
|
|
6811
|
+
if ((config === null || config === void 0 ? void 0 : config.enabled) === false) {
|
|
6812
|
+
return config;
|
|
6813
|
+
}
|
|
6814
|
+
return {
|
|
6815
|
+
enabled: true,
|
|
6816
|
+
name: (_config$name = config === null || config === void 0 ? void 0 : config.name) !== null && _config$name !== void 0 ? _config$name : "@auth0/auth0-auth-js",
|
|
6817
|
+
version: (_config$version = config === null || config === void 0 ? void 0 : config.version) !== null && _config$version !== void 0 ? _config$version : "1.5.0"
|
|
6818
|
+
};
|
|
6819
|
+
}
|
|
6802
6820
|
var TokenResponse = class _TokenResponse {
|
|
6803
6821
|
constructor(accessToken, expiresAt, idToken, refreshToken, scope, claims, authorizationDetails) {
|
|
6804
6822
|
_defineProperty(this, "accessToken", void 0);
|
|
@@ -6826,6 +6844,75 @@
|
|
|
6826
6844
|
return tokenResponse;
|
|
6827
6845
|
}
|
|
6828
6846
|
};
|
|
6847
|
+
var LruCache = (_entries = new WeakMap, _ttlMs = new WeakMap, _maxEntries = new WeakMap,
|
|
6848
|
+
class LruCache {
|
|
6849
|
+
constructor(maxEntries, ttlMs) {
|
|
6850
|
+
_classPrivateFieldInitSpec(this, _entries, new Map);
|
|
6851
|
+
_classPrivateFieldInitSpec(this, _ttlMs, void 0);
|
|
6852
|
+
_classPrivateFieldInitSpec(this, _maxEntries, void 0);
|
|
6853
|
+
_classPrivateFieldSet2(_maxEntries, this, Math.max(1, Math.floor(maxEntries)));
|
|
6854
|
+
_classPrivateFieldSet2(_ttlMs, this, Math.max(0, Math.floor(ttlMs)));
|
|
6855
|
+
}
|
|
6856
|
+
get(key) {
|
|
6857
|
+
const entry = _classPrivateFieldGet2(_entries, this).get(key);
|
|
6858
|
+
if (!entry) {
|
|
6859
|
+
return;
|
|
6860
|
+
}
|
|
6861
|
+
if (Date.now() >= entry.expiresAt) {
|
|
6862
|
+
_classPrivateFieldGet2(_entries, this).delete(key);
|
|
6863
|
+
return;
|
|
6864
|
+
}
|
|
6865
|
+
_classPrivateFieldGet2(_entries, this).delete(key);
|
|
6866
|
+
_classPrivateFieldGet2(_entries, this).set(key, entry);
|
|
6867
|
+
return entry.value;
|
|
6868
|
+
}
|
|
6869
|
+
set(key, value) {
|
|
6870
|
+
if (_classPrivateFieldGet2(_entries, this).has(key)) {
|
|
6871
|
+
_classPrivateFieldGet2(_entries, this).delete(key);
|
|
6872
|
+
}
|
|
6873
|
+
_classPrivateFieldGet2(_entries, this).set(key, {
|
|
6874
|
+
value: value,
|
|
6875
|
+
expiresAt: Date.now() + _classPrivateFieldGet2(_ttlMs, this)
|
|
6876
|
+
});
|
|
6877
|
+
while (_classPrivateFieldGet2(_entries, this).size > _classPrivateFieldGet2(_maxEntries, this)) {
|
|
6878
|
+
const oldestKey = _classPrivateFieldGet2(_entries, this).keys().next().value;
|
|
6879
|
+
if (oldestKey === void 0) {
|
|
6880
|
+
break;
|
|
6881
|
+
}
|
|
6882
|
+
_classPrivateFieldGet2(_entries, this).delete(oldestKey);
|
|
6883
|
+
}
|
|
6884
|
+
}
|
|
6885
|
+
});
|
|
6886
|
+
var globalCaches = new Map;
|
|
6887
|
+
function getGlobalCache(key) {
|
|
6888
|
+
return globalCaches.get(key);
|
|
6889
|
+
}
|
|
6890
|
+
function getGlobalCacheKey(maxEntries, ttlMs) {
|
|
6891
|
+
return "".concat(maxEntries, ":").concat(ttlMs);
|
|
6892
|
+
}
|
|
6893
|
+
function resolveCacheConfig(options) {
|
|
6894
|
+
const ttlSeconds = typeof (options === null || options === void 0 ? void 0 : options.ttl) === "number" ? options.ttl : 600;
|
|
6895
|
+
const maxEntries = typeof (options === null || options === void 0 ? void 0 : options.maxEntries) === "number" && options.maxEntries > 0 ? options.maxEntries : 100;
|
|
6896
|
+
const ttlMs = ttlSeconds * 1e3;
|
|
6897
|
+
return {
|
|
6898
|
+
ttlMs: ttlMs,
|
|
6899
|
+
maxEntries: maxEntries
|
|
6900
|
+
};
|
|
6901
|
+
}
|
|
6902
|
+
var DiscoveryCacheFactory = class {
|
|
6903
|
+
static createDiscoveryCache(config) {
|
|
6904
|
+
const cacheKey = getGlobalCacheKey(config.maxEntries, config.ttlMs);
|
|
6905
|
+
let cache = getGlobalCache(cacheKey);
|
|
6906
|
+
if (!cache) {
|
|
6907
|
+
cache = new LruCache(config.maxEntries, config.ttlMs);
|
|
6908
|
+
globalCaches.set(cacheKey, cache);
|
|
6909
|
+
}
|
|
6910
|
+
return cache;
|
|
6911
|
+
}
|
|
6912
|
+
static createJwksCache() {
|
|
6913
|
+
return {};
|
|
6914
|
+
}
|
|
6915
|
+
};
|
|
6829
6916
|
var DEFAULT_SCOPES = "openid profile email offline_access";
|
|
6830
6917
|
var MAX_ARRAY_VALUES_PER_KEY = 20;
|
|
6831
6918
|
var PARAM_DENYLIST = Object.freeze(new Set([ "grant_type", "client_id", "client_secret", "client_assertion", "client_assertion_type", "subject_token", "subject_token_type", "requested_token_type", "actor_token", "actor_token_type", "audience", "aud", "resource", "resources", "resource_indicator", "scope", "connection", "login_hint", "organization", "assertion" ]));
|
|
@@ -6854,9 +6941,9 @@
|
|
|
6854
6941
|
if (parameterValue.length > MAX_ARRAY_VALUES_PER_KEY) {
|
|
6855
6942
|
throw new TokenExchangeError("Parameter '".concat(parameterKey, "' exceeds maximum array size of ").concat(MAX_ARRAY_VALUES_PER_KEY));
|
|
6856
6943
|
}
|
|
6857
|
-
parameterValue.forEach(
|
|
6944
|
+
parameterValue.forEach(arrayItem => {
|
|
6858
6945
|
params.append(parameterKey, arrayItem);
|
|
6859
|
-
})
|
|
6946
|
+
});
|
|
6860
6947
|
} else {
|
|
6861
6948
|
params.append(parameterKey, parameterValue);
|
|
6862
6949
|
}
|
|
@@ -6867,39 +6954,58 @@
|
|
|
6867
6954
|
var SUBJECT_TYPE_REFRESH_TOKEN = "urn:ietf:params:oauth:token-type:refresh_token";
|
|
6868
6955
|
var SUBJECT_TYPE_ACCESS_TOKEN = "urn:ietf:params:oauth:token-type:access_token";
|
|
6869
6956
|
var REQUESTED_TOKEN_TYPE_FEDERATED_CONNECTION_ACCESS_TOKEN = "http://auth0.com/oauth/token-type/federated-connection-access-token";
|
|
6870
|
-
var AuthClient = (_configuration = new WeakMap, _serverMetadata = new WeakMap,
|
|
6871
|
-
|
|
6957
|
+
var AuthClient = (_configuration = new WeakMap, _serverMetadata = new WeakMap, _clientAuthPromise = new WeakMap,
|
|
6958
|
+
_options = new WeakMap, _customFetch2 = new WeakMap, _jwks = new WeakMap, _discoveryCache = new WeakMap,
|
|
6959
|
+
_inFlightDiscovery = new WeakMap, _jwksCache = new WeakMap, _Class9_brand = new WeakSet,
|
|
6960
|
+
class AuthClient {
|
|
6872
6961
|
constructor(_options2) {
|
|
6873
|
-
|
|
6962
|
+
var _options2$customFetch;
|
|
6963
|
+
_classPrivateMethodInitSpec(this, _Class9_brand);
|
|
6874
6964
|
_classPrivateFieldInitSpec(this, _configuration, void 0);
|
|
6875
6965
|
_classPrivateFieldInitSpec(this, _serverMetadata, void 0);
|
|
6966
|
+
_classPrivateFieldInitSpec(this, _clientAuthPromise, void 0);
|
|
6876
6967
|
_classPrivateFieldInitSpec(this, _options, void 0);
|
|
6968
|
+
_classPrivateFieldInitSpec(this, _customFetch2, void 0);
|
|
6877
6969
|
_classPrivateFieldInitSpec(this, _jwks, void 0);
|
|
6970
|
+
_classPrivateFieldInitSpec(this, _discoveryCache, void 0);
|
|
6971
|
+
_classPrivateFieldInitSpec(this, _inFlightDiscovery, void 0);
|
|
6972
|
+
_classPrivateFieldInitSpec(this, _jwksCache, void 0);
|
|
6878
6973
|
_defineProperty(this, "mfa", void 0);
|
|
6879
6974
|
_classPrivateFieldSet2(_options, this, _options2);
|
|
6880
6975
|
if (_options2.useMtls && !_options2.customFetch) {
|
|
6881
6976
|
throw new NotSupportedError("mtls_without_custom_fetch_not_supported", "Using mTLS without a custom fetch implementation is not supported");
|
|
6882
6977
|
}
|
|
6978
|
+
_classPrivateFieldSet2(_customFetch2, this, createTelemetryFetch((_options2$customFetch = _options2.customFetch) !== null && _options2$customFetch !== void 0 ? _options2$customFetch : function() {
|
|
6979
|
+
return fetch(...arguments);
|
|
6980
|
+
}, getTelemetryConfig(_options2.telemetry)));
|
|
6981
|
+
const cacheConfig = resolveCacheConfig(_options2.discoveryCache);
|
|
6982
|
+
_classPrivateFieldSet2(_discoveryCache, this, DiscoveryCacheFactory.createDiscoveryCache(cacheConfig));
|
|
6983
|
+
_classPrivateFieldSet2(_inFlightDiscovery, this, new Map);
|
|
6984
|
+
_classPrivateFieldSet2(_jwksCache, this, DiscoveryCacheFactory.createJwksCache());
|
|
6883
6985
|
this.mfa = new MfaClient({
|
|
6884
6986
|
domain: _classPrivateFieldGet2(_options, this).domain,
|
|
6885
6987
|
clientId: _classPrivateFieldGet2(_options, this).clientId,
|
|
6886
|
-
customFetch: _classPrivateFieldGet2(
|
|
6988
|
+
customFetch: _classPrivateFieldGet2(_customFetch2, this)
|
|
6887
6989
|
});
|
|
6888
6990
|
}
|
|
6991
|
+
async getServerMetadata() {
|
|
6992
|
+
const {serverMetadata: serverMetadata} = await _assertClassBrand(_Class9_brand, this, _discover).call(this);
|
|
6993
|
+
return serverMetadata;
|
|
6994
|
+
}
|
|
6889
6995
|
async buildAuthorizationUrl(options) {
|
|
6890
|
-
const {serverMetadata: serverMetadata} = await _assertClassBrand(
|
|
6996
|
+
const {serverMetadata: serverMetadata} = await _assertClassBrand(_Class9_brand, this, _discover).call(this);
|
|
6891
6997
|
if (options !== null && options !== void 0 && options.pushedAuthorizationRequests && !serverMetadata.pushed_authorization_request_endpoint) {
|
|
6892
6998
|
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");
|
|
6893
6999
|
}
|
|
6894
7000
|
try {
|
|
6895
|
-
return await _assertClassBrand(
|
|
7001
|
+
return await _assertClassBrand(_Class9_brand, this, _buildAuthorizationUrl).call(this, options);
|
|
6896
7002
|
} catch (e) {
|
|
6897
7003
|
throw new BuildAuthorizationUrlError(e);
|
|
6898
7004
|
}
|
|
6899
7005
|
}
|
|
6900
7006
|
async buildLinkUserUrl(options) {
|
|
6901
7007
|
try {
|
|
6902
|
-
const result = await _assertClassBrand(
|
|
7008
|
+
const result = await _assertClassBrand(_Class9_brand, this, _buildAuthorizationUrl).call(this, {
|
|
6903
7009
|
authorizationParams: _objectSpread2(_objectSpread2({}, options.authorizationParams), {}, {
|
|
6904
7010
|
requested_connection: options.connection,
|
|
6905
7011
|
requested_connection_scope: options.connectionScope,
|
|
@@ -6917,7 +7023,7 @@
|
|
|
6917
7023
|
}
|
|
6918
7024
|
async buildUnlinkUserUrl(options) {
|
|
6919
7025
|
try {
|
|
6920
|
-
const result = await _assertClassBrand(
|
|
7026
|
+
const result = await _assertClassBrand(_Class9_brand, this, _buildAuthorizationUrl).call(this, {
|
|
6921
7027
|
authorizationParams: _objectSpread2(_objectSpread2({}, options.authorizationParams), {}, {
|
|
6922
7028
|
requested_connection: options.connection,
|
|
6923
7029
|
scope: "openid unlink_account",
|
|
@@ -6933,7 +7039,7 @@
|
|
|
6933
7039
|
}
|
|
6934
7040
|
}
|
|
6935
7041
|
async backchannelAuthentication(options) {
|
|
6936
|
-
const {configuration: configuration, serverMetadata: serverMetadata} = await _assertClassBrand(
|
|
7042
|
+
const {configuration: configuration, serverMetadata: serverMetadata} = await _assertClassBrand(_Class9_brand, this, _discover).call(this);
|
|
6937
7043
|
const additionalParams = stripUndefinedProperties(_objectSpread2(_objectSpread2({}, _classPrivateFieldGet2(_options, this).authorizationParams), options === null || options === void 0 ? void 0 : options.authorizationParams));
|
|
6938
7044
|
const params = new URLSearchParams(_objectSpread2(_objectSpread2({
|
|
6939
7045
|
scope: DEFAULT_SCOPES
|
|
@@ -6961,7 +7067,7 @@
|
|
|
6961
7067
|
}
|
|
6962
7068
|
}
|
|
6963
7069
|
async initiateBackchannelAuthentication(options) {
|
|
6964
|
-
const {configuration: configuration, serverMetadata: serverMetadata} = await _assertClassBrand(
|
|
7070
|
+
const {configuration: configuration, serverMetadata: serverMetadata} = await _assertClassBrand(_Class9_brand, this, _discover).call(this);
|
|
6965
7071
|
const additionalParams = stripUndefinedProperties(_objectSpread2(_objectSpread2({}, _classPrivateFieldGet2(_options, this).authorizationParams), options === null || options === void 0 ? void 0 : options.authorizationParams));
|
|
6966
7072
|
const params = new URLSearchParams(_objectSpread2(_objectSpread2({
|
|
6967
7073
|
scope: DEFAULT_SCOPES
|
|
@@ -6993,7 +7099,7 @@
|
|
|
6993
7099
|
}
|
|
6994
7100
|
async backchannelAuthenticationGrant(_ref2) {
|
|
6995
7101
|
let {authReqId: authReqId} = _ref2;
|
|
6996
|
-
const {configuration: configuration} = await _assertClassBrand(
|
|
7102
|
+
const {configuration: configuration} = await _assertClassBrand(_Class9_brand, this, _discover).call(this);
|
|
6997
7103
|
const params = new URLSearchParams({
|
|
6998
7104
|
auth_req_id: authReqId
|
|
6999
7105
|
});
|
|
@@ -7028,10 +7134,10 @@
|
|
|
7028
7134
|
}
|
|
7029
7135
|
}
|
|
7030
7136
|
async exchangeToken(options) {
|
|
7031
|
-
return "connection" in options ? _assertClassBrand(
|
|
7137
|
+
return "connection" in options ? _assertClassBrand(_Class9_brand, this, _exchangeTokenVaultToken).call(this, options) : _assertClassBrand(_Class9_brand, this, _exchangeProfileToken).call(this, options);
|
|
7032
7138
|
}
|
|
7033
7139
|
async getTokenByCode(url, options) {
|
|
7034
|
-
const {configuration: configuration} = await _assertClassBrand(
|
|
7140
|
+
const {configuration: configuration} = await _assertClassBrand(_Class9_brand, this, _discover).call(this);
|
|
7035
7141
|
try {
|
|
7036
7142
|
const tokenEndpointResponse = await authorizationCodeGrant(configuration, url, {
|
|
7037
7143
|
pkceCodeVerifier: options.codeVerifier
|
|
@@ -7042,16 +7148,23 @@
|
|
|
7042
7148
|
}
|
|
7043
7149
|
}
|
|
7044
7150
|
async getTokenByRefreshToken(options) {
|
|
7045
|
-
const {configuration: configuration} = await _assertClassBrand(
|
|
7151
|
+
const {configuration: configuration} = await _assertClassBrand(_Class9_brand, this, _discover).call(this);
|
|
7152
|
+
const additionalParameters = new URLSearchParams;
|
|
7153
|
+
if (options.audience) {
|
|
7154
|
+
additionalParameters.append("audience", options.audience);
|
|
7155
|
+
}
|
|
7156
|
+
if (options.scope) {
|
|
7157
|
+
additionalParameters.append("scope", options.scope);
|
|
7158
|
+
}
|
|
7046
7159
|
try {
|
|
7047
|
-
const tokenEndpointResponse = await refreshTokenGrant(configuration, options.refreshToken);
|
|
7160
|
+
const tokenEndpointResponse = await refreshTokenGrant(configuration, options.refreshToken, additionalParameters);
|
|
7048
7161
|
return TokenResponse.fromTokenEndpointResponse(tokenEndpointResponse);
|
|
7049
7162
|
} catch (e) {
|
|
7050
7163
|
throw new TokenByRefreshTokenError("The access token has expired and there was an error while trying to refresh it.", e);
|
|
7051
7164
|
}
|
|
7052
7165
|
}
|
|
7053
7166
|
async getTokenByClientCredentials(options) {
|
|
7054
|
-
const {configuration: configuration} = await _assertClassBrand(
|
|
7167
|
+
const {configuration: configuration} = await _assertClassBrand(_Class9_brand, this, _discover).call(this);
|
|
7055
7168
|
try {
|
|
7056
7169
|
const params = new URLSearchParams({
|
|
7057
7170
|
audience: options.audience
|
|
@@ -7066,7 +7179,7 @@
|
|
|
7066
7179
|
}
|
|
7067
7180
|
}
|
|
7068
7181
|
async buildLogoutUrl(options) {
|
|
7069
|
-
const {configuration: configuration, serverMetadata: serverMetadata} = await _assertClassBrand(
|
|
7182
|
+
const {configuration: configuration, serverMetadata: serverMetadata} = await _assertClassBrand(_Class9_brand, this, _discover).call(this);
|
|
7070
7183
|
if (!serverMetadata.end_session_endpoint) {
|
|
7071
7184
|
const url = new URL("https://".concat(_classPrivateFieldGet2(_options, this).domain, "/v2/logout"));
|
|
7072
7185
|
url.searchParams.set("returnTo", options.returnTo);
|
|
@@ -7078,9 +7191,13 @@
|
|
|
7078
7191
|
});
|
|
7079
7192
|
}
|
|
7080
7193
|
async verifyLogoutToken(options) {
|
|
7081
|
-
const {serverMetadata: serverMetadata} = await _assertClassBrand(
|
|
7082
|
-
|
|
7083
|
-
|
|
7194
|
+
const {serverMetadata: serverMetadata} = await _assertClassBrand(_Class9_brand, this, _discover).call(this);
|
|
7195
|
+
const cacheConfig = resolveCacheConfig(_classPrivateFieldGet2(_options, this).discoveryCache);
|
|
7196
|
+
const jwksUri = serverMetadata.jwks_uri;
|
|
7197
|
+
_classPrivateFieldGet2(_jwks, this) || _classPrivateFieldSet2(_jwks, this, createRemoteJWKSet(new URL(jwksUri), {
|
|
7198
|
+
cacheMaxAge: cacheConfig.ttlMs,
|
|
7199
|
+
[customFetch]: _classPrivateFieldGet2(_customFetch2, this),
|
|
7200
|
+
[jwksCache]: _classPrivateFieldGet2(_jwksCache, this)
|
|
7084
7201
|
}));
|
|
7085
7202
|
const {payload: payload} = await jwtVerify(options.logoutToken, _classPrivateFieldGet2(_jwks, this), {
|
|
7086
7203
|
issuer: serverMetadata.issuer,
|
|
@@ -7118,6 +7235,16 @@
|
|
|
7118
7235
|
};
|
|
7119
7236
|
}
|
|
7120
7237
|
});
|
|
7238
|
+
function _getDiscoveryCacheKey() {
|
|
7239
|
+
const domain = _classPrivateFieldGet2(_options, this).domain.toLowerCase();
|
|
7240
|
+
return "".concat(domain, "|mtls:").concat(_classPrivateFieldGet2(_options, this).useMtls ? "1" : "0");
|
|
7241
|
+
}
|
|
7242
|
+
async function _createConfiguration(serverMetadata) {
|
|
7243
|
+
const clientAuth = await _assertClassBrand(_Class9_brand, this, _getClientAuth).call(this);
|
|
7244
|
+
const configuration = new Configuration(serverMetadata, _classPrivateFieldGet2(_options, this).clientId, _classPrivateFieldGet2(_options, this).clientSecret, clientAuth);
|
|
7245
|
+
configuration[customFetch$1] = _classPrivateFieldGet2(_customFetch2, this);
|
|
7246
|
+
return configuration;
|
|
7247
|
+
}
|
|
7121
7248
|
async function _discover() {
|
|
7122
7249
|
if (_classPrivateFieldGet2(_configuration, this) && _classPrivateFieldGet2(_serverMetadata, this)) {
|
|
7123
7250
|
return {
|
|
@@ -7125,14 +7252,58 @@
|
|
|
7125
7252
|
serverMetadata: _classPrivateFieldGet2(_serverMetadata, this)
|
|
7126
7253
|
};
|
|
7127
7254
|
}
|
|
7128
|
-
const
|
|
7129
|
-
|
|
7130
|
-
|
|
7131
|
-
|
|
7132
|
-
|
|
7133
|
-
|
|
7134
|
-
|
|
7135
|
-
|
|
7255
|
+
const cacheKey = _assertClassBrand(_Class9_brand, this, _getDiscoveryCacheKey).call(this);
|
|
7256
|
+
const cached = _classPrivateFieldGet2(_discoveryCache, this).get(cacheKey);
|
|
7257
|
+
if (cached) {
|
|
7258
|
+
_classPrivateFieldSet2(_serverMetadata, this, cached.serverMetadata);
|
|
7259
|
+
_classPrivateFieldSet2(_configuration, this, await _assertClassBrand(_Class9_brand, this, _createConfiguration).call(this, cached.serverMetadata));
|
|
7260
|
+
return {
|
|
7261
|
+
configuration: _classPrivateFieldGet2(_configuration, this),
|
|
7262
|
+
serverMetadata: _classPrivateFieldGet2(_serverMetadata, this)
|
|
7263
|
+
};
|
|
7264
|
+
}
|
|
7265
|
+
const inFlight = _classPrivateFieldGet2(_inFlightDiscovery, this).get(cacheKey);
|
|
7266
|
+
if (inFlight) {
|
|
7267
|
+
const entry = await inFlight;
|
|
7268
|
+
_classPrivateFieldSet2(_serverMetadata, this, entry.serverMetadata);
|
|
7269
|
+
_classPrivateFieldSet2(_configuration, this, await _assertClassBrand(_Class9_brand, this, _createConfiguration).call(this, entry.serverMetadata));
|
|
7270
|
+
return {
|
|
7271
|
+
configuration: _classPrivateFieldGet2(_configuration, this),
|
|
7272
|
+
serverMetadata: _classPrivateFieldGet2(_serverMetadata, this)
|
|
7273
|
+
};
|
|
7274
|
+
}
|
|
7275
|
+
const discoveryPromise = (async () => {
|
|
7276
|
+
const clientAuth = await _assertClassBrand(_Class9_brand, this, _getClientAuth).call(this);
|
|
7277
|
+
const configuration = await discovery(new URL("https://".concat(_classPrivateFieldGet2(_options, this).domain)), _classPrivateFieldGet2(_options, this).clientId, {
|
|
7278
|
+
use_mtls_endpoint_aliases: _classPrivateFieldGet2(_options, this).useMtls
|
|
7279
|
+
}, clientAuth, {
|
|
7280
|
+
[customFetch$1]: _classPrivateFieldGet2(_customFetch2, this)
|
|
7281
|
+
});
|
|
7282
|
+
const serverMetadata = configuration.serverMetadata();
|
|
7283
|
+
_classPrivateFieldGet2(_discoveryCache, this).set(cacheKey, {
|
|
7284
|
+
serverMetadata: serverMetadata
|
|
7285
|
+
});
|
|
7286
|
+
return {
|
|
7287
|
+
configuration: configuration,
|
|
7288
|
+
serverMetadata: serverMetadata
|
|
7289
|
+
};
|
|
7290
|
+
})();
|
|
7291
|
+
const inFlightEntry = discoveryPromise.then(_ref3 => {
|
|
7292
|
+
let {serverMetadata: serverMetadata} = _ref3;
|
|
7293
|
+
return {
|
|
7294
|
+
serverMetadata: serverMetadata
|
|
7295
|
+
};
|
|
7296
|
+
});
|
|
7297
|
+
void inFlightEntry.catch(() => void 0);
|
|
7298
|
+
_classPrivateFieldGet2(_inFlightDiscovery, this).set(cacheKey, inFlightEntry);
|
|
7299
|
+
try {
|
|
7300
|
+
const {configuration: configuration, serverMetadata: serverMetadata} = await discoveryPromise;
|
|
7301
|
+
_classPrivateFieldSet2(_configuration, this, configuration);
|
|
7302
|
+
_classPrivateFieldSet2(_serverMetadata, this, serverMetadata);
|
|
7303
|
+
_classPrivateFieldGet2(_configuration, this)[customFetch$1] = _classPrivateFieldGet2(_customFetch2, this);
|
|
7304
|
+
} finally {
|
|
7305
|
+
_classPrivateFieldGet2(_inFlightDiscovery, this).delete(cacheKey);
|
|
7306
|
+
}
|
|
7136
7307
|
return {
|
|
7137
7308
|
configuration: _classPrivateFieldGet2(_configuration, this),
|
|
7138
7309
|
serverMetadata: _classPrivateFieldGet2(_serverMetadata, this)
|
|
@@ -7140,7 +7311,7 @@
|
|
|
7140
7311
|
}
|
|
7141
7312
|
async function _exchangeTokenVaultToken(options) {
|
|
7142
7313
|
var _options$subjectToken, _options$requestedTok;
|
|
7143
|
-
const {configuration: configuration} = await _assertClassBrand(
|
|
7314
|
+
const {configuration: configuration} = await _assertClassBrand(_Class9_brand, this, _discover).call(this);
|
|
7144
7315
|
if ("audience" in options || "resource" in options) {
|
|
7145
7316
|
throw new TokenExchangeError("audience and resource parameters are not supported for Token Vault exchanges");
|
|
7146
7317
|
}
|
|
@@ -7166,7 +7337,7 @@
|
|
|
7166
7337
|
}
|
|
7167
7338
|
}
|
|
7168
7339
|
async function _exchangeProfileToken(options) {
|
|
7169
|
-
const {configuration: configuration} = await _assertClassBrand(
|
|
7340
|
+
const {configuration: configuration} = await _assertClassBrand(_Class9_brand, this, _discover).call(this);
|
|
7170
7341
|
validateSubjectToken(options.subjectToken);
|
|
7171
7342
|
const tokenRequestParams = new URLSearchParams({
|
|
7172
7343
|
subject_token_type: options.subjectTokenType,
|
|
@@ -7193,20 +7364,28 @@
|
|
|
7193
7364
|
}
|
|
7194
7365
|
}
|
|
7195
7366
|
async function _getClientAuth() {
|
|
7196
|
-
if (!_classPrivateFieldGet2(
|
|
7197
|
-
|
|
7198
|
-
|
|
7199
|
-
|
|
7200
|
-
|
|
7201
|
-
|
|
7202
|
-
|
|
7203
|
-
|
|
7204
|
-
|
|
7367
|
+
if (!_classPrivateFieldGet2(_clientAuthPromise, this)) {
|
|
7368
|
+
_classPrivateFieldSet2(_clientAuthPromise, this, (async () => {
|
|
7369
|
+
if (!_classPrivateFieldGet2(_options, this).clientSecret && !_classPrivateFieldGet2(_options, this).clientAssertionSigningKey && !_classPrivateFieldGet2(_options, this).useMtls) {
|
|
7370
|
+
throw new MissingClientAuthError;
|
|
7371
|
+
}
|
|
7372
|
+
if (_classPrivateFieldGet2(_options, this).useMtls) {
|
|
7373
|
+
return TlsClientAuth();
|
|
7374
|
+
}
|
|
7375
|
+
let clientPrivateKey = _classPrivateFieldGet2(_options, this).clientAssertionSigningKey;
|
|
7376
|
+
if (clientPrivateKey && !(clientPrivateKey instanceof CryptoKey)) {
|
|
7377
|
+
clientPrivateKey = await importPKCS8(clientPrivateKey, _classPrivateFieldGet2(_options, this).clientAssertionSigningAlg || "RS256");
|
|
7378
|
+
}
|
|
7379
|
+
return clientPrivateKey ? PrivateKeyJwt(clientPrivateKey) : ClientSecretPost(_classPrivateFieldGet2(_options, this).clientSecret);
|
|
7380
|
+
})().catch(error => {
|
|
7381
|
+
_classPrivateFieldSet2(_clientAuthPromise, this, void 0);
|
|
7382
|
+
throw error;
|
|
7383
|
+
}));
|
|
7205
7384
|
}
|
|
7206
|
-
return
|
|
7385
|
+
return _classPrivateFieldGet2(_clientAuthPromise, this);
|
|
7207
7386
|
}
|
|
7208
7387
|
async function _buildAuthorizationUrl(options) {
|
|
7209
|
-
const {configuration: configuration} = await _assertClassBrand(
|
|
7388
|
+
const {configuration: configuration} = await _assertClassBrand(_Class9_brand, this, _discover).call(this);
|
|
7210
7389
|
const codeChallengeMethod = "S256";
|
|
7211
7390
|
const codeVerifier = randomPKCECodeVerifier();
|
|
7212
7391
|
const codeChallenge = await calculatePKCECodeChallenge(codeVerifier);
|
|
@@ -7322,15 +7501,15 @@
|
|
|
7322
7501
|
if (!((_a = context === null || context === void 0 ? void 0 : context.mfaRequirements) === null || _a === void 0 ? void 0 : _a.challenge) || context.mfaRequirements.challenge.length === 0) {
|
|
7323
7502
|
throw new MfaListAuthenticatorsError("invalid_request", "challengeType is required and must contain at least one challenge type, please check mfa_required error payload");
|
|
7324
7503
|
}
|
|
7325
|
-
const challengeTypes = context.mfaRequirements.challenge.map(
|
|
7504
|
+
const challengeTypes = context.mfaRequirements.challenge.map(c => c.type);
|
|
7326
7505
|
try {
|
|
7327
7506
|
const allAuthenticators = await this.authJsMfaClient.listAuthenticators({
|
|
7328
7507
|
mfaToken: mfaToken
|
|
7329
7508
|
});
|
|
7330
|
-
return allAuthenticators.filter(
|
|
7509
|
+
return allAuthenticators.filter(auth => {
|
|
7331
7510
|
if (!auth.type) return false;
|
|
7332
7511
|
return challengeTypes.includes(auth.type);
|
|
7333
|
-
})
|
|
7512
|
+
});
|
|
7334
7513
|
} catch (error) {
|
|
7335
7514
|
if (error instanceof MfaListAuthenticatorsError$1) {
|
|
7336
7515
|
throw new MfaListAuthenticatorsError((_b = error.cause) === null || _b === void 0 ? void 0 : _b.error, error.message);
|
|
@@ -7695,7 +7874,7 @@
|
|
|
7695
7874
|
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)
|
|
7696
7875
|
})
|
|
7697
7876
|
});
|
|
7698
|
-
const result = await singlePromise((
|
|
7877
|
+
const result = await singlePromise(() => this._getTokenSilently(localOptions), "".concat(this.options.clientId, "::").concat(localOptions.authorizationParams.audience, "::").concat(localOptions.authorizationParams.scope));
|
|
7699
7878
|
return options.detailedResponse ? result : result === null || result === void 0 ? void 0 : result.access_token;
|
|
7700
7879
|
}
|
|
7701
7880
|
async _getTokenSilently(options) {
|
|
@@ -7716,7 +7895,7 @@
|
|
|
7716
7895
|
}
|
|
7717
7896
|
const lockKey = buildGetTokenSilentlyLockKey(this.options.clientId, getTokenOptions.authorizationParams.audience || "default");
|
|
7718
7897
|
try {
|
|
7719
|
-
return await this.lockManager.runWithLock(lockKey, 5e3,
|
|
7898
|
+
return await this.lockManager.runWithLock(lockKey, 5e3, async () => {
|
|
7720
7899
|
if (cacheMode !== "off") {
|
|
7721
7900
|
const entry = await this._getEntryFromCache({
|
|
7722
7901
|
scope: getTokenOptions.authorizationParams.scope,
|
|
@@ -7738,7 +7917,7 @@
|
|
|
7738
7917
|
} : null), {
|
|
7739
7918
|
expires_in: expires_in
|
|
7740
7919
|
});
|
|
7741
|
-
})
|
|
7920
|
+
});
|
|
7742
7921
|
} catch (error) {
|
|
7743
7922
|
if (this._isInteractiveError(error) && this.options.interactiveErrorHandler === "popup") {
|
|
7744
7923
|
return await this._handleInteractiveErrorWithPopup(getTokenOptions);
|
|
@@ -7747,7 +7926,10 @@
|
|
|
7747
7926
|
}
|
|
7748
7927
|
}
|
|
7749
7928
|
_isInteractiveError(error) {
|
|
7750
|
-
return error instanceof MfaRequiredError;
|
|
7929
|
+
return error instanceof MfaRequiredError || error instanceof GenericError && this._isIframeMfaError(error);
|
|
7930
|
+
}
|
|
7931
|
+
_isIframeMfaError(error) {
|
|
7932
|
+
return error.error === "login_required" && error.error_description === MFA_STEP_UP_ERROR_DESCRIPTION;
|
|
7751
7933
|
}
|
|
7752
7934
|
async _handleInteractiveErrorWithPopup(options) {
|
|
7753
7935
|
try {
|
|
@@ -7829,7 +8011,7 @@
|
|
|
7829
8011
|
async _getTokenFromIFrame(options) {
|
|
7830
8012
|
const iframeLockKey = buildIframeLockKey(this.options.clientId);
|
|
7831
8013
|
try {
|
|
7832
|
-
return await this.lockManager.runWithLock(iframeLockKey, 5e3,
|
|
8014
|
+
return await this.lockManager.runWithLock(iframeLockKey, 5e3, async () => {
|
|
7833
8015
|
const params = Object.assign(Object.assign({}, options.authorizationParams), {
|
|
7834
8016
|
prompt: "none"
|
|
7835
8017
|
});
|
|
@@ -7869,12 +8051,15 @@
|
|
|
7869
8051
|
oauthTokenScope: tokenResult.scope,
|
|
7870
8052
|
audience: audience
|
|
7871
8053
|
});
|
|
7872
|
-
})
|
|
8054
|
+
});
|
|
7873
8055
|
} catch (e) {
|
|
7874
8056
|
if (e.error === "login_required") {
|
|
7875
|
-
this.
|
|
7876
|
-
|
|
7877
|
-
|
|
8057
|
+
const shouldSkipLogoutForMfaStepUp = e instanceof GenericError && this._isIframeMfaError(e) && this.options.interactiveErrorHandler === "popup";
|
|
8058
|
+
if (!shouldSkipLogoutForMfaStepUp) {
|
|
8059
|
+
this.logout({
|
|
8060
|
+
openUrl: false
|
|
8061
|
+
});
|
|
8062
|
+
}
|
|
7878
8063
|
}
|
|
7879
8064
|
throw e;
|
|
7880
8065
|
}
|
|
@@ -8153,5 +8338,5 @@
|
|
|
8153
8338
|
Object.defineProperty(exports, "__esModule", {
|
|
8154
8339
|
value: true
|
|
8155
8340
|
});
|
|
8156
|
-
})
|
|
8341
|
+
});
|
|
8157
8342
|
//# sourceMappingURL=auth0-spa-js.development.js.map
|