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