zudoku 0.3.0-dev.54 → 0.3.0-dev.55
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/lib/AnchorLink-BaXHjhF-.js +989 -0
- package/lib/{AnchorLink-BCN_a_Uz.js.map → AnchorLink-BaXHjhF-.js.map} +1 -1
- package/lib/Combination-BfufJFkX.js +1365 -0
- package/lib/{Combination-B0Iu6mhJ.js.map → Combination-BfufJFkX.js.map} +1 -1
- package/lib/DevPortalProvider-GjdO0Xr-.js +1610 -0
- package/lib/{DevPortalProvider-Do9oJqme.js.map → DevPortalProvider-GjdO0Xr-.js.map} +1 -1
- package/lib/Markdown-B8nPVql1.js +19708 -0
- package/lib/Markdown-B8nPVql1.js.map +1 -0
- package/lib/MdxPage-Dlujuj-J.js +223 -0
- package/lib/{MdxPage-Bsc79cD-.js.map → MdxPage-Dlujuj-J.js.map} +1 -1
- package/lib/OperationList-krPgt6sE.js +8041 -0
- package/lib/{OperationList-K-JWBxau.js.map → OperationList-krPgt6sE.js.map} +1 -1
- package/lib/Playground-DOHxca0P.js +539 -0
- package/lib/{Playground-Czy7ha9z.js.map → Playground-DOHxca0P.js.map} +1 -1
- package/lib/Route-CR6TEwVC.js +13 -0
- package/lib/{Route-D-egsGHx.js.map → Route-CR6TEwVC.js.map} +1 -1
- package/lib/Select-Boi_pe3L.js +5298 -0
- package/lib/{Select-CcBbwJ2R.js.map → Select-Boi_pe3L.js.map} +1 -1
- package/lib/Spinner-oU0QJmi_.js +16 -0
- package/lib/{Spinner-C9_Opdev.js.map → Spinner-oU0QJmi_.js.map} +1 -1
- package/lib/_commonjsHelpers-BxmBWJD2.js +34 -0
- package/lib/_commonjsHelpers-BxmBWJD2.js.map +1 -0
- package/lib/assets/index-CpIig0AX.js +6341 -0
- package/lib/{index-pI9JkN46.js.map → assets/index-CpIig0AX.js.map} +1 -1
- package/lib/assets/worker-B5k2aBV9.js +18921 -0
- package/lib/assets/{worker-BjPv-hjP.js.map → worker-B5k2aBV9.js.map} +1 -1
- package/lib/context-BoN_3uxi.js +17 -0
- package/lib/{context-_fYfJFgk.js.map → context-BoN_3uxi.js.map} +1 -1
- package/lib/hook-CIuFuyBT.js +90 -0
- package/lib/{hook-CKqQERWo.js.map → hook-CIuFuyBT.js.map} +1 -1
- package/lib/index-BL1P4Gqq.js +280 -0
- package/lib/{index-ByHya67R.js.map → index-BL1P4Gqq.js.map} +1 -1
- package/lib/index-Bn03IPZt.js +6341 -0
- package/lib/{assets/index-BPdJm2ty.js.map → index-Bn03IPZt.js.map} +1 -1
- package/lib/{index-jsFBaizC.js → index-Dih8IAqw.js} +103 -83
- package/lib/{index-jsFBaizC.js.map → index-Dih8IAqw.js.map} +1 -1
- package/lib/index-FprhHF51.js +253 -0
- package/lib/{index-DseBZFJ-.js.map → index-FprhHF51.js.map} +1 -1
- package/lib/jsx-runtime-DvZ6OKMM.js +2110 -0
- package/lib/{jsx-runtime-CJZJivg2.js.map → jsx-runtime-DvZ6OKMM.js.map} +1 -1
- package/lib/mutation-DWY9x2Uc.js +250 -0
- package/lib/{mutation-DjbQSHzT.js.map → mutation-DWY9x2Uc.js.map} +1 -1
- package/lib/prism-bash.min-BtBk0onv.js +7 -0
- package/lib/{prism-bash.min-DadFsM4Z.js.map → prism-bash.min-BtBk0onv.js.map} +1 -1
- package/lib/prism-csharp.min-Cv7D49bv.js +30 -0
- package/lib/{prism-csharp.min-Yizuc34Y.js.map → prism-csharp.min-Cv7D49bv.js.map} +1 -1
- package/lib/prism-java.min-tNK-JX6x.js +7 -0
- package/lib/{prism-java.min-d5iT_mOd.js.map → prism-java.min-tNK-JX6x.js.map} +1 -1
- package/lib/prism-json.min-Cdtv-CME.js +2 -0
- package/lib/{prism-json.min-B1GJqK1k.js.map → prism-json.min-Cdtv-CME.js.map} +1 -1
- package/lib/prism-markup-templating-iotg2sCU.js +94 -0
- package/lib/{prism-markup-templating-DZrrEs0A.js.map → prism-markup-templating-iotg2sCU.js.map} +1 -1
- package/lib/prism-objectivec.min-CY4WGixz.js +2 -0
- package/lib/{prism-objectivec.min-BXSWqpJJ.js.map → prism-objectivec.min-CY4WGixz.js.map} +1 -1
- package/lib/prism-php.min-T6sIVgED.js +11 -0
- package/lib/{prism-php.min-o7FpoMP_.js.map → prism-php.min-T6sIVgED.js.map} +1 -1
- package/lib/prism-ruby.min-B-2KAa4y.js +8 -0
- package/lib/{prism-ruby.min-C7LwcKyz.js.map → prism-ruby.min-B-2KAa4y.js.map} +1 -1
- package/lib/router-ButO1QyY.js +4062 -0
- package/lib/{router-CBw2vqJE.js.map → router-ButO1QyY.js.map} +1 -1
- package/lib/slugify-CmS97Vy8.js +50 -0
- package/lib/{slugify-CiPVjteN.js.map → slugify-CmS97Vy8.js.map} +1 -1
- package/lib/state-CmGfNKhR.js +436 -0
- package/lib/{state-DKdaQzvh.js.map → state-CmGfNKhR.js.map} +1 -1
- package/lib/urql-DtVKPBx_.js +2567 -0
- package/lib/{urql-DEKdguFl.js.map → urql-DtVKPBx_.js.map} +1 -1
- package/lib/util-B5KX4h4M.js +55 -0
- package/lib/{util-_jwUlTBU.js.map → util-B5KX4h4M.js.map} +1 -1
- package/lib/zudoku.auth-auth0.js +24 -18
- package/lib/zudoku.auth-auth0.js.map +1 -1
- package/lib/zudoku.auth-clerk.js +43 -34
- package/lib/zudoku.auth-clerk.js.map +1 -1
- package/lib/zudoku.auth-openid.js +1121 -734
- package/lib/zudoku.auth-openid.js.map +1 -1
- package/lib/zudoku.components.js +1076 -823
- package/lib/zudoku.components.js.map +1 -1
- package/lib/zudoku.openapi-worker.js +13776 -9681
- package/lib/zudoku.openapi-worker.js.map +1 -1
- package/lib/zudoku.plugin-api-keys.js +206 -165
- package/lib/zudoku.plugin-api-keys.js.map +1 -1
- package/lib/zudoku.plugin-markdown.js +41 -33
- package/lib/zudoku.plugin-markdown.js.map +1 -1
- package/lib/zudoku.plugin-openapi.js +6 -6
- package/lib/zudoku.plugin-redirect.js +10 -8
- package/lib/zudoku.plugin-redirect.js.map +1 -1
- package/package.json +1 -1
- package/lib/AnchorLink-BCN_a_Uz.js +0 -705
- package/lib/Combination-B0Iu6mhJ.js +0 -915
- package/lib/DevPortalProvider-Do9oJqme.js +0 -1081
- package/lib/Markdown-aE_XoLNs.js +0 -15030
- package/lib/Markdown-aE_XoLNs.js.map +0 -1
- package/lib/MdxPage-Bsc79cD-.js +0 -190
- package/lib/OperationList-K-JWBxau.js +0 -5091
- package/lib/Playground-Czy7ha9z.js +0 -502
- package/lib/Route-D-egsGHx.js +0 -13
- package/lib/Select-CcBbwJ2R.js +0 -3667
- package/lib/Spinner-C9_Opdev.js +0 -15
- package/lib/_commonjsHelpers-BVfed4GL.js +0 -29
- package/lib/_commonjsHelpers-BVfed4GL.js.map +0 -1
- package/lib/assets/index-BPdJm2ty.js +0 -4765
- package/lib/assets/worker-BjPv-hjP.js +0 -14897
- package/lib/context-_fYfJFgk.js +0 -14
- package/lib/hook-CKqQERWo.js +0 -77
- package/lib/index-ByHya67R.js +0 -207
- package/lib/index-DseBZFJ-.js +0 -170
- package/lib/index-pI9JkN46.js +0 -4765
- package/lib/jsx-runtime-CJZJivg2.js +0 -1526
- package/lib/mutation-DjbQSHzT.js +0 -208
- package/lib/prism-bash.min-DadFsM4Z.js +0 -7
- package/lib/prism-csharp.min-Yizuc34Y.js +0 -35
- package/lib/prism-java.min-d5iT_mOd.js +0 -7
- package/lib/prism-json.min-B1GJqK1k.js +0 -2
- package/lib/prism-markup-templating-DZrrEs0A.js +0 -62
- package/lib/prism-objectivec.min-BXSWqpJJ.js +0 -2
- package/lib/prism-php.min-o7FpoMP_.js +0 -11
- package/lib/prism-ruby.min-C7LwcKyz.js +0 -10
- package/lib/router-CBw2vqJE.js +0 -2973
- package/lib/slugify-CiPVjteN.js +0 -28
- package/lib/state-DKdaQzvh.js +0 -288
- package/lib/urql-DEKdguFl.js +0 -1592
- package/lib/util-_jwUlTBU.js +0 -41
|
@@ -1,348 +1,529 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
+
var _a, _b;
|
|
5
|
+
import { a as useNavigate, j as jsxRuntimeExports } from "./jsx-runtime-DvZ6OKMM.js";
|
|
6
|
+
import { c as commonjsGlobal, a as getDefaultExportFromCjs } from "./_commonjsHelpers-BxmBWJD2.js";
|
|
7
|
+
import { useRef, useState, useEffect } from "react";
|
|
8
|
+
import { u as useAuthState } from "./state-CmGfNKhR.js";
|
|
9
|
+
var loglevel = { exports: {} };
|
|
10
|
+
(function(module) {
|
|
11
|
+
(function(root, definition) {
|
|
12
|
+
if (module.exports) {
|
|
13
|
+
module.exports = definition();
|
|
14
|
+
} else {
|
|
15
|
+
root.log = definition();
|
|
16
|
+
}
|
|
17
|
+
})(commonjsGlobal, function() {
|
|
18
|
+
var noop = function() {
|
|
19
|
+
};
|
|
20
|
+
var undefinedType = "undefined";
|
|
21
|
+
var isIE = typeof window !== undefinedType && typeof window.navigator !== undefinedType && /Trident\/|MSIE /.test(window.navigator.userAgent);
|
|
22
|
+
var logMethods = [
|
|
15
23
|
"trace",
|
|
16
24
|
"debug",
|
|
17
25
|
"info",
|
|
18
26
|
"warn",
|
|
19
27
|
"error"
|
|
20
|
-
]
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return Function.prototype.
|
|
30
|
-
}
|
|
28
|
+
];
|
|
29
|
+
var _loggersByName = {};
|
|
30
|
+
var defaultLogger = null;
|
|
31
|
+
function bindMethod(obj, methodName) {
|
|
32
|
+
var method = obj[methodName];
|
|
33
|
+
if (typeof method.bind === "function") {
|
|
34
|
+
return method.bind(obj);
|
|
35
|
+
} else {
|
|
36
|
+
try {
|
|
37
|
+
return Function.prototype.bind.call(method, obj);
|
|
38
|
+
} catch (e) {
|
|
39
|
+
return function() {
|
|
40
|
+
return Function.prototype.apply.apply(method, [obj, arguments]);
|
|
41
|
+
};
|
|
42
|
+
}
|
|
31
43
|
}
|
|
32
44
|
}
|
|
33
|
-
function
|
|
34
|
-
|
|
45
|
+
function traceForIE() {
|
|
46
|
+
if (console.log) {
|
|
47
|
+
if (console.log.apply) {
|
|
48
|
+
console.log.apply(console, arguments);
|
|
49
|
+
} else {
|
|
50
|
+
Function.prototype.apply.apply(console.log, [console, arguments]);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if (console.trace) console.trace();
|
|
35
54
|
}
|
|
36
|
-
function
|
|
37
|
-
|
|
55
|
+
function realMethod(methodName) {
|
|
56
|
+
if (methodName === "debug") {
|
|
57
|
+
methodName = "log";
|
|
58
|
+
}
|
|
59
|
+
if (typeof console === undefinedType) {
|
|
60
|
+
return false;
|
|
61
|
+
} else if (methodName === "trace" && isIE) {
|
|
62
|
+
return traceForIE;
|
|
63
|
+
} else if (console[methodName] !== void 0) {
|
|
64
|
+
return bindMethod(console, methodName);
|
|
65
|
+
} else if (console.log !== void 0) {
|
|
66
|
+
return bindMethod(console, "log");
|
|
67
|
+
} else {
|
|
68
|
+
return noop;
|
|
69
|
+
}
|
|
38
70
|
}
|
|
39
|
-
function
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
71
|
+
function replaceLoggingMethods() {
|
|
72
|
+
var level = this.getLevel();
|
|
73
|
+
for (var i = 0; i < logMethods.length; i++) {
|
|
74
|
+
var methodName = logMethods[i];
|
|
75
|
+
this[methodName] = i < level ? noop : this.methodFactory(methodName, level, this.name);
|
|
43
76
|
}
|
|
44
|
-
|
|
77
|
+
this.log = this.debug;
|
|
78
|
+
if (typeof console === undefinedType && level < this.levels.SILENT) {
|
|
45
79
|
return "No console available for logging";
|
|
80
|
+
}
|
|
46
81
|
}
|
|
47
|
-
function
|
|
82
|
+
function enableLoggingWhenConsoleArrives(methodName) {
|
|
48
83
|
return function() {
|
|
49
|
-
typeof console !==
|
|
84
|
+
if (typeof console !== undefinedType) {
|
|
85
|
+
replaceLoggingMethods.call(this);
|
|
86
|
+
this[methodName].apply(this, arguments);
|
|
87
|
+
}
|
|
50
88
|
};
|
|
51
89
|
}
|
|
52
|
-
function
|
|
53
|
-
return
|
|
90
|
+
function defaultMethodFactory(methodName, _level, _loggerName) {
|
|
91
|
+
return realMethod(methodName) || enableLoggingWhenConsoleArrives.apply(this, arguments);
|
|
54
92
|
}
|
|
55
|
-
function
|
|
56
|
-
var
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
93
|
+
function Logger(name, factory) {
|
|
94
|
+
var self = this;
|
|
95
|
+
var inheritedLevel;
|
|
96
|
+
var defaultLevel;
|
|
97
|
+
var userLevel;
|
|
98
|
+
var storageKey = "loglevel";
|
|
99
|
+
if (typeof name === "string") {
|
|
100
|
+
storageKey += ":" + name;
|
|
101
|
+
} else if (typeof name === "symbol") {
|
|
102
|
+
storageKey = void 0;
|
|
103
|
+
}
|
|
104
|
+
function persistLevelIfPossible(levelNum) {
|
|
105
|
+
var levelName = (logMethods[levelNum] || "silent").toUpperCase();
|
|
106
|
+
if (typeof window === undefinedType || !storageKey) return;
|
|
107
|
+
try {
|
|
108
|
+
window.localStorage[storageKey] = levelName;
|
|
109
|
+
return;
|
|
110
|
+
} catch (ignore) {
|
|
111
|
+
}
|
|
112
|
+
try {
|
|
113
|
+
window.document.cookie = encodeURIComponent(storageKey) + "=" + levelName + ";";
|
|
114
|
+
} catch (ignore) {
|
|
70
115
|
}
|
|
71
116
|
}
|
|
72
|
-
function
|
|
73
|
-
var
|
|
74
|
-
if (
|
|
117
|
+
function getPersistedLevel() {
|
|
118
|
+
var storedLevel;
|
|
119
|
+
if (typeof window === undefinedType || !storageKey) return;
|
|
120
|
+
try {
|
|
121
|
+
storedLevel = window.localStorage[storageKey];
|
|
122
|
+
} catch (ignore) {
|
|
123
|
+
}
|
|
124
|
+
if (typeof storedLevel === undefinedType) {
|
|
75
125
|
try {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
p.slice(ne + O.length + 1)
|
|
84
|
-
)[1]);
|
|
85
|
-
} catch {
|
|
126
|
+
var cookie = window.document.cookie;
|
|
127
|
+
var cookieName = encodeURIComponent(storageKey);
|
|
128
|
+
var location2 = cookie.indexOf(cookieName + "=");
|
|
129
|
+
if (location2 !== -1) {
|
|
130
|
+
storedLevel = /^([^;]+)/.exec(
|
|
131
|
+
cookie.slice(location2 + cookieName.length + 1)
|
|
132
|
+
)[1];
|
|
86
133
|
}
|
|
87
|
-
|
|
134
|
+
} catch (ignore) {
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
if (self.levels[storedLevel] === void 0) {
|
|
138
|
+
storedLevel = void 0;
|
|
88
139
|
}
|
|
140
|
+
return storedLevel;
|
|
89
141
|
}
|
|
90
|
-
function
|
|
91
|
-
if (
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}
|
|
142
|
+
function clearPersistedLevel() {
|
|
143
|
+
if (typeof window === undefinedType || !storageKey) return;
|
|
144
|
+
try {
|
|
145
|
+
window.localStorage.removeItem(storageKey);
|
|
146
|
+
} catch (ignore) {
|
|
147
|
+
}
|
|
148
|
+
try {
|
|
149
|
+
window.document.cookie = encodeURIComponent(storageKey) + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC";
|
|
150
|
+
} catch (ignore) {
|
|
100
151
|
}
|
|
101
152
|
}
|
|
102
|
-
function
|
|
103
|
-
var
|
|
104
|
-
if (typeof
|
|
105
|
-
|
|
106
|
-
|
|
153
|
+
function normalizeLevel(input) {
|
|
154
|
+
var level = input;
|
|
155
|
+
if (typeof level === "string" && self.levels[level.toUpperCase()] !== void 0) {
|
|
156
|
+
level = self.levels[level.toUpperCase()];
|
|
157
|
+
}
|
|
158
|
+
if (typeof level === "number" && level >= 0 && level <= self.levels.SILENT) {
|
|
159
|
+
return level;
|
|
160
|
+
} else {
|
|
161
|
+
throw new TypeError("log.setLevel() called with invalid level: " + input);
|
|
162
|
+
}
|
|
107
163
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
164
|
+
self.name = name;
|
|
165
|
+
self.levels = {
|
|
166
|
+
"TRACE": 0,
|
|
167
|
+
"DEBUG": 1,
|
|
168
|
+
"INFO": 2,
|
|
169
|
+
"WARN": 3,
|
|
170
|
+
"ERROR": 4,
|
|
171
|
+
"SILENT": 5
|
|
172
|
+
};
|
|
173
|
+
self.methodFactory = factory || defaultMethodFactory;
|
|
174
|
+
self.getLevel = function() {
|
|
175
|
+
if (userLevel != null) {
|
|
176
|
+
return userLevel;
|
|
177
|
+
} else if (defaultLevel != null) {
|
|
178
|
+
return defaultLevel;
|
|
179
|
+
} else {
|
|
180
|
+
return inheritedLevel;
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
self.setLevel = function(level, persist) {
|
|
184
|
+
userLevel = normalizeLevel(level);
|
|
185
|
+
if (persist !== false) {
|
|
186
|
+
persistLevelIfPossible(userLevel);
|
|
187
|
+
}
|
|
188
|
+
return replaceLoggingMethods.call(self);
|
|
189
|
+
};
|
|
190
|
+
self.setDefaultLevel = function(level) {
|
|
191
|
+
defaultLevel = normalizeLevel(level);
|
|
192
|
+
if (!getPersistedLevel()) {
|
|
193
|
+
self.setLevel(level, false);
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
self.resetLevel = function() {
|
|
197
|
+
userLevel = null;
|
|
198
|
+
clearPersistedLevel();
|
|
199
|
+
replaceLoggingMethods.call(self);
|
|
200
|
+
};
|
|
201
|
+
self.enableAll = function(persist) {
|
|
202
|
+
self.setLevel(self.levels.TRACE, persist);
|
|
203
|
+
};
|
|
204
|
+
self.disableAll = function(persist) {
|
|
205
|
+
self.setLevel(self.levels.SILENT, persist);
|
|
206
|
+
};
|
|
207
|
+
self.rebuild = function() {
|
|
208
|
+
if (defaultLogger !== self) {
|
|
209
|
+
inheritedLevel = normalizeLevel(defaultLogger.getLevel());
|
|
210
|
+
}
|
|
211
|
+
replaceLoggingMethods.call(self);
|
|
212
|
+
if (defaultLogger === self) {
|
|
213
|
+
for (var childName in _loggersByName) {
|
|
214
|
+
_loggersByName[childName].rebuild();
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
inheritedLevel = normalizeLevel(
|
|
219
|
+
defaultLogger ? defaultLogger.getLevel() : "WARN"
|
|
133
220
|
);
|
|
134
|
-
var
|
|
135
|
-
|
|
221
|
+
var initialLevel = getPersistedLevel();
|
|
222
|
+
if (initialLevel != null) {
|
|
223
|
+
userLevel = normalizeLevel(initialLevel);
|
|
224
|
+
}
|
|
225
|
+
replaceLoggingMethods.call(self);
|
|
136
226
|
}
|
|
137
|
-
|
|
138
|
-
|
|
227
|
+
defaultLogger = new Logger();
|
|
228
|
+
defaultLogger.getLogger = function getLogger(name) {
|
|
229
|
+
if (typeof name !== "symbol" && typeof name !== "string" || name === "") {
|
|
139
230
|
throw new TypeError("You must supply a name when creating a logger.");
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
231
|
+
}
|
|
232
|
+
var logger2 = _loggersByName[name];
|
|
233
|
+
if (!logger2) {
|
|
234
|
+
logger2 = _loggersByName[name] = new Logger(
|
|
235
|
+
name,
|
|
236
|
+
defaultLogger.methodFactory
|
|
237
|
+
);
|
|
238
|
+
}
|
|
239
|
+
return logger2;
|
|
240
|
+
};
|
|
241
|
+
var _log = typeof window !== undefinedType ? window.log : void 0;
|
|
242
|
+
defaultLogger.noConflict = function() {
|
|
243
|
+
if (typeof window !== undefinedType && window.log === defaultLogger) {
|
|
244
|
+
window.log = _log;
|
|
245
|
+
}
|
|
246
|
+
return defaultLogger;
|
|
145
247
|
};
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
}, i.default = i, i;
|
|
248
|
+
defaultLogger.getLoggers = function getLoggers() {
|
|
249
|
+
return _loggersByName;
|
|
250
|
+
};
|
|
251
|
+
defaultLogger["default"] = defaultLogger;
|
|
252
|
+
return defaultLogger;
|
|
152
253
|
});
|
|
153
|
-
})(
|
|
154
|
-
var
|
|
155
|
-
const
|
|
156
|
-
let
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
254
|
+
})(loglevel);
|
|
255
|
+
var loglevelExports = loglevel.exports;
|
|
256
|
+
const logger = /* @__PURE__ */ getDefaultExportFromCjs(loglevelExports);
|
|
257
|
+
let USER_AGENT;
|
|
258
|
+
if (typeof navigator === "undefined" || !((_b = (_a = navigator.userAgent) == null ? void 0 : _a.startsWith) == null ? void 0 : _b.call(_a, "Mozilla/5.0 "))) {
|
|
259
|
+
const NAME = "oauth4webapi";
|
|
260
|
+
const VERSION = "v2.11.1";
|
|
261
|
+
USER_AGENT = `${NAME}/${VERSION}`;
|
|
262
|
+
}
|
|
263
|
+
function looseInstanceOf(input, expected) {
|
|
264
|
+
if (input == null) {
|
|
265
|
+
return false;
|
|
266
|
+
}
|
|
162
267
|
try {
|
|
163
|
-
return
|
|
268
|
+
return input instanceof expected || Object.getPrototypeOf(input)[Symbol.toStringTag] === expected.prototype[Symbol.toStringTag];
|
|
164
269
|
} catch {
|
|
165
|
-
return
|
|
270
|
+
return false;
|
|
166
271
|
}
|
|
167
272
|
}
|
|
168
|
-
const
|
|
169
|
-
|
|
170
|
-
|
|
273
|
+
const clockSkew = Symbol();
|
|
274
|
+
const clockTolerance = Symbol();
|
|
275
|
+
const customFetch = Symbol();
|
|
276
|
+
const encoder = new TextEncoder();
|
|
277
|
+
const decoder = new TextDecoder();
|
|
278
|
+
function buf(input) {
|
|
279
|
+
if (typeof input === "string") {
|
|
280
|
+
return encoder.encode(input);
|
|
281
|
+
}
|
|
282
|
+
return decoder.decode(input);
|
|
171
283
|
}
|
|
172
|
-
const
|
|
173
|
-
function
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
284
|
+
const CHUNK_SIZE = 32768;
|
|
285
|
+
function encodeBase64Url(input) {
|
|
286
|
+
if (input instanceof ArrayBuffer) {
|
|
287
|
+
input = new Uint8Array(input);
|
|
288
|
+
}
|
|
289
|
+
const arr = [];
|
|
290
|
+
for (let i = 0; i < input.byteLength; i += CHUNK_SIZE) {
|
|
291
|
+
arr.push(String.fromCharCode.apply(null, input.subarray(i, i + CHUNK_SIZE)));
|
|
292
|
+
}
|
|
293
|
+
return btoa(arr.join("")).replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
|
|
179
294
|
}
|
|
180
|
-
function
|
|
295
|
+
function decodeBase64Url(input) {
|
|
181
296
|
try {
|
|
182
|
-
const
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
297
|
+
const binary = atob(input.replace(/-/g, "+").replace(/_/g, "/").replace(/\s/g, ""));
|
|
298
|
+
const bytes = new Uint8Array(binary.length);
|
|
299
|
+
for (let i = 0; i < binary.length; i++) {
|
|
300
|
+
bytes[i] = binary.charCodeAt(i);
|
|
301
|
+
}
|
|
302
|
+
return bytes;
|
|
303
|
+
} catch (cause) {
|
|
304
|
+
throw new OPE("The input to be decoded is not correctly encoded.", { cause });
|
|
188
305
|
}
|
|
189
306
|
}
|
|
190
|
-
function
|
|
191
|
-
|
|
307
|
+
function b64u(input) {
|
|
308
|
+
if (typeof input === "string") {
|
|
309
|
+
return decodeBase64Url(input);
|
|
310
|
+
}
|
|
311
|
+
return encodeBase64Url(input);
|
|
192
312
|
}
|
|
193
|
-
class
|
|
194
|
-
constructor(
|
|
195
|
-
this.cache = /* @__PURE__ */ new Map()
|
|
313
|
+
class LRU {
|
|
314
|
+
constructor(maxSize) {
|
|
315
|
+
this.cache = /* @__PURE__ */ new Map();
|
|
316
|
+
this._cache = /* @__PURE__ */ new Map();
|
|
317
|
+
this.maxSize = maxSize;
|
|
196
318
|
}
|
|
197
|
-
get(
|
|
198
|
-
let
|
|
199
|
-
if (
|
|
200
|
-
return
|
|
201
|
-
|
|
202
|
-
|
|
319
|
+
get(key) {
|
|
320
|
+
let v = this.cache.get(key);
|
|
321
|
+
if (v) {
|
|
322
|
+
return v;
|
|
323
|
+
}
|
|
324
|
+
if (v = this._cache.get(key)) {
|
|
325
|
+
this.update(key, v);
|
|
326
|
+
return v;
|
|
327
|
+
}
|
|
328
|
+
return void 0;
|
|
203
329
|
}
|
|
204
|
-
has(
|
|
205
|
-
return this.cache.has(
|
|
330
|
+
has(key) {
|
|
331
|
+
return this.cache.has(key) || this._cache.has(key);
|
|
206
332
|
}
|
|
207
|
-
set(
|
|
208
|
-
|
|
333
|
+
set(key, value) {
|
|
334
|
+
if (this.cache.has(key)) {
|
|
335
|
+
this.cache.set(key, value);
|
|
336
|
+
} else {
|
|
337
|
+
this.update(key, value);
|
|
338
|
+
}
|
|
339
|
+
return this;
|
|
209
340
|
}
|
|
210
|
-
delete(
|
|
211
|
-
|
|
341
|
+
delete(key) {
|
|
342
|
+
if (this.cache.has(key)) {
|
|
343
|
+
return this.cache.delete(key);
|
|
344
|
+
}
|
|
345
|
+
if (this._cache.has(key)) {
|
|
346
|
+
return this._cache.delete(key);
|
|
347
|
+
}
|
|
348
|
+
return false;
|
|
212
349
|
}
|
|
213
|
-
update(
|
|
214
|
-
this.cache.set(
|
|
350
|
+
update(key, value) {
|
|
351
|
+
this.cache.set(key, value);
|
|
352
|
+
if (this.cache.size >= this.maxSize) {
|
|
353
|
+
this._cache = this.cache;
|
|
354
|
+
this.cache = /* @__PURE__ */ new Map();
|
|
355
|
+
}
|
|
215
356
|
}
|
|
216
357
|
}
|
|
217
|
-
class
|
|
218
|
-
constructor(
|
|
219
|
-
var
|
|
220
|
-
super(
|
|
358
|
+
class UnsupportedOperationError extends Error {
|
|
359
|
+
constructor(message) {
|
|
360
|
+
var _a2;
|
|
361
|
+
super(message ?? "operation not supported");
|
|
362
|
+
this.name = this.constructor.name;
|
|
363
|
+
(_a2 = Error.captureStackTrace) == null ? void 0 : _a2.call(Error, this, this.constructor);
|
|
221
364
|
}
|
|
222
365
|
}
|
|
223
|
-
class
|
|
224
|
-
constructor(
|
|
225
|
-
var
|
|
226
|
-
super(
|
|
366
|
+
class OperationProcessingError extends Error {
|
|
367
|
+
constructor(message, options) {
|
|
368
|
+
var _a2;
|
|
369
|
+
super(message, options);
|
|
370
|
+
this.name = this.constructor.name;
|
|
371
|
+
(_a2 = Error.captureStackTrace) == null ? void 0 : _a2.call(Error, this, this.constructor);
|
|
227
372
|
}
|
|
228
373
|
}
|
|
229
|
-
const
|
|
230
|
-
|
|
231
|
-
|
|
374
|
+
const OPE = OperationProcessingError;
|
|
375
|
+
const dpopNonces = new LRU(100);
|
|
376
|
+
function isCryptoKey(key) {
|
|
377
|
+
return key instanceof CryptoKey;
|
|
232
378
|
}
|
|
233
|
-
function
|
|
234
|
-
return
|
|
379
|
+
function isPrivateKey(key) {
|
|
380
|
+
return isCryptoKey(key) && key.type === "private";
|
|
235
381
|
}
|
|
236
|
-
function
|
|
237
|
-
return
|
|
382
|
+
function isPublicKey(key) {
|
|
383
|
+
return isCryptoKey(key) && key.type === "public";
|
|
238
384
|
}
|
|
239
|
-
function
|
|
385
|
+
function processDpopNonce(response) {
|
|
240
386
|
try {
|
|
241
|
-
const
|
|
242
|
-
|
|
387
|
+
const nonce = response.headers.get("dpop-nonce");
|
|
388
|
+
if (nonce) {
|
|
389
|
+
dpopNonces.set(new URL(response.url).origin, nonce);
|
|
390
|
+
}
|
|
243
391
|
} catch {
|
|
244
392
|
}
|
|
245
|
-
return
|
|
393
|
+
return response;
|
|
246
394
|
}
|
|
247
|
-
function
|
|
248
|
-
|
|
395
|
+
function isJsonObject(input) {
|
|
396
|
+
if (input === null || typeof input !== "object" || Array.isArray(input)) {
|
|
397
|
+
return false;
|
|
398
|
+
}
|
|
399
|
+
return true;
|
|
249
400
|
}
|
|
250
|
-
function
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
401
|
+
function prepareHeaders(input) {
|
|
402
|
+
if (looseInstanceOf(input, Headers)) {
|
|
403
|
+
input = Object.fromEntries(input.entries());
|
|
404
|
+
}
|
|
405
|
+
const headers = new Headers(input);
|
|
406
|
+
if (USER_AGENT && !headers.has("user-agent")) {
|
|
407
|
+
headers.set("user-agent", USER_AGENT);
|
|
408
|
+
}
|
|
409
|
+
if (headers.has("authorization")) {
|
|
254
410
|
throw new TypeError('"options.headers" must not include the "authorization" header name');
|
|
255
|
-
|
|
411
|
+
}
|
|
412
|
+
if (headers.has("dpop")) {
|
|
256
413
|
throw new TypeError('"options.headers" must not include the "dpop" header name');
|
|
257
|
-
|
|
414
|
+
}
|
|
415
|
+
return headers;
|
|
258
416
|
}
|
|
259
|
-
function
|
|
260
|
-
if (typeof
|
|
417
|
+
function signal(value) {
|
|
418
|
+
if (typeof value === "function") {
|
|
419
|
+
value = value();
|
|
420
|
+
}
|
|
421
|
+
if (!(value instanceof AbortSignal)) {
|
|
261
422
|
throw new TypeError('"options.signal" must return or be an instance of AbortSignal');
|
|
262
|
-
|
|
423
|
+
}
|
|
424
|
+
return value;
|
|
263
425
|
}
|
|
264
|
-
async function
|
|
265
|
-
if (!(
|
|
426
|
+
async function discoveryRequest(issuerIdentifier, options) {
|
|
427
|
+
if (!(issuerIdentifier instanceof URL)) {
|
|
266
428
|
throw new TypeError('"issuerIdentifier" must be an instance of URL');
|
|
267
|
-
|
|
429
|
+
}
|
|
430
|
+
if (issuerIdentifier.protocol !== "https:" && issuerIdentifier.protocol !== "http:") {
|
|
268
431
|
throw new TypeError('"issuer.protocol" must be "https:" or "http:"');
|
|
269
|
-
|
|
270
|
-
|
|
432
|
+
}
|
|
433
|
+
const url = new URL(issuerIdentifier.href);
|
|
434
|
+
switch (options == null ? void 0 : options.algorithm) {
|
|
271
435
|
case void 0:
|
|
272
436
|
case "oidc":
|
|
273
|
-
|
|
437
|
+
url.pathname = `${url.pathname}/.well-known/openid-configuration`.replace("//", "/");
|
|
274
438
|
break;
|
|
275
439
|
case "oauth2":
|
|
276
|
-
|
|
440
|
+
if (url.pathname === "/") {
|
|
441
|
+
url.pathname = ".well-known/oauth-authorization-server";
|
|
442
|
+
} else {
|
|
443
|
+
url.pathname = `.well-known/oauth-authorization-server/${url.pathname}`.replace("//", "/");
|
|
444
|
+
}
|
|
277
445
|
break;
|
|
278
446
|
default:
|
|
279
447
|
throw new TypeError('"options.algorithm" must be "oidc" (default), or "oauth2"');
|
|
280
448
|
}
|
|
281
|
-
const
|
|
282
|
-
|
|
283
|
-
|
|
449
|
+
const headers = prepareHeaders(options == null ? void 0 : options.headers);
|
|
450
|
+
headers.set("accept", "application/json");
|
|
451
|
+
return ((options == null ? void 0 : options[customFetch]) || fetch)(url.href, {
|
|
452
|
+
headers: Object.fromEntries(headers.entries()),
|
|
284
453
|
method: "GET",
|
|
285
454
|
redirect: "manual",
|
|
286
|
-
signal:
|
|
287
|
-
}).then(
|
|
455
|
+
signal: (options == null ? void 0 : options.signal) ? signal(options.signal) : null
|
|
456
|
+
}).then(processDpopNonce);
|
|
288
457
|
}
|
|
289
|
-
function
|
|
290
|
-
return typeof
|
|
458
|
+
function validateString(input) {
|
|
459
|
+
return typeof input === "string" && input.length !== 0;
|
|
291
460
|
}
|
|
292
|
-
async function
|
|
293
|
-
if (!(
|
|
461
|
+
async function processDiscoveryResponse(expectedIssuerIdentifier, response) {
|
|
462
|
+
if (!(expectedIssuerIdentifier instanceof URL)) {
|
|
294
463
|
throw new TypeError('"expectedIssuer" must be an instance of URL');
|
|
295
|
-
|
|
464
|
+
}
|
|
465
|
+
if (!looseInstanceOf(response, Response)) {
|
|
296
466
|
throw new TypeError('"response" must be an instance of Response');
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
467
|
+
}
|
|
468
|
+
if (response.status !== 200) {
|
|
469
|
+
throw new OPE('"response" is not a conform Authorization Server Metadata response');
|
|
470
|
+
}
|
|
471
|
+
assertReadableResponse(response);
|
|
472
|
+
let json;
|
|
301
473
|
try {
|
|
302
|
-
|
|
303
|
-
} catch (
|
|
304
|
-
throw new
|
|
474
|
+
json = await response.json();
|
|
475
|
+
} catch (cause) {
|
|
476
|
+
throw new OPE('failed to parse "response" body as JSON', { cause });
|
|
477
|
+
}
|
|
478
|
+
if (!isJsonObject(json)) {
|
|
479
|
+
throw new OPE('"response" body must be a top level object');
|
|
480
|
+
}
|
|
481
|
+
if (!validateString(json.issuer)) {
|
|
482
|
+
throw new OPE('"response" body "issuer" property must be a non-empty string');
|
|
305
483
|
}
|
|
306
|
-
if (
|
|
307
|
-
throw new
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
if (new URL(n.issuer).href !== e.href)
|
|
311
|
-
throw new a('"response" body "issuer" does not match "expectedIssuer"');
|
|
312
|
-
return n;
|
|
484
|
+
if (new URL(json.issuer).href !== expectedIssuerIdentifier.href) {
|
|
485
|
+
throw new OPE('"response" body "issuer" does not match "expectedIssuer"');
|
|
486
|
+
}
|
|
487
|
+
return json;
|
|
313
488
|
}
|
|
314
|
-
function
|
|
315
|
-
return
|
|
489
|
+
function randomBytes() {
|
|
490
|
+
return b64u(crypto.getRandomValues(new Uint8Array(32)));
|
|
316
491
|
}
|
|
317
|
-
function
|
|
318
|
-
return
|
|
492
|
+
function generateRandomCodeVerifier() {
|
|
493
|
+
return randomBytes();
|
|
319
494
|
}
|
|
320
|
-
function
|
|
321
|
-
return
|
|
495
|
+
function generateRandomState() {
|
|
496
|
+
return randomBytes();
|
|
322
497
|
}
|
|
323
|
-
async function
|
|
324
|
-
if (!
|
|
498
|
+
async function calculatePKCECodeChallenge(codeVerifier) {
|
|
499
|
+
if (!validateString(codeVerifier)) {
|
|
325
500
|
throw new TypeError('"codeVerifier" must be a non-empty string');
|
|
326
|
-
|
|
501
|
+
}
|
|
502
|
+
return b64u(await crypto.subtle.digest("SHA-256", buf(codeVerifier)));
|
|
327
503
|
}
|
|
328
|
-
function
|
|
329
|
-
if (
|
|
330
|
-
return { key:
|
|
331
|
-
|
|
504
|
+
function getKeyAndKid(input) {
|
|
505
|
+
if (input instanceof CryptoKey) {
|
|
506
|
+
return { key: input };
|
|
507
|
+
}
|
|
508
|
+
if (!((input == null ? void 0 : input.key) instanceof CryptoKey)) {
|
|
332
509
|
return {};
|
|
333
|
-
|
|
510
|
+
}
|
|
511
|
+
if (input.kid !== void 0 && !validateString(input.kid)) {
|
|
334
512
|
throw new TypeError('"kid" must be a non-empty string');
|
|
335
|
-
|
|
513
|
+
}
|
|
514
|
+
return { key: input.key, kid: input.kid };
|
|
336
515
|
}
|
|
337
|
-
function
|
|
338
|
-
return encodeURIComponent(
|
|
516
|
+
function formUrlEncode(token) {
|
|
517
|
+
return encodeURIComponent(token).replace(/%20/g, "+");
|
|
339
518
|
}
|
|
340
|
-
function
|
|
341
|
-
const
|
|
342
|
-
|
|
519
|
+
function clientSecretBasic(clientId, clientSecret) {
|
|
520
|
+
const username = formUrlEncode(clientId);
|
|
521
|
+
const password = formUrlEncode(clientSecret);
|
|
522
|
+
const credentials = btoa(`${username}:${password}`);
|
|
523
|
+
return `Basic ${credentials}`;
|
|
343
524
|
}
|
|
344
|
-
function
|
|
345
|
-
switch (
|
|
525
|
+
function psAlg(key) {
|
|
526
|
+
switch (key.algorithm.hash.name) {
|
|
346
527
|
case "SHA-256":
|
|
347
528
|
return "PS256";
|
|
348
529
|
case "SHA-384":
|
|
@@ -350,11 +531,11 @@ function Ze(e) {
|
|
|
350
531
|
case "SHA-512":
|
|
351
532
|
return "PS512";
|
|
352
533
|
default:
|
|
353
|
-
throw new
|
|
534
|
+
throw new UnsupportedOperationError("unsupported RsaHashedKeyAlgorithm hash name");
|
|
354
535
|
}
|
|
355
536
|
}
|
|
356
|
-
function
|
|
357
|
-
switch (
|
|
537
|
+
function rsAlg(key) {
|
|
538
|
+
switch (key.algorithm.hash.name) {
|
|
358
539
|
case "SHA-256":
|
|
359
540
|
return "RS256";
|
|
360
541
|
case "SHA-384":
|
|
@@ -362,11 +543,11 @@ function Qe(e) {
|
|
|
362
543
|
case "SHA-512":
|
|
363
544
|
return "RS512";
|
|
364
545
|
default:
|
|
365
|
-
throw new
|
|
546
|
+
throw new UnsupportedOperationError("unsupported RsaHashedKeyAlgorithm hash name");
|
|
366
547
|
}
|
|
367
548
|
}
|
|
368
|
-
function
|
|
369
|
-
switch (
|
|
549
|
+
function esAlg(key) {
|
|
550
|
+
switch (key.algorithm.namedCurve) {
|
|
370
551
|
case "P-256":
|
|
371
552
|
return "ES256";
|
|
372
553
|
case "P-384":
|
|
@@ -374,281 +555,367 @@ function Xe(e) {
|
|
|
374
555
|
case "P-521":
|
|
375
556
|
return "ES512";
|
|
376
557
|
default:
|
|
377
|
-
throw new
|
|
558
|
+
throw new UnsupportedOperationError("unsupported EcKeyAlgorithm namedCurve");
|
|
378
559
|
}
|
|
379
560
|
}
|
|
380
|
-
function
|
|
381
|
-
switch (
|
|
561
|
+
function keyToJws(key) {
|
|
562
|
+
switch (key.algorithm.name) {
|
|
382
563
|
case "RSA-PSS":
|
|
383
|
-
return
|
|
564
|
+
return psAlg(key);
|
|
384
565
|
case "RSASSA-PKCS1-v1_5":
|
|
385
|
-
return
|
|
566
|
+
return rsAlg(key);
|
|
386
567
|
case "ECDSA":
|
|
387
|
-
return
|
|
568
|
+
return esAlg(key);
|
|
388
569
|
case "Ed25519":
|
|
389
570
|
case "Ed448":
|
|
390
571
|
return "EdDSA";
|
|
391
572
|
default:
|
|
392
|
-
throw new
|
|
573
|
+
throw new UnsupportedOperationError("unsupported CryptoKey algorithm name");
|
|
393
574
|
}
|
|
394
575
|
}
|
|
395
|
-
function
|
|
396
|
-
const
|
|
397
|
-
return typeof
|
|
576
|
+
function getClockSkew(client) {
|
|
577
|
+
const skew = client == null ? void 0 : client[clockSkew];
|
|
578
|
+
return typeof skew === "number" && Number.isFinite(skew) ? skew : 0;
|
|
398
579
|
}
|
|
399
|
-
function
|
|
400
|
-
const
|
|
401
|
-
return typeof
|
|
580
|
+
function getClockTolerance(client) {
|
|
581
|
+
const tolerance = client == null ? void 0 : client[clockTolerance];
|
|
582
|
+
return typeof tolerance === "number" && Number.isFinite(tolerance) && Math.sign(tolerance) !== -1 ? tolerance : 30;
|
|
402
583
|
}
|
|
403
|
-
function
|
|
584
|
+
function epochTime() {
|
|
404
585
|
return Math.floor(Date.now() / 1e3);
|
|
405
586
|
}
|
|
406
|
-
function
|
|
407
|
-
const
|
|
587
|
+
function clientAssertion(as, client) {
|
|
588
|
+
const now = epochTime() + getClockSkew(client);
|
|
408
589
|
return {
|
|
409
|
-
jti:
|
|
410
|
-
aud: [
|
|
411
|
-
exp:
|
|
412
|
-
iat:
|
|
413
|
-
nbf:
|
|
414
|
-
iss:
|
|
415
|
-
sub:
|
|
590
|
+
jti: randomBytes(),
|
|
591
|
+
aud: [as.issuer, as.token_endpoint],
|
|
592
|
+
exp: now + 60,
|
|
593
|
+
iat: now,
|
|
594
|
+
nbf: now,
|
|
595
|
+
iss: client.client_id,
|
|
596
|
+
sub: client.client_id
|
|
416
597
|
};
|
|
417
598
|
}
|
|
418
|
-
async function
|
|
419
|
-
return
|
|
420
|
-
alg:
|
|
421
|
-
kid
|
|
422
|
-
},
|
|
599
|
+
async function privateKeyJwt(as, client, key, kid) {
|
|
600
|
+
return jwt({
|
|
601
|
+
alg: keyToJws(key),
|
|
602
|
+
kid
|
|
603
|
+
}, clientAssertion(as, client), key);
|
|
423
604
|
}
|
|
424
|
-
function
|
|
425
|
-
if (typeof
|
|
605
|
+
function assertAs(as) {
|
|
606
|
+
if (typeof as !== "object" || as === null) {
|
|
426
607
|
throw new TypeError('"as" must be an object');
|
|
427
|
-
|
|
608
|
+
}
|
|
609
|
+
if (!validateString(as.issuer)) {
|
|
428
610
|
throw new TypeError('"as.issuer" property must be a non-empty string');
|
|
429
|
-
|
|
611
|
+
}
|
|
612
|
+
return true;
|
|
430
613
|
}
|
|
431
|
-
function
|
|
432
|
-
if (typeof
|
|
614
|
+
function assertClient(client) {
|
|
615
|
+
if (typeof client !== "object" || client === null) {
|
|
433
616
|
throw new TypeError('"client" must be an object');
|
|
434
|
-
|
|
617
|
+
}
|
|
618
|
+
if (!validateString(client.client_id)) {
|
|
435
619
|
throw new TypeError('"client.client_id" property must be a non-empty string');
|
|
436
|
-
|
|
620
|
+
}
|
|
621
|
+
return true;
|
|
437
622
|
}
|
|
438
|
-
function
|
|
439
|
-
if (!
|
|
623
|
+
function assertClientSecret(clientSecret) {
|
|
624
|
+
if (!validateString(clientSecret)) {
|
|
440
625
|
throw new TypeError('"client.client_secret" property must be a non-empty string');
|
|
441
|
-
|
|
626
|
+
}
|
|
627
|
+
return clientSecret;
|
|
442
628
|
}
|
|
443
|
-
function
|
|
444
|
-
if (
|
|
445
|
-
throw new TypeError(`"options.clientPrivateKey" property must not be provided when ${
|
|
629
|
+
function assertNoClientPrivateKey(clientAuthMethod, clientPrivateKey) {
|
|
630
|
+
if (clientPrivateKey !== void 0) {
|
|
631
|
+
throw new TypeError(`"options.clientPrivateKey" property must not be provided when ${clientAuthMethod} client authentication method is used.`);
|
|
632
|
+
}
|
|
446
633
|
}
|
|
447
|
-
function
|
|
448
|
-
if (
|
|
449
|
-
throw new TypeError(`"client.client_secret" property must not be provided when ${
|
|
634
|
+
function assertNoClientSecret(clientAuthMethod, clientSecret) {
|
|
635
|
+
if (clientSecret !== void 0) {
|
|
636
|
+
throw new TypeError(`"client.client_secret" property must not be provided when ${clientAuthMethod} client authentication method is used.`);
|
|
637
|
+
}
|
|
450
638
|
}
|
|
451
|
-
async function
|
|
452
|
-
|
|
639
|
+
async function clientAuthentication(as, client, body, headers, clientPrivateKey) {
|
|
640
|
+
body.delete("client_secret");
|
|
641
|
+
body.delete("client_assertion_type");
|
|
642
|
+
body.delete("client_assertion");
|
|
643
|
+
switch (client.token_endpoint_auth_method) {
|
|
453
644
|
case void 0:
|
|
454
645
|
case "client_secret_basic": {
|
|
455
|
-
|
|
646
|
+
assertNoClientPrivateKey("client_secret_basic", clientPrivateKey);
|
|
647
|
+
headers.set("authorization", clientSecretBasic(client.client_id, assertClientSecret(client.client_secret)));
|
|
456
648
|
break;
|
|
457
649
|
}
|
|
458
650
|
case "client_secret_post": {
|
|
459
|
-
|
|
651
|
+
assertNoClientPrivateKey("client_secret_post", clientPrivateKey);
|
|
652
|
+
body.set("client_id", client.client_id);
|
|
653
|
+
body.set("client_secret", assertClientSecret(client.client_secret));
|
|
460
654
|
break;
|
|
461
655
|
}
|
|
462
656
|
case "private_key_jwt": {
|
|
463
|
-
|
|
657
|
+
assertNoClientSecret("private_key_jwt", client.client_secret);
|
|
658
|
+
if (clientPrivateKey === void 0) {
|
|
464
659
|
throw new TypeError('"options.clientPrivateKey" must be provided when "client.token_endpoint_auth_method" is "private_key_jwt"');
|
|
465
|
-
|
|
466
|
-
|
|
660
|
+
}
|
|
661
|
+
const { key, kid } = getKeyAndKid(clientPrivateKey);
|
|
662
|
+
if (!isPrivateKey(key)) {
|
|
467
663
|
throw new TypeError('"options.clientPrivateKey.key" must be a private CryptoKey');
|
|
468
|
-
|
|
664
|
+
}
|
|
665
|
+
body.set("client_id", client.client_id);
|
|
666
|
+
body.set("client_assertion_type", "urn:ietf:params:oauth:client-assertion-type:jwt-bearer");
|
|
667
|
+
body.set("client_assertion", await privateKeyJwt(as, client, key, kid));
|
|
469
668
|
break;
|
|
470
669
|
}
|
|
471
670
|
case "tls_client_auth":
|
|
472
671
|
case "self_signed_tls_client_auth":
|
|
473
672
|
case "none": {
|
|
474
|
-
|
|
673
|
+
assertNoClientSecret(client.token_endpoint_auth_method, client.client_secret);
|
|
674
|
+
assertNoClientPrivateKey(client.token_endpoint_auth_method, clientPrivateKey);
|
|
675
|
+
body.set("client_id", client.client_id);
|
|
475
676
|
break;
|
|
476
677
|
}
|
|
477
678
|
default:
|
|
478
|
-
throw new
|
|
679
|
+
throw new UnsupportedOperationError("unsupported client token_endpoint_auth_method");
|
|
479
680
|
}
|
|
480
681
|
}
|
|
481
|
-
async function
|
|
482
|
-
if (!
|
|
682
|
+
async function jwt(header, claimsSet, key) {
|
|
683
|
+
if (!key.usages.includes("sign")) {
|
|
483
684
|
throw new TypeError('CryptoKey instances used for signing assertions must include "sign" in their "usages"');
|
|
484
|
-
|
|
485
|
-
|
|
685
|
+
}
|
|
686
|
+
const input = `${b64u(buf(JSON.stringify(header)))}.${b64u(buf(JSON.stringify(claimsSet)))}`;
|
|
687
|
+
const signature = b64u(await crypto.subtle.sign(keyToSubtle(key), key, buf(input)));
|
|
688
|
+
return `${input}.${signature}`;
|
|
486
689
|
}
|
|
487
|
-
async function
|
|
488
|
-
const { privateKey
|
|
489
|
-
if (!
|
|
690
|
+
async function dpopProofJwt(headers, options, url, htm, clockSkew2, accessToken) {
|
|
691
|
+
const { privateKey, publicKey, nonce = dpopNonces.get(url.origin) } = options;
|
|
692
|
+
if (!isPrivateKey(privateKey)) {
|
|
490
693
|
throw new TypeError('"DPoP.privateKey" must be a private CryptoKey');
|
|
491
|
-
|
|
694
|
+
}
|
|
695
|
+
if (!isPublicKey(publicKey)) {
|
|
492
696
|
throw new TypeError('"DPoP.publicKey" must be a public CryptoKey');
|
|
493
|
-
|
|
697
|
+
}
|
|
698
|
+
if (nonce !== void 0 && !validateString(nonce)) {
|
|
494
699
|
throw new TypeError('"DPoP.nonce" must be a non-empty string or undefined');
|
|
495
|
-
|
|
700
|
+
}
|
|
701
|
+
if (!publicKey.extractable) {
|
|
496
702
|
throw new TypeError('"DPoP.publicKey.extractable" must be true');
|
|
497
|
-
|
|
498
|
-
|
|
703
|
+
}
|
|
704
|
+
const now = epochTime() + clockSkew2;
|
|
705
|
+
const proof = await jwt({
|
|
706
|
+
alg: keyToJws(privateKey),
|
|
499
707
|
typ: "dpop+jwt",
|
|
500
|
-
jwk: await
|
|
708
|
+
jwk: await publicJwk(publicKey)
|
|
501
709
|
}, {
|
|
502
|
-
iat:
|
|
503
|
-
jti:
|
|
504
|
-
htm
|
|
505
|
-
nonce
|
|
506
|
-
htu: `${
|
|
507
|
-
ath:
|
|
508
|
-
},
|
|
509
|
-
|
|
510
|
-
}
|
|
511
|
-
let
|
|
512
|
-
async function
|
|
513
|
-
const { kty
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
return
|
|
530
|
-
}
|
|
531
|
-
|
|
532
|
-
|
|
710
|
+
iat: now,
|
|
711
|
+
jti: randomBytes(),
|
|
712
|
+
htm,
|
|
713
|
+
nonce,
|
|
714
|
+
htu: `${url.origin}${url.pathname}`,
|
|
715
|
+
ath: accessToken ? b64u(await crypto.subtle.digest("SHA-256", buf(accessToken))) : void 0
|
|
716
|
+
}, privateKey);
|
|
717
|
+
headers.set("dpop", proof);
|
|
718
|
+
}
|
|
719
|
+
let jwkCache;
|
|
720
|
+
async function getSetPublicJwkCache(key) {
|
|
721
|
+
const { kty, e, n, x, y, crv } = await crypto.subtle.exportKey("jwk", key);
|
|
722
|
+
const jwk = { kty, e, n, x, y, crv };
|
|
723
|
+
jwkCache.set(key, jwk);
|
|
724
|
+
return jwk;
|
|
725
|
+
}
|
|
726
|
+
async function publicJwk(key) {
|
|
727
|
+
jwkCache || (jwkCache = /* @__PURE__ */ new WeakMap());
|
|
728
|
+
return jwkCache.get(key) || getSetPublicJwkCache(key);
|
|
729
|
+
}
|
|
730
|
+
function validateEndpoint(value, endpoint, options) {
|
|
731
|
+
if (typeof value !== "string") {
|
|
732
|
+
throw new TypeError(`"as.${endpoint}" must be a string`);
|
|
733
|
+
}
|
|
734
|
+
return new URL(value);
|
|
735
|
+
}
|
|
736
|
+
function resolveEndpoint(as, endpoint, options) {
|
|
737
|
+
return validateEndpoint(as[endpoint], endpoint);
|
|
738
|
+
}
|
|
739
|
+
function isOAuth2Error(input) {
|
|
740
|
+
const value = input;
|
|
741
|
+
if (typeof value !== "object" || Array.isArray(value) || value === null) {
|
|
742
|
+
return false;
|
|
743
|
+
}
|
|
744
|
+
return value.error !== void 0;
|
|
745
|
+
}
|
|
746
|
+
async function protectedResourceRequest(accessToken, method, url, headers, body, options) {
|
|
747
|
+
if (!validateString(accessToken)) {
|
|
533
748
|
throw new TypeError('"accessToken" must be a non-empty string');
|
|
534
|
-
|
|
749
|
+
}
|
|
750
|
+
if (!(url instanceof URL)) {
|
|
535
751
|
throw new TypeError('"url" must be an instance of URL');
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
752
|
+
}
|
|
753
|
+
headers = prepareHeaders(headers);
|
|
754
|
+
if ((options == null ? void 0 : options.DPoP) === void 0) {
|
|
755
|
+
headers.set("authorization", `Bearer ${accessToken}`);
|
|
756
|
+
} else {
|
|
757
|
+
await dpopProofJwt(headers, options.DPoP, url, "GET", getClockSkew({ [clockSkew]: options == null ? void 0 : options[clockSkew] }), accessToken);
|
|
758
|
+
headers.set("authorization", `DPoP ${accessToken}`);
|
|
759
|
+
}
|
|
760
|
+
return ((options == null ? void 0 : options[customFetch]) || fetch)(url.href, {
|
|
761
|
+
body,
|
|
762
|
+
headers: Object.fromEntries(headers.entries()),
|
|
763
|
+
method,
|
|
540
764
|
redirect: "manual",
|
|
541
|
-
signal:
|
|
542
|
-
}).then(
|
|
543
|
-
}
|
|
544
|
-
async function
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
765
|
+
signal: (options == null ? void 0 : options.signal) ? signal(options.signal) : null
|
|
766
|
+
}).then(processDpopNonce);
|
|
767
|
+
}
|
|
768
|
+
async function userInfoRequest(as, client, accessToken, options) {
|
|
769
|
+
assertAs(as);
|
|
770
|
+
assertClient(client);
|
|
771
|
+
const url = resolveEndpoint(as, "userinfo_endpoint");
|
|
772
|
+
const headers = prepareHeaders(options == null ? void 0 : options.headers);
|
|
773
|
+
if (client.userinfo_signed_response_alg) {
|
|
774
|
+
headers.set("accept", "application/jwt");
|
|
775
|
+
} else {
|
|
776
|
+
headers.set("accept", "application/json");
|
|
777
|
+
headers.append("accept", "application/jwt");
|
|
778
|
+
}
|
|
779
|
+
return protectedResourceRequest(accessToken, "GET", url, headers, null, {
|
|
780
|
+
...options,
|
|
781
|
+
[clockSkew]: getClockSkew(client)
|
|
550
782
|
});
|
|
551
783
|
}
|
|
552
|
-
async function
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
784
|
+
async function authenticatedRequest(as, client, method, url, body, headers, options) {
|
|
785
|
+
await clientAuthentication(as, client, body, headers, options == null ? void 0 : options.clientPrivateKey);
|
|
786
|
+
headers.set("content-type", "application/x-www-form-urlencoded;charset=UTF-8");
|
|
787
|
+
return ((options == null ? void 0 : options[customFetch]) || fetch)(url.href, {
|
|
788
|
+
body,
|
|
789
|
+
headers: Object.fromEntries(headers.entries()),
|
|
790
|
+
method,
|
|
557
791
|
redirect: "manual",
|
|
558
|
-
signal:
|
|
559
|
-
}).then(
|
|
560
|
-
}
|
|
561
|
-
async function
|
|
562
|
-
const
|
|
563
|
-
|
|
564
|
-
const
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
792
|
+
signal: (options == null ? void 0 : options.signal) ? signal(options.signal) : null
|
|
793
|
+
}).then(processDpopNonce);
|
|
794
|
+
}
|
|
795
|
+
async function tokenEndpointRequest(as, client, grantType, parameters, options) {
|
|
796
|
+
const url = resolveEndpoint(as, "token_endpoint");
|
|
797
|
+
parameters.set("grant_type", grantType);
|
|
798
|
+
const headers = prepareHeaders(options == null ? void 0 : options.headers);
|
|
799
|
+
headers.set("accept", "application/json");
|
|
800
|
+
return authenticatedRequest(as, client, "POST", url, parameters, headers, options);
|
|
801
|
+
}
|
|
802
|
+
async function refreshTokenGrantRequest(as, client, refreshToken, options) {
|
|
803
|
+
assertAs(as);
|
|
804
|
+
assertClient(client);
|
|
805
|
+
if (!validateString(refreshToken)) {
|
|
569
806
|
throw new TypeError('"refreshToken" must be a non-empty string');
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
807
|
+
}
|
|
808
|
+
const parameters = new URLSearchParams(options == null ? void 0 : options.additionalParameters);
|
|
809
|
+
parameters.set("refresh_token", refreshToken);
|
|
810
|
+
return tokenEndpointRequest(as, client, "refresh_token", parameters, options);
|
|
811
|
+
}
|
|
812
|
+
const idTokenClaims = /* @__PURE__ */ new WeakMap();
|
|
813
|
+
async function processGenericAccessTokenResponse(as, client, response, ignoreIdToken = false, ignoreRefreshToken = false) {
|
|
814
|
+
assertAs(as);
|
|
815
|
+
assertClient(client);
|
|
816
|
+
if (!looseInstanceOf(response, Response)) {
|
|
576
817
|
throw new TypeError('"response" must be an instance of Response');
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
818
|
+
}
|
|
819
|
+
if (response.status !== 200) {
|
|
820
|
+
let err;
|
|
821
|
+
if (err = await handleOAuthBodyError(response)) {
|
|
822
|
+
return err;
|
|
823
|
+
}
|
|
824
|
+
throw new OPE('"response" is not a conform Token Endpoint response');
|
|
825
|
+
}
|
|
826
|
+
assertReadableResponse(response);
|
|
827
|
+
let json;
|
|
585
828
|
try {
|
|
586
|
-
|
|
587
|
-
} catch (
|
|
588
|
-
throw new
|
|
589
|
-
}
|
|
590
|
-
if (!
|
|
591
|
-
throw new
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
if (
|
|
597
|
-
throw new
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
if (
|
|
601
|
-
throw new
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
829
|
+
json = await response.json();
|
|
830
|
+
} catch (cause) {
|
|
831
|
+
throw new OPE('failed to parse "response" body as JSON', { cause });
|
|
832
|
+
}
|
|
833
|
+
if (!isJsonObject(json)) {
|
|
834
|
+
throw new OPE('"response" body must be a top level object');
|
|
835
|
+
}
|
|
836
|
+
if (!validateString(json.access_token)) {
|
|
837
|
+
throw new OPE('"response" body "access_token" property must be a non-empty string');
|
|
838
|
+
}
|
|
839
|
+
if (!validateString(json.token_type)) {
|
|
840
|
+
throw new OPE('"response" body "token_type" property must be a non-empty string');
|
|
841
|
+
}
|
|
842
|
+
json.token_type = json.token_type.toLowerCase();
|
|
843
|
+
if (json.token_type !== "dpop" && json.token_type !== "bearer") {
|
|
844
|
+
throw new UnsupportedOperationError("unsupported `token_type` value");
|
|
845
|
+
}
|
|
846
|
+
if (json.expires_in !== void 0 && (typeof json.expires_in !== "number" || json.expires_in <= 0)) {
|
|
847
|
+
throw new OPE('"response" body "expires_in" property must be a positive number');
|
|
848
|
+
}
|
|
849
|
+
if (!ignoreRefreshToken && json.refresh_token !== void 0 && !validateString(json.refresh_token)) {
|
|
850
|
+
throw new OPE('"response" body "refresh_token" property must be a non-empty string');
|
|
851
|
+
}
|
|
852
|
+
if (json.scope !== void 0 && typeof json.scope !== "string") {
|
|
853
|
+
throw new OPE('"response" body "scope" property must be a string');
|
|
854
|
+
}
|
|
855
|
+
if (!ignoreIdToken) {
|
|
856
|
+
if (json.id_token !== void 0 && !validateString(json.id_token)) {
|
|
857
|
+
throw new OPE('"response" body "id_token" property must be a non-empty string');
|
|
858
|
+
}
|
|
859
|
+
if (json.id_token) {
|
|
860
|
+
const { claims } = await validateJwt(json.id_token, checkSigningAlgorithm.bind(void 0, client.id_token_signed_response_alg, as.id_token_signing_alg_values_supported), noSignatureCheck, getClockSkew(client), getClockTolerance(client)).then(validatePresence.bind(void 0, ["aud", "exp", "iat", "iss", "sub"])).then(validateIssuer.bind(void 0, as.issuer)).then(validateAudience.bind(void 0, client.client_id));
|
|
861
|
+
if (Array.isArray(claims.aud) && claims.aud.length !== 1 && claims.azp !== client.client_id) {
|
|
862
|
+
throw new OPE('unexpected ID Token "azp" (authorized party) claim value');
|
|
863
|
+
}
|
|
864
|
+
if (claims.auth_time !== void 0 && (!Number.isFinite(claims.auth_time) || Math.sign(claims.auth_time) !== 1)) {
|
|
865
|
+
throw new OPE('ID Token "auth_time" (authentication time) must be a positive number');
|
|
866
|
+
}
|
|
867
|
+
idTokenClaims.set(json, claims);
|
|
614
868
|
}
|
|
615
869
|
}
|
|
616
|
-
return
|
|
870
|
+
return json;
|
|
617
871
|
}
|
|
618
|
-
async function
|
|
619
|
-
return
|
|
872
|
+
async function processRefreshTokenResponse(as, client, response) {
|
|
873
|
+
return processGenericAccessTokenResponse(as, client, response);
|
|
620
874
|
}
|
|
621
|
-
function
|
|
622
|
-
if (Array.isArray(
|
|
623
|
-
if (!
|
|
624
|
-
throw new
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
875
|
+
function validateAudience(expected, result) {
|
|
876
|
+
if (Array.isArray(result.claims.aud)) {
|
|
877
|
+
if (!result.claims.aud.includes(expected)) {
|
|
878
|
+
throw new OPE('unexpected JWT "aud" (audience) claim value');
|
|
879
|
+
}
|
|
880
|
+
} else if (result.claims.aud !== expected) {
|
|
881
|
+
throw new OPE('unexpected JWT "aud" (audience) claim value');
|
|
882
|
+
}
|
|
883
|
+
return result;
|
|
628
884
|
}
|
|
629
|
-
function
|
|
630
|
-
if (
|
|
631
|
-
throw new
|
|
632
|
-
|
|
885
|
+
function validateIssuer(expected, result) {
|
|
886
|
+
if (result.claims.iss !== expected) {
|
|
887
|
+
throw new OPE('unexpected JWT "iss" (issuer) claim value');
|
|
888
|
+
}
|
|
889
|
+
return result;
|
|
633
890
|
}
|
|
634
|
-
const
|
|
635
|
-
function
|
|
636
|
-
|
|
891
|
+
const branded = /* @__PURE__ */ new WeakSet();
|
|
892
|
+
function brand(searchParams) {
|
|
893
|
+
branded.add(searchParams);
|
|
894
|
+
return searchParams;
|
|
637
895
|
}
|
|
638
|
-
async function
|
|
639
|
-
|
|
896
|
+
async function authorizationCodeGrantRequest(as, client, callbackParameters, redirectUri, codeVerifier, options) {
|
|
897
|
+
assertAs(as);
|
|
898
|
+
assertClient(client);
|
|
899
|
+
if (!branded.has(callbackParameters)) {
|
|
640
900
|
throw new TypeError('"callbackParameters" must be an instance of URLSearchParams obtained from "validateAuthResponse()", or "validateJwtAuthResponse()');
|
|
641
|
-
|
|
901
|
+
}
|
|
902
|
+
if (!validateString(redirectUri)) {
|
|
642
903
|
throw new TypeError('"redirectUri" must be a non-empty string');
|
|
643
|
-
|
|
904
|
+
}
|
|
905
|
+
if (!validateString(codeVerifier)) {
|
|
644
906
|
throw new TypeError('"codeVerifier" must be a non-empty string');
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
907
|
+
}
|
|
908
|
+
const code = getURLSearchParameter(callbackParameters, "code");
|
|
909
|
+
if (!code) {
|
|
910
|
+
throw new OPE('no authorization code in "callbackParameters"');
|
|
911
|
+
}
|
|
912
|
+
const parameters = new URLSearchParams(options == null ? void 0 : options.additionalParameters);
|
|
913
|
+
parameters.set("redirect_uri", redirectUri);
|
|
914
|
+
parameters.set("code_verifier", codeVerifier);
|
|
915
|
+
parameters.set("code", code);
|
|
916
|
+
return tokenEndpointRequest(as, client, "authorization_code", parameters, options);
|
|
650
917
|
}
|
|
651
|
-
const
|
|
918
|
+
const jwtClaimNames = {
|
|
652
919
|
aud: "audience",
|
|
653
920
|
c_hash: "code hash",
|
|
654
921
|
client_id: "client id",
|
|
@@ -664,44 +931,64 @@ const yt = {
|
|
|
664
931
|
htu: "http uri",
|
|
665
932
|
cnf: "confirmation"
|
|
666
933
|
};
|
|
667
|
-
function
|
|
668
|
-
for (const
|
|
669
|
-
if (
|
|
670
|
-
throw new
|
|
671
|
-
|
|
672
|
-
}
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
if (
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
}
|
|
684
|
-
|
|
685
|
-
|
|
934
|
+
function validatePresence(required, result) {
|
|
935
|
+
for (const claim of required) {
|
|
936
|
+
if (result.claims[claim] === void 0) {
|
|
937
|
+
throw new OPE(`JWT "${claim}" (${jwtClaimNames[claim]}) claim missing`);
|
|
938
|
+
}
|
|
939
|
+
}
|
|
940
|
+
return result;
|
|
941
|
+
}
|
|
942
|
+
async function processAuthorizationCodeOAuth2Response(as, client, response) {
|
|
943
|
+
const result = await processGenericAccessTokenResponse(as, client, response, true);
|
|
944
|
+
if (isOAuth2Error(result)) {
|
|
945
|
+
return result;
|
|
946
|
+
}
|
|
947
|
+
if (result.id_token !== void 0) {
|
|
948
|
+
if (typeof result.id_token === "string" && result.id_token.length) {
|
|
949
|
+
throw new OPE("Unexpected ID Token returned, use processAuthorizationCodeOpenIDResponse() for OpenID Connect callback processing");
|
|
950
|
+
}
|
|
951
|
+
delete result.id_token;
|
|
952
|
+
}
|
|
953
|
+
return result;
|
|
954
|
+
}
|
|
955
|
+
function assertReadableResponse(response) {
|
|
956
|
+
if (response.bodyUsed) {
|
|
686
957
|
throw new TypeError('"response" body has been used already');
|
|
958
|
+
}
|
|
687
959
|
}
|
|
688
|
-
async function
|
|
689
|
-
if (
|
|
690
|
-
|
|
960
|
+
async function handleOAuthBodyError(response) {
|
|
961
|
+
if (response.status > 399 && response.status < 500) {
|
|
962
|
+
assertReadableResponse(response);
|
|
691
963
|
try {
|
|
692
|
-
const
|
|
693
|
-
if (
|
|
694
|
-
|
|
964
|
+
const json = await response.json();
|
|
965
|
+
if (isJsonObject(json) && typeof json.error === "string" && json.error.length) {
|
|
966
|
+
if (json.error_description !== void 0 && typeof json.error_description !== "string") {
|
|
967
|
+
delete json.error_description;
|
|
968
|
+
}
|
|
969
|
+
if (json.error_uri !== void 0 && typeof json.error_uri !== "string") {
|
|
970
|
+
delete json.error_uri;
|
|
971
|
+
}
|
|
972
|
+
if (json.algs !== void 0 && typeof json.algs !== "string") {
|
|
973
|
+
delete json.algs;
|
|
974
|
+
}
|
|
975
|
+
if (json.scope !== void 0 && typeof json.scope !== "string") {
|
|
976
|
+
delete json.scope;
|
|
977
|
+
}
|
|
978
|
+
return json;
|
|
979
|
+
}
|
|
695
980
|
} catch {
|
|
696
981
|
}
|
|
697
982
|
}
|
|
983
|
+
return void 0;
|
|
698
984
|
}
|
|
699
|
-
function
|
|
700
|
-
if (typeof
|
|
701
|
-
throw new
|
|
985
|
+
function checkRsaKeyAlgorithm(algorithm) {
|
|
986
|
+
if (typeof algorithm.modulusLength !== "number" || algorithm.modulusLength < 2048) {
|
|
987
|
+
throw new OPE(`${algorithm.name} modulusLength must be at least 2048 bits`);
|
|
988
|
+
}
|
|
702
989
|
}
|
|
703
|
-
function
|
|
704
|
-
switch (
|
|
990
|
+
function ecdsaHashName(namedCurve) {
|
|
991
|
+
switch (namedCurve) {
|
|
705
992
|
case "P-256":
|
|
706
993
|
return "SHA-256";
|
|
707
994
|
case "P-384":
|
|
@@ -709,353 +996,453 @@ function St(e) {
|
|
|
709
996
|
case "P-521":
|
|
710
997
|
return "SHA-512";
|
|
711
998
|
default:
|
|
712
|
-
throw new
|
|
999
|
+
throw new UnsupportedOperationError();
|
|
713
1000
|
}
|
|
714
1001
|
}
|
|
715
|
-
function
|
|
716
|
-
switch (
|
|
1002
|
+
function keyToSubtle(key) {
|
|
1003
|
+
switch (key.algorithm.name) {
|
|
717
1004
|
case "ECDSA":
|
|
718
1005
|
return {
|
|
719
|
-
name:
|
|
720
|
-
hash:
|
|
1006
|
+
name: key.algorithm.name,
|
|
1007
|
+
hash: ecdsaHashName(key.algorithm.namedCurve)
|
|
721
1008
|
};
|
|
722
|
-
case "RSA-PSS":
|
|
723
|
-
|
|
1009
|
+
case "RSA-PSS": {
|
|
1010
|
+
checkRsaKeyAlgorithm(key.algorithm);
|
|
1011
|
+
switch (key.algorithm.hash.name) {
|
|
724
1012
|
case "SHA-256":
|
|
725
1013
|
case "SHA-384":
|
|
726
1014
|
case "SHA-512":
|
|
727
1015
|
return {
|
|
728
|
-
name:
|
|
729
|
-
saltLength: parseInt(
|
|
1016
|
+
name: key.algorithm.name,
|
|
1017
|
+
saltLength: parseInt(key.algorithm.hash.name.slice(-3), 10) >> 3
|
|
730
1018
|
};
|
|
731
1019
|
default:
|
|
732
|
-
throw new
|
|
1020
|
+
throw new UnsupportedOperationError();
|
|
733
1021
|
}
|
|
1022
|
+
}
|
|
734
1023
|
case "RSASSA-PKCS1-v1_5":
|
|
735
|
-
|
|
1024
|
+
checkRsaKeyAlgorithm(key.algorithm);
|
|
1025
|
+
return key.algorithm.name;
|
|
736
1026
|
case "Ed448":
|
|
737
1027
|
case "Ed25519":
|
|
738
|
-
return
|
|
739
|
-
}
|
|
740
|
-
throw new
|
|
741
|
-
}
|
|
742
|
-
const
|
|
743
|
-
async function
|
|
744
|
-
const { 0:
|
|
745
|
-
if (
|
|
746
|
-
throw new
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
1028
|
+
return key.algorithm.name;
|
|
1029
|
+
}
|
|
1030
|
+
throw new UnsupportedOperationError();
|
|
1031
|
+
}
|
|
1032
|
+
const noSignatureCheck = Symbol();
|
|
1033
|
+
async function validateJwt(jws, checkAlg, getKey, clockSkew2, clockTolerance2) {
|
|
1034
|
+
const { 0: protectedHeader, 1: payload, 2: encodedSignature, length } = jws.split(".");
|
|
1035
|
+
if (length === 5) {
|
|
1036
|
+
throw new UnsupportedOperationError("JWE structure JWTs are not supported");
|
|
1037
|
+
}
|
|
1038
|
+
if (length !== 3) {
|
|
1039
|
+
throw new OPE("Invalid JWT");
|
|
1040
|
+
}
|
|
1041
|
+
let header;
|
|
750
1042
|
try {
|
|
751
|
-
|
|
752
|
-
} catch (
|
|
753
|
-
throw new
|
|
754
|
-
}
|
|
755
|
-
if (!
|
|
756
|
-
throw new
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
1043
|
+
header = JSON.parse(buf(b64u(protectedHeader)));
|
|
1044
|
+
} catch (cause) {
|
|
1045
|
+
throw new OPE("failed to parse JWT Header body as base64url encoded JSON", { cause });
|
|
1046
|
+
}
|
|
1047
|
+
if (!isJsonObject(header)) {
|
|
1048
|
+
throw new OPE("JWT Header must be a top level object");
|
|
1049
|
+
}
|
|
1050
|
+
checkAlg(header);
|
|
1051
|
+
if (header.crit !== void 0) {
|
|
1052
|
+
throw new OPE('unexpected JWT "crit" header parameter');
|
|
1053
|
+
}
|
|
1054
|
+
const signature = b64u(encodedSignature);
|
|
1055
|
+
let key;
|
|
1056
|
+
if (getKey !== noSignatureCheck) {
|
|
1057
|
+
key = await getKey(header);
|
|
1058
|
+
const input = `${protectedHeader}.${payload}`;
|
|
1059
|
+
const verified = await crypto.subtle.verify(keyToSubtle(key), key, signature, buf(input));
|
|
1060
|
+
if (!verified) {
|
|
1061
|
+
throw new OPE("JWT signature verification failed");
|
|
1062
|
+
}
|
|
1063
|
+
}
|
|
1064
|
+
let claims;
|
|
768
1065
|
try {
|
|
769
|
-
|
|
770
|
-
} catch (
|
|
771
|
-
throw new
|
|
772
|
-
}
|
|
773
|
-
if (!
|
|
774
|
-
throw new
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
1066
|
+
claims = JSON.parse(buf(b64u(payload)));
|
|
1067
|
+
} catch (cause) {
|
|
1068
|
+
throw new OPE("failed to parse JWT Payload body as base64url encoded JSON", { cause });
|
|
1069
|
+
}
|
|
1070
|
+
if (!isJsonObject(claims)) {
|
|
1071
|
+
throw new OPE("JWT Payload must be a top level object");
|
|
1072
|
+
}
|
|
1073
|
+
const now = epochTime() + clockSkew2;
|
|
1074
|
+
if (claims.exp !== void 0) {
|
|
1075
|
+
if (typeof claims.exp !== "number") {
|
|
1076
|
+
throw new OPE('unexpected JWT "exp" (expiration time) claim type');
|
|
1077
|
+
}
|
|
1078
|
+
if (claims.exp <= now - clockTolerance2) {
|
|
1079
|
+
throw new OPE('unexpected JWT "exp" (expiration time) claim value, timestamp is <= now()');
|
|
1080
|
+
}
|
|
1081
|
+
}
|
|
1082
|
+
if (claims.iat !== void 0) {
|
|
1083
|
+
if (typeof claims.iat !== "number") {
|
|
1084
|
+
throw new OPE('unexpected JWT "iat" (issued at) claim type');
|
|
1085
|
+
}
|
|
1086
|
+
}
|
|
1087
|
+
if (claims.iss !== void 0) {
|
|
1088
|
+
if (typeof claims.iss !== "string") {
|
|
1089
|
+
throw new OPE('unexpected JWT "iss" (issuer) claim type');
|
|
1090
|
+
}
|
|
1091
|
+
}
|
|
1092
|
+
if (claims.nbf !== void 0) {
|
|
1093
|
+
if (typeof claims.nbf !== "number") {
|
|
1094
|
+
throw new OPE('unexpected JWT "nbf" (not before) claim type');
|
|
1095
|
+
}
|
|
1096
|
+
if (claims.nbf > now + clockTolerance2) {
|
|
1097
|
+
throw new OPE('unexpected JWT "nbf" (not before) claim value, timestamp is > now()');
|
|
1098
|
+
}
|
|
1099
|
+
}
|
|
1100
|
+
if (claims.aud !== void 0) {
|
|
1101
|
+
if (typeof claims.aud !== "string" && !Array.isArray(claims.aud)) {
|
|
1102
|
+
throw new OPE('unexpected JWT "aud" (audience) claim type');
|
|
1103
|
+
}
|
|
1104
|
+
}
|
|
1105
|
+
return { header, claims, signature, key };
|
|
1106
|
+
}
|
|
1107
|
+
function checkSigningAlgorithm(client, issuer, header) {
|
|
1108
|
+
if (client !== void 0) {
|
|
1109
|
+
if (header.alg !== client) {
|
|
1110
|
+
throw new OPE('unexpected JWT "alg" header parameter');
|
|
1111
|
+
}
|
|
800
1112
|
return;
|
|
801
1113
|
}
|
|
802
|
-
if (Array.isArray(
|
|
803
|
-
if (!
|
|
804
|
-
throw new
|
|
1114
|
+
if (Array.isArray(issuer)) {
|
|
1115
|
+
if (!issuer.includes(header.alg)) {
|
|
1116
|
+
throw new OPE('unexpected JWT "alg" header parameter');
|
|
1117
|
+
}
|
|
805
1118
|
return;
|
|
806
1119
|
}
|
|
807
|
-
if (
|
|
808
|
-
throw new
|
|
809
|
-
}
|
|
810
|
-
function E(e, t) {
|
|
811
|
-
const { 0: n, length: o } = e.getAll(t);
|
|
812
|
-
if (o > 1)
|
|
813
|
-
throw new a(`"${t}" parameter must be provided only once`);
|
|
814
|
-
return n;
|
|
1120
|
+
if (header.alg !== "RS256") {
|
|
1121
|
+
throw new OPE('unexpected JWT "alg" header parameter');
|
|
1122
|
+
}
|
|
815
1123
|
}
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
if (
|
|
1124
|
+
function getURLSearchParameter(parameters, name) {
|
|
1125
|
+
const { 0: value, length } = parameters.getAll(name);
|
|
1126
|
+
if (length > 1) {
|
|
1127
|
+
throw new OPE(`"${name}" parameter must be provided only once`);
|
|
1128
|
+
}
|
|
1129
|
+
return value;
|
|
1130
|
+
}
|
|
1131
|
+
const skipStateCheck = Symbol();
|
|
1132
|
+
const expectNoState = Symbol();
|
|
1133
|
+
function validateAuthResponse(as, client, parameters, expectedState) {
|
|
1134
|
+
assertAs(as);
|
|
1135
|
+
assertClient(client);
|
|
1136
|
+
if (parameters instanceof URL) {
|
|
1137
|
+
parameters = parameters.searchParams;
|
|
1138
|
+
}
|
|
1139
|
+
if (!(parameters instanceof URLSearchParams)) {
|
|
819
1140
|
throw new TypeError('"parameters" must be an instance of URLSearchParams, or URL');
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
1141
|
+
}
|
|
1142
|
+
if (getURLSearchParameter(parameters, "response")) {
|
|
1143
|
+
throw new OPE('"parameters" contains a JARM response, use validateJwtAuthResponse() instead of validateAuthResponse()');
|
|
1144
|
+
}
|
|
1145
|
+
const iss = getURLSearchParameter(parameters, "iss");
|
|
1146
|
+
const state = getURLSearchParameter(parameters, "state");
|
|
1147
|
+
if (!iss && as.authorization_response_iss_parameter_supported) {
|
|
1148
|
+
throw new OPE('response parameter "iss" (issuer) missing');
|
|
1149
|
+
}
|
|
1150
|
+
if (iss && iss !== as.issuer) {
|
|
1151
|
+
throw new OPE('unexpected "iss" (issuer) response parameter value');
|
|
1152
|
+
}
|
|
1153
|
+
switch (expectedState) {
|
|
828
1154
|
case void 0:
|
|
829
|
-
case
|
|
830
|
-
if (
|
|
831
|
-
throw new
|
|
1155
|
+
case expectNoState:
|
|
1156
|
+
if (state !== void 0) {
|
|
1157
|
+
throw new OPE('unexpected "state" response parameter encountered');
|
|
1158
|
+
}
|
|
832
1159
|
break;
|
|
833
|
-
case
|
|
1160
|
+
case skipStateCheck:
|
|
834
1161
|
break;
|
|
835
1162
|
default:
|
|
836
|
-
if (!
|
|
837
|
-
throw new
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
1163
|
+
if (!validateString(expectedState)) {
|
|
1164
|
+
throw new OPE('"expectedState" must be a non-empty string');
|
|
1165
|
+
}
|
|
1166
|
+
if (state === void 0) {
|
|
1167
|
+
throw new OPE('response parameter "state" missing');
|
|
1168
|
+
}
|
|
1169
|
+
if (state !== expectedState) {
|
|
1170
|
+
throw new OPE('unexpected "state" response parameter value');
|
|
1171
|
+
}
|
|
1172
|
+
}
|
|
1173
|
+
const error = getURLSearchParameter(parameters, "error");
|
|
1174
|
+
if (error) {
|
|
845
1175
|
return {
|
|
846
|
-
error
|
|
847
|
-
error_description:
|
|
848
|
-
error_uri:
|
|
1176
|
+
error,
|
|
1177
|
+
error_description: getURLSearchParameter(parameters, "error_description"),
|
|
1178
|
+
error_uri: getURLSearchParameter(parameters, "error_uri")
|
|
849
1179
|
};
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
1180
|
+
}
|
|
1181
|
+
const id_token = getURLSearchParameter(parameters, "id_token");
|
|
1182
|
+
const token = getURLSearchParameter(parameters, "token");
|
|
1183
|
+
if (id_token !== void 0 || token !== void 0) {
|
|
1184
|
+
throw new UnsupportedOperationError("implicit and hybrid flows are not supported");
|
|
1185
|
+
}
|
|
1186
|
+
return brand(new URLSearchParams(parameters));
|
|
854
1187
|
}
|
|
855
|
-
class
|
|
1188
|
+
class AuthorizationError extends Error {
|
|
856
1189
|
}
|
|
857
|
-
class
|
|
858
|
-
constructor(
|
|
859
|
-
super(
|
|
1190
|
+
class OAuthAuthorizationError extends AuthorizationError {
|
|
1191
|
+
constructor(message, error, options) {
|
|
1192
|
+
super(message, options);
|
|
1193
|
+
this.error = error;
|
|
860
1194
|
}
|
|
861
1195
|
}
|
|
862
|
-
function
|
|
863
|
-
handleCallback
|
|
1196
|
+
function Callback({
|
|
1197
|
+
handleCallback
|
|
864
1198
|
}) {
|
|
865
|
-
const
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
}
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
1199
|
+
const didInitialize = useRef(false);
|
|
1200
|
+
const [error, setError] = useState(void 0);
|
|
1201
|
+
const navigate = useNavigate();
|
|
1202
|
+
useEffect(() => {
|
|
1203
|
+
if (didInitialize.current) {
|
|
1204
|
+
return;
|
|
1205
|
+
}
|
|
1206
|
+
didInitialize.current = true;
|
|
1207
|
+
handleCallback().then(() => {
|
|
1208
|
+
navigate("/");
|
|
1209
|
+
}).catch((err) => {
|
|
1210
|
+
setError(err);
|
|
1211
|
+
});
|
|
1212
|
+
}, []);
|
|
1213
|
+
if (error) {
|
|
1214
|
+
if (error instanceof OAuthAuthorizationError) {
|
|
1215
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
|
|
1216
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("h2", { children: "Error" }),
|
|
1217
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("pre", { children: [
|
|
1218
|
+
error.error.error,
|
|
1219
|
+
error.error.error_description,
|
|
1220
|
+
error.error.error_uri
|
|
1221
|
+
] })
|
|
1222
|
+
] });
|
|
1223
|
+
}
|
|
1224
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
|
|
1225
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("h2", { children: "Error" }),
|
|
1226
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("pre", { children: [
|
|
1227
|
+
error.message,
|
|
1228
|
+
error.stack
|
|
1229
|
+
] })
|
|
1230
|
+
] });
|
|
1231
|
+
}
|
|
1232
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { children: "Loading..." });
|
|
1233
|
+
}
|
|
1234
|
+
const CODE_VERIFIER_KEY = "code-verifier";
|
|
1235
|
+
class OpenIDAuthenticationProvider {
|
|
889
1236
|
constructor({
|
|
890
|
-
issuer
|
|
891
|
-
authorizationEndpoint
|
|
892
|
-
tokenEndpoint
|
|
893
|
-
clientId
|
|
1237
|
+
issuer,
|
|
1238
|
+
authorizationEndpoint,
|
|
1239
|
+
tokenEndpoint,
|
|
1240
|
+
clientId
|
|
894
1241
|
}) {
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
const
|
|
905
|
-
|
|
906
|
-
|
|
1242
|
+
__publicField(this, "client");
|
|
1243
|
+
__publicField(this, "issuer");
|
|
1244
|
+
__publicField(this, "authorizationEndpoint");
|
|
1245
|
+
__publicField(this, "tokenEndpoint");
|
|
1246
|
+
__publicField(this, "authorizationServer");
|
|
1247
|
+
__publicField(this, "tokens");
|
|
1248
|
+
__publicField(this, "callbackUrlPath", "/oauth/callback");
|
|
1249
|
+
__publicField(this, "logoutRedirectUrlPath", "/");
|
|
1250
|
+
__publicField(this, "handleCallback", async () => {
|
|
1251
|
+
const url = new URL(window.location.href);
|
|
1252
|
+
const state = url.searchParams.get("state");
|
|
1253
|
+
const codeVerifier = localStorage.getItem(CODE_VERIFIER_KEY);
|
|
1254
|
+
if (!codeVerifier) {
|
|
1255
|
+
throw new AuthorizationError(
|
|
907
1256
|
"Code verifier not found. Invalid auth state."
|
|
908
1257
|
);
|
|
909
|
-
|
|
910
|
-
|
|
1258
|
+
}
|
|
1259
|
+
const authServer = await this.getAuthServer();
|
|
1260
|
+
const params = validateAuthResponse(
|
|
1261
|
+
authServer,
|
|
911
1262
|
this.client,
|
|
912
|
-
|
|
913
|
-
|
|
1263
|
+
url.searchParams,
|
|
1264
|
+
state ?? void 0
|
|
914
1265
|
);
|
|
915
|
-
if (
|
|
916
|
-
|
|
1266
|
+
if (isOAuth2Error(params)) {
|
|
1267
|
+
logger.error("Error validating OAuth response", params);
|
|
1268
|
+
throw new OAuthAuthorizationError(
|
|
917
1269
|
"Error validating OAuth response",
|
|
918
|
-
|
|
1270
|
+
params
|
|
919
1271
|
);
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
1272
|
+
}
|
|
1273
|
+
const redirectUrl = new URL(url);
|
|
1274
|
+
redirectUrl.pathname = this.callbackUrlPath;
|
|
1275
|
+
redirectUrl.search = "";
|
|
1276
|
+
const response = await authorizationCodeGrantRequest(
|
|
1277
|
+
authServer,
|
|
924
1278
|
this.client,
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
)
|
|
929
|
-
|
|
1279
|
+
params,
|
|
1280
|
+
redirectUrl.toString(),
|
|
1281
|
+
codeVerifier
|
|
1282
|
+
);
|
|
1283
|
+
const oauthResult = await processAuthorizationCodeOAuth2Response(
|
|
1284
|
+
authServer,
|
|
930
1285
|
this.client,
|
|
931
|
-
|
|
1286
|
+
response
|
|
932
1287
|
);
|
|
933
|
-
this.setTokensFromResponse(
|
|
934
|
-
const
|
|
935
|
-
|
|
1288
|
+
this.setTokensFromResponse(oauthResult);
|
|
1289
|
+
const accessToken = await this.getAccessToken();
|
|
1290
|
+
const userInfoResponse = await userInfoRequest(
|
|
1291
|
+
authServer,
|
|
936
1292
|
this.client,
|
|
937
|
-
|
|
938
|
-
)
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
1293
|
+
accessToken
|
|
1294
|
+
);
|
|
1295
|
+
const userInfo = await userInfoResponse.json();
|
|
1296
|
+
const profile = {
|
|
1297
|
+
sub: userInfo.sub,
|
|
1298
|
+
email: userInfo.email,
|
|
1299
|
+
name: userInfo.name,
|
|
1300
|
+
emailVerified: userInfo.email_verified ?? false,
|
|
1301
|
+
pictureUrl: userInfo.picture
|
|
944
1302
|
};
|
|
945
|
-
|
|
946
|
-
isAuthenticated:
|
|
947
|
-
isPending:
|
|
948
|
-
profile
|
|
1303
|
+
useAuthState.setState({
|
|
1304
|
+
isAuthenticated: true,
|
|
1305
|
+
isPending: false,
|
|
1306
|
+
profile
|
|
949
1307
|
});
|
|
950
1308
|
});
|
|
951
1309
|
this.client = {
|
|
952
|
-
client_id:
|
|
1310
|
+
client_id: clientId,
|
|
953
1311
|
token_endpoint_auth_method: "none"
|
|
954
|
-
}
|
|
1312
|
+
};
|
|
1313
|
+
this.issuer = issuer;
|
|
1314
|
+
this.authorizationEndpoint = authorizationEndpoint;
|
|
1315
|
+
this.tokenEndpoint = tokenEndpoint;
|
|
955
1316
|
}
|
|
956
1317
|
async getAuthServer() {
|
|
957
|
-
if (!this.authorizationServer)
|
|
958
|
-
if (this.tokenEndpoint && this.authorizationEndpoint)
|
|
1318
|
+
if (!this.authorizationServer) {
|
|
1319
|
+
if (this.tokenEndpoint && this.authorizationEndpoint) {
|
|
959
1320
|
this.authorizationServer = {
|
|
960
1321
|
issuer: new URL(this.authorizationEndpoint).origin,
|
|
961
1322
|
authorization_endpoint: this.authorizationEndpoint,
|
|
962
1323
|
token_endpoint: this.tokenEndpoint,
|
|
963
1324
|
code_challenge_methods_supported: []
|
|
964
1325
|
};
|
|
965
|
-
else {
|
|
966
|
-
const
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
1326
|
+
} else {
|
|
1327
|
+
const issuerUrl = new URL(this.issuer);
|
|
1328
|
+
const response = await discoveryRequest(issuerUrl);
|
|
1329
|
+
this.authorizationServer = await processDiscoveryResponse(
|
|
1330
|
+
issuerUrl,
|
|
1331
|
+
response
|
|
970
1332
|
);
|
|
971
1333
|
}
|
|
1334
|
+
}
|
|
972
1335
|
return this.authorizationServer;
|
|
973
1336
|
}
|
|
974
1337
|
/**
|
|
975
1338
|
* Sets the tokens from various OAuth responses
|
|
976
1339
|
* @param response
|
|
977
1340
|
*/
|
|
978
|
-
setTokensFromResponse(
|
|
979
|
-
if (
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
1341
|
+
setTokensFromResponse(response) {
|
|
1342
|
+
if (isOAuth2Error(response)) {
|
|
1343
|
+
logger.error("Bad Token Response", response);
|
|
1344
|
+
throw new OAuthAuthorizationError("Bad Token Response", response);
|
|
1345
|
+
}
|
|
1346
|
+
if (!response.expires_in) {
|
|
1347
|
+
throw new AuthorizationError("No expires_in in response");
|
|
1348
|
+
}
|
|
983
1349
|
this.tokens = {
|
|
984
|
-
accessToken:
|
|
985
|
-
refreshToken:
|
|
986
|
-
expiresOn: new Date(Date.now() +
|
|
987
|
-
tokenType:
|
|
1350
|
+
accessToken: response.access_token,
|
|
1351
|
+
refreshToken: response.refresh_token,
|
|
1352
|
+
expiresOn: new Date(Date.now() + response.expires_in * 1e3),
|
|
1353
|
+
tokenType: response.token_type
|
|
988
1354
|
};
|
|
989
1355
|
}
|
|
990
1356
|
async initialize() {
|
|
991
1357
|
}
|
|
992
1358
|
async login() {
|
|
993
|
-
var
|
|
994
|
-
const
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
const
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1359
|
+
var _a2;
|
|
1360
|
+
const code_challenge_method = "S256";
|
|
1361
|
+
const authorizationServer = await this.getAuthServer();
|
|
1362
|
+
if (!authorizationServer.authorization_endpoint) {
|
|
1363
|
+
throw new AuthorizationError("No authorization endpoint");
|
|
1364
|
+
}
|
|
1365
|
+
const codeVerifier = generateRandomCodeVerifier();
|
|
1366
|
+
const codeChallenge = await calculatePKCECodeChallenge(codeVerifier);
|
|
1367
|
+
localStorage.setItem(CODE_VERIFIER_KEY, codeVerifier);
|
|
1368
|
+
const authorizationUrl = new URL(
|
|
1369
|
+
authorizationServer.authorization_endpoint
|
|
1370
|
+
);
|
|
1371
|
+
const redirectUrl = new URL(window.location.href);
|
|
1372
|
+
redirectUrl.pathname = this.callbackUrlPath;
|
|
1373
|
+
redirectUrl.search = "";
|
|
1374
|
+
authorizationUrl.searchParams.set("client_id", this.client.client_id);
|
|
1375
|
+
authorizationUrl.searchParams.set("redirect_uri", redirectUrl.toString());
|
|
1376
|
+
authorizationUrl.searchParams.set("response_type", "code");
|
|
1377
|
+
authorizationUrl.searchParams.set("scope", "openid+profile+email");
|
|
1378
|
+
authorizationUrl.searchParams.set("code_challenge", codeChallenge);
|
|
1379
|
+
authorizationUrl.searchParams.set(
|
|
1003
1380
|
"code_challenge_method",
|
|
1004
|
-
|
|
1005
|
-
)
|
|
1006
|
-
|
|
1007
|
-
|
|
1381
|
+
code_challenge_method
|
|
1382
|
+
);
|
|
1383
|
+
if (((_a2 = authorizationServer.code_challenge_methods_supported) == null ? void 0 : _a2.includes("S256")) !== true) {
|
|
1384
|
+
const state = generateRandomState();
|
|
1385
|
+
authorizationUrl.searchParams.set("state", state);
|
|
1008
1386
|
}
|
|
1009
|
-
location.href =
|
|
1387
|
+
location.href = authorizationUrl.href;
|
|
1010
1388
|
}
|
|
1011
1389
|
async getAccessToken() {
|
|
1012
|
-
const
|
|
1013
|
-
if (!this.tokens)
|
|
1014
|
-
throw new
|
|
1390
|
+
const as = await this.getAuthServer();
|
|
1391
|
+
if (!this.tokens) {
|
|
1392
|
+
throw new AuthorizationError("User is not authenticated");
|
|
1393
|
+
}
|
|
1015
1394
|
if (this.tokens.expiresOn < /* @__PURE__ */ new Date()) {
|
|
1016
|
-
if (!this.tokens.refreshToken)
|
|
1017
|
-
throw new
|
|
1395
|
+
if (!this.tokens.refreshToken) {
|
|
1396
|
+
throw new AuthorizationError(
|
|
1018
1397
|
"Token expired and no refresh token available"
|
|
1019
1398
|
);
|
|
1020
|
-
|
|
1021
|
-
|
|
1399
|
+
}
|
|
1400
|
+
const request = await refreshTokenGrantRequest(
|
|
1401
|
+
as,
|
|
1022
1402
|
this.client,
|
|
1023
1403
|
this.tokens.refreshToken
|
|
1024
|
-
)
|
|
1025
|
-
|
|
1404
|
+
);
|
|
1405
|
+
const response = await processRefreshTokenResponse(
|
|
1406
|
+
as,
|
|
1026
1407
|
this.client,
|
|
1027
|
-
|
|
1408
|
+
request
|
|
1028
1409
|
);
|
|
1029
|
-
this.setTokensFromResponse(
|
|
1410
|
+
this.setTokensFromResponse(response);
|
|
1030
1411
|
}
|
|
1031
1412
|
return this.tokens.accessToken;
|
|
1032
1413
|
}
|
|
1033
1414
|
async logout() {
|
|
1034
|
-
|
|
1035
|
-
isAuthenticated:
|
|
1036
|
-
isPending:
|
|
1415
|
+
useAuthState.setState({
|
|
1416
|
+
isAuthenticated: false,
|
|
1417
|
+
isPending: false,
|
|
1037
1418
|
profile: void 0
|
|
1038
1419
|
});
|
|
1039
|
-
const
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1420
|
+
const as = await this.getAuthServer();
|
|
1421
|
+
const redirectUrl = new URL(window.location.href);
|
|
1422
|
+
redirectUrl.pathname = this.logoutRedirectUrlPath;
|
|
1423
|
+
let logoutUrl;
|
|
1424
|
+
if (as.end_session_endpoint) {
|
|
1425
|
+
logoutUrl = new URL(as.end_session_endpoint);
|
|
1426
|
+
logoutUrl.searchParams.set(
|
|
1427
|
+
"post_logout_redirect_uri",
|
|
1428
|
+
redirectUrl.toString()
|
|
1429
|
+
);
|
|
1430
|
+
} else {
|
|
1431
|
+
logoutUrl = redirectUrl;
|
|
1432
|
+
}
|
|
1046
1433
|
}
|
|
1047
1434
|
getRoutes() {
|
|
1048
1435
|
return [
|
|
1049
1436
|
{
|
|
1050
1437
|
path: this.callbackUrlPath,
|
|
1051
|
-
element: /* @__PURE__ */
|
|
1438
|
+
element: /* @__PURE__ */ jsxRuntimeExports.jsx(Callback, { handleCallback: this.handleCallback })
|
|
1052
1439
|
}
|
|
1053
1440
|
];
|
|
1054
1441
|
}
|
|
1055
1442
|
}
|
|
1056
|
-
const
|
|
1443
|
+
const openIDAuth = (options) => new OpenIDAuthenticationProvider(options);
|
|
1057
1444
|
export {
|
|
1058
|
-
|
|
1059
|
-
|
|
1445
|
+
OpenIDAuthenticationProvider,
|
|
1446
|
+
openIDAuth as default
|
|
1060
1447
|
};
|
|
1061
1448
|
//# sourceMappingURL=zudoku.auth-openid.js.map
|