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