@axa-fr/oidc-client 7.4.1 → 7.5.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 +14 -2
- package/dist/crypto.d.ts +1 -0
- package/dist/index.js +798 -624
- package/dist/index.umd.cjs +2 -2
- package/dist/initSession.d.ts +6 -2
- package/dist/initWorker.d.ts +11 -7
- package/dist/jwt.d.ts +6 -0
- package/dist/login.d.ts +1 -1
- package/dist/oidc.d.ts +1 -0
- package/dist/oidcClient.d.ts +1 -0
- package/dist/requests.d.ts +9 -9
- package/dist/types.d.ts +1 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/version.d.ts +1 -1
- package/package.json +2 -2
- package/src/crypto.ts +11 -6
- package/src/initSession.ts +29 -9
- package/src/initWorker.ts +37 -10
- package/src/jwt.ts +248 -0
- package/src/login.ts +61 -21
- package/src/oidc.ts +68 -29
- package/src/oidcClient.ts +4 -0
- package/src/requests.ts +43 -10
- package/src/types.ts +1 -0
- package/src/version.ts +1 -1
package/dist/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
const
|
|
2
|
-
class
|
|
3
|
-
constructor(e,
|
|
4
|
-
this._callback = e, this._client_id =
|
|
5
|
-
const r =
|
|
6
|
-
this._frame_origin =
|
|
1
|
+
const R = console;
|
|
2
|
+
class Ie {
|
|
3
|
+
constructor(e, s, t, i = 2e3, o = !0) {
|
|
4
|
+
this._callback = e, this._client_id = s, this._url = t, this._interval = i || 2e3, this._stopOnError = o;
|
|
5
|
+
const r = t.indexOf("/", t.indexOf("//") + 2);
|
|
6
|
+
this._frame_origin = t.substr(0, r), this._frame = window.document.createElement("iframe"), this._frame.style.visibility = "hidden", this._frame.style.position = "absolute", this._frame.style.display = "none", this._frame.width = 0, this._frame.height = 0, this._frame.src = t;
|
|
7
7
|
}
|
|
8
8
|
load() {
|
|
9
9
|
return new Promise((e) => {
|
|
@@ -13,20 +13,20 @@ class ge {
|
|
|
13
13
|
});
|
|
14
14
|
}
|
|
15
15
|
_message(e) {
|
|
16
|
-
e.origin === this._frame_origin && e.source === this._frame.contentWindow && (e.data === "error" ? (
|
|
16
|
+
e.origin === this._frame_origin && e.source === this._frame.contentWindow && (e.data === "error" ? (R.error("CheckSessionIFrame: error message from check session op iframe"), this._stopOnError && this.stop()) : e.data === "changed" ? (R.debug(e), R.debug("CheckSessionIFrame: changed message from check session op iframe"), this.stop(), this._callback()) : R.debug("CheckSessionIFrame: " + e.data + " message from check session op iframe"));
|
|
17
17
|
}
|
|
18
18
|
start(e) {
|
|
19
|
-
|
|
20
|
-
const
|
|
19
|
+
R.debug("CheckSessionIFrame.start :" + e), this.stop();
|
|
20
|
+
const s = () => {
|
|
21
21
|
this._frame.contentWindow.postMessage(this._client_id + " " + e, this._frame_origin);
|
|
22
22
|
};
|
|
23
|
-
|
|
23
|
+
s(), this._timer = window.setInterval(s, this._interval);
|
|
24
24
|
}
|
|
25
25
|
stop() {
|
|
26
|
-
this._timer && (
|
|
26
|
+
this._timer && (R.debug("CheckSessionIFrame.stop"), window.clearInterval(this._timer), this._timer = null);
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
|
-
const
|
|
29
|
+
const k = {
|
|
30
30
|
service_worker_not_supported_by_browser: "service_worker_not_supported_by_browser",
|
|
31
31
|
token_aquired: "token_aquired",
|
|
32
32
|
logout_from_another_tab: "logout_from_another_tab",
|
|
@@ -53,89 +53,97 @@ const m = {
|
|
|
53
53
|
syncTokensAsync_begin: "syncTokensAsync_begin",
|
|
54
54
|
syncTokensAsync_end: "syncTokensAsync_end",
|
|
55
55
|
syncTokensAsync_error: "syncTokensAsync_error"
|
|
56
|
-
},
|
|
57
|
-
const
|
|
56
|
+
}, I = (n, e = sessionStorage) => {
|
|
57
|
+
const s = (p) => (e[`oidc.${n}`] = JSON.stringify({ tokens: null, status: p }), Promise.resolve()), t = async () => {
|
|
58
58
|
if (!e[`oidc.${n}`])
|
|
59
59
|
return e[`oidc.${n}`] = JSON.stringify({ tokens: null, status: null }), { tokens: null, status: null };
|
|
60
|
-
const
|
|
61
|
-
return Promise.resolve({ tokens:
|
|
62
|
-
}, i = (
|
|
63
|
-
e[`oidc.${n}`] = JSON.stringify({ tokens:
|
|
64
|
-
}, o = async (
|
|
65
|
-
e[`oidc.session_state.${n}`] =
|
|
66
|
-
}, r = async () => e[`oidc.session_state.${n}`], l = (
|
|
67
|
-
|
|
68
|
-
},
|
|
69
|
-
|
|
60
|
+
const p = JSON.parse(e[`oidc.${n}`]);
|
|
61
|
+
return Promise.resolve({ tokens: p.tokens, status: p.status });
|
|
62
|
+
}, i = (p) => {
|
|
63
|
+
e[`oidc.${n}`] = JSON.stringify({ tokens: p });
|
|
64
|
+
}, o = async (p) => {
|
|
65
|
+
e[`oidc.session_state.${n}`] = p;
|
|
66
|
+
}, r = async () => e[`oidc.session_state.${n}`], l = (p) => {
|
|
67
|
+
e[`oidc.nonce.${n}`] = p.nonce;
|
|
68
|
+
}, a = (p) => {
|
|
69
|
+
e[`oidc.jwk.${n}`] = JSON.stringify(p);
|
|
70
|
+
}, h = () => JSON.parse(e[`oidc.jwk.${n}`]), c = async () => ({ nonce: e[`oidc.nonce.${n}`] }), _ = (p) => {
|
|
71
|
+
e[`oidc.dpop_nonce.${n}`] = p;
|
|
72
|
+
}, y = () => e[`oidc.dpop_nonce.${n}`], u = () => e[`oidc.${n}`] ? JSON.stringify({ tokens: JSON.parse(e[`oidc.${n}`]).tokens }) : null;
|
|
73
|
+
let d = {};
|
|
70
74
|
return {
|
|
71
|
-
clearAsync:
|
|
72
|
-
initAsync:
|
|
75
|
+
clearAsync: s,
|
|
76
|
+
initAsync: t,
|
|
73
77
|
setTokens: i,
|
|
74
|
-
getTokens:
|
|
78
|
+
getTokens: u,
|
|
75
79
|
setSessionStateAsync: o,
|
|
76
80
|
getSessionStateAsync: r,
|
|
77
81
|
setNonceAsync: l,
|
|
78
82
|
getNonceAsync: c,
|
|
79
|
-
setLoginParams: (
|
|
80
|
-
|
|
83
|
+
setLoginParams: (p) => {
|
|
84
|
+
d[n] = p, e[`oidc.login.${n}`] = JSON.stringify(p);
|
|
81
85
|
},
|
|
82
|
-
getLoginParams: (
|
|
83
|
-
const
|
|
84
|
-
return
|
|
86
|
+
getLoginParams: () => {
|
|
87
|
+
const p = e[`oidc.login.${n}`];
|
|
88
|
+
return d[n] || (d[n] = JSON.parse(p)), d[n];
|
|
85
89
|
},
|
|
86
90
|
getStateAsync: async () => e[`oidc.state.${n}`],
|
|
87
|
-
setStateAsync: async (
|
|
88
|
-
e[`oidc.state.${n}`] =
|
|
91
|
+
setStateAsync: async (p) => {
|
|
92
|
+
e[`oidc.state.${n}`] = p;
|
|
89
93
|
},
|
|
90
94
|
getCodeVerifierAsync: async () => e[`oidc.code_verifier.${n}`],
|
|
91
|
-
setCodeVerifierAsync: async (
|
|
92
|
-
e[`oidc.code_verifier.${n}`] =
|
|
93
|
-
}
|
|
95
|
+
setCodeVerifierAsync: async (p) => {
|
|
96
|
+
e[`oidc.code_verifier.${n}`] = p;
|
|
97
|
+
},
|
|
98
|
+
setDemonstratingProofOfPossessionNonce: _,
|
|
99
|
+
getDemonstratingProofOfPossessionNonce: y,
|
|
100
|
+
setDemonstratingProofOfPossessionJwkAsync: a,
|
|
101
|
+
getDemonstratingProofOfPossessionJwkAsync: h
|
|
94
102
|
};
|
|
95
|
-
},
|
|
103
|
+
}, Ce = (n) => decodeURIComponent(Array.prototype.map.call(atob(n), (e) => "%" + ("00" + e.charCodeAt(0).toString(16)).slice(-2)).join("")), xe = (n) => JSON.parse(Ce(n.split(".")[1].replace("-", "+").replace("_", "/"))), re = (n) => {
|
|
96
104
|
try {
|
|
97
|
-
return n &&
|
|
105
|
+
return n && Ne(n, ".") === 2 ? xe(n) : null;
|
|
98
106
|
} catch (e) {
|
|
99
107
|
console.warn(e);
|
|
100
108
|
}
|
|
101
109
|
return null;
|
|
102
|
-
},
|
|
110
|
+
}, Ne = (n, e) => n.split(e).length - 1, Y = {
|
|
103
111
|
access_token_or_id_token_invalid: "access_token_or_id_token_invalid",
|
|
104
112
|
access_token_invalid: "access_token_invalid",
|
|
105
113
|
id_token_invalid: "id_token_invalid"
|
|
106
114
|
};
|
|
107
|
-
function
|
|
115
|
+
function Le(n, e, s) {
|
|
108
116
|
if (n.issuedAt) {
|
|
109
117
|
if (typeof n.issuedAt == "string")
|
|
110
118
|
return parseInt(n.issuedAt, 10);
|
|
111
119
|
} else
|
|
112
|
-
return e && e.iat ? e.iat :
|
|
120
|
+
return e && e.iat ? e.iat : s && s.iat ? s.iat : (/* @__PURE__ */ new Date()).getTime() / 1e3;
|
|
113
121
|
return n.issuedAt;
|
|
114
122
|
}
|
|
115
|
-
const
|
|
123
|
+
const ye = (n, e = null, s) => {
|
|
116
124
|
if (!n)
|
|
117
125
|
return null;
|
|
118
|
-
let
|
|
126
|
+
let t;
|
|
119
127
|
const i = typeof n.expiresIn == "string" ? parseInt(n.expiresIn, 10) : n.expiresIn;
|
|
120
|
-
n.accessTokenPayload !== void 0 ?
|
|
121
|
-
const o = n.idTokenPayload ? n.idTokenPayload :
|
|
122
|
-
n.issuedAt =
|
|
123
|
-
let
|
|
124
|
-
n.expiresAt ?
|
|
125
|
-
const h = { ...n, idTokenPayload: o, accessTokenPayload:
|
|
128
|
+
n.accessTokenPayload !== void 0 ? t = n.accessTokenPayload : t = re(n.accessToken);
|
|
129
|
+
const o = n.idTokenPayload ? n.idTokenPayload : re(n.idToken), r = o && o.exp ? o.exp : Number.MAX_VALUE, l = t && t.exp ? t.exp : n.issuedAt + i;
|
|
130
|
+
n.issuedAt = Le(n, t, o);
|
|
131
|
+
let a;
|
|
132
|
+
n.expiresAt ? a = n.expiresAt : s === Y.access_token_invalid ? a = l : s === Y.id_token_invalid ? a = r : a = r < l ? r : l;
|
|
133
|
+
const h = { ...n, idTokenPayload: o, accessTokenPayload: t, expiresAt: a };
|
|
126
134
|
if (e != null && "refreshToken" in e && !("refreshToken" in n)) {
|
|
127
|
-
const
|
|
128
|
-
return { ...h, refreshToken:
|
|
135
|
+
const c = e.refreshToken;
|
|
136
|
+
return { ...h, refreshToken: c };
|
|
129
137
|
}
|
|
130
138
|
return h;
|
|
131
|
-
},
|
|
139
|
+
}, se = (n, e, s) => {
|
|
132
140
|
if (!n)
|
|
133
141
|
return null;
|
|
134
142
|
if (!n.issued_at) {
|
|
135
143
|
const i = (/* @__PURE__ */ new Date()).getTime() / 1e3;
|
|
136
144
|
n.issued_at = i;
|
|
137
145
|
}
|
|
138
|
-
const
|
|
146
|
+
const t = {
|
|
139
147
|
accessToken: n.access_token,
|
|
140
148
|
expiresIn: n.expires_in,
|
|
141
149
|
idToken: n.id_token,
|
|
@@ -143,129 +151,129 @@ const ae = (n, e = null, t) => {
|
|
|
143
151
|
tokenType: n.token_type,
|
|
144
152
|
issuedAt: n.issued_at
|
|
145
153
|
};
|
|
146
|
-
return "refresh_token" in n && (
|
|
147
|
-
},
|
|
148
|
-
const
|
|
149
|
-
return Math.round(
|
|
150
|
-
},
|
|
151
|
-
let
|
|
154
|
+
return "refresh_token" in n && (t.refreshToken = n.refresh_token), n.accessTokenPayload !== void 0 && (t.accessTokenPayload = n.accessTokenPayload), n.idTokenPayload !== void 0 && (t.idTokenPayload = n.idTokenPayload), ye(t, e, s);
|
|
155
|
+
}, U = (n, e) => {
|
|
156
|
+
const s = (/* @__PURE__ */ new Date()).getTime() / 1e3, t = e - s;
|
|
157
|
+
return Math.round(t - n);
|
|
158
|
+
}, z = (n) => n ? U(0, n.expiresAt) > 0 : !1, We = async (n, e = 200, s = 50) => {
|
|
159
|
+
let t = s;
|
|
152
160
|
if (!n.tokens)
|
|
153
161
|
return null;
|
|
154
|
-
for (; !
|
|
155
|
-
await
|
|
162
|
+
for (; !z(n.tokens) && t > 0; )
|
|
163
|
+
await D(e), t = t - 1;
|
|
156
164
|
return {
|
|
157
|
-
isTokensValid:
|
|
165
|
+
isTokensValid: z(n.tokens),
|
|
158
166
|
tokens: n.tokens,
|
|
159
|
-
numberWaited:
|
|
167
|
+
numberWaited: t - s
|
|
160
168
|
};
|
|
161
|
-
},
|
|
169
|
+
}, ge = (n, e, s) => {
|
|
162
170
|
if (n.idTokenPayload) {
|
|
163
|
-
const
|
|
164
|
-
if (
|
|
165
|
-
return { isValid: !1, reason: `Issuer does not match (oidcServerConfiguration issuer) ${
|
|
171
|
+
const t = n.idTokenPayload;
|
|
172
|
+
if (s.issuer !== t.iss)
|
|
173
|
+
return { isValid: !1, reason: `Issuer does not match (oidcServerConfiguration issuer) ${s.issuer} !== (idTokenPayload issuer) ${t.iss}` };
|
|
166
174
|
const i = (/* @__PURE__ */ new Date()).getTime() / 1e3;
|
|
167
|
-
if (
|
|
168
|
-
return { isValid: !1, reason: `Token expired (idTokenPayload exp) ${
|
|
175
|
+
if (t.exp && t.exp < i)
|
|
176
|
+
return { isValid: !1, reason: `Token expired (idTokenPayload exp) ${t.exp} < (currentTimeUnixSecond) ${i}` };
|
|
169
177
|
const o = 60 * 60 * 24 * 7;
|
|
170
|
-
if (
|
|
171
|
-
return { isValid: !1, reason: `Token is used from too long time (idTokenPayload iat + timeInSevenDays) ${
|
|
172
|
-
if (
|
|
173
|
-
return { isValid: !1, reason: `Nonce does not match (idTokenPayload nonce) ${
|
|
178
|
+
if (t.iat && t.iat + o < i)
|
|
179
|
+
return { isValid: !1, reason: `Token is used from too long time (idTokenPayload iat + timeInSevenDays) ${t.iat + o} < (currentTimeUnixSecond) ${i}` };
|
|
180
|
+
if (t.nonce && t.nonce !== e)
|
|
181
|
+
return { isValid: !1, reason: `Nonce does not match (idTokenPayload nonce) ${t.nonce} !== (nonce) ${e}` };
|
|
174
182
|
}
|
|
175
183
|
return { isValid: !0, reason: "" };
|
|
176
|
-
},
|
|
184
|
+
}, K = function() {
|
|
177
185
|
const n = function() {
|
|
178
|
-
let
|
|
179
|
-
const
|
|
180
|
-
const
|
|
181
|
-
setTimeout: function(
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
},
|
|
186
|
+
let a, h;
|
|
187
|
+
const c = (function() {
|
|
188
|
+
const y = {}, u = {
|
|
189
|
+
setTimeout: function(f, g, w) {
|
|
190
|
+
y[g] = setTimeout(function() {
|
|
191
|
+
f.postMessage(g), y[g] = null;
|
|
192
|
+
}, w);
|
|
185
193
|
},
|
|
186
|
-
setInterval: function(
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
},
|
|
194
|
+
setInterval: function(f, g, w) {
|
|
195
|
+
y[g] = setInterval(function() {
|
|
196
|
+
f.postMessage(g);
|
|
197
|
+
}, w);
|
|
190
198
|
},
|
|
191
|
-
clearTimeout: function(
|
|
192
|
-
clearTimeout(
|
|
199
|
+
clearTimeout: function(f, g) {
|
|
200
|
+
clearTimeout(y[g]), y[g] = null;
|
|
193
201
|
},
|
|
194
|
-
clearInterval: function(
|
|
195
|
-
clearInterval(
|
|
202
|
+
clearInterval: function(f, g) {
|
|
203
|
+
clearInterval(y[g]), y[g] = null;
|
|
196
204
|
}
|
|
197
205
|
};
|
|
198
|
-
function
|
|
199
|
-
const
|
|
200
|
-
u[
|
|
206
|
+
function d(f, g) {
|
|
207
|
+
const w = g.data[0], v = g.data[1], b = g.data[2];
|
|
208
|
+
u[w] && u[w](f, v, b);
|
|
201
209
|
}
|
|
202
|
-
this.onmessage = function(
|
|
203
|
-
|
|
204
|
-
}, this.onconnect = function(
|
|
205
|
-
const g =
|
|
206
|
-
g.onmessage = function(
|
|
207
|
-
|
|
210
|
+
this.onmessage = function(f) {
|
|
211
|
+
d(self, f);
|
|
212
|
+
}, this.onconnect = function(f) {
|
|
213
|
+
const g = f.ports[0];
|
|
214
|
+
g.onmessage = function(w) {
|
|
215
|
+
d(g, w);
|
|
208
216
|
};
|
|
209
217
|
};
|
|
210
218
|
}).toString();
|
|
211
219
|
try {
|
|
212
|
-
const
|
|
213
|
-
h = URL.createObjectURL(
|
|
220
|
+
const y = new Blob(["(", c, ")()"], { type: "application/javascript" });
|
|
221
|
+
h = URL.createObjectURL(y);
|
|
214
222
|
} catch {
|
|
215
223
|
return null;
|
|
216
224
|
}
|
|
217
225
|
const _ = typeof process > "u";
|
|
218
226
|
try {
|
|
219
227
|
if (SharedWorker)
|
|
220
|
-
return
|
|
228
|
+
return a = new SharedWorker(h), a.port;
|
|
221
229
|
} catch {
|
|
222
230
|
_ && console.warn("SharedWorker not available");
|
|
223
231
|
}
|
|
224
232
|
try {
|
|
225
233
|
if (Worker)
|
|
226
|
-
return
|
|
234
|
+
return a = new Worker(h), a;
|
|
227
235
|
} catch {
|
|
228
236
|
_ && console.warn("Worker not available");
|
|
229
237
|
}
|
|
230
238
|
return null;
|
|
231
239
|
}();
|
|
232
240
|
if (!n) {
|
|
233
|
-
const
|
|
241
|
+
const a = typeof window > "u" ? global : window;
|
|
234
242
|
return {
|
|
235
|
-
setTimeout: setTimeout.bind(
|
|
236
|
-
clearTimeout: clearTimeout.bind(
|
|
237
|
-
setInterval: setInterval.bind(
|
|
238
|
-
clearInterval: clearInterval.bind(
|
|
243
|
+
setTimeout: setTimeout.bind(a),
|
|
244
|
+
clearTimeout: clearTimeout.bind(a),
|
|
245
|
+
setInterval: setInterval.bind(a),
|
|
246
|
+
clearInterval: clearInterval.bind(a)
|
|
239
247
|
};
|
|
240
248
|
}
|
|
241
249
|
const e = function() {
|
|
242
|
-
let
|
|
250
|
+
let a = 0;
|
|
243
251
|
return function() {
|
|
244
|
-
return
|
|
252
|
+
return a++, a;
|
|
245
253
|
};
|
|
246
|
-
}(),
|
|
247
|
-
n.onmessage = function(
|
|
248
|
-
const h =
|
|
249
|
-
if (
|
|
250
|
-
|
|
254
|
+
}(), s = {}, t = {};
|
|
255
|
+
n.onmessage = function(a) {
|
|
256
|
+
const h = a.data, c = s[h];
|
|
257
|
+
if (c) {
|
|
258
|
+
c(), s[h] = null;
|
|
251
259
|
return;
|
|
252
260
|
}
|
|
253
|
-
const _ =
|
|
261
|
+
const _ = t[h];
|
|
254
262
|
_ && _();
|
|
255
263
|
};
|
|
256
|
-
function i(
|
|
257
|
-
const
|
|
258
|
-
return n.postMessage(["setTimeout",
|
|
264
|
+
function i(a, h) {
|
|
265
|
+
const c = e();
|
|
266
|
+
return n.postMessage(["setTimeout", c, h]), s[c] = a, c;
|
|
259
267
|
}
|
|
260
|
-
function o(
|
|
261
|
-
n.postMessage(["clearTimeout",
|
|
268
|
+
function o(a) {
|
|
269
|
+
n.postMessage(["clearTimeout", a]), s[a] = null;
|
|
262
270
|
}
|
|
263
|
-
function r(
|
|
264
|
-
const
|
|
265
|
-
return n.postMessage(["setInterval",
|
|
271
|
+
function r(a, h) {
|
|
272
|
+
const c = e();
|
|
273
|
+
return n.postMessage(["setInterval", c, h]), t[c] = a, c;
|
|
266
274
|
}
|
|
267
|
-
function l(
|
|
268
|
-
n.postMessage(["clearInterval",
|
|
275
|
+
function l(a) {
|
|
276
|
+
n.postMessage(["clearInterval", a]), t[a] = null;
|
|
269
277
|
}
|
|
270
278
|
return {
|
|
271
279
|
setTimeout: i,
|
|
@@ -273,9 +281,9 @@ const ae = (n, e = null, t) => {
|
|
|
273
281
|
setInterval: r,
|
|
274
282
|
clearInterval: l
|
|
275
283
|
};
|
|
276
|
-
}(),
|
|
277
|
-
const e = n.appVersion,
|
|
278
|
-
let i =
|
|
284
|
+
}(), ae = "7.5.1", ke = (n) => {
|
|
285
|
+
const e = n.appVersion, s = n.userAgent, t = "-";
|
|
286
|
+
let i = t;
|
|
279
287
|
const o = [
|
|
280
288
|
{ s: "Windows 10", r: /(Windows 10.0|Windows NT 10.0)/ },
|
|
281
289
|
{ s: "Windows 8.1", r: /(Windows 8.1|Windows NT 6.3)/ },
|
|
@@ -306,18 +314,18 @@ const ae = (n, e = null, t) => {
|
|
|
306
314
|
{ s: "Search Bot", r: /(nuhk|Googlebot|Yammybot|Openbot|Slurp|MSNBot|Ask Jeeves\/Teoma|ia_archiver)/ }
|
|
307
315
|
];
|
|
308
316
|
for (const l in o) {
|
|
309
|
-
const
|
|
310
|
-
if (
|
|
311
|
-
i =
|
|
317
|
+
const a = o[l];
|
|
318
|
+
if (a.r.test(s)) {
|
|
319
|
+
i = a.s;
|
|
312
320
|
break;
|
|
313
321
|
}
|
|
314
322
|
}
|
|
315
|
-
let r =
|
|
323
|
+
let r = t;
|
|
316
324
|
switch (/Windows/.test(i) && (r = /Windows (.*)/.exec(i)[1], i = "Windows"), i) {
|
|
317
325
|
case "Mac OS":
|
|
318
326
|
case "Mac OS X":
|
|
319
327
|
case "Android":
|
|
320
|
-
r = /(?:Android|Mac OS|Mac OS X|MacPPC|MacIntel|Mac_PowerPC|Macintosh) ([._\d]+)/.exec(
|
|
328
|
+
r = /(?:Android|Mac OS|Mac OS X|MacPPC|MacIntel|Mac_PowerPC|Macintosh) ([._\d]+)/.exec(s)[1];
|
|
321
329
|
break;
|
|
322
330
|
case "iOS": {
|
|
323
331
|
const l = /OS (\d+)_(\d+)_?(\d+)?/.exec(e);
|
|
@@ -330,57 +338,57 @@ const ae = (n, e = null, t) => {
|
|
|
330
338
|
osVersion: r
|
|
331
339
|
};
|
|
332
340
|
};
|
|
333
|
-
function
|
|
341
|
+
function De() {
|
|
334
342
|
const n = navigator.userAgent;
|
|
335
|
-
let e,
|
|
336
|
-
if (/trident/i.test(
|
|
343
|
+
let e, s = n.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || [];
|
|
344
|
+
if (/trident/i.test(s[1]))
|
|
337
345
|
return e = /\brv[ :]+(\d+)/g.exec(n) || [], { name: "ie", version: e[1] || "" };
|
|
338
|
-
if (
|
|
339
|
-
let
|
|
340
|
-
if (!
|
|
346
|
+
if (s[1] === "Chrome" && (e = n.match(/\bOPR|Edge\/(\d+)/), e != null)) {
|
|
347
|
+
let t = e[1];
|
|
348
|
+
if (!t) {
|
|
341
349
|
const i = n.split(e[0] + "/");
|
|
342
|
-
i.length > 1 && (
|
|
350
|
+
i.length > 1 && (t = i[1]);
|
|
343
351
|
}
|
|
344
|
-
return { name: "opera", version:
|
|
352
|
+
return { name: "opera", version: t };
|
|
345
353
|
}
|
|
346
|
-
return
|
|
347
|
-
name:
|
|
348
|
-
version:
|
|
354
|
+
return s = s[2] ? [s[1], s[2]] : [navigator.appName, navigator.appVersion, "-?"], (e = n.match(/version\/(\d+)/i)) != null && s.splice(1, 1, e[1]), {
|
|
355
|
+
name: s[0].toLowerCase(),
|
|
356
|
+
version: s[1]
|
|
349
357
|
};
|
|
350
358
|
}
|
|
351
|
-
let
|
|
352
|
-
const
|
|
353
|
-
let
|
|
354
|
-
const
|
|
359
|
+
let ce = null;
|
|
360
|
+
const D = (n) => new Promise((e) => K.setTimeout(e, n));
|
|
361
|
+
let q;
|
|
362
|
+
const me = () => {
|
|
355
363
|
try {
|
|
356
|
-
const e =
|
|
357
|
-
|
|
358
|
-
console.log(
|
|
359
|
-
}),
|
|
364
|
+
const e = ke(navigator).os === "Android" ? 240 : 150;
|
|
365
|
+
q = new AbortController(), fetch(`/OidcKeepAliveServiceWorker.json?minSleepSeconds=${e}`, { signal: q.signal }).catch((t) => {
|
|
366
|
+
console.log(t);
|
|
367
|
+
}), D(e * 1e3).then(me);
|
|
360
368
|
} catch (n) {
|
|
361
369
|
console.log(n);
|
|
362
370
|
}
|
|
363
|
-
},
|
|
364
|
-
|
|
365
|
-
},
|
|
371
|
+
}, le = () => {
|
|
372
|
+
q && q.abort();
|
|
373
|
+
}, $e = () => fetch("/OidcKeepAliveServiceWorker.json", {
|
|
366
374
|
headers: {
|
|
367
375
|
"oidc-vanilla": "true"
|
|
368
376
|
}
|
|
369
377
|
}).then((n) => n.statusText === "oidc-service-worker").catch((n) => {
|
|
370
378
|
console.log(n);
|
|
371
|
-
}),
|
|
379
|
+
}), Re = (n) => !!(n.os === "iOS" && n.osVersion.startsWith("12") || n.os === "Mac OS X" && n.osVersion.startsWith("10_15_6")), P = (n) => (e) => new Promise(function(s, t) {
|
|
372
380
|
const i = new MessageChannel();
|
|
373
381
|
i.port1.onmessage = function(o) {
|
|
374
|
-
o.data && o.data.error ?
|
|
382
|
+
o.data && o.data.error ? t(o.data.error) : s(o.data);
|
|
375
383
|
}, n.active.postMessage(e, [i.port2]);
|
|
376
|
-
}),
|
|
384
|
+
}), x = async (n, e) => {
|
|
377
385
|
if (typeof window > "u" || typeof navigator > "u" || !navigator.serviceWorker || !n)
|
|
378
386
|
return null;
|
|
379
|
-
const { name:
|
|
380
|
-
if (
|
|
387
|
+
const { name: s, version: t } = De();
|
|
388
|
+
if (s === "chrome" && parseInt(t) <= 70 || s === "opera" && (!t || parseInt(t.split(".")[0]) < 80) || s === "ie")
|
|
381
389
|
return null;
|
|
382
|
-
const i =
|
|
383
|
-
if (
|
|
390
|
+
const i = ke(navigator);
|
|
391
|
+
if (Re(i))
|
|
384
392
|
return null;
|
|
385
393
|
const o = await navigator.serviceWorker.register(n);
|
|
386
394
|
try {
|
|
@@ -388,569 +396,705 @@ const ue = () => {
|
|
|
388
396
|
} catch {
|
|
389
397
|
return null;
|
|
390
398
|
}
|
|
391
|
-
const r = async (
|
|
392
|
-
const
|
|
399
|
+
const r = async (m) => P(o)({ type: "clear", data: { status: m }, configurationName: e }), l = async (m, S, A) => {
|
|
400
|
+
const T = await P(o)({
|
|
393
401
|
type: "init",
|
|
394
402
|
data: {
|
|
395
|
-
oidcServerConfiguration:
|
|
396
|
-
where:
|
|
403
|
+
oidcServerConfiguration: m,
|
|
404
|
+
where: S,
|
|
397
405
|
oidcConfiguration: {
|
|
398
|
-
token_renew_mode:
|
|
399
|
-
service_worker_convert_all_requests_to_cors:
|
|
406
|
+
token_renew_mode: A.token_renew_mode,
|
|
407
|
+
service_worker_convert_all_requests_to_cors: A.service_worker_convert_all_requests_to_cors
|
|
400
408
|
}
|
|
401
409
|
},
|
|
402
410
|
configurationName: e
|
|
403
|
-
}),
|
|
404
|
-
if (
|
|
405
|
-
if (console.warn(`Service worker ${
|
|
406
|
-
await
|
|
411
|
+
}), B = T.version;
|
|
412
|
+
if (B !== ae)
|
|
413
|
+
if (console.warn(`Service worker ${B} version mismatch with js client version ${ae}, unregistering and reloading`), A.service_worker_update_require_callback)
|
|
414
|
+
await A.service_worker_update_require_callback(o, le);
|
|
407
415
|
else {
|
|
408
|
-
|
|
409
|
-
const
|
|
410
|
-
console.log(`Service worker unregistering ${
|
|
416
|
+
le(), await o.update();
|
|
417
|
+
const X = await o.unregister();
|
|
418
|
+
console.log(`Service worker unregistering ${X}`), await D(2e3), window.location.reload();
|
|
411
419
|
}
|
|
412
|
-
return { tokens:
|
|
413
|
-
},
|
|
414
|
-
|
|
415
|
-
}, h = (
|
|
416
|
-
let
|
|
417
|
-
return
|
|
420
|
+
return { tokens: se(T.tokens, null, A.token_renew_mode), status: T.status };
|
|
421
|
+
}, a = () => {
|
|
422
|
+
ce == null && (ce = "not_null", me());
|
|
423
|
+
}, h = (m) => P(o)({ type: "setSessionState", data: { sessionState: m }, configurationName: e }), c = async () => (await P(o)({ type: "getSessionState", data: null, configurationName: e })).sessionState, _ = (m) => (sessionStorage[`oidc.nonce.${e}`] = m.nonce, P(o)({ type: "setNonce", data: { nonce: m }, configurationName: e })), y = async () => {
|
|
424
|
+
let S = (await P(o)({ type: "getNonce", data: null, configurationName: e })).nonce;
|
|
425
|
+
return S || (S = sessionStorage[`oidc.nonce.${e}`], console.warn("nonce not found in service worker, using sessionStorage")), { nonce: S };
|
|
418
426
|
};
|
|
419
|
-
let u =
|
|
427
|
+
let u = {};
|
|
420
428
|
return {
|
|
421
429
|
clearAsync: r,
|
|
422
430
|
initAsync: l,
|
|
423
|
-
startKeepAliveServiceWorker:
|
|
424
|
-
isServiceWorkerProxyActiveAsync:
|
|
431
|
+
startKeepAliveServiceWorker: a,
|
|
432
|
+
isServiceWorkerProxyActiveAsync: $e,
|
|
425
433
|
setSessionStateAsync: h,
|
|
426
|
-
getSessionStateAsync:
|
|
434
|
+
getSessionStateAsync: c,
|
|
427
435
|
setNonceAsync: _,
|
|
428
|
-
getNonceAsync:
|
|
429
|
-
setLoginParams: (
|
|
430
|
-
u =
|
|
436
|
+
getNonceAsync: y,
|
|
437
|
+
setLoginParams: (m) => {
|
|
438
|
+
u[e] = m, localStorage[`oidc.login.${e}`] = JSON.stringify(m);
|
|
431
439
|
},
|
|
432
|
-
getLoginParams: (
|
|
433
|
-
const
|
|
434
|
-
return u || (u = JSON.parse(
|
|
440
|
+
getLoginParams: () => {
|
|
441
|
+
const m = localStorage[`oidc.login.${e}`];
|
|
442
|
+
return u[e] || (u[e] = JSON.parse(m)), u[e];
|
|
435
443
|
},
|
|
436
444
|
getStateAsync: async () => {
|
|
437
|
-
let
|
|
438
|
-
return
|
|
445
|
+
let S = (await P(o)({ type: "getState", data: null, configurationName: e })).state;
|
|
446
|
+
return S || (S = sessionStorage[`oidc.state.${e}`], console.warn("state not found in service worker, using sessionStorage")), S;
|
|
439
447
|
},
|
|
440
|
-
setStateAsync: async (
|
|
448
|
+
setStateAsync: async (m) => (sessionStorage[`oidc.state.${e}`] = m, P(o)({ type: "setState", data: { state: m }, configurationName: e })),
|
|
441
449
|
getCodeVerifierAsync: async () => {
|
|
442
|
-
let
|
|
443
|
-
return
|
|
450
|
+
let S = (await P(o)({ type: "getCodeVerifier", data: null, configurationName: e })).codeVerifier;
|
|
451
|
+
return S || (S = sessionStorage[`oidc.code_verifier.${e}`], console.warn("codeVerifier not found in service worker, using sessionStorage")), S;
|
|
444
452
|
},
|
|
445
|
-
setCodeVerifierAsync: async (
|
|
453
|
+
setCodeVerifierAsync: async (m) => (sessionStorage[`oidc.code_verifier.${e}`] = m, P(o)({ type: "setCodeVerifier", data: { codeVerifier: m }, configurationName: e })),
|
|
454
|
+
setDemonstratingProofOfPossessionNonce: (m) => {
|
|
455
|
+
P(o)({ type: "setDemonstratingProofOfPossessionNonce", data: { demonstratingProofOfPossessionNonce: m }, configurationName: e });
|
|
456
|
+
},
|
|
457
|
+
getDemonstratingProofOfPossessionNonce: async () => (await P(o)({ type: "getDemonstratingProofOfPossessionNonce", data: null, configurationName: e })).demonstratingProofOfPossessionNonce,
|
|
458
|
+
setDemonstratingProofOfPossessionJwkAsync: (m) => {
|
|
459
|
+
const S = JSON.stringify(m);
|
|
460
|
+
P(o)({ type: "setDemonstratingProofOfPossessionJwk", data: { demonstratingProofOfPossessionJwkJson: S }, configurationName: e });
|
|
461
|
+
},
|
|
462
|
+
getDemonstratingProofOfPossessionJwkAsync: async () => {
|
|
463
|
+
const m = await P(o)({ type: "getDemonstratingProofOfPossessionJwk", data: null, configurationName: e });
|
|
464
|
+
return m.demonstratingProofOfPossessionJwkJson ? JSON.parse(m.demonstratingProofOfPossessionJwkJson) : null;
|
|
465
|
+
}
|
|
446
466
|
};
|
|
447
467
|
};
|
|
448
|
-
async function
|
|
449
|
-
const i = (
|
|
450
|
-
n.tokens =
|
|
451
|
-
}, { tokens: o, status: r } = await n.synchroniseTokensAsync(e, 0,
|
|
452
|
-
if (await
|
|
468
|
+
async function pe(n, e, s = !1, t = null) {
|
|
469
|
+
const i = (a) => {
|
|
470
|
+
n.tokens = a;
|
|
471
|
+
}, { tokens: o, status: r } = await n.synchroniseTokensAsync(e, 0, s, t, i);
|
|
472
|
+
if (await x(n.configuration.service_worker_relative_url, n.configurationName) || await I(n.configurationName, n.configuration.storage).setTokens(n.tokens), !n.tokens) {
|
|
453
473
|
await n.destroyAsync(r);
|
|
454
474
|
return;
|
|
455
475
|
}
|
|
456
|
-
return n.timeoutId && (n.timeoutId =
|
|
476
|
+
return n.timeoutId && (n.timeoutId = M(n, o.refreshToken, n.tokens.expiresAt, t)), n.tokens;
|
|
457
477
|
}
|
|
458
|
-
const
|
|
478
|
+
const M = (n, e, s, t = null) => {
|
|
459
479
|
const i = n.configuration.refresh_time_before_tokens_expiration_in_second;
|
|
460
|
-
return
|
|
461
|
-
const r = { timeLeft:
|
|
462
|
-
n.publishEvent(
|
|
480
|
+
return K.setTimeout(async () => {
|
|
481
|
+
const r = { timeLeft: U(i, s) };
|
|
482
|
+
n.publishEvent($.eventNames.token_timer, r), await pe(n, e, !1, t);
|
|
463
483
|
}, 1e3);
|
|
464
|
-
},
|
|
484
|
+
}, te = (n, e, s) => (t = null, i = null, o = null) => {
|
|
465
485
|
if (!e.silent_redirect_uri || !e.silent_login_uri)
|
|
466
486
|
return Promise.resolve(null);
|
|
467
487
|
try {
|
|
468
|
-
|
|
488
|
+
s(k.silentLoginAsync_begin, {});
|
|
469
489
|
let r = "";
|
|
470
|
-
if (i && (
|
|
471
|
-
for (const [_,
|
|
472
|
-
r === "" ? r = `?${encodeURIComponent(_)}=${encodeURIComponent(
|
|
473
|
-
const l = e.silent_login_uri + r,
|
|
474
|
-
return
|
|
490
|
+
if (i && (t == null && (t = {}), t.state = i), o && (t == null && (t = {}), t.scope = o), t != null)
|
|
491
|
+
for (const [_, y] of Object.entries(t))
|
|
492
|
+
r === "" ? r = `?${encodeURIComponent(_)}=${encodeURIComponent(y)}` : r += `&${encodeURIComponent(_)}=${encodeURIComponent(y)}`;
|
|
493
|
+
const l = e.silent_login_uri + r, a = l.indexOf("/", l.indexOf("//") + 2), h = l.substr(0, a), c = document.createElement("iframe");
|
|
494
|
+
return c.width = "0px", c.height = "0px", c.id = `${n}_oidc_iframe`, c.setAttribute("src", l), document.body.appendChild(c), new Promise((_, y) => {
|
|
475
495
|
try {
|
|
476
496
|
let u = !1;
|
|
477
|
-
window.onmessage = (
|
|
478
|
-
if (
|
|
479
|
-
const g = `${n}_oidc_tokens:`,
|
|
480
|
-
if (
|
|
481
|
-
if (
|
|
482
|
-
const
|
|
483
|
-
|
|
484
|
-
} else if (
|
|
485
|
-
const
|
|
486
|
-
|
|
497
|
+
window.onmessage = (f) => {
|
|
498
|
+
if (f.origin === h && f.source === c.contentWindow) {
|
|
499
|
+
const g = `${n}_oidc_tokens:`, w = `${n}_oidc_error:`, v = f.data;
|
|
500
|
+
if (v && typeof v == "string" && !u) {
|
|
501
|
+
if (v.startsWith(g)) {
|
|
502
|
+
const b = JSON.parse(f.data.replace(g, ""));
|
|
503
|
+
s(k.silentLoginAsync_end, {}), c.remove(), u = !0, _(b);
|
|
504
|
+
} else if (v.startsWith(w)) {
|
|
505
|
+
const b = JSON.parse(f.data.replace(w, ""));
|
|
506
|
+
s(k.silentLoginAsync_error, b), c.remove(), u = !0, y(new Error("oidc_" + b.error));
|
|
487
507
|
}
|
|
488
508
|
}
|
|
489
509
|
}
|
|
490
510
|
};
|
|
491
|
-
const
|
|
511
|
+
const d = e.silent_login_timeout;
|
|
492
512
|
setTimeout(() => {
|
|
493
|
-
u || (
|
|
494
|
-
},
|
|
513
|
+
u || (s(k.silentLoginAsync_error, { reason: "timeout" }), c.remove(), u = !0, y(new Error("timeout")));
|
|
514
|
+
}, d);
|
|
495
515
|
} catch (u) {
|
|
496
|
-
|
|
516
|
+
c.remove(), s(k.silentLoginAsync_error, u), y(u);
|
|
497
517
|
}
|
|
498
518
|
});
|
|
499
519
|
} catch (r) {
|
|
500
|
-
throw
|
|
520
|
+
throw s(k.silentLoginAsync_error, r), r;
|
|
501
521
|
}
|
|
502
|
-
},
|
|
522
|
+
}, Fe = (n, e, s, t, i) => (o = null, r = void 0) => {
|
|
503
523
|
o = { ...o };
|
|
504
|
-
const l = (h,
|
|
524
|
+
const l = (h, c, _) => te(e, s, t.bind(i))(h, c, _);
|
|
505
525
|
return (async () => {
|
|
506
|
-
i.timeoutId &&
|
|
526
|
+
i.timeoutId && K.clearTimeout(i.timeoutId);
|
|
507
527
|
let h;
|
|
508
528
|
o && "state" in o && (h = o.state, delete o.state);
|
|
509
529
|
try {
|
|
510
|
-
const
|
|
511
|
-
...
|
|
530
|
+
const c = s.extras ? { ...s.extras, ...o } : o, _ = await l({
|
|
531
|
+
...c,
|
|
512
532
|
prompt: "none"
|
|
513
533
|
}, h, r);
|
|
514
534
|
if (_)
|
|
515
|
-
return i.tokens = _.tokens,
|
|
516
|
-
} catch (
|
|
517
|
-
return
|
|
535
|
+
return i.tokens = _.tokens, t(k.token_aquired, {}), i.timeoutId = M(i, i.tokens.refreshToken, i.tokens.expiresAt, o), {};
|
|
536
|
+
} catch (c) {
|
|
537
|
+
return c;
|
|
518
538
|
}
|
|
519
539
|
})();
|
|
520
|
-
},
|
|
521
|
-
const l = (
|
|
522
|
-
return new Promise((
|
|
523
|
-
if (
|
|
524
|
-
const
|
|
540
|
+
}, Ve = (n, e, s) => (t, i, o, r = !1) => {
|
|
541
|
+
const l = (a, h = void 0, c = void 0) => te(n.configurationName, s, n.publishEvent.bind(n))(a, h, c);
|
|
542
|
+
return new Promise((a, h) => {
|
|
543
|
+
if (s.silent_login_uri && s.silent_redirect_uri && s.monitor_session && t && o && !r) {
|
|
544
|
+
const c = () => {
|
|
525
545
|
n.checkSessionIFrame.stop();
|
|
526
546
|
const _ = n.tokens;
|
|
527
547
|
if (_ === null)
|
|
528
548
|
return;
|
|
529
|
-
const
|
|
549
|
+
const y = _.idToken, u = _.idTokenPayload;
|
|
530
550
|
return l({
|
|
531
551
|
prompt: "none",
|
|
532
|
-
id_token_hint:
|
|
533
|
-
scope:
|
|
534
|
-
}).then((
|
|
535
|
-
const
|
|
536
|
-
if (u.sub ===
|
|
537
|
-
const g =
|
|
538
|
-
n.checkSessionIFrame.start(
|
|
552
|
+
id_token_hint: y,
|
|
553
|
+
scope: s.scope || "openid"
|
|
554
|
+
}).then((d) => {
|
|
555
|
+
const f = d.tokens.idTokenPayload;
|
|
556
|
+
if (u.sub === f.sub) {
|
|
557
|
+
const g = d.sessionState;
|
|
558
|
+
n.checkSessionIFrame.start(d.sessionState), u.sid === f.sid ? console.debug("SessionMonitor._callback: Same sub still logged in at OP, restarting check session iframe; session_state:", g) : console.debug("SessionMonitor._callback: Same sub still logged in at OP, session state has changed, restarting check session iframe; session_state:", g);
|
|
539
559
|
} else
|
|
540
|
-
console.debug("SessionMonitor._callback: Different subject signed into OP:",
|
|
541
|
-
}).catch(async (
|
|
542
|
-
console.warn("SessionMonitor._callback: Silent login failed, logging out other tabs:",
|
|
543
|
-
for (const [
|
|
544
|
-
await g.logoutOtherTabAsync(
|
|
560
|
+
console.debug("SessionMonitor._callback: Different subject signed into OP:", f.sub);
|
|
561
|
+
}).catch(async (d) => {
|
|
562
|
+
console.warn("SessionMonitor._callback: Silent login failed, logging out other tabs:", d);
|
|
563
|
+
for (const [f, g] of Object.entries(e))
|
|
564
|
+
await g.logoutOtherTabAsync(s.client_id, u.sub);
|
|
545
565
|
});
|
|
546
566
|
};
|
|
547
|
-
n.checkSessionIFrame = new
|
|
548
|
-
n.checkSessionIFrame.start(o),
|
|
567
|
+
n.checkSessionIFrame = new Ie(c, i, t), n.checkSessionIFrame.load().then(() => {
|
|
568
|
+
n.checkSessionIFrame.start(o), a(n.checkSessionIFrame);
|
|
549
569
|
}).catch((_) => {
|
|
550
570
|
h(_);
|
|
551
571
|
});
|
|
552
572
|
} else
|
|
553
|
-
|
|
573
|
+
a(null);
|
|
554
574
|
});
|
|
555
575
|
};
|
|
556
|
-
var
|
|
557
|
-
for (var
|
|
558
|
-
|
|
559
|
-
function
|
|
560
|
-
return
|
|
576
|
+
var Ue = Be, N = [], ue = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
577
|
+
for (var j = 0, Me = ue.length; j < Me; ++j)
|
|
578
|
+
N[j] = ue[j];
|
|
579
|
+
function Ke(n) {
|
|
580
|
+
return N[n >> 18 & 63] + N[n >> 12 & 63] + N[n >> 6 & 63] + N[n & 63];
|
|
561
581
|
}
|
|
562
|
-
function
|
|
563
|
-
for (var
|
|
564
|
-
|
|
582
|
+
function Je(n, e, s) {
|
|
583
|
+
for (var t, i = [], o = e; o < s; o += 3)
|
|
584
|
+
t = (n[o] << 16 & 16711680) + (n[o + 1] << 8 & 65280) + (n[o + 2] & 255), i.push(Ke(t));
|
|
565
585
|
return i.join("");
|
|
566
586
|
}
|
|
567
|
-
function
|
|
568
|
-
for (var e,
|
|
569
|
-
i.push(
|
|
570
|
-
return
|
|
571
|
-
|
|
572
|
-
)) :
|
|
573
|
-
|
|
587
|
+
function Be(n) {
|
|
588
|
+
for (var e, s = n.length, t = s % 3, i = [], o = 16383, r = 0, l = s - t; r < l; r += o)
|
|
589
|
+
i.push(Je(n, r, r + o > l ? l : r + o));
|
|
590
|
+
return t === 1 ? (e = n[s - 1], i.push(
|
|
591
|
+
N[e >> 2] + N[e << 4 & 63] + "=="
|
|
592
|
+
)) : t === 2 && (e = (n[s - 2] << 8) + n[s - 1], i.push(
|
|
593
|
+
N[e >> 10] + N[e >> 4 & 63] + N[e << 2 & 63] + "="
|
|
574
594
|
)), i.join("");
|
|
575
595
|
}
|
|
576
|
-
const
|
|
596
|
+
const we = () => {
|
|
577
597
|
const n = typeof window < "u" && !!window.crypto, e = n && !!window.crypto.subtle;
|
|
578
598
|
return { hasCrypto: n, hasSubtleCrypto: e };
|
|
579
|
-
},
|
|
599
|
+
}, Q = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", je = (n) => {
|
|
580
600
|
const e = [];
|
|
581
|
-
for (let
|
|
582
|
-
const
|
|
583
|
-
e.push(
|
|
601
|
+
for (let s = 0; s < n.byteLength; s += 1) {
|
|
602
|
+
const t = n[s] % Q.length;
|
|
603
|
+
e.push(Q[t]);
|
|
584
604
|
}
|
|
585
605
|
return e.join("");
|
|
586
|
-
},
|
|
587
|
-
const e = new Uint8Array(n), { hasCrypto:
|
|
588
|
-
if (
|
|
606
|
+
}, qe = (n) => Ue(new Uint8Array(n)).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, ""), Z = (n) => {
|
|
607
|
+
const e = new Uint8Array(n), { hasCrypto: s } = we();
|
|
608
|
+
if (s)
|
|
589
609
|
window.crypto.getRandomValues(e);
|
|
590
610
|
else
|
|
591
|
-
for (let
|
|
592
|
-
e[
|
|
593
|
-
return
|
|
611
|
+
for (let t = 0; t < n; t += 1)
|
|
612
|
+
e[t] = Math.random() * Q.length | 0;
|
|
613
|
+
return je(e);
|
|
594
614
|
};
|
|
595
|
-
function
|
|
596
|
-
const e = new ArrayBuffer(n.length),
|
|
597
|
-
for (let
|
|
598
|
-
t
|
|
599
|
-
return
|
|
615
|
+
function Ge(n) {
|
|
616
|
+
const e = new ArrayBuffer(n.length), s = new Uint8Array(e);
|
|
617
|
+
for (let t = 0; t < n.length; t++)
|
|
618
|
+
s[t] = n.charCodeAt(t);
|
|
619
|
+
return s;
|
|
620
|
+
}
|
|
621
|
+
function Ae(n) {
|
|
622
|
+
return new Promise((e, s) => {
|
|
623
|
+
crypto.subtle.digest("SHA-256", Ge(n)).then((t) => e(qe(new Uint8Array(t))), (t) => s(t));
|
|
624
|
+
});
|
|
600
625
|
}
|
|
601
|
-
const
|
|
626
|
+
const He = (n) => {
|
|
602
627
|
if (n.length < 43 || n.length > 128)
|
|
603
628
|
return Promise.reject(new Error("Invalid code length."));
|
|
604
|
-
const { hasSubtleCrypto: e } =
|
|
605
|
-
return e ?
|
|
606
|
-
|
|
607
|
-
}) : Promise.reject(new Error("window.crypto.subtle is unavailable."));
|
|
608
|
-
}, F = {}, Fe = (n, e = window.sessionStorage, t) => {
|
|
629
|
+
const { hasSubtleCrypto: e } = we();
|
|
630
|
+
return e ? Ae(n) : Promise.reject(new Error("window.crypto.subtle is unavailable."));
|
|
631
|
+
}, F = {}, Xe = (n, e = window.sessionStorage, s) => {
|
|
609
632
|
if (!F[n] && e) {
|
|
610
633
|
const i = e.getItem(n);
|
|
611
634
|
i && (F[n] = JSON.parse(i));
|
|
612
635
|
}
|
|
613
|
-
const
|
|
614
|
-
return F[n] && F[n].timestamp +
|
|
615
|
-
},
|
|
616
|
-
const
|
|
617
|
-
F[n] = { result: e, timestamp:
|
|
618
|
-
},
|
|
619
|
-
const o = `${e}/.well-known/openid-configuration`, r = `oidc.server:${e}`, l =
|
|
636
|
+
const t = 1e3 * s;
|
|
637
|
+
return F[n] && F[n].timestamp + t > Date.now() ? F[n].result : null;
|
|
638
|
+
}, Ye = (n, e, s = window.sessionStorage) => {
|
|
639
|
+
const t = Date.now();
|
|
640
|
+
F[n] = { result: e, timestamp: t }, s && s.setItem(n, JSON.stringify({ result: e, timestamp: t }));
|
|
641
|
+
}, ze = 60 * 60, Qe = (n) => async (e, s = ze, t = window.sessionStorage, i = 1e4) => {
|
|
642
|
+
const o = `${e}/.well-known/openid-configuration`, r = `oidc.server:${e}`, l = Xe(r, t, s);
|
|
620
643
|
if (l)
|
|
621
|
-
return new
|
|
622
|
-
const
|
|
623
|
-
if (
|
|
644
|
+
return new ne(l);
|
|
645
|
+
const a = await J(n)(o, {}, i);
|
|
646
|
+
if (a.status !== 200)
|
|
624
647
|
return null;
|
|
625
|
-
const h = await
|
|
626
|
-
return
|
|
627
|
-
},
|
|
648
|
+
const h = await a.json();
|
|
649
|
+
return Ye(r, h, t), new ne(h);
|
|
650
|
+
}, J = (n) => async (e, s = {}, t = 1e4, i = 0) => {
|
|
628
651
|
let o;
|
|
629
652
|
try {
|
|
630
653
|
const r = new AbortController();
|
|
631
|
-
setTimeout(() => r.abort(),
|
|
654
|
+
setTimeout(() => r.abort(), t), o = await n(e, { ...s, signal: r.signal });
|
|
632
655
|
} catch (r) {
|
|
633
656
|
if (r.name === "AbortError" || r.message === "Network request failed") {
|
|
634
657
|
if (i <= 1)
|
|
635
|
-
return await
|
|
658
|
+
return await J(n)(e, s, t, i + 1);
|
|
636
659
|
throw r;
|
|
637
660
|
} else
|
|
638
661
|
throw console.error(r.message), r;
|
|
639
662
|
}
|
|
640
663
|
return o;
|
|
641
|
-
},
|
|
664
|
+
}, ee = {
|
|
642
665
|
refresh_token: "refresh_token",
|
|
643
666
|
access_token: "access_token"
|
|
644
|
-
},
|
|
667
|
+
}, de = (n) => async (e, s, t = ee.refresh_token, i, o = 1e4) => {
|
|
645
668
|
const r = {
|
|
646
|
-
token:
|
|
647
|
-
token_type_hint:
|
|
669
|
+
token: s,
|
|
670
|
+
token_type_hint: t,
|
|
648
671
|
client_id: i
|
|
649
672
|
}, l = [];
|
|
650
|
-
for (const
|
|
651
|
-
const _ = encodeURIComponent(
|
|
652
|
-
l.push(`${_}=${
|
|
673
|
+
for (const c in r) {
|
|
674
|
+
const _ = encodeURIComponent(c), y = encodeURIComponent(r[c]);
|
|
675
|
+
l.push(`${_}=${y}`);
|
|
653
676
|
}
|
|
654
|
-
const
|
|
655
|
-
return (await
|
|
677
|
+
const a = l.join("&");
|
|
678
|
+
return (await J(n)(e, {
|
|
656
679
|
method: "POST",
|
|
657
680
|
headers: {
|
|
658
681
|
"Content-Type": "application/x-www-form-urlencoded;charset=UTF-8"
|
|
659
682
|
},
|
|
660
|
-
body:
|
|
683
|
+
body: a
|
|
661
684
|
}, o)).status !== 200 ? { success: !1 } : {
|
|
662
685
|
success: !0
|
|
663
686
|
};
|
|
664
|
-
},
|
|
665
|
-
for (const [
|
|
666
|
-
|
|
667
|
-
const
|
|
668
|
-
for (const
|
|
669
|
-
const
|
|
670
|
-
|
|
671
|
-
}
|
|
672
|
-
const
|
|
687
|
+
}, Ze = (n) => async (e, s, t, i, o = {}, r, l = 1e4) => {
|
|
688
|
+
for (const [u, d] of Object.entries(t))
|
|
689
|
+
s[u] === void 0 && (s[u] = d);
|
|
690
|
+
const a = [];
|
|
691
|
+
for (const u in s) {
|
|
692
|
+
const d = encodeURIComponent(u), f = encodeURIComponent(s[u]);
|
|
693
|
+
a.push(`${d}=${f}`);
|
|
694
|
+
}
|
|
695
|
+
const h = a.join("&"), c = await J(n)(e, {
|
|
673
696
|
method: "POST",
|
|
674
697
|
headers: {
|
|
675
|
-
"Content-Type": "application/x-www-form-urlencoded;charset=UTF-8"
|
|
698
|
+
"Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
|
|
699
|
+
...o
|
|
676
700
|
},
|
|
677
|
-
body:
|
|
678
|
-
},
|
|
679
|
-
if (
|
|
680
|
-
return { success: !1, status:
|
|
681
|
-
const
|
|
682
|
-
|
|
701
|
+
body: h
|
|
702
|
+
}, l);
|
|
703
|
+
if (c.status !== 200)
|
|
704
|
+
return { success: !1, status: c.status, demonstratingProofOfPossessionNonce: null };
|
|
705
|
+
const _ = await c.json();
|
|
706
|
+
let y = null;
|
|
707
|
+
return c.headers.has(G) && (y = c.headers.get(G)), {
|
|
683
708
|
success: !0,
|
|
684
|
-
data:
|
|
709
|
+
data: se(_, i, r),
|
|
710
|
+
demonstratingProofOfPossessionNonce: y
|
|
685
711
|
};
|
|
686
|
-
},
|
|
687
|
-
|
|
688
|
-
const
|
|
689
|
-
await n.setCodeVerifierAsync(
|
|
712
|
+
}, en = (n) => async (e, s) => {
|
|
713
|
+
s = s ? { ...s } : {};
|
|
714
|
+
const t = Z(128), i = await He(t);
|
|
715
|
+
await n.setCodeVerifierAsync(t), await n.setStateAsync(s.state), s.code_challenge = i, s.code_challenge_method = "S256";
|
|
690
716
|
let o = "";
|
|
691
|
-
if (
|
|
692
|
-
for (const [r, l] of Object.entries(
|
|
717
|
+
if (s)
|
|
718
|
+
for (const [r, l] of Object.entries(s))
|
|
693
719
|
o === "" ? o += "?" : o += "&", o += `${r}=${encodeURIComponent(l)}`;
|
|
694
720
|
window.location.href = `${e}${o}`;
|
|
695
|
-
},
|
|
696
|
-
|
|
697
|
-
const
|
|
698
|
-
for (const
|
|
699
|
-
const
|
|
700
|
-
|
|
701
|
-
}
|
|
702
|
-
const
|
|
721
|
+
}, G = "DPoP-Nonce", nn = (n) => async (e, s, t, i, o = 1e4) => {
|
|
722
|
+
s = s ? { ...s } : {}, s.code_verifier = await n.getCodeVerifierAsync();
|
|
723
|
+
const r = [];
|
|
724
|
+
for (const _ in s) {
|
|
725
|
+
const y = encodeURIComponent(_), u = encodeURIComponent(s[_]);
|
|
726
|
+
r.push(`${y}=${u}`);
|
|
727
|
+
}
|
|
728
|
+
const l = r.join("&"), a = await J(fetch)(e, {
|
|
703
729
|
method: "POST",
|
|
704
730
|
headers: {
|
|
705
|
-
"Content-Type": "application/x-www-form-urlencoded;charset=UTF-8"
|
|
731
|
+
"Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
|
|
732
|
+
...t
|
|
706
733
|
},
|
|
707
|
-
body:
|
|
708
|
-
},
|
|
709
|
-
if (await Promise.all([n.setCodeVerifierAsync(null), n.setStateAsync(null)]),
|
|
710
|
-
return { success: !1, status:
|
|
711
|
-
|
|
734
|
+
body: l
|
|
735
|
+
}, o);
|
|
736
|
+
if (await Promise.all([n.setCodeVerifierAsync(null), n.setStateAsync(null)]), a.status !== 200)
|
|
737
|
+
return { success: !1, status: a.status };
|
|
738
|
+
let h = null;
|
|
739
|
+
a.headers.has(G) && (h = a.headers.get(G));
|
|
740
|
+
const c = await a.json();
|
|
712
741
|
return {
|
|
713
742
|
success: !0,
|
|
714
743
|
data: {
|
|
715
|
-
state:
|
|
716
|
-
tokens:
|
|
744
|
+
state: s.state,
|
|
745
|
+
tokens: se(c, null, i),
|
|
746
|
+
demonstratingProofOfPossessionNonce: h
|
|
717
747
|
}
|
|
718
748
|
};
|
|
719
|
-
},
|
|
749
|
+
}, ve = (n) => {
|
|
720
750
|
const e = n.match(
|
|
721
751
|
// eslint-disable-next-line no-useless-escape
|
|
722
752
|
/^([a-z][\w-]+\:)\/\/(([^:\/?#]*)(?:\:([0-9]+))?)([\/]{0,1}[^?#]*)(\?[^#]*|)(#.*|)$/
|
|
723
753
|
);
|
|
724
754
|
if (!e)
|
|
725
755
|
throw new Error("Invalid URL");
|
|
726
|
-
let
|
|
727
|
-
if (
|
|
728
|
-
const i =
|
|
729
|
-
i.length === 2 && (
|
|
756
|
+
let s = e[6], t = e[7];
|
|
757
|
+
if (t) {
|
|
758
|
+
const i = t.split("?");
|
|
759
|
+
i.length === 2 && (t = i[0], s = i[1]);
|
|
730
760
|
}
|
|
731
|
-
return
|
|
761
|
+
return s.startsWith("?") && (s = s.slice(1)), e && {
|
|
732
762
|
href: n,
|
|
733
763
|
protocol: e[1],
|
|
734
764
|
host: e[2],
|
|
735
765
|
hostname: e[3],
|
|
736
766
|
port: e[4],
|
|
737
767
|
path: e[5],
|
|
738
|
-
search:
|
|
739
|
-
hash:
|
|
768
|
+
search: s,
|
|
769
|
+
hash: t
|
|
740
770
|
};
|
|
741
|
-
},
|
|
742
|
-
const e =
|
|
743
|
-
let { path:
|
|
744
|
-
|
|
745
|
-
let { hash:
|
|
746
|
-
return
|
|
747
|
-
},
|
|
748
|
-
const e =
|
|
749
|
-
return
|
|
750
|
-
},
|
|
771
|
+
}, kn = (n) => {
|
|
772
|
+
const e = ve(n);
|
|
773
|
+
let { path: s } = e;
|
|
774
|
+
s.endsWith("/") && (s = s.slice(0, -1));
|
|
775
|
+
let { hash: t } = e;
|
|
776
|
+
return t === "#_=_" && (t = ""), t && (s += t), s;
|
|
777
|
+
}, H = (n) => {
|
|
778
|
+
const e = ve(n), { search: s } = e;
|
|
779
|
+
return sn(s);
|
|
780
|
+
}, sn = (n) => {
|
|
751
781
|
const e = {};
|
|
752
|
-
let
|
|
782
|
+
let s, t, i;
|
|
753
783
|
const o = n.split("&");
|
|
754
|
-
for (
|
|
755
|
-
|
|
784
|
+
for (t = 0, i = o.length; t < i; t++)
|
|
785
|
+
s = o[t].split("="), e[decodeURIComponent(s[0])] = decodeURIComponent(s[1]);
|
|
756
786
|
return e;
|
|
757
|
-
}
|
|
787
|
+
};
|
|
788
|
+
function Se(n) {
|
|
789
|
+
return new TextEncoder().encode(n);
|
|
790
|
+
}
|
|
791
|
+
function Te(n) {
|
|
792
|
+
return btoa(n).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+/g, "");
|
|
793
|
+
}
|
|
794
|
+
function tn(n) {
|
|
795
|
+
return encodeURIComponent(n).replace(/%([0-9A-F]{2})/g, function(t, i) {
|
|
796
|
+
return String.fromCharCode(parseInt(i, 16));
|
|
797
|
+
});
|
|
798
|
+
}
|
|
799
|
+
function be(n) {
|
|
800
|
+
let e = "";
|
|
801
|
+
return n.forEach(function(s) {
|
|
802
|
+
e += String.fromCharCode(s);
|
|
803
|
+
}), Te(e);
|
|
804
|
+
}
|
|
805
|
+
function fe(n) {
|
|
806
|
+
return Te(tn(n));
|
|
807
|
+
}
|
|
808
|
+
var Pe = {};
|
|
809
|
+
Pe.sign = (n, e, s, t = "dpop+jwt") => {
|
|
810
|
+
n = Object.assign({}, n), e.typ = t, e.alg = "ES256", e.kid || (e.jwk = { kty: n.kty, crv: n.crv, x: n.x, y: n.y });
|
|
811
|
+
const i = {
|
|
812
|
+
// @ts-ignore
|
|
813
|
+
// JWT "headers" really means JWS "protected headers"
|
|
814
|
+
protected: fe(JSON.stringify(e)),
|
|
815
|
+
// @ts-ignore
|
|
816
|
+
// JWT "claims" are really a JSON-defined JWS "payload"
|
|
817
|
+
payload: fe(JSON.stringify(s))
|
|
818
|
+
}, o = {
|
|
819
|
+
name: "ECDSA",
|
|
820
|
+
namedCurve: "P-256",
|
|
821
|
+
hash: { name: "ES256" }
|
|
822
|
+
}, r = !0, l = ["sign"];
|
|
823
|
+
return window.crypto.subtle.importKey("jwk", n, o, r, l).then(function(a) {
|
|
824
|
+
const h = Se(i.protected + "." + i.payload), c = { name: "ECDSA", hash: { name: "SHA-256" } };
|
|
825
|
+
return window.crypto.subtle.sign(c, a, h).then(function(_) {
|
|
826
|
+
return i.signature = be(new Uint8Array(_)), i.protected + "." + i.payload + "." + i.signature;
|
|
827
|
+
});
|
|
828
|
+
});
|
|
829
|
+
};
|
|
830
|
+
const oe = {};
|
|
831
|
+
oe.generate = function() {
|
|
832
|
+
const n = {
|
|
833
|
+
name: "ECDSA",
|
|
834
|
+
namedCurve: "P-256"
|
|
835
|
+
}, e = !0, s = ["sign", "verify"];
|
|
836
|
+
return window.crypto.subtle.generateKey(n, e, s).then(function(t) {
|
|
837
|
+
return window.crypto.subtle.exportKey("jwk", t.privateKey);
|
|
838
|
+
});
|
|
839
|
+
};
|
|
840
|
+
oe.neuter = function(n) {
|
|
841
|
+
const e = Object.assign({}, n);
|
|
842
|
+
return delete e.d, e.key_ops = ["verify"], e;
|
|
843
|
+
};
|
|
844
|
+
var Oe = {};
|
|
845
|
+
Oe.thumbprint = function(n) {
|
|
846
|
+
const e = '{"crv":"CRV","kty":"EC","x":"X","y":"Y"}'.replace("CRV", n.crv).replace("X", n.x).replace("Y", n.y);
|
|
847
|
+
return window.crypto.subtle.digest({ name: "SHA-256" }, Se(e)).then(function(s) {
|
|
848
|
+
return be(new Uint8Array(s));
|
|
849
|
+
});
|
|
850
|
+
};
|
|
851
|
+
const on = function() {
|
|
852
|
+
const n = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx", e = "0123456789abcdef";
|
|
853
|
+
let s = 0, t = "";
|
|
854
|
+
for (let i = 0; i < 36; i++)
|
|
855
|
+
n[i] !== "-" && n[i] !== "4" && (s = Math.random() * 16 | 0), n[i] === "x" ? t += e[s] : n[i] === "y" ? (s &= 3, s |= 8, t += e[s]) : t += n[i];
|
|
856
|
+
return t;
|
|
857
|
+
}, rn = () => oe.generate().then(function(n) {
|
|
858
|
+
return n;
|
|
859
|
+
}), Ee = (n, e = "POST", s, t = {}) => {
|
|
860
|
+
const i = {
|
|
861
|
+
// https://www.rfc-editor.org/rfc/rfc9449.html#name-concept
|
|
862
|
+
jit: btoa(on()),
|
|
863
|
+
htm: e,
|
|
864
|
+
htu: s,
|
|
865
|
+
iat: Math.round(Date.now() / 1e3),
|
|
866
|
+
...t
|
|
867
|
+
};
|
|
868
|
+
return Oe.thumbprint(n).then(function(o) {
|
|
869
|
+
return Pe.sign(n, {
|
|
870
|
+
/*kid: kid*/
|
|
871
|
+
}, i).then(function(r) {
|
|
872
|
+
return r;
|
|
873
|
+
});
|
|
874
|
+
});
|
|
875
|
+
}, an = (n, e, s, t, i) => (o = void 0, r = null, l = !1, a = void 0) => {
|
|
758
876
|
const h = r;
|
|
759
877
|
return r = { ...r }, (async () => {
|
|
760
|
-
const _ = n.location,
|
|
761
|
-
if ("state" in r || (r.state =
|
|
878
|
+
const _ = n.location, y = o || _.pathname + (_.search || "") + (_.hash || "");
|
|
879
|
+
if ("state" in r || (r.state = Z(16)), t(k.loginAsync_begin, {}), r)
|
|
762
880
|
for (const u of Object.keys(r))
|
|
763
881
|
u.endsWith(":token_request") && delete r[u];
|
|
764
882
|
try {
|
|
765
|
-
const u = l ?
|
|
766
|
-
|
|
767
|
-
const
|
|
768
|
-
|
|
769
|
-
const
|
|
770
|
-
let
|
|
883
|
+
const u = l ? s.silent_redirect_uri : s.redirect_uri;
|
|
884
|
+
a || (a = s.scope);
|
|
885
|
+
const d = s.extras ? { ...s.extras, ...r } : r;
|
|
886
|
+
d.nonce || (d.nonce = Z(12));
|
|
887
|
+
const f = { nonce: d.nonce }, g = await x(s.service_worker_relative_url, e), w = await i(s.authority, s.authority_configuration);
|
|
888
|
+
let v;
|
|
771
889
|
if (g)
|
|
772
|
-
g.setLoginParams(
|
|
890
|
+
g.setLoginParams({ callbackPath: y, extras: h }), await g.initAsync(w, "loginAsync", s), await g.setNonceAsync(f), g.startKeepAliveServiceWorker(), v = g;
|
|
773
891
|
else {
|
|
774
|
-
const
|
|
775
|
-
|
|
892
|
+
const O = I(e, s.storage ?? sessionStorage);
|
|
893
|
+
O.setLoginParams({ callbackPath: y, extras: h }), await O.setNonceAsync(f), v = O;
|
|
776
894
|
}
|
|
777
|
-
const
|
|
778
|
-
client_id:
|
|
895
|
+
const b = {
|
|
896
|
+
client_id: s.client_id,
|
|
779
897
|
redirect_uri: u,
|
|
780
|
-
scope:
|
|
898
|
+
scope: a,
|
|
781
899
|
response_type: "code",
|
|
782
|
-
...
|
|
900
|
+
...d
|
|
783
901
|
};
|
|
784
|
-
await
|
|
902
|
+
await en(v)(w.authorizationEndpoint, b);
|
|
785
903
|
} catch (u) {
|
|
786
|
-
throw
|
|
904
|
+
throw t(k.loginAsync_error, u), u;
|
|
787
905
|
}
|
|
788
906
|
})();
|
|
789
|
-
},
|
|
907
|
+
}, cn = (n) => async (e = !1) => {
|
|
790
908
|
try {
|
|
791
|
-
n.publishEvent(
|
|
792
|
-
const
|
|
793
|
-
let _,
|
|
794
|
-
if (
|
|
795
|
-
await
|
|
909
|
+
n.publishEvent(k.loginCallbackAsync_begin, {});
|
|
910
|
+
const s = n.configuration, t = s.client_id, i = e ? s.silent_redirect_uri : s.redirect_uri, o = s.authority, r = s.token_request_timeout, l = await n.initAsync(o, s.authority_configuration), h = H(window.location.href).session_state, c = await x(s.service_worker_relative_url, n.configurationName);
|
|
911
|
+
let _, y, u, d;
|
|
912
|
+
if (c)
|
|
913
|
+
await c.initAsync(l, "loginCallbackAsync", s), await c.setSessionStateAsync(h), y = await c.getNonceAsync(), u = c.getLoginParams(), d = await c.getStateAsync(), c.startKeepAliveServiceWorker(), _ = c;
|
|
796
914
|
else {
|
|
797
|
-
const
|
|
798
|
-
await
|
|
915
|
+
const A = I(n.configurationName, s.storage ?? sessionStorage);
|
|
916
|
+
await A.setSessionStateAsync(h), y = await A.getNonceAsync(), u = A.getLoginParams(), d = await A.getStateAsync(), _ = A;
|
|
799
917
|
}
|
|
800
|
-
const
|
|
801
|
-
if (
|
|
802
|
-
throw console.error(), new Error(`issuer not valid (expected: ${l.issuer}, received: ${
|
|
803
|
-
if (
|
|
804
|
-
throw new Error(`state not valid (expected: ${
|
|
918
|
+
const f = H(window.location.toString());
|
|
919
|
+
if (f.iss && f.iss !== l.issuer)
|
|
920
|
+
throw console.error(), new Error(`issuer not valid (expected: ${l.issuer}, received: ${f.iss})`);
|
|
921
|
+
if (f.state && f.state !== d)
|
|
922
|
+
throw new Error(`state not valid (expected: ${d}, received: ${f.state})`);
|
|
805
923
|
const g = {
|
|
806
|
-
code:
|
|
924
|
+
code: f.code,
|
|
807
925
|
grant_type: "authorization_code",
|
|
808
|
-
client_id:
|
|
926
|
+
client_id: s.client_id,
|
|
809
927
|
redirect_uri: i
|
|
810
|
-
},
|
|
811
|
-
if (
|
|
812
|
-
for (const [
|
|
813
|
-
|
|
928
|
+
}, w = {};
|
|
929
|
+
if (s.token_request_extras)
|
|
930
|
+
for (const [A, T] of Object.entries(s.token_request_extras))
|
|
931
|
+
w[A] = T;
|
|
814
932
|
if (u && u.extras)
|
|
815
|
-
for (const [
|
|
816
|
-
|
|
817
|
-
const
|
|
818
|
-
if (
|
|
933
|
+
for (const [A, T] of Object.entries(u.extras))
|
|
934
|
+
A.endsWith(":token_request") && (w[A.replace(":token_request", "")] = T);
|
|
935
|
+
const v = l.tokenEndpoint, b = {};
|
|
936
|
+
if (s.demonstrating_proof_of_possession) {
|
|
937
|
+
const A = await rn();
|
|
938
|
+
c ? await c.setDemonstratingProofOfPossessionJwkAsync(A) : await I(n.configurationName, s.storage).setDemonstratingProofOfPossessionJwkAsync(A), b.DPoP = await Ee(A, "POST", v);
|
|
939
|
+
}
|
|
940
|
+
const O = await nn(_)(
|
|
941
|
+
v,
|
|
942
|
+
{ ...g, ...w },
|
|
943
|
+
b,
|
|
944
|
+
n.configuration.token_renew_mode,
|
|
945
|
+
r
|
|
946
|
+
);
|
|
947
|
+
if (!O.success)
|
|
819
948
|
throw new Error("Token request failed");
|
|
820
|
-
let
|
|
821
|
-
const
|
|
822
|
-
if (
|
|
949
|
+
let p;
|
|
950
|
+
const E = O.data.tokens, C = O.data.demonstratingProofOfPossessionNonce;
|
|
951
|
+
if (O.data.state !== w.state)
|
|
823
952
|
throw new Error("state is not valid");
|
|
824
|
-
const { isValid:
|
|
825
|
-
if (!
|
|
826
|
-
throw new Error(`Tokens are not OpenID valid, reason: ${
|
|
827
|
-
|
|
828
|
-
|
|
953
|
+
const { isValid: m, reason: S } = ge(E, y.nonce, l);
|
|
954
|
+
if (!m)
|
|
955
|
+
throw new Error(`Tokens are not OpenID valid, reason: ${S}`);
|
|
956
|
+
if (c) {
|
|
957
|
+
if (E.refreshToken && !E.refreshToken.includes("SECURED_BY_OIDC_SERVICE_WORKER"))
|
|
958
|
+
throw new Error("Refresh token should be hidden by service worker");
|
|
959
|
+
if (C && E.accessToken && E.accessToken.includes("SECURED_BY_OIDC_SERVICE_WORKER"))
|
|
960
|
+
throw new Error("Demonstration of proof of possession require Access token not hidden by service worker");
|
|
961
|
+
}
|
|
962
|
+
if (c)
|
|
963
|
+
await c.initAsync(i, "syncTokensAsync", s), p = c.getLoginParams(), C && await c.setDemonstratingProofOfPossessionNonce(C);
|
|
964
|
+
else {
|
|
965
|
+
const A = I(n.configurationName, s.storage);
|
|
966
|
+
p = A.getLoginParams(), C && await A.setDemonstratingProofOfPossessionNonce(C);
|
|
967
|
+
}
|
|
968
|
+
return await n.startCheckSessionAsync(l.checkSessionIframe, t, h, e), n.publishEvent(k.loginCallbackAsync_end, {}), {
|
|
969
|
+
tokens: E,
|
|
829
970
|
state: "request.state",
|
|
830
|
-
callbackPath:
|
|
971
|
+
callbackPath: p.callbackPath
|
|
831
972
|
};
|
|
832
|
-
} catch (
|
|
833
|
-
throw console.error(
|
|
973
|
+
} catch (s) {
|
|
974
|
+
throw console.error(s), n.publishEvent(k.loginCallbackAsync_error, s), s;
|
|
834
975
|
}
|
|
835
|
-
},
|
|
976
|
+
}, he = {
|
|
836
977
|
access_token: "access_token",
|
|
837
978
|
refresh_token: "refresh_token"
|
|
838
|
-
},
|
|
839
|
-
|
|
840
|
-
const
|
|
841
|
-
|
|
842
|
-
},
|
|
843
|
-
const l = n.configuration,
|
|
979
|
+
}, ln = (n) => async (e) => {
|
|
980
|
+
K.clearTimeout(n.timeoutId), n.timeoutId = null, n.checkSessionIFrame && n.checkSessionIFrame.stop();
|
|
981
|
+
const s = await x(n.configuration.service_worker_relative_url, n.configurationName);
|
|
982
|
+
s ? await s.clearAsync(e) : await I(n.configurationName, n.configuration.storage).clearAsync(e), n.tokens = null, n.userInfo = null;
|
|
983
|
+
}, un = (n, e, s, t, i) => async (o = void 0, r = null) => {
|
|
984
|
+
const l = n.configuration, a = await n.initAsync(l.authority, l.authority_configuration);
|
|
844
985
|
o && typeof o != "string" && (o = void 0, i.warn("callbackPathOrUrl path is not a string"));
|
|
845
986
|
const h = o ?? location.pathname + (location.search || "") + (location.hash || "");
|
|
846
|
-
let
|
|
847
|
-
o && (
|
|
848
|
-
const _ =
|
|
987
|
+
let c = !1;
|
|
988
|
+
o && (c = o.includes("https://") || o.includes("http://"));
|
|
989
|
+
const _ = c ? o : t.location.origin + h, y = n.tokens ? n.tokens.idToken : "";
|
|
849
990
|
try {
|
|
850
|
-
const
|
|
851
|
-
if (
|
|
852
|
-
const
|
|
853
|
-
if (g && l.logout_tokens_to_invalidate.includes(
|
|
854
|
-
const
|
|
855
|
-
|
|
991
|
+
const d = a.revocationEndpoint;
|
|
992
|
+
if (d) {
|
|
993
|
+
const f = [], g = n.tokens.accessToken;
|
|
994
|
+
if (g && l.logout_tokens_to_invalidate.includes(he.access_token)) {
|
|
995
|
+
const v = de(s)(d, g, ee.access_token, l.client_id);
|
|
996
|
+
f.push(v);
|
|
856
997
|
}
|
|
857
|
-
const
|
|
858
|
-
if (
|
|
859
|
-
const
|
|
860
|
-
|
|
998
|
+
const w = n.tokens.refreshToken;
|
|
999
|
+
if (w && l.logout_tokens_to_invalidate.includes(he.refresh_token)) {
|
|
1000
|
+
const v = de(s)(d, w, ee.refresh_token, l.client_id);
|
|
1001
|
+
f.push(v);
|
|
861
1002
|
}
|
|
862
|
-
|
|
1003
|
+
f.length > 0 && await Promise.all(f);
|
|
863
1004
|
}
|
|
864
|
-
} catch (
|
|
865
|
-
i.warn("logoutAsync: error when revoking tokens, if the error persist, you ay configure property logout_tokens_to_invalidate from configuration to avoid this error"), i.warn(
|
|
1005
|
+
} catch (d) {
|
|
1006
|
+
i.warn("logoutAsync: error when revoking tokens, if the error persist, you ay configure property logout_tokens_to_invalidate from configuration to avoid this error"), i.warn(d);
|
|
866
1007
|
}
|
|
867
1008
|
const u = n.tokens && n.tokens.idTokenPayload ? n.tokens.idTokenPayload.sub : null;
|
|
868
1009
|
await n.destroyAsync("LOGGED_OUT");
|
|
869
|
-
for (const [
|
|
870
|
-
|
|
871
|
-
if (
|
|
1010
|
+
for (const [d, f] of Object.entries(e))
|
|
1011
|
+
f !== n && await n.logoutSameTabAsync(n.configuration.client_id, u);
|
|
1012
|
+
if (a.endSessionEndpoint) {
|
|
872
1013
|
r || (r = {
|
|
873
|
-
id_token_hint:
|
|
1014
|
+
id_token_hint: y
|
|
874
1015
|
}, o !== null && (r.post_logout_redirect_uri = _));
|
|
875
|
-
let
|
|
1016
|
+
let d = "";
|
|
876
1017
|
if (r)
|
|
877
|
-
for (const [
|
|
878
|
-
|
|
879
|
-
|
|
1018
|
+
for (const [f, g] of Object.entries(r))
|
|
1019
|
+
d === "" ? d += "?" : d += "&", d += `${f}=${encodeURIComponent(g)}`;
|
|
1020
|
+
t.location.href = `${a.endSessionEndpoint}${d}`;
|
|
880
1021
|
} else
|
|
881
|
-
|
|
882
|
-
},
|
|
1022
|
+
t.location.reload();
|
|
1023
|
+
}, dn = (n) => async (e = !1) => {
|
|
883
1024
|
if (n.userInfo != null && !e)
|
|
884
1025
|
return n.userInfo;
|
|
885
|
-
for (; n.tokens && !
|
|
886
|
-
await
|
|
1026
|
+
for (; n.tokens && !z(n.tokens); )
|
|
1027
|
+
await D(200);
|
|
887
1028
|
if (!n.tokens)
|
|
888
1029
|
return null;
|
|
889
|
-
const
|
|
890
|
-
if (!
|
|
1030
|
+
const s = n.tokens.accessToken;
|
|
1031
|
+
if (!s)
|
|
891
1032
|
return null;
|
|
892
1033
|
const i = (await n.initAsync(n.configuration.authority, n.configuration.authority_configuration)).userInfoEndpoint, r = await (async (l) => {
|
|
893
|
-
const
|
|
1034
|
+
const a = await fetch(i, {
|
|
894
1035
|
headers: {
|
|
895
1036
|
authorization: `Bearer ${l}`
|
|
896
1037
|
}
|
|
897
1038
|
});
|
|
898
|
-
return
|
|
899
|
-
})(
|
|
1039
|
+
return a.status !== 200 ? null : a.json();
|
|
1040
|
+
})(s);
|
|
900
1041
|
return n.userInfo = r, r;
|
|
901
|
-
},
|
|
902
|
-
class
|
|
1042
|
+
}, fn = () => fetch;
|
|
1043
|
+
class ne {
|
|
903
1044
|
constructor(e) {
|
|
904
1045
|
this.authorizationEndpoint = e.authorization_endpoint, this.tokenEndpoint = e.token_endpoint, this.revocationEndpoint = e.revocation_endpoint, this.userInfoEndpoint = e.userinfo_endpoint, this.checkSessionIframe = e.check_session_iframe, this.issuer = e.issuer, this.endSessionEndpoint = e.end_session_endpoint;
|
|
905
1046
|
}
|
|
906
1047
|
}
|
|
907
|
-
const
|
|
908
|
-
const { parsedTokens: e, callbackPath:
|
|
909
|
-
return n.timeoutId =
|
|
910
|
-
},
|
|
911
|
-
constructor(e,
|
|
1048
|
+
const W = {}, hn = (n) => (e, s = "default") => (W[s] || (W[s] = new $(e, s, n)), W[s]), _n = async (n) => {
|
|
1049
|
+
const { parsedTokens: e, callbackPath: s } = await n.loginCallbackAsync();
|
|
1050
|
+
return n.timeoutId = M(n, e.refreshToken, e.expiresAt), { callbackPath: s };
|
|
1051
|
+
}, yn = (n) => Math.floor(Math.random() * n), L = class L {
|
|
1052
|
+
constructor(e, s = "default", t) {
|
|
912
1053
|
this.initPromise = null, this.tryKeepExistingSessionPromise = null, this.loginPromise = null, this.loginCallbackPromise = null, this.loginCallbackWithAutoTokensRenewPromise = null, this.userInfoPromise = null, this.renewTokensPromise = null, this.logoutPromise = null;
|
|
913
1054
|
let i = e.silent_login_uri;
|
|
914
1055
|
e.silent_redirect_uri && !e.silent_login_uri && (i = `${e.silent_redirect_uri.replace("-callback", "").replace("callback", "")}-login`);
|
|
915
1056
|
let o = e.refresh_time_before_tokens_expiration_in_second ?? 120;
|
|
916
|
-
o > 60 && (o = o - Math.floor(Math.random() * 40)),
|
|
1057
|
+
o > 60 && (o = o - Math.floor(Math.random() * 40)), this.configuration = {
|
|
917
1058
|
...e,
|
|
918
1059
|
silent_login_uri: i,
|
|
919
1060
|
monitor_session: e.monitor_session ?? !1,
|
|
920
1061
|
refresh_time_before_tokens_expiration_in_second: o,
|
|
921
1062
|
silent_login_timeout: e.silent_login_timeout ?? 12e3,
|
|
922
|
-
token_renew_mode: e.token_renew_mode ??
|
|
923
|
-
|
|
1063
|
+
token_renew_mode: e.token_renew_mode ?? Y.access_token_or_id_token_invalid,
|
|
1064
|
+
demonstrating_proof_of_possession: e.demonstrating_proof_of_possession ?? !1,
|
|
1065
|
+
authority_timeout_wellknowurl_in_millisecond: e.authority_timeout_wellknowurl_in_millisecond ?? 1e4,
|
|
1066
|
+
logout_tokens_to_invalidate: e.logout_tokens_to_invalidate ?? ["access_token", "refresh_token"]
|
|
1067
|
+
}, this.getFetch = t ?? fn, this.configurationName = s, this.tokens = null, this.userInfo = null, this.events = [], this.timeoutId = null, this.synchroniseTokensAsync.bind(this), this.loginCallbackWithAutoTokensRenewAsync.bind(this), this.initAsync.bind(this), this.loginCallbackAsync.bind(this), this.subscribeEvents.bind(this), this.removeEventSubscription.bind(this), this.publishEvent.bind(this), this.destroyAsync.bind(this), this.logoutAsync.bind(this), this.renewTokensAsync.bind(this), this.initAsync(this.configuration.authority, this.configuration.authority_configuration);
|
|
924
1068
|
}
|
|
925
1069
|
subscribeEvents(e) {
|
|
926
|
-
const
|
|
927
|
-
return this.events.push({ id:
|
|
1070
|
+
const s = yn(9999999999999).toString();
|
|
1071
|
+
return this.events.push({ id: s, func: e }), s;
|
|
928
1072
|
}
|
|
929
1073
|
removeEventSubscription(e) {
|
|
930
|
-
const
|
|
931
|
-
this.events =
|
|
1074
|
+
const s = this.events.filter((t) => t.id !== e);
|
|
1075
|
+
this.events = s;
|
|
932
1076
|
}
|
|
933
|
-
publishEvent(e,
|
|
934
|
-
this.events.forEach((
|
|
935
|
-
|
|
1077
|
+
publishEvent(e, s) {
|
|
1078
|
+
this.events.forEach((t) => {
|
|
1079
|
+
t.func(e, s);
|
|
936
1080
|
});
|
|
937
1081
|
}
|
|
938
1082
|
static get(e = "default") {
|
|
939
|
-
const
|
|
940
|
-
if (!Object.prototype.hasOwnProperty.call(
|
|
1083
|
+
const s = typeof process > "u";
|
|
1084
|
+
if (!Object.prototype.hasOwnProperty.call(W, e) && s)
|
|
941
1085
|
throw Error(`OIDC library does seem initialized.
|
|
942
1086
|
Please checkout that you are using OIDC hook inside a <OidcProvider configurationName="${e}"></OidcProvider> compoment.`);
|
|
943
|
-
return
|
|
1087
|
+
return W[e];
|
|
944
1088
|
}
|
|
945
1089
|
_silentLoginCallbackFromIFrame() {
|
|
946
1090
|
if (this.configuration.silent_redirect_uri && this.configuration.silent_login_uri) {
|
|
947
|
-
const e =
|
|
1091
|
+
const e = H(window.location.href);
|
|
948
1092
|
window.parent.postMessage(`${this.configurationName}_oidc_tokens:${JSON.stringify({ tokens: this.tokens, sessionState: e.session_state })}`, window.location.origin);
|
|
949
1093
|
}
|
|
950
1094
|
}
|
|
951
1095
|
_silentLoginErrorCallbackFromIFrame() {
|
|
952
1096
|
if (this.configuration.silent_redirect_uri && this.configuration.silent_login_uri) {
|
|
953
|
-
const e =
|
|
1097
|
+
const e = H(window.location.href);
|
|
954
1098
|
window.parent.postMessage(`${this.configurationName}_oidc_error:${JSON.stringify({ error: e.error })}`, window.location.origin);
|
|
955
1099
|
}
|
|
956
1100
|
}
|
|
@@ -961,229 +1105,256 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
|
|
|
961
1105
|
console.error(e), this._silentLoginErrorCallbackFromIFrame();
|
|
962
1106
|
}
|
|
963
1107
|
}
|
|
964
|
-
async initAsync(e,
|
|
1108
|
+
async initAsync(e, s) {
|
|
965
1109
|
if (this.initPromise !== null)
|
|
966
1110
|
return this.initPromise;
|
|
967
|
-
const
|
|
968
|
-
if (
|
|
969
|
-
return new
|
|
970
|
-
authorization_endpoint:
|
|
971
|
-
end_session_endpoint:
|
|
972
|
-
revocation_endpoint:
|
|
973
|
-
token_endpoint:
|
|
974
|
-
userinfo_endpoint:
|
|
975
|
-
check_session_iframe:
|
|
976
|
-
issuer:
|
|
1111
|
+
const t = async () => {
|
|
1112
|
+
if (s != null)
|
|
1113
|
+
return new ne({
|
|
1114
|
+
authorization_endpoint: s.authorization_endpoint,
|
|
1115
|
+
end_session_endpoint: s.end_session_endpoint,
|
|
1116
|
+
revocation_endpoint: s.revocation_endpoint,
|
|
1117
|
+
token_endpoint: s.token_endpoint,
|
|
1118
|
+
userinfo_endpoint: s.userinfo_endpoint,
|
|
1119
|
+
check_session_iframe: s.check_session_iframe,
|
|
1120
|
+
issuer: s.issuer
|
|
977
1121
|
});
|
|
978
|
-
const o = await
|
|
979
|
-
return await
|
|
1122
|
+
const o = await x(this.configuration.service_worker_relative_url, this.configurationName) ? window.localStorage : null;
|
|
1123
|
+
return await Qe(this.getFetch())(e, this.configuration.authority_time_cache_wellknowurl_in_second ?? 60 * 60, o, this.configuration.authority_timeout_wellknowurl_in_millisecond);
|
|
980
1124
|
};
|
|
981
|
-
return this.initPromise =
|
|
1125
|
+
return this.initPromise = t(), this.initPromise.then((i) => (this.initPromise = null, i));
|
|
982
1126
|
}
|
|
983
1127
|
async tryKeepExistingSessionAsync() {
|
|
984
1128
|
if (this.tryKeepExistingSessionPromise !== null)
|
|
985
1129
|
return this.tryKeepExistingSessionPromise;
|
|
986
1130
|
const e = async () => {
|
|
987
|
-
let
|
|
1131
|
+
let s;
|
|
988
1132
|
if (this.tokens != null)
|
|
989
1133
|
return !1;
|
|
990
|
-
this.publishEvent(
|
|
1134
|
+
this.publishEvent(k.tryKeepExistingSessionAsync_begin, {});
|
|
991
1135
|
try {
|
|
992
|
-
const
|
|
993
|
-
if (
|
|
994
|
-
const { tokens: o } = await
|
|
1136
|
+
const t = this.configuration, i = await this.initAsync(t.authority, t.authority_configuration);
|
|
1137
|
+
if (s = await x(t.service_worker_relative_url, this.configurationName), s) {
|
|
1138
|
+
const { tokens: o } = await s.initAsync(i, "tryKeepExistingSessionAsync", t);
|
|
995
1139
|
if (o) {
|
|
996
|
-
|
|
997
|
-
const r =
|
|
998
|
-
this.timeoutId =
|
|
999
|
-
const l = await
|
|
1000
|
-
return await this.startCheckSessionAsync(i.check_session_iframe,
|
|
1140
|
+
s.startKeepAliveServiceWorker(), this.tokens = o;
|
|
1141
|
+
const r = s.getLoginParams(this.configurationName);
|
|
1142
|
+
this.timeoutId = M(this, this.tokens.refreshToken, this.tokens.expiresAt, r.extras);
|
|
1143
|
+
const l = await s.getSessionStateAsync();
|
|
1144
|
+
return await this.startCheckSessionAsync(i.check_session_iframe, t.client_id, l), this.publishEvent(k.tryKeepExistingSessionAsync_end, {
|
|
1001
1145
|
success: !0,
|
|
1002
1146
|
message: "tokens inside ServiceWorker are valid"
|
|
1003
1147
|
}), !0;
|
|
1004
1148
|
}
|
|
1005
|
-
this.publishEvent(
|
|
1149
|
+
this.publishEvent(k.tryKeepExistingSessionAsync_end, {
|
|
1006
1150
|
success: !1,
|
|
1007
1151
|
message: "no exiting session found"
|
|
1008
1152
|
});
|
|
1009
1153
|
} else {
|
|
1010
|
-
|
|
1154
|
+
t.service_worker_relative_url && this.publishEvent(k.service_worker_not_supported_by_browser, {
|
|
1011
1155
|
message: "service worker is not supported by this browser"
|
|
1012
1156
|
});
|
|
1013
|
-
const o =
|
|
1157
|
+
const o = I(this.configurationName, t.storage ?? sessionStorage), { tokens: r } = await o.initAsync();
|
|
1014
1158
|
if (r) {
|
|
1015
|
-
this.tokens =
|
|
1016
|
-
const l = o.getLoginParams(
|
|
1017
|
-
this.timeoutId =
|
|
1018
|
-
const
|
|
1019
|
-
return await this.startCheckSessionAsync(i.check_session_iframe,
|
|
1159
|
+
this.tokens = ye(r, null, t.token_renew_mode);
|
|
1160
|
+
const l = o.getLoginParams();
|
|
1161
|
+
this.timeoutId = M(this, r.refreshToken, this.tokens.expiresAt, l.extras);
|
|
1162
|
+
const a = await o.getSessionStateAsync();
|
|
1163
|
+
return await this.startCheckSessionAsync(i.check_session_iframe, t.client_id, a), this.publishEvent(k.tryKeepExistingSessionAsync_end, {
|
|
1020
1164
|
success: !0,
|
|
1021
1165
|
message: "tokens inside storage are valid"
|
|
1022
1166
|
}), !0;
|
|
1023
1167
|
}
|
|
1024
1168
|
}
|
|
1025
|
-
return this.publishEvent(
|
|
1169
|
+
return this.publishEvent(k.tryKeepExistingSessionAsync_end, {
|
|
1026
1170
|
success: !1,
|
|
1027
|
-
message:
|
|
1171
|
+
message: s ? "service worker sessions not retrieved" : "session storage sessions not retrieved"
|
|
1028
1172
|
}), !1;
|
|
1029
|
-
} catch (
|
|
1030
|
-
return console.error(
|
|
1173
|
+
} catch (t) {
|
|
1174
|
+
return console.error(t), s && await s.clearAsync(), this.publishEvent(k.tryKeepExistingSessionAsync_error, "tokens inside ServiceWorker are invalid"), !1;
|
|
1031
1175
|
}
|
|
1032
1176
|
};
|
|
1033
|
-
return this.tryKeepExistingSessionPromise = e(), this.tryKeepExistingSessionPromise.then((
|
|
1177
|
+
return this.tryKeepExistingSessionPromise = e(), this.tryKeepExistingSessionPromise.then((s) => (this.tryKeepExistingSessionPromise = null, s));
|
|
1034
1178
|
}
|
|
1035
|
-
async startCheckSessionAsync(e,
|
|
1036
|
-
await
|
|
1179
|
+
async startCheckSessionAsync(e, s, t, i = !1) {
|
|
1180
|
+
await Ve(this, W, this.configuration)(e, s, t, i);
|
|
1037
1181
|
}
|
|
1038
|
-
async loginAsync(e = void 0,
|
|
1039
|
-
return this.loginPromise !== null ? this.loginPromise : o ?
|
|
1182
|
+
async loginAsync(e = void 0, s = null, t = !1, i = void 0, o = !1) {
|
|
1183
|
+
return this.loginPromise !== null ? this.loginPromise : o ? Fe(window, this.configurationName, this.configuration, this.publishEvent.bind(this), this)(s, i) : (this.loginPromise = an(window, this.configurationName, this.configuration, this.publishEvent.bind(this), this.initAsync.bind(this))(e, s, t, i), this.loginPromise.then((r) => (this.loginPromise = null, r)));
|
|
1040
1184
|
}
|
|
1041
1185
|
async loginCallbackAsync(e = !1) {
|
|
1042
1186
|
if (this.loginCallbackPromise !== null)
|
|
1043
1187
|
return this.loginCallbackPromise;
|
|
1044
|
-
const
|
|
1045
|
-
const
|
|
1046
|
-
return this.tokens = i, await
|
|
1188
|
+
const s = async () => {
|
|
1189
|
+
const t = await cn(this)(e), i = t.tokens;
|
|
1190
|
+
return this.tokens = i, await x(this.configuration.service_worker_relative_url, this.configurationName) || I(this.configurationName, this.configuration.storage).setTokens(i), this.publishEvent(L.eventNames.token_aquired, i), { parsedTokens: i, state: t.state, callbackPath: t.callbackPath };
|
|
1047
1191
|
};
|
|
1048
|
-
return this.loginCallbackPromise =
|
|
1192
|
+
return this.loginCallbackPromise = s(), this.loginCallbackPromise.then((t) => (this.loginCallbackPromise = null, t));
|
|
1049
1193
|
}
|
|
1050
|
-
async synchroniseTokensAsync(e,
|
|
1194
|
+
async synchroniseTokensAsync(e, s = 0, t = !1, i = null, o) {
|
|
1051
1195
|
for (; !navigator.onLine && document.hidden; )
|
|
1052
|
-
await
|
|
1196
|
+
await D(1e3), this.publishEvent(k.refreshTokensAsync, { message: "wait because navigator is offline and hidden" });
|
|
1053
1197
|
let r = 6;
|
|
1054
1198
|
for (; !navigator.onLine && r > 0; )
|
|
1055
|
-
await
|
|
1199
|
+
await D(1e3), r--, this.publishEvent(k.refreshTokensAsync, { message: `wait because navigator is offline try ${r}` });
|
|
1056
1200
|
let l = Math.floor(Math.random() * 15) + 10;
|
|
1057
1201
|
for (; document.hidden && l > 0; )
|
|
1058
|
-
await
|
|
1059
|
-
const h = document.hidden ?
|
|
1202
|
+
await D(1e3), l--, this.publishEvent(k.refreshTokensAsync, { message: `wait because navigator is hidden try ${l}` });
|
|
1203
|
+
const h = document.hidden ? s : s + 1;
|
|
1060
1204
|
i || (i = {});
|
|
1061
|
-
const
|
|
1205
|
+
const c = this.configuration, _ = (u, d, f = null) => te(this.configurationName, this.configuration, this.publishEvent.bind(this))(u, d, f), y = async () => {
|
|
1062
1206
|
try {
|
|
1063
1207
|
let u;
|
|
1064
|
-
const
|
|
1065
|
-
|
|
1066
|
-
const
|
|
1208
|
+
const d = await x(c.service_worker_relative_url, this.configurationName);
|
|
1209
|
+
d ? u = d.getLoginParams() : u = I(this.configurationName, c.storage).getLoginParams();
|
|
1210
|
+
const f = await _({
|
|
1067
1211
|
...u.extras,
|
|
1068
1212
|
...i,
|
|
1069
1213
|
prompt: "none"
|
|
1070
1214
|
}, u.state);
|
|
1071
|
-
if (
|
|
1072
|
-
return o(
|
|
1215
|
+
if (f)
|
|
1216
|
+
return o(f.tokens), this.publishEvent(L.eventNames.token_renewed, {}), { tokens: f.tokens, status: "LOGGED" };
|
|
1073
1217
|
} catch (u) {
|
|
1074
|
-
if (console.error(u), this.publishEvent(
|
|
1075
|
-
return o(null), this.publishEvent(
|
|
1218
|
+
if (console.error(u), this.publishEvent(k.refreshTokensAsync_silent_error, { message: "exceptionSilent", exception: u.message }), u && u.message && u.message.startsWith("oidc"))
|
|
1219
|
+
return o(null), this.publishEvent(k.refreshTokensAsync_error, { message: "refresh token silent" }), { tokens: null, status: "SESSION_LOST" };
|
|
1076
1220
|
}
|
|
1077
|
-
return this.publishEvent(
|
|
1221
|
+
return this.publishEvent(k.refreshTokensAsync_error, { message: "refresh token silent return" }), await this.synchroniseTokensAsync(null, h, t, i, o);
|
|
1078
1222
|
};
|
|
1079
|
-
if (
|
|
1080
|
-
return o(null), this.publishEvent(
|
|
1223
|
+
if (s > 4)
|
|
1224
|
+
return o(null), this.publishEvent(k.refreshTokensAsync_error, { message: "refresh token" }), { tokens: null, status: "SESSION_LOST" };
|
|
1081
1225
|
try {
|
|
1082
|
-
const { status: u, tokens:
|
|
1226
|
+
const { status: u, tokens: d, nonce: f } = await this.syncTokensInfoAsync(c, this.configurationName, this.tokens, t);
|
|
1083
1227
|
switch (u) {
|
|
1084
1228
|
case "SESSION_LOST":
|
|
1085
|
-
return o(null), this.publishEvent(
|
|
1229
|
+
return o(null), this.publishEvent(k.refreshTokensAsync_error, { message: "refresh token session lost" }), { tokens: null, status: "SESSION_LOST" };
|
|
1086
1230
|
case "NOT_CONNECTED":
|
|
1087
1231
|
return o(null), { tokens: null, status: null };
|
|
1088
1232
|
case "TOKENS_VALID":
|
|
1089
|
-
return o(
|
|
1233
|
+
return o(d), { tokens: d, status: "LOGGED_IN" };
|
|
1090
1234
|
case "TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID":
|
|
1091
|
-
return o(
|
|
1235
|
+
return o(d), this.publishEvent(L.eventNames.token_renewed, { reason: "TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID" }), { tokens: d, status: "LOGGED_IN" };
|
|
1092
1236
|
case "LOGOUT_FROM_ANOTHER_TAB":
|
|
1093
|
-
return o(null), this.publishEvent(
|
|
1237
|
+
return o(null), this.publishEvent(k.logout_from_another_tab, { status: "session syncTokensAsync" }), { tokens: null, status: "LOGGED_OUT" };
|
|
1094
1238
|
case "REQUIRE_SYNC_TOKENS":
|
|
1095
|
-
return this.publishEvent(
|
|
1239
|
+
return this.publishEvent(k.refreshTokensAsync_begin, { refreshToken: e, status: u, tryNumber: s }), await y();
|
|
1096
1240
|
default: {
|
|
1097
|
-
if (this.publishEvent(
|
|
1098
|
-
return await
|
|
1099
|
-
const g =
|
|
1100
|
-
for (const [
|
|
1101
|
-
|
|
1241
|
+
if (this.publishEvent(k.refreshTokensAsync_begin, { refreshToken: e, status: u, tryNumber: s }), !e)
|
|
1242
|
+
return await y();
|
|
1243
|
+
const g = c.client_id, w = c.redirect_uri, v = c.authority, O = { ...c.token_request_extras ? c.token_request_extras : {} };
|
|
1244
|
+
for (const [E, C] of Object.entries(i))
|
|
1245
|
+
E.endsWith(":token_request") && (O[E.replace(":token_request", "")] = C);
|
|
1102
1246
|
return await (async () => {
|
|
1103
|
-
const
|
|
1247
|
+
const E = {
|
|
1104
1248
|
client_id: g,
|
|
1105
|
-
redirect_uri:
|
|
1249
|
+
redirect_uri: w,
|
|
1106
1250
|
grant_type: "refresh_token",
|
|
1107
|
-
refresh_token:
|
|
1108
|
-
},
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1251
|
+
refresh_token: d.refreshToken
|
|
1252
|
+
}, C = await this.initAsync(v, c.authority_configuration), m = document.hidden ? 1e4 : 3e4 * 10, S = C.tokenEndpoint, A = {};
|
|
1253
|
+
c.demonstrating_proof_of_possession && (A.DPoP = await this.generateDemonstrationOfProofOfPossessionAsync(d.accessToken, S, "POST"));
|
|
1254
|
+
const T = await Ze(this.getFetch())(
|
|
1255
|
+
S,
|
|
1256
|
+
E,
|
|
1257
|
+
O,
|
|
1258
|
+
d,
|
|
1259
|
+
A,
|
|
1260
|
+
c.token_renew_mode,
|
|
1261
|
+
m
|
|
1262
|
+
);
|
|
1263
|
+
if (T.success) {
|
|
1264
|
+
const { isValid: B, reason: X } = ge(T.data, f.nonce, C);
|
|
1265
|
+
if (!B)
|
|
1266
|
+
return o(null), this.publishEvent(k.refreshTokensAsync_error, { message: `refresh token return not valid tokens, reason: ${X}` }), { tokens: null, status: "SESSION_LOST" };
|
|
1267
|
+
if (o(T.data), T.demonstratingProofOfPossessionNonce) {
|
|
1268
|
+
const ie = await x(c.service_worker_relative_url, this.configurationName);
|
|
1269
|
+
ie ? await ie.setDemonstratingProofOfPossessionNonce(T.demonstratingProofOfPossessionNonce) : await I(this.configurationName, c.storage).setDemonstratingProofOfPossessionNonce(T.demonstratingProofOfPossessionNonce);
|
|
1270
|
+
}
|
|
1271
|
+
return this.publishEvent(k.refreshTokensAsync_end, { success: T.success }), this.publishEvent(L.eventNames.token_renewed, { reason: "REFRESH_TOKEN" }), { tokens: T.data, status: "LOGGED_IN" };
|
|
1112
1272
|
} else
|
|
1113
|
-
return this.publishEvent(
|
|
1273
|
+
return this.publishEvent(k.refreshTokensAsync_silent_error, {
|
|
1114
1274
|
message: "bad request",
|
|
1115
|
-
tokenResponse:
|
|
1116
|
-
}), await this.synchroniseTokensAsync(e, h,
|
|
1275
|
+
tokenResponse: T
|
|
1276
|
+
}), await this.synchroniseTokensAsync(e, h, t, i, o);
|
|
1117
1277
|
})();
|
|
1118
1278
|
}
|
|
1119
1279
|
}
|
|
1120
1280
|
} catch (u) {
|
|
1121
|
-
return console.error(u), this.publishEvent(
|
|
1281
|
+
return console.error(u), this.publishEvent(k.refreshTokensAsync_silent_error, { message: "exception", exception: u.message }), this.synchroniseTokensAsync(e, h, t, i, o);
|
|
1282
|
+
}
|
|
1283
|
+
}
|
|
1284
|
+
async generateDemonstrationOfProofOfPossessionAsync(e, s, t) {
|
|
1285
|
+
const i = this.configuration, o = { ath: await Ae(e) }, r = await x(i.service_worker_relative_url, this.configurationName);
|
|
1286
|
+
let l = null, a;
|
|
1287
|
+
if (r)
|
|
1288
|
+
l = await r.getDemonstratingProofOfPossessionNonce(), a = await r.getDemonstratingProofOfPossessionJwkAsync();
|
|
1289
|
+
else {
|
|
1290
|
+
const h = I(this.configurationName, i.storage);
|
|
1291
|
+
a = await h.getDemonstratingProofOfPossessionJwkAsync(), l = await h.getDemonstratingProofOfPossessionNonce();
|
|
1122
1292
|
}
|
|
1293
|
+
return l && (o.nonce = l), await Ee(a, t, s, o);
|
|
1123
1294
|
}
|
|
1124
|
-
async syncTokensInfoAsync(e,
|
|
1295
|
+
async syncTokensInfoAsync(e, s, t, i = !1) {
|
|
1125
1296
|
const o = { nonce: null };
|
|
1126
|
-
if (!
|
|
1297
|
+
if (!t)
|
|
1127
1298
|
return { tokens: null, status: "NOT_CONNECTED", nonce: o };
|
|
1128
1299
|
let r = o;
|
|
1129
|
-
const l = await this.initAsync(e.authority, e.authority_configuration),
|
|
1130
|
-
if (
|
|
1131
|
-
const { status: _, tokens:
|
|
1300
|
+
const l = await this.initAsync(e.authority, e.authority_configuration), a = await x(e.service_worker_relative_url, s);
|
|
1301
|
+
if (a) {
|
|
1302
|
+
const { status: _, tokens: y } = await a.initAsync(l, "syncTokensAsync", e);
|
|
1132
1303
|
if (_ === "LOGGED_OUT")
|
|
1133
1304
|
return { tokens: null, status: "LOGOUT_FROM_ANOTHER_TAB", nonce: o };
|
|
1134
1305
|
if (_ === "SESSIONS_LOST")
|
|
1135
1306
|
return { tokens: null, status: "SESSIONS_LOST", nonce: o };
|
|
1136
|
-
if (!_ || !
|
|
1307
|
+
if (!_ || !y)
|
|
1137
1308
|
return { tokens: null, status: "REQUIRE_SYNC_TOKENS", nonce: o };
|
|
1138
|
-
if (
|
|
1139
|
-
const
|
|
1140
|
-
return { tokens:
|
|
1309
|
+
if (y.issuedAt !== t.issuedAt) {
|
|
1310
|
+
const d = U(e.refresh_time_before_tokens_expiration_in_second, y.expiresAt) > 0 ? "TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID" : "TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_INVALID", f = await a.getNonceAsync();
|
|
1311
|
+
return { tokens: y, status: d, nonce: f };
|
|
1141
1312
|
}
|
|
1142
|
-
r = await
|
|
1313
|
+
r = await a.getNonceAsync();
|
|
1143
1314
|
} else {
|
|
1144
|
-
const _ =
|
|
1145
|
-
if (
|
|
1315
|
+
const _ = I(s, e.storage ?? sessionStorage), { tokens: y, status: u } = await _.initAsync();
|
|
1316
|
+
if (y) {
|
|
1146
1317
|
if (u === "SESSIONS_LOST")
|
|
1147
1318
|
return { tokens: null, status: "SESSIONS_LOST", nonce: o };
|
|
1148
|
-
if (
|
|
1149
|
-
const
|
|
1150
|
-
return { tokens:
|
|
1319
|
+
if (y.issuedAt !== t.issuedAt) {
|
|
1320
|
+
const f = U(e.refresh_time_before_tokens_expiration_in_second, y.expiresAt) > 0 ? "TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID" : "TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_INVALID", g = await _.getNonceAsync();
|
|
1321
|
+
return { tokens: y, status: f, nonce: g };
|
|
1151
1322
|
}
|
|
1152
1323
|
} else
|
|
1153
1324
|
return { tokens: null, status: "LOGOUT_FROM_ANOTHER_TAB", nonce: o };
|
|
1154
1325
|
r = await _.getNonceAsync();
|
|
1155
1326
|
}
|
|
1156
|
-
const
|
|
1157
|
-
return i ? { tokens:
|
|
1327
|
+
const c = U(e.refresh_time_before_tokens_expiration_in_second, t.expiresAt) > 0 ? "TOKENS_VALID" : "TOKENS_INVALID";
|
|
1328
|
+
return i ? { tokens: t, status: "FORCE_REFRESH", nonce: r } : { tokens: t, status: c, nonce: r };
|
|
1158
1329
|
}
|
|
1159
1330
|
loginCallbackWithAutoTokensRenewAsync() {
|
|
1160
|
-
return this.loginCallbackWithAutoTokensRenewPromise !== null ? this.loginCallbackWithAutoTokensRenewPromise : (this.loginCallbackWithAutoTokensRenewPromise =
|
|
1331
|
+
return this.loginCallbackWithAutoTokensRenewPromise !== null ? this.loginCallbackWithAutoTokensRenewPromise : (this.loginCallbackWithAutoTokensRenewPromise = _n(this), this.loginCallbackWithAutoTokensRenewPromise.then((e) => (this.loginCallbackWithAutoTokensRenewPromise = null, e)));
|
|
1161
1332
|
}
|
|
1162
1333
|
userInfoAsync(e = !1) {
|
|
1163
|
-
return this.userInfoPromise !== null ? this.userInfoPromise : (this.userInfoPromise =
|
|
1334
|
+
return this.userInfoPromise !== null ? this.userInfoPromise : (this.userInfoPromise = dn(this)(e), this.userInfoPromise.then((s) => (this.userInfoPromise = null, s)));
|
|
1164
1335
|
}
|
|
1165
1336
|
async renewTokensAsync(e = null) {
|
|
1166
1337
|
if (this.renewTokensPromise !== null)
|
|
1167
1338
|
return this.renewTokensPromise;
|
|
1168
1339
|
if (this.timeoutId)
|
|
1169
|
-
return
|
|
1340
|
+
return K.clearTimeout(this.timeoutId), this.renewTokensPromise = pe(this, this.tokens.refreshToken, !0, e), this.renewTokensPromise.then((s) => (this.renewTokensPromise = null, s));
|
|
1170
1341
|
}
|
|
1171
1342
|
async destroyAsync(e) {
|
|
1172
|
-
return await
|
|
1343
|
+
return await ln(this)(e);
|
|
1173
1344
|
}
|
|
1174
|
-
async logoutSameTabAsync(e,
|
|
1175
|
-
this.configuration.monitor_session && this.configuration.client_id === e &&
|
|
1345
|
+
async logoutSameTabAsync(e, s) {
|
|
1346
|
+
this.configuration.monitor_session && this.configuration.client_id === e && s && this.tokens && this.tokens.idTokenPayload && this.tokens.idTokenPayload.sub === s && (this.publishEvent(k.logout_from_same_tab, { message: s }), await this.destroyAsync("LOGGED_OUT"));
|
|
1176
1347
|
}
|
|
1177
|
-
async logoutOtherTabAsync(e,
|
|
1178
|
-
this.configuration.monitor_session && this.configuration.client_id === e &&
|
|
1348
|
+
async logoutOtherTabAsync(e, s) {
|
|
1349
|
+
this.configuration.monitor_session && this.configuration.client_id === e && s && this.tokens && this.tokens.idTokenPayload && this.tokens.idTokenPayload.sub === s && (await this.destroyAsync("LOGGED_OUT"), this.publishEvent(k.logout_from_another_tab, { message: "SessionMonitor", sub: s }));
|
|
1179
1350
|
}
|
|
1180
|
-
async logoutAsync(e = void 0,
|
|
1181
|
-
return this.logoutPromise ? this.logoutPromise : (this.logoutPromise =
|
|
1351
|
+
async logoutAsync(e = void 0, s = null) {
|
|
1352
|
+
return this.logoutPromise ? this.logoutPromise : (this.logoutPromise = un(this, W, this.getFetch(), window, console)(e, s), this.logoutPromise.then((t) => (this.logoutPromise = null, t)));
|
|
1182
1353
|
}
|
|
1183
1354
|
};
|
|
1184
|
-
L.getOrCreate = (e) => (
|
|
1185
|
-
let
|
|
1186
|
-
const
|
|
1355
|
+
L.getOrCreate = (e) => (s, t = "default") => hn(e)(s, t), L.eventNames = k;
|
|
1356
|
+
let $ = L;
|
|
1357
|
+
const V = class V {
|
|
1187
1358
|
constructor(e) {
|
|
1188
1359
|
this._oidc = e;
|
|
1189
1360
|
}
|
|
@@ -1193,20 +1364,20 @@ const R = class R {
|
|
|
1193
1364
|
removeEventSubscription(e) {
|
|
1194
1365
|
this._oidc.removeEventSubscription(e);
|
|
1195
1366
|
}
|
|
1196
|
-
publishEvent(e,
|
|
1197
|
-
this._oidc.publishEvent(e,
|
|
1367
|
+
publishEvent(e, s) {
|
|
1368
|
+
this._oidc.publishEvent(e, s);
|
|
1198
1369
|
}
|
|
1199
1370
|
static get(e = "default") {
|
|
1200
|
-
return new
|
|
1371
|
+
return new V($.get(e));
|
|
1201
1372
|
}
|
|
1202
1373
|
tryKeepExistingSessionAsync() {
|
|
1203
1374
|
return this._oidc.tryKeepExistingSessionAsync();
|
|
1204
1375
|
}
|
|
1205
|
-
loginAsync(e = void 0,
|
|
1206
|
-
return this._oidc.loginAsync(e,
|
|
1376
|
+
loginAsync(e = void 0, s = null, t = !1, i = void 0, o = !1) {
|
|
1377
|
+
return this._oidc.loginAsync(e, s, t, i, o);
|
|
1207
1378
|
}
|
|
1208
|
-
logoutAsync(e = void 0,
|
|
1209
|
-
return this._oidc.logoutAsync(e,
|
|
1379
|
+
logoutAsync(e = void 0, s = null) {
|
|
1380
|
+
return this._oidc.logoutAsync(e, s);
|
|
1210
1381
|
}
|
|
1211
1382
|
silentLoginCallbackAsync() {
|
|
1212
1383
|
return this._oidc.silentLoginCallbackAsync();
|
|
@@ -1223,19 +1394,22 @@ const R = class R {
|
|
|
1223
1394
|
get configuration() {
|
|
1224
1395
|
return this._oidc.configuration;
|
|
1225
1396
|
}
|
|
1226
|
-
async
|
|
1227
|
-
return
|
|
1397
|
+
async generateDemonstrationOfProofOfPossessionAsync(e, s, t) {
|
|
1398
|
+
return this._oidc.generateDemonstrationOfProofOfPossessionAsync(e, s, t);
|
|
1399
|
+
}
|
|
1400
|
+
async getValidTokenAsync(e = 200, s = 50) {
|
|
1401
|
+
return We(this._oidc, e, s);
|
|
1228
1402
|
}
|
|
1229
1403
|
async userInfoAsync(e = !1) {
|
|
1230
1404
|
return this._oidc.userInfoAsync(e);
|
|
1231
1405
|
}
|
|
1232
1406
|
};
|
|
1233
|
-
|
|
1234
|
-
let
|
|
1407
|
+
V.getOrCreate = (e) => (s, t = "default") => new V($.getOrCreate(e)(s, t)), V.eventNames = $.eventNames;
|
|
1408
|
+
let _e = V;
|
|
1235
1409
|
export {
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1410
|
+
_e as OidcClient,
|
|
1411
|
+
Y as TokenRenewMode,
|
|
1412
|
+
fn as getFetchDefault,
|
|
1413
|
+
H as getParseQueryStringFromLocation,
|
|
1414
|
+
kn as getPath
|
|
1241
1415
|
};
|