@opengeoweb/authentication 17.0.1 → 17.1.0
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/package.json +24 -11
- package/readme.mdx +7 -0
- package/index.d.ts +0 -1
- package/index.esm.js +0 -1423
package/index.esm.js
DELETED
|
@@ -1,1423 +0,0 @@
|
|
|
1
|
-
import axios from 'axios';
|
|
2
|
-
import React, { useRef, useEffect, useState } from 'react';
|
|
3
|
-
import { Navigate, Link } from 'react-router-dom';
|
|
4
|
-
import { sessionStorageProvider, useIsMounted, SHARED_NAMESPACE, AlertBanner, useDebounce } from '@opengeoweb/shared';
|
|
5
|
-
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
6
|
-
import { useTranslation, Trans } from 'react-i18next';
|
|
7
|
-
import { ThemeWrapper } from '@opengeoweb/theme';
|
|
8
|
-
import 'i18next';
|
|
9
|
-
import { FormControl, FormLabel, RadioGroup, FormControlLabel, Radio } from '@mui/material';
|
|
10
|
-
|
|
11
|
-
var en$1 = {
|
|
12
|
-
"api-role-title-user": "User",
|
|
13
|
-
"api-role-title-preset-admin": "Preset-admin"
|
|
14
|
-
};
|
|
15
|
-
var fi$1 = {
|
|
16
|
-
"api-role-title-user": "Käyttäjä",
|
|
17
|
-
"api-role-title-preset-admin": "Preset-pääkäyttäjä"
|
|
18
|
-
};
|
|
19
|
-
var no$1 = {
|
|
20
|
-
"api-role-title-user": "Bruker",
|
|
21
|
-
"api-role-title-preset-admin": "Preset-admin"
|
|
22
|
-
};
|
|
23
|
-
var nl$1 = {
|
|
24
|
-
"api-role-title-user": "Gebruiker",
|
|
25
|
-
"api-role-title-preset-admin": "Preset-beheerder"
|
|
26
|
-
};
|
|
27
|
-
var apiTranslations = {
|
|
28
|
-
en: en$1,
|
|
29
|
-
fi: fi$1,
|
|
30
|
-
no: no$1,
|
|
31
|
-
nl: nl$1
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
var en = {
|
|
35
|
-
"auth-logout-go-back-to-home-page": "Go back to the <1>Home Page</1>",
|
|
36
|
-
"auth-logout-you-are-logged-out": "You are logged out.",
|
|
37
|
-
"auth-role-title": "Role"
|
|
38
|
-
};
|
|
39
|
-
var fi = {
|
|
40
|
-
"auth-logout-go-back-to-home-page": "Palaa takaisin <1>Kotisivulle</1>",
|
|
41
|
-
"auth-logout-you-are-logged-out": "Olet kirjautunut ulos.",
|
|
42
|
-
"auth-role-title": "Rooli"
|
|
43
|
-
};
|
|
44
|
-
var no = {
|
|
45
|
-
"auth-logout-go-back-to-home-page": "Gå tilbake til <1>Hjemmesiden</1>",
|
|
46
|
-
"auth-logout-you-are-logged-out": "Du er logget ut",
|
|
47
|
-
"auth-role-title": "Rolle"
|
|
48
|
-
};
|
|
49
|
-
var nl = {
|
|
50
|
-
"auth-logout-go-back-to-home-page": "Ga terug naar de <1>Startpagina</1>",
|
|
51
|
-
"auth-logout-you-are-logged-out": "Je bent uitgelogd.",
|
|
52
|
-
"auth-role-title": "Rol"
|
|
53
|
-
};
|
|
54
|
-
var authTranslations = {
|
|
55
|
-
en: en,
|
|
56
|
-
fi: fi,
|
|
57
|
-
no: no,
|
|
58
|
-
nl: nl
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
function _OverloadYield(e, d) {
|
|
62
|
-
this.v = e, this.k = d;
|
|
63
|
-
}
|
|
64
|
-
function asyncGeneratorStep(n, t, e, r, o, a, c) {
|
|
65
|
-
try {
|
|
66
|
-
var i = n[a](c),
|
|
67
|
-
u = i.value;
|
|
68
|
-
} catch (n) {
|
|
69
|
-
return void e(n);
|
|
70
|
-
}
|
|
71
|
-
i.done ? t(u) : Promise.resolve(u).then(r, o);
|
|
72
|
-
}
|
|
73
|
-
function _asyncToGenerator(n) {
|
|
74
|
-
return function () {
|
|
75
|
-
var t = this,
|
|
76
|
-
e = arguments;
|
|
77
|
-
return new Promise(function (r, o) {
|
|
78
|
-
var a = n.apply(t, e);
|
|
79
|
-
function _next(n) {
|
|
80
|
-
asyncGeneratorStep(a, r, o, _next, _throw, "next", n);
|
|
81
|
-
}
|
|
82
|
-
function _throw(n) {
|
|
83
|
-
asyncGeneratorStep(a, r, o, _next, _throw, "throw", n);
|
|
84
|
-
}
|
|
85
|
-
_next(void 0);
|
|
86
|
-
});
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
function _regenerator() {
|
|
90
|
-
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
|
|
91
|
-
var e,
|
|
92
|
-
t,
|
|
93
|
-
r = "function" == typeof Symbol ? Symbol : {},
|
|
94
|
-
n = r.iterator || "@@iterator",
|
|
95
|
-
o = r.toStringTag || "@@toStringTag";
|
|
96
|
-
function i(r, n, o, i) {
|
|
97
|
-
var c = n && n.prototype instanceof Generator ? n : Generator,
|
|
98
|
-
u = Object.create(c.prototype);
|
|
99
|
-
return _regeneratorDefine(u, "_invoke", function (r, n, o) {
|
|
100
|
-
var i,
|
|
101
|
-
c,
|
|
102
|
-
u,
|
|
103
|
-
f = 0,
|
|
104
|
-
p = o || [],
|
|
105
|
-
y = false,
|
|
106
|
-
G = {
|
|
107
|
-
p: 0,
|
|
108
|
-
n: 0,
|
|
109
|
-
v: e,
|
|
110
|
-
a: d,
|
|
111
|
-
f: d.bind(e, 4),
|
|
112
|
-
d: function (t, r) {
|
|
113
|
-
return i = t, c = 0, u = e, G.n = r, a;
|
|
114
|
-
}
|
|
115
|
-
};
|
|
116
|
-
function d(r, n) {
|
|
117
|
-
for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) {
|
|
118
|
-
var o,
|
|
119
|
-
i = p[t],
|
|
120
|
-
d = G.p,
|
|
121
|
-
l = i[2];
|
|
122
|
-
r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0));
|
|
123
|
-
}
|
|
124
|
-
if (o || r > 1) return a;
|
|
125
|
-
throw y = true, n;
|
|
126
|
-
}
|
|
127
|
-
return function (o, p, l) {
|
|
128
|
-
if (f > 1) throw TypeError("Generator is already running");
|
|
129
|
-
for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) {
|
|
130
|
-
i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u);
|
|
131
|
-
try {
|
|
132
|
-
if (f = 2, i) {
|
|
133
|
-
if (c || (o = "next"), t = i[o]) {
|
|
134
|
-
if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object");
|
|
135
|
-
if (!t.done) return t;
|
|
136
|
-
u = t.value, c < 2 && (c = 0);
|
|
137
|
-
} else 1 === c && (t = i.return) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1);
|
|
138
|
-
i = e;
|
|
139
|
-
} else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break;
|
|
140
|
-
} catch (t) {
|
|
141
|
-
i = e, c = 1, u = t;
|
|
142
|
-
} finally {
|
|
143
|
-
f = 1;
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
return {
|
|
147
|
-
value: t,
|
|
148
|
-
done: y
|
|
149
|
-
};
|
|
150
|
-
};
|
|
151
|
-
}(r, o, i), true), u;
|
|
152
|
-
}
|
|
153
|
-
var a = {};
|
|
154
|
-
function Generator() {}
|
|
155
|
-
function GeneratorFunction() {}
|
|
156
|
-
function GeneratorFunctionPrototype() {}
|
|
157
|
-
t = Object.getPrototypeOf;
|
|
158
|
-
var c = [][n] ? t(t([][n]())) : (_regeneratorDefine(t = {}, n, function () {
|
|
159
|
-
return this;
|
|
160
|
-
}), t),
|
|
161
|
-
u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c);
|
|
162
|
-
function f(e) {
|
|
163
|
-
return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e;
|
|
164
|
-
}
|
|
165
|
-
return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine(u), _regeneratorDefine(u, o, "Generator"), _regeneratorDefine(u, n, function () {
|
|
166
|
-
return this;
|
|
167
|
-
}), _regeneratorDefine(u, "toString", function () {
|
|
168
|
-
return "[object Generator]";
|
|
169
|
-
}), (_regenerator = function () {
|
|
170
|
-
return {
|
|
171
|
-
w: i,
|
|
172
|
-
m: f
|
|
173
|
-
};
|
|
174
|
-
})();
|
|
175
|
-
}
|
|
176
|
-
function _regeneratorAsync(n, e, r, t, o) {
|
|
177
|
-
var a = _regeneratorAsyncGen(n, e, r, t, o);
|
|
178
|
-
return a.next().then(function (n) {
|
|
179
|
-
return n.done ? n.value : a.next();
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
function _regeneratorAsyncGen(r, e, t, o, n) {
|
|
183
|
-
return new _regeneratorAsyncIterator(_regenerator().w(r, e, t, o), n || Promise);
|
|
184
|
-
}
|
|
185
|
-
function _regeneratorAsyncIterator(t, e) {
|
|
186
|
-
function n(r, o, i, f) {
|
|
187
|
-
try {
|
|
188
|
-
var c = t[r](o),
|
|
189
|
-
u = c.value;
|
|
190
|
-
return u instanceof _OverloadYield ? e.resolve(u.v).then(function (t) {
|
|
191
|
-
n("next", t, i, f);
|
|
192
|
-
}, function (t) {
|
|
193
|
-
n("throw", t, i, f);
|
|
194
|
-
}) : e.resolve(u).then(function (t) {
|
|
195
|
-
c.value = t, i(c);
|
|
196
|
-
}, function (t) {
|
|
197
|
-
return n("throw", t, i, f);
|
|
198
|
-
});
|
|
199
|
-
} catch (t) {
|
|
200
|
-
f(t);
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
var r;
|
|
204
|
-
this.next || (_regeneratorDefine(_regeneratorAsyncIterator.prototype), _regeneratorDefine(_regeneratorAsyncIterator.prototype, "function" == typeof Symbol && Symbol.asyncIterator || "@asyncIterator", function () {
|
|
205
|
-
return this;
|
|
206
|
-
})), _regeneratorDefine(this, "_invoke", function (t, o, i) {
|
|
207
|
-
function f() {
|
|
208
|
-
return new e(function (e, r) {
|
|
209
|
-
n(t, i, e, r);
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
return r = r ? r.then(f, f) : f();
|
|
213
|
-
}, true);
|
|
214
|
-
}
|
|
215
|
-
function _regeneratorDefine(e, r, n, t) {
|
|
216
|
-
var i = Object.defineProperty;
|
|
217
|
-
try {
|
|
218
|
-
i({}, "", {});
|
|
219
|
-
} catch (e) {
|
|
220
|
-
i = 0;
|
|
221
|
-
}
|
|
222
|
-
_regeneratorDefine = function (e, r, n, t) {
|
|
223
|
-
if (r) i ? i(e, r, {
|
|
224
|
-
value: n,
|
|
225
|
-
enumerable: !t,
|
|
226
|
-
configurable: !t,
|
|
227
|
-
writable: !t
|
|
228
|
-
}) : e[r] = n;else {
|
|
229
|
-
function o(r, n) {
|
|
230
|
-
_regeneratorDefine(e, r, function (e) {
|
|
231
|
-
return this._invoke(r, n, e);
|
|
232
|
-
});
|
|
233
|
-
}
|
|
234
|
-
o("next", 0), o("throw", 1), o("return", 2);
|
|
235
|
-
}
|
|
236
|
-
}, _regeneratorDefine(e, r, n, t);
|
|
237
|
-
}
|
|
238
|
-
function _regeneratorKeys(e) {
|
|
239
|
-
var n = Object(e),
|
|
240
|
-
r = [];
|
|
241
|
-
for (var t in n) r.unshift(t);
|
|
242
|
-
return function e() {
|
|
243
|
-
for (; r.length;) if ((t = r.pop()) in n) return e.value = t, e.done = false, e;
|
|
244
|
-
return e.done = true, e;
|
|
245
|
-
};
|
|
246
|
-
}
|
|
247
|
-
function _regeneratorValues(e) {
|
|
248
|
-
if (null != e) {
|
|
249
|
-
var t = e["function" == typeof Symbol && Symbol.iterator || "@@iterator"],
|
|
250
|
-
r = 0;
|
|
251
|
-
if (t) return t.call(e);
|
|
252
|
-
if ("function" == typeof e.next) return e;
|
|
253
|
-
if (!isNaN(e.length)) return {
|
|
254
|
-
next: function () {
|
|
255
|
-
return e && r >= e.length && (e = void 0), {
|
|
256
|
-
value: e && e[r++],
|
|
257
|
-
done: !e
|
|
258
|
-
};
|
|
259
|
-
}
|
|
260
|
-
};
|
|
261
|
-
}
|
|
262
|
-
throw new TypeError(typeof e + " is not iterable");
|
|
263
|
-
}
|
|
264
|
-
function _regeneratorRuntime() {
|
|
265
|
-
|
|
266
|
-
var r = _regenerator(),
|
|
267
|
-
e = r.m(_regeneratorRuntime),
|
|
268
|
-
t = (Object.getPrototypeOf ? Object.getPrototypeOf(e) : e.__proto__).constructor;
|
|
269
|
-
function n(r) {
|
|
270
|
-
var e = "function" == typeof r && r.constructor;
|
|
271
|
-
return !!e && (e === t || "GeneratorFunction" === (e.displayName || e.name));
|
|
272
|
-
}
|
|
273
|
-
var o = {
|
|
274
|
-
throw: 1,
|
|
275
|
-
return: 2,
|
|
276
|
-
break: 3,
|
|
277
|
-
continue: 3
|
|
278
|
-
};
|
|
279
|
-
function a(r) {
|
|
280
|
-
var e, t;
|
|
281
|
-
return function (n) {
|
|
282
|
-
e || (e = {
|
|
283
|
-
stop: function () {
|
|
284
|
-
return t(n.a, 2);
|
|
285
|
-
},
|
|
286
|
-
catch: function () {
|
|
287
|
-
return n.v;
|
|
288
|
-
},
|
|
289
|
-
abrupt: function (r, e) {
|
|
290
|
-
return t(n.a, o[r], e);
|
|
291
|
-
},
|
|
292
|
-
delegateYield: function (r, o, a) {
|
|
293
|
-
return e.resultName = o, t(n.d, _regeneratorValues(r), a);
|
|
294
|
-
},
|
|
295
|
-
finish: function (r) {
|
|
296
|
-
return t(n.f, r);
|
|
297
|
-
}
|
|
298
|
-
}, t = function (r, t, o) {
|
|
299
|
-
n.p = e.prev, n.n = e.next;
|
|
300
|
-
try {
|
|
301
|
-
return r(t, o);
|
|
302
|
-
} finally {
|
|
303
|
-
e.next = n.n;
|
|
304
|
-
}
|
|
305
|
-
}), e.resultName && (e[e.resultName] = n.v, e.resultName = void 0), e.sent = n.v, e.next = n.n;
|
|
306
|
-
try {
|
|
307
|
-
return r.call(this, e);
|
|
308
|
-
} finally {
|
|
309
|
-
n.p = e.prev, n.n = e.next;
|
|
310
|
-
}
|
|
311
|
-
};
|
|
312
|
-
}
|
|
313
|
-
return (_regeneratorRuntime = function () {
|
|
314
|
-
return {
|
|
315
|
-
wrap: function (e, t, n, o) {
|
|
316
|
-
return r.w(a(e), t, n, o && o.reverse());
|
|
317
|
-
},
|
|
318
|
-
isGeneratorFunction: n,
|
|
319
|
-
mark: r.m,
|
|
320
|
-
awrap: function (r, e) {
|
|
321
|
-
return new _OverloadYield(r, e);
|
|
322
|
-
},
|
|
323
|
-
AsyncIterator: _regeneratorAsyncIterator,
|
|
324
|
-
async: function (r, e, t, o, u) {
|
|
325
|
-
return (n(e) ? _regeneratorAsyncGen : _regeneratorAsync)(a(r), e, t, o, u);
|
|
326
|
-
},
|
|
327
|
-
keys: _regeneratorKeys,
|
|
328
|
-
values: _regeneratorValues
|
|
329
|
-
};
|
|
330
|
-
})();
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
var DEFAULT_TIMEOUT = 15000;
|
|
334
|
-
var KEEP_ALIVE_POLLER_IN_SECONDS = 60; // Number of seconds between the checks if the token should be refreshed.
|
|
335
|
-
|
|
336
|
-
var REFRESH_TOKEN_WHEN_PCT_EXPIRED = 75; // Refresh token when 75% expired. Set to (10 / 3600) * 100 = 0.2777778% to test with 10 second interval (assuming 1 hour token expiration).
|
|
337
|
-
|
|
338
|
-
var DEFAULT_TOKEN_EXPIRES_IN = 3600; // Number of seconds a token expires by default
|
|
339
|
-
|
|
340
|
-
var MILLISECOND_TO_SECOND = 1 / 1000;
|
|
341
|
-
var GEOWEB_ROLE_PRESETS_ADMIN = {
|
|
342
|
-
name: 'ROLE_PRESET_ADMIN',
|
|
343
|
-
title: 'api-role-title-preset-admin'
|
|
344
|
-
};
|
|
345
|
-
var GEOWEB_ROLE_USER = {
|
|
346
|
-
name: 'ROLE_USER',
|
|
347
|
-
title: 'api-role-title-user'
|
|
348
|
-
};
|
|
349
|
-
|
|
350
|
-
/**
|
|
351
|
-
* Creates a Credentials object based on the axios response from the token service.
|
|
352
|
-
*
|
|
353
|
-
* It will calculate the expires_at attribute based on the expires_in property found in the JWT.
|
|
354
|
-
*
|
|
355
|
-
* @param tokenResponse Response of the tokenservice as axios response object.
|
|
356
|
-
* @returns Credentials object.
|
|
357
|
-
*/
|
|
358
|
-
var makeCredentialsFromTokenResponse = function makeCredentialsFromTokenResponse(tokenResponse, authConfig) {
|
|
359
|
-
var _tokenResponse$data$b;
|
|
360
|
-
var token = (_tokenResponse$data$b = tokenResponse.data.body) != null ? _tokenResponse$data$b : tokenResponse.data;
|
|
361
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
362
|
-
var access_token = token.access_token,
|
|
363
|
-
refresh_token = token.refresh_token,
|
|
364
|
-
id_token = token.id_token,
|
|
365
|
-
expires_in = token.expires_in;
|
|
366
|
-
if (!access_token || !id_token) {
|
|
367
|
-
// message is not user-facing
|
|
368
|
-
throw new Error('Login failed');
|
|
369
|
-
}
|
|
370
|
-
var userInfoString = atob(
|
|
371
|
-
// convert base64url specific characters before parsing as base64
|
|
372
|
-
id_token.split('.')[1].replace(/-/g, '+').replace(/_/g, '/'));
|
|
373
|
-
var userInfo = JSON.parse(userInfoString);
|
|
374
|
-
var tokenExpirationInSeconds = expires_in && expires_in > 0 ? expires_in : DEFAULT_TOKEN_EXPIRES_IN; // If not set or zero in the token, assume valid for 1 hour.
|
|
375
|
-
var pctTokenExpirationInSeconds = tokenExpirationInSeconds * (REFRESH_TOKEN_WHEN_PCT_EXPIRED / 100);
|
|
376
|
-
var epochTimeTokenExpirationInSeconds = pctTokenExpirationInSeconds + getCurrentTimeInSeconds();
|
|
377
|
-
var isAuthCognito = userInfo.iss.includes('cognito');
|
|
378
|
-
var roleClaimName = authConfig == null ? void 0 : authConfig.GW_AUTH_ROLE_CLAIM_NAME;
|
|
379
|
-
var groups = userInfo[roleClaimName];
|
|
380
|
-
var newAuth = {
|
|
381
|
-
username: isAuthCognito ? userInfo['cognito:username'] : userInfo.email,
|
|
382
|
-
roles: groupsToRoles(groups, authConfig),
|
|
383
|
-
token: access_token,
|
|
384
|
-
refresh_token: refresh_token != null ? refresh_token : '',
|
|
385
|
-
expires_at: epochTimeTokenExpirationInSeconds,
|
|
386
|
-
has_connection_issue: false
|
|
387
|
-
};
|
|
388
|
-
return newAuth;
|
|
389
|
-
};
|
|
390
|
-
var refreshAccessToken = /*#__PURE__*/function () {
|
|
391
|
-
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
|
|
392
|
-
var auth, _ref$config, _ref$config2, authTokenURL, authClientId, appURL, _ref$timeout, timeout, tokenAxiosInstance, refreshPayload, useDefaultContentType, data, axiosConfig;
|
|
393
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
394
|
-
while (1) switch (_context.prev = _context.next) {
|
|
395
|
-
case 0:
|
|
396
|
-
auth = _ref.auth, _ref$config = _ref.config, _ref$config2 = _ref$config === void 0 ? {} : _ref$config, authTokenURL = _ref$config2.authTokenURL, authClientId = _ref$config2.authClientId, appURL = _ref$config2.appURL, _ref$timeout = _ref.timeout, timeout = _ref$timeout === void 0 ? DEFAULT_TIMEOUT : _ref$timeout;
|
|
397
|
-
// Refresh token request with a new axios instance
|
|
398
|
-
// without request interceptor
|
|
399
|
-
tokenAxiosInstance = axios.create({
|
|
400
|
-
headers: {},
|
|
401
|
-
timeout: timeout
|
|
402
|
-
});
|
|
403
|
-
refreshPayload = {
|
|
404
|
-
refresh_token: auth.refresh_token,
|
|
405
|
-
redirect_uri: appURL + "/code",
|
|
406
|
-
grant_type: 'refresh_token',
|
|
407
|
-
client_id: authClientId
|
|
408
|
-
};
|
|
409
|
-
/* Send data in the "application/x-www-form-urlencoded" format.
|
|
410
|
-
If only JSON is supported, use Axios' default content type ("application/x-www-form-urlencoded"). */
|
|
411
|
-
useDefaultContentType = authTokenURL.includes('amazonaws.com');
|
|
412
|
-
data = useDefaultContentType ? refreshPayload : new URLSearchParams(refreshPayload);
|
|
413
|
-
axiosConfig = {
|
|
414
|
-
headers: {
|
|
415
|
-
'Content-Type': useDefaultContentType ? 'application/json' : 'application/x-www-form-urlencoded'
|
|
416
|
-
}
|
|
417
|
-
};
|
|
418
|
-
return _context.abrupt("return", tokenAxiosInstance.post(authTokenURL, data, axiosConfig));
|
|
419
|
-
case 7:
|
|
420
|
-
case "end":
|
|
421
|
-
return _context.stop();
|
|
422
|
-
}
|
|
423
|
-
}, _callee);
|
|
424
|
-
}));
|
|
425
|
-
return function refreshAccessToken(_x) {
|
|
426
|
-
return _ref2.apply(this, arguments);
|
|
427
|
-
};
|
|
428
|
-
}();
|
|
429
|
-
var refreshAccessTokenAndSetAuthContext = /*#__PURE__*/function () {
|
|
430
|
-
var _ref4 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref3) {
|
|
431
|
-
var auth, onSetAuth, config, _ref3$timeout, timeout, configURLS, onLogin, refreshedToken, newAuth, _response, status;
|
|
432
|
-
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
433
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
434
|
-
case 0:
|
|
435
|
-
auth = _ref3.auth, onSetAuth = _ref3.onSetAuth, config = _ref3.config, _ref3$timeout = _ref3.timeout, timeout = _ref3$timeout === void 0 ? DEFAULT_TIMEOUT : _ref3$timeout, configURLS = _ref3.configURLS, onLogin = _ref3.onLogin;
|
|
436
|
-
_context2.prev = 1;
|
|
437
|
-
_context2.next = 4;
|
|
438
|
-
return refreshAccessToken({
|
|
439
|
-
auth: auth,
|
|
440
|
-
config: config,
|
|
441
|
-
timeout: timeout
|
|
442
|
-
});
|
|
443
|
-
case 4:
|
|
444
|
-
refreshedToken = _context2.sent;
|
|
445
|
-
newAuth = makeCredentialsFromTokenResponse(refreshedToken, configURLS); // Cognito does not send a new refresh token, but gitlab does. Set it here into the auth context.
|
|
446
|
-
if (!newAuth.refresh_token || newAuth.refresh_token.length === 0) {
|
|
447
|
-
newAuth.refresh_token = auth.refresh_token;
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
// If the prop for the role config is not set, keep the roles of the current auth context.
|
|
451
|
-
if (!configURLS) {
|
|
452
|
-
newAuth.roles = auth.roles;
|
|
453
|
-
}
|
|
454
|
-
onSetAuth(newAuth);
|
|
455
|
-
_context2.next = 15;
|
|
456
|
-
break;
|
|
457
|
-
case 11:
|
|
458
|
-
_context2.prev = 11;
|
|
459
|
-
_context2.t0 = _context2["catch"](1);
|
|
460
|
-
status = (_response = _context2.t0.response) == null ? void 0 : _response.status;
|
|
461
|
-
if (status === 400) {
|
|
462
|
-
onLogin(false);
|
|
463
|
-
} else {
|
|
464
|
-
onSetAuth(Object.assign({}, auth, {
|
|
465
|
-
has_connection_issue: true
|
|
466
|
-
}));
|
|
467
|
-
}
|
|
468
|
-
case 15:
|
|
469
|
-
case "end":
|
|
470
|
-
return _context2.stop();
|
|
471
|
-
}
|
|
472
|
-
}, _callee2, null, [[1, 11]]);
|
|
473
|
-
}));
|
|
474
|
-
return function refreshAccessTokenAndSetAuthContext(_x2) {
|
|
475
|
-
return _ref4.apply(this, arguments);
|
|
476
|
-
};
|
|
477
|
-
}();
|
|
478
|
-
var createApiInstance = function createApiInstance(_ref5) {
|
|
479
|
-
var auth = _ref5.auth,
|
|
480
|
-
_ref5$config = _ref5.config,
|
|
481
|
-
_ref5$config2 = _ref5$config === void 0 ? {} : _ref5$config,
|
|
482
|
-
baseURL = _ref5$config2.baseURL,
|
|
483
|
-
_ref5$timeout = _ref5.timeout,
|
|
484
|
-
timeout = _ref5$timeout === void 0 ? DEFAULT_TIMEOUT : _ref5$timeout;
|
|
485
|
-
var axiosInstance = axios.create({
|
|
486
|
-
baseURL: baseURL,
|
|
487
|
-
headers: {},
|
|
488
|
-
timeout: timeout
|
|
489
|
-
});
|
|
490
|
-
// Request interceptor for API calls done BEFORE the request is made.
|
|
491
|
-
axiosInstance.interceptors.request.use(/*#__PURE__*/function () {
|
|
492
|
-
var _ref6 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(axiosConfig) {
|
|
493
|
-
var newConfig;
|
|
494
|
-
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
495
|
-
while (1) switch (_context3.prev = _context3.next) {
|
|
496
|
-
case 0:
|
|
497
|
-
// Add the access token to the headers of the request.
|
|
498
|
-
newConfig = Object.assign({}, axiosConfig, {
|
|
499
|
-
headers: Object.assign({
|
|
500
|
-
'Content-Type': 'application/json',
|
|
501
|
-
Authorization: "Bearer " + auth.token,
|
|
502
|
-
Accept: 'application/json'
|
|
503
|
-
}, axiosConfig.headers || {})
|
|
504
|
-
});
|
|
505
|
-
return _context3.abrupt("return", newConfig);
|
|
506
|
-
case 2:
|
|
507
|
-
case "end":
|
|
508
|
-
return _context3.stop();
|
|
509
|
-
}
|
|
510
|
-
}, _callee3);
|
|
511
|
-
}));
|
|
512
|
-
return function (_x3) {
|
|
513
|
-
return _ref6.apply(this, arguments);
|
|
514
|
-
};
|
|
515
|
-
}(), /*#__PURE__*/function () {
|
|
516
|
-
var _ref7 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(error) {
|
|
517
|
-
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
518
|
-
while (1) switch (_context4.prev = _context4.next) {
|
|
519
|
-
case 0:
|
|
520
|
-
_context4.next = 2;
|
|
521
|
-
return Promise.reject(error);
|
|
522
|
-
case 2:
|
|
523
|
-
case "end":
|
|
524
|
-
return _context4.stop();
|
|
525
|
-
}
|
|
526
|
-
}, _callee4);
|
|
527
|
-
}));
|
|
528
|
-
return function (_x4) {
|
|
529
|
-
return _ref7.apply(this, arguments);
|
|
530
|
-
};
|
|
531
|
-
}());
|
|
532
|
-
|
|
533
|
-
// Response interceptor for API calls done AFTER the request is made.
|
|
534
|
-
axiosInstance.interceptors.response.use(function (response) {
|
|
535
|
-
return response;
|
|
536
|
-
}, /*#__PURE__*/function () {
|
|
537
|
-
var _ref8 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(error) {
|
|
538
|
-
var _error$response;
|
|
539
|
-
var originalRequest, _originalRequest$head;
|
|
540
|
-
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
541
|
-
while (1) switch (_context5.prev = _context5.next) {
|
|
542
|
-
case 0:
|
|
543
|
-
originalRequest = error.config; // If request fails with 401, retry the request once.
|
|
544
|
-
if (!((_error$response = error.response) != null && _error$response.status && error.response.status === 401 && !originalRequest.inRetry)) {
|
|
545
|
-
_context5.next = 5;
|
|
546
|
-
break;
|
|
547
|
-
}
|
|
548
|
-
originalRequest.inRetry = true;
|
|
549
|
-
// Update the headers of the original request with the token from the current auth context.
|
|
550
|
-
if ((_originalRequest$head = originalRequest.headers) != null && _originalRequest$head.Authorization) {
|
|
551
|
-
originalRequest.headers.Authorization = "Bearer " + (auth == null ? void 0 : auth.token);
|
|
552
|
-
}
|
|
553
|
-
return _context5.abrupt("return", axiosInstance(originalRequest));
|
|
554
|
-
case 5:
|
|
555
|
-
return _context5.abrupt("return", Promise.reject(error));
|
|
556
|
-
case 6:
|
|
557
|
-
case "end":
|
|
558
|
-
return _context5.stop();
|
|
559
|
-
}
|
|
560
|
-
}, _callee5);
|
|
561
|
-
}));
|
|
562
|
-
return function (_x5) {
|
|
563
|
-
return _ref8.apply(this, arguments);
|
|
564
|
-
};
|
|
565
|
-
}());
|
|
566
|
-
return axiosInstance;
|
|
567
|
-
};
|
|
568
|
-
var createNonAuthApiInstance = function createNonAuthApiInstance(_ref9) {
|
|
569
|
-
var _ref9$config = _ref9.config,
|
|
570
|
-
_ref9$config2 = _ref9$config === void 0 ? {} : _ref9$config,
|
|
571
|
-
baseURL = _ref9$config2.baseURL,
|
|
572
|
-
_ref9$timeout = _ref9.timeout,
|
|
573
|
-
timeout = _ref9$timeout === void 0 ? DEFAULT_TIMEOUT : _ref9$timeout;
|
|
574
|
-
var axiosInstance = axios.create({
|
|
575
|
-
baseURL: baseURL,
|
|
576
|
-
headers: {},
|
|
577
|
-
timeout: timeout
|
|
578
|
-
});
|
|
579
|
-
|
|
580
|
-
// Request interceptor for API calls
|
|
581
|
-
axiosInstance.interceptors.request.use(/*#__PURE__*/function () {
|
|
582
|
-
var _ref0 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6(config) {
|
|
583
|
-
var newConfig;
|
|
584
|
-
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
585
|
-
while (1) switch (_context6.prev = _context6.next) {
|
|
586
|
-
case 0:
|
|
587
|
-
newConfig = Object.assign({}, config, {
|
|
588
|
-
headers: Object.assign({
|
|
589
|
-
'Content-Type': 'application/json',
|
|
590
|
-
Accept: 'application/json'
|
|
591
|
-
}, config.headers || {})
|
|
592
|
-
});
|
|
593
|
-
return _context6.abrupt("return", newConfig);
|
|
594
|
-
case 2:
|
|
595
|
-
case "end":
|
|
596
|
-
return _context6.stop();
|
|
597
|
-
}
|
|
598
|
-
}, _callee6);
|
|
599
|
-
}));
|
|
600
|
-
return function (_x6) {
|
|
601
|
-
return _ref0.apply(this, arguments);
|
|
602
|
-
};
|
|
603
|
-
}(), /*#__PURE__*/function () {
|
|
604
|
-
var _ref1 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7(error) {
|
|
605
|
-
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
606
|
-
while (1) switch (_context7.prev = _context7.next) {
|
|
607
|
-
case 0:
|
|
608
|
-
_context7.next = 2;
|
|
609
|
-
return Promise.reject(error);
|
|
610
|
-
case 2:
|
|
611
|
-
case "end":
|
|
612
|
-
return _context7.stop();
|
|
613
|
-
}
|
|
614
|
-
}, _callee7);
|
|
615
|
-
}));
|
|
616
|
-
return function (_x7) {
|
|
617
|
-
return _ref1.apply(this, arguments);
|
|
618
|
-
};
|
|
619
|
-
}());
|
|
620
|
-
return axiosInstance;
|
|
621
|
-
};
|
|
622
|
-
var fakeApiRequest = /*#__PURE__*/function () {
|
|
623
|
-
var _ref10 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8(signal) {
|
|
624
|
-
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
625
|
-
while (1) switch (_context8.prev = _context8.next) {
|
|
626
|
-
case 0:
|
|
627
|
-
return _context8.abrupt("return", new Promise(function (resolve, reject) {
|
|
628
|
-
var timer = setTimeout(function () {
|
|
629
|
-
resolve();
|
|
630
|
-
}, 300);
|
|
631
|
-
signal == null || signal.signal.addEventListener('abort', function () {
|
|
632
|
-
clearTimeout(timer);
|
|
633
|
-
reject(new Error('canceled'));
|
|
634
|
-
});
|
|
635
|
-
}));
|
|
636
|
-
case 1:
|
|
637
|
-
case "end":
|
|
638
|
-
return _context8.stop();
|
|
639
|
-
}
|
|
640
|
-
}, _callee8);
|
|
641
|
-
}));
|
|
642
|
-
return function fakeApiRequest(_x8) {
|
|
643
|
-
return _ref10.apply(this, arguments);
|
|
644
|
-
};
|
|
645
|
-
}();
|
|
646
|
-
var createFakeApiInstance = function createFakeApiInstance() {
|
|
647
|
-
return {
|
|
648
|
-
get: function () {
|
|
649
|
-
var _get = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee9(_url, _params) {
|
|
650
|
-
return _regeneratorRuntime().wrap(function _callee9$(_context9) {
|
|
651
|
-
while (1) switch (_context9.prev = _context9.next) {
|
|
652
|
-
case 0:
|
|
653
|
-
return _context9.abrupt("return", fakeApiRequest());
|
|
654
|
-
case 1:
|
|
655
|
-
case "end":
|
|
656
|
-
return _context9.stop();
|
|
657
|
-
}
|
|
658
|
-
}, _callee9);
|
|
659
|
-
}));
|
|
660
|
-
function get(_x9, _x0) {
|
|
661
|
-
return _get.apply(this, arguments);
|
|
662
|
-
}
|
|
663
|
-
return get;
|
|
664
|
-
}(),
|
|
665
|
-
put: function () {
|
|
666
|
-
var _put = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee0(_url, _params) {
|
|
667
|
-
return _regeneratorRuntime().wrap(function _callee0$(_context0) {
|
|
668
|
-
while (1) switch (_context0.prev = _context0.next) {
|
|
669
|
-
case 0:
|
|
670
|
-
return _context0.abrupt("return", fakeApiRequest());
|
|
671
|
-
case 1:
|
|
672
|
-
case "end":
|
|
673
|
-
return _context0.stop();
|
|
674
|
-
}
|
|
675
|
-
}, _callee0);
|
|
676
|
-
}));
|
|
677
|
-
function put(_x1, _x10) {
|
|
678
|
-
return _put.apply(this, arguments);
|
|
679
|
-
}
|
|
680
|
-
return put;
|
|
681
|
-
}(),
|
|
682
|
-
post: function () {
|
|
683
|
-
var _post = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee1(_url, _params) {
|
|
684
|
-
return _regeneratorRuntime().wrap(function _callee1$(_context1) {
|
|
685
|
-
while (1) switch (_context1.prev = _context1.next) {
|
|
686
|
-
case 0:
|
|
687
|
-
return _context1.abrupt("return", fakeApiRequest());
|
|
688
|
-
case 1:
|
|
689
|
-
case "end":
|
|
690
|
-
return _context1.stop();
|
|
691
|
-
}
|
|
692
|
-
}, _callee1);
|
|
693
|
-
}));
|
|
694
|
-
function post(_x11, _x12) {
|
|
695
|
-
return _post.apply(this, arguments);
|
|
696
|
-
}
|
|
697
|
-
return post;
|
|
698
|
-
}(),
|
|
699
|
-
"delete": function () {
|
|
700
|
-
var _delete2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee10(_url, _params) {
|
|
701
|
-
return _regeneratorRuntime().wrap(function _callee10$(_context10) {
|
|
702
|
-
while (1) switch (_context10.prev = _context10.next) {
|
|
703
|
-
case 0:
|
|
704
|
-
return _context10.abrupt("return", fakeApiRequest());
|
|
705
|
-
case 1:
|
|
706
|
-
case "end":
|
|
707
|
-
return _context10.stop();
|
|
708
|
-
}
|
|
709
|
-
}, _callee10);
|
|
710
|
-
}));
|
|
711
|
-
function _delete(_x13, _x14) {
|
|
712
|
-
return _delete2.apply(this, arguments);
|
|
713
|
-
}
|
|
714
|
-
return _delete;
|
|
715
|
-
}(),
|
|
716
|
-
patch: function () {
|
|
717
|
-
var _patch = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee11(_url, _params, _signal) {
|
|
718
|
-
return _regeneratorRuntime().wrap(function _callee11$(_context11) {
|
|
719
|
-
while (1) switch (_context11.prev = _context11.next) {
|
|
720
|
-
case 0:
|
|
721
|
-
return _context11.abrupt("return", fakeApiRequest(_signal));
|
|
722
|
-
case 1:
|
|
723
|
-
case "end":
|
|
724
|
-
return _context11.stop();
|
|
725
|
-
}
|
|
726
|
-
}, _callee11);
|
|
727
|
-
}));
|
|
728
|
-
function patch(_x15, _x16, _x17) {
|
|
729
|
-
return _patch.apply(this, arguments);
|
|
730
|
-
}
|
|
731
|
-
return patch;
|
|
732
|
-
}()
|
|
733
|
-
};
|
|
734
|
-
};
|
|
735
|
-
var getCurrentTimeInSeconds = function getCurrentTimeInSeconds() {
|
|
736
|
-
return Date.now() * MILLISECOND_TO_SECOND;
|
|
737
|
-
};
|
|
738
|
-
var groupsToRoles = function groupsToRoles(groups, authConfig) {
|
|
739
|
-
if (!Array.isArray(groups)) {
|
|
740
|
-
return [GEOWEB_ROLE_USER];
|
|
741
|
-
}
|
|
742
|
-
var requiredGroupForPresetsAdmin = authConfig == null ? void 0 : authConfig.GW_AUTH_ROLE_CLAIM_VALUE_PRESETS_ADMIN;
|
|
743
|
-
var roles = groups.reduce(function (acc, group) {
|
|
744
|
-
if (requiredGroupForPresetsAdmin && group === requiredGroupForPresetsAdmin) {
|
|
745
|
-
acc.push(GEOWEB_ROLE_PRESETS_ADMIN);
|
|
746
|
-
}
|
|
747
|
-
return acc;
|
|
748
|
-
}, [GEOWEB_ROLE_USER]);
|
|
749
|
-
return roles;
|
|
750
|
-
};
|
|
751
|
-
|
|
752
|
-
var authConfigKeys = {
|
|
753
|
-
GW_AUTH_LOGIN_URL: null,
|
|
754
|
-
GW_AUTH_LOGOUT_URL: null,
|
|
755
|
-
GW_AUTH_TOKEN_URL: null,
|
|
756
|
-
GW_APP_URL: null,
|
|
757
|
-
GW_BE_VERSION_BASE_URL: null,
|
|
758
|
-
GW_AUTH_CLIENT_ID: null,
|
|
759
|
-
GW_AUTH_ROLE_CLAIM_NAME: null,
|
|
760
|
-
GW_AUTH_ROLE_CLAIM_VALUE_PRESETS_ADMIN: null
|
|
761
|
-
};
|
|
762
|
-
var getRandomString = function getRandomString() {
|
|
763
|
-
var array = new Uint32Array(8);
|
|
764
|
-
window.crypto.getRandomValues(array);
|
|
765
|
-
var randomString = Array.from(array, function (dec) {
|
|
766
|
-
return dec.toString(16);
|
|
767
|
-
}).join('');
|
|
768
|
-
return randomString;
|
|
769
|
-
};
|
|
770
|
-
var getCodeChallenge = /*#__PURE__*/function () {
|
|
771
|
-
var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(codeVerifier) {
|
|
772
|
-
var encoder, data, digest;
|
|
773
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
774
|
-
while (1) switch (_context.prev = _context.next) {
|
|
775
|
-
case 0:
|
|
776
|
-
encoder = new TextEncoder();
|
|
777
|
-
data = encoder.encode(codeVerifier);
|
|
778
|
-
_context.next = 4;
|
|
779
|
-
return crypto.subtle.digest('SHA-256', data);
|
|
780
|
-
case 4:
|
|
781
|
-
digest = _context.sent;
|
|
782
|
-
return _context.abrupt("return", btoa(String.fromCharCode.apply(null, new Uint8Array(digest))).replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, ''));
|
|
783
|
-
case 6:
|
|
784
|
-
case "end":
|
|
785
|
-
return _context.stop();
|
|
786
|
-
}
|
|
787
|
-
}, _callee);
|
|
788
|
-
}));
|
|
789
|
-
return function getCodeChallenge(_x) {
|
|
790
|
-
return _ref.apply(this, arguments);
|
|
791
|
-
};
|
|
792
|
-
}();
|
|
793
|
-
var replaceTemplateKeys = function replaceTemplateKeys(url, clientId, appUrl, oauthState, codeChallenge) {
|
|
794
|
-
return url.replace('{client_id}', clientId).replace('{app_url}', appUrl).replace('{state}', oauthState).replace('{code_challenge}', codeChallenge);
|
|
795
|
-
};
|
|
796
|
-
var getAuthConfig = function getAuthConfig(_configUrls) {
|
|
797
|
-
var GW_AUTH_LOGIN_URL = _configUrls.GW_AUTH_LOGIN_URL,
|
|
798
|
-
GW_AUTH_LOGOUT_URL = _configUrls.GW_AUTH_LOGOUT_URL,
|
|
799
|
-
GW_AUTH_TOKEN_URL = _configUrls.GW_AUTH_TOKEN_URL,
|
|
800
|
-
GW_APP_URL = _configUrls.GW_APP_URL,
|
|
801
|
-
GW_BE_VERSION_BASE_URL = _configUrls.GW_BE_VERSION_BASE_URL,
|
|
802
|
-
GW_AUTH_CLIENT_ID = _configUrls.GW_AUTH_CLIENT_ID,
|
|
803
|
-
GW_AUTH_ROLE_CLAIM_NAME = _configUrls.GW_AUTH_ROLE_CLAIM_NAME,
|
|
804
|
-
GW_AUTH_ROLE_CLAIM_VALUE_PRESETS_ADMIN = _configUrls.GW_AUTH_ROLE_CLAIM_VALUE_PRESETS_ADMIN;
|
|
805
|
-
var loginUrl = replaceTemplateKeys(GW_AUTH_LOGIN_URL, GW_AUTH_CLIENT_ID, GW_APP_URL, sessionStorageProvider.getOauthState(), sessionStorageProvider.getOauthCodeChallenge());
|
|
806
|
-
var logOutUrl = replaceTemplateKeys(GW_AUTH_LOGOUT_URL, GW_AUTH_CLIENT_ID, GW_APP_URL);
|
|
807
|
-
return {
|
|
808
|
-
GW_AUTH_LOGIN_URL: loginUrl,
|
|
809
|
-
GW_AUTH_LOGOUT_URL: logOutUrl,
|
|
810
|
-
GW_AUTH_TOKEN_URL: GW_AUTH_TOKEN_URL,
|
|
811
|
-
GW_APP_URL: GW_APP_URL,
|
|
812
|
-
GW_BE_VERSION_BASE_URL: GW_BE_VERSION_BASE_URL,
|
|
813
|
-
GW_AUTH_CLIENT_ID: GW_AUTH_CLIENT_ID,
|
|
814
|
-
GW_AUTH_ROLE_CLAIM_NAME: GW_AUTH_ROLE_CLAIM_NAME,
|
|
815
|
-
GW_AUTH_ROLE_CLAIM_VALUE_PRESETS_ADMIN: GW_AUTH_ROLE_CLAIM_VALUE_PRESETS_ADMIN
|
|
816
|
-
};
|
|
817
|
-
};
|
|
818
|
-
var AuthenticationContext = /*#__PURE__*/React.createContext({
|
|
819
|
-
isLoggedIn: null,
|
|
820
|
-
onLogin: null,
|
|
821
|
-
auth: null,
|
|
822
|
-
onSetAuth: null,
|
|
823
|
-
authConfig: null,
|
|
824
|
-
sessionStorageProvider: null,
|
|
825
|
-
currentRole: null
|
|
826
|
-
});
|
|
827
|
-
var authChangeListener = null;
|
|
828
|
-
var setAuthChangeListener = function setAuthChangeListener(listener) {
|
|
829
|
-
authChangeListener = listener;
|
|
830
|
-
};
|
|
831
|
-
var useAuthenticationDefaultProps = function useAuthenticationDefaultProps() {
|
|
832
|
-
var _auth$roles$, _auth$roles;
|
|
833
|
-
var _React$useState = React.useState(false),
|
|
834
|
-
isLoggedIn = _React$useState[0],
|
|
835
|
-
setIsLoggedIn = _React$useState[1];
|
|
836
|
-
var _React$useState2 = React.useState(false),
|
|
837
|
-
hasConnectionIssue = _React$useState2[0],
|
|
838
|
-
setHasConnectionIssue = _React$useState2[1];
|
|
839
|
-
var emptyCredentials = {
|
|
840
|
-
username: '',
|
|
841
|
-
roles: [],
|
|
842
|
-
token: '',
|
|
843
|
-
refresh_token: '',
|
|
844
|
-
expires_at: 0,
|
|
845
|
-
has_connection_issue: false
|
|
846
|
-
};
|
|
847
|
-
var _React$useState3 = React.useState(Object.assign({}, emptyCredentials)),
|
|
848
|
-
auth = _React$useState3[0],
|
|
849
|
-
setAuth = _React$useState3[1];
|
|
850
|
-
|
|
851
|
-
// TODO clean this up.
|
|
852
|
-
// hotfix revert to ref. There are parts of the state down the tree that rely on ref to work.
|
|
853
|
-
var authRef = React.useRef(auth).current;
|
|
854
|
-
var onSetAuth = React.useCallback(function (newAuth) {
|
|
855
|
-
if (newAuth) {
|
|
856
|
-
setAuth(function (prevAuth) {
|
|
857
|
-
return Object.assign({}, prevAuth, newAuth);
|
|
858
|
-
});
|
|
859
|
-
Object.assign(authRef, newAuth);
|
|
860
|
-
if (newAuth.has_connection_issue !== undefined && hasConnectionIssue !== newAuth.has_connection_issue) {
|
|
861
|
-
setHasConnectionIssue(newAuth.has_connection_issue);
|
|
862
|
-
}
|
|
863
|
-
} else {
|
|
864
|
-
setAuth(Object.assign({}, emptyCredentials));
|
|
865
|
-
Object.assign(authRef, Object.assign({}, emptyCredentials));
|
|
866
|
-
}
|
|
867
|
-
},
|
|
868
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
869
|
-
[hasConnectionIssue]);
|
|
870
|
-
var _React$useState4 = React.useState((_auth$roles$ = (_auth$roles = auth.roles) == null ? void 0 : _auth$roles[0]) != null ? _auth$roles$ : GEOWEB_ROLE_USER),
|
|
871
|
-
currentRole = _React$useState4[0],
|
|
872
|
-
setCurrentRole = _React$useState4[1];
|
|
873
|
-
useEffect(function () {
|
|
874
|
-
authChangeListener == null || authChangeListener(isLoggedIn, auth);
|
|
875
|
-
}, [isLoggedIn, auth]);
|
|
876
|
-
return {
|
|
877
|
-
isLoggedIn: isLoggedIn,
|
|
878
|
-
onLogin: setIsLoggedIn,
|
|
879
|
-
auth: isLoggedIn ? authRef : null,
|
|
880
|
-
onSetAuth: onSetAuth,
|
|
881
|
-
sessionStorageProvider: sessionStorageProvider,
|
|
882
|
-
currentRole: currentRole,
|
|
883
|
-
setCurrentRole: setCurrentRole
|
|
884
|
-
};
|
|
885
|
-
};
|
|
886
|
-
var AuthenticationProvider = function AuthenticationProvider(_ref2) {
|
|
887
|
-
var children = _ref2.children,
|
|
888
|
-
value = _ref2.value,
|
|
889
|
-
_ref2$configURLS = _ref2.configURLS,
|
|
890
|
-
configURLS = _ref2$configURLS === void 0 ? authConfigKeys : _ref2$configURLS;
|
|
891
|
-
var defaultValues = useAuthenticationDefaultProps();
|
|
892
|
-
var _ref3 = value != null ? value : defaultValues,
|
|
893
|
-
isLoggedIn = _ref3.isLoggedIn,
|
|
894
|
-
onLogin = _ref3.onLogin,
|
|
895
|
-
auth = _ref3.auth,
|
|
896
|
-
onSetAuth = _ref3.onSetAuth,
|
|
897
|
-
sessionStorageProvider = _ref3.sessionStorageProvider,
|
|
898
|
-
currentRole = _ref3.currentRole,
|
|
899
|
-
setCurrentRole = _ref3.setCurrentRole;
|
|
900
|
-
var authConfig = configURLS;
|
|
901
|
-
|
|
902
|
-
// Checks the token expiration time regularly and renews it before it expires.
|
|
903
|
-
var interval = useRef();
|
|
904
|
-
React.useEffect(function () {
|
|
905
|
-
interval.current = setInterval(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
906
|
-
var currentTime, timeInSecondsLeftBeforeExpiration;
|
|
907
|
-
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
908
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
909
|
-
case 0:
|
|
910
|
-
if (!auth) {
|
|
911
|
-
_context2.next = 6;
|
|
912
|
-
break;
|
|
913
|
-
}
|
|
914
|
-
currentTime = getCurrentTimeInSeconds();
|
|
915
|
-
timeInSecondsLeftBeforeExpiration = auth.expires_at ? auth.expires_at - currentTime : 0;
|
|
916
|
-
if (!(timeInSecondsLeftBeforeExpiration < 60)) {
|
|
917
|
-
_context2.next = 6;
|
|
918
|
-
break;
|
|
919
|
-
}
|
|
920
|
-
_context2.next = 6;
|
|
921
|
-
return refreshAccessTokenAndSetAuthContext({
|
|
922
|
-
auth: auth,
|
|
923
|
-
onSetAuth: onSetAuth,
|
|
924
|
-
config: {
|
|
925
|
-
baseURL: '',
|
|
926
|
-
authTokenURL: configURLS.GW_AUTH_TOKEN_URL,
|
|
927
|
-
appURL: configURLS.GW_APP_URL,
|
|
928
|
-
authClientId: configURLS.GW_AUTH_CLIENT_ID
|
|
929
|
-
},
|
|
930
|
-
configURLS: configURLS,
|
|
931
|
-
onLogin: onLogin
|
|
932
|
-
});
|
|
933
|
-
case 6:
|
|
934
|
-
case "end":
|
|
935
|
-
return _context2.stop();
|
|
936
|
-
}
|
|
937
|
-
}, _callee2);
|
|
938
|
-
})), KEEP_ALIVE_POLLER_IN_SECONDS / MILLISECOND_TO_SECOND);
|
|
939
|
-
return function () {
|
|
940
|
-
clearInterval(interval.current);
|
|
941
|
-
};
|
|
942
|
-
}, [auth, configURLS.GW_APP_URL, configURLS.GW_AUTH_CLIENT_ID, configURLS.GW_AUTH_TOKEN_URL, onSetAuth, configURLS, onLogin]);
|
|
943
|
-
var contextValue = React.useMemo(function () {
|
|
944
|
-
return {
|
|
945
|
-
isLoggedIn: isLoggedIn,
|
|
946
|
-
onLogin: onLogin,
|
|
947
|
-
auth: auth,
|
|
948
|
-
onSetAuth: onSetAuth,
|
|
949
|
-
authConfig: authConfig,
|
|
950
|
-
sessionStorageProvider: sessionStorageProvider,
|
|
951
|
-
currentRole: currentRole,
|
|
952
|
-
setCurrentRole: setCurrentRole
|
|
953
|
-
};
|
|
954
|
-
}, [isLoggedIn, onLogin, auth, onSetAuth, authConfig, sessionStorageProvider, currentRole, setCurrentRole]);
|
|
955
|
-
return /*#__PURE__*/jsx(AuthenticationContext.Provider, {
|
|
956
|
-
value: contextValue,
|
|
957
|
-
children: children
|
|
958
|
-
});
|
|
959
|
-
};
|
|
960
|
-
var useAuthenticationContext = function useAuthenticationContext() {
|
|
961
|
-
return React.useContext(AuthenticationContext);
|
|
962
|
-
};
|
|
963
|
-
|
|
964
|
-
var axiosInstance = axios.create({
|
|
965
|
-
headers: {}
|
|
966
|
-
});
|
|
967
|
-
var HandleOAuth2Code = function HandleOAuth2Code() {
|
|
968
|
-
var _useAuthenticationCon = useAuthenticationContext(),
|
|
969
|
-
onSetAuth = _useAuthenticationCon.onSetAuth,
|
|
970
|
-
authConfig = _useAuthenticationCon.authConfig,
|
|
971
|
-
isLoggedIn = _useAuthenticationCon.isLoggedIn,
|
|
972
|
-
onLogin = _useAuthenticationCon.onLogin,
|
|
973
|
-
sessionStorageProvider = _useAuthenticationCon.sessionStorageProvider;
|
|
974
|
-
var _React$useState = React.useState(null),
|
|
975
|
-
error = _React$useState[0],
|
|
976
|
-
setError = _React$useState[1];
|
|
977
|
-
var _useIsMounted = useIsMounted(),
|
|
978
|
-
isMounted = _useIsMounted.isMounted;
|
|
979
|
-
var loginInProgress = React.useRef(false);
|
|
980
|
-
var authenticate = React.useCallback(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
981
|
-
var _Object$fromEntries, code, state, isStateRequired, isPkceRequired, payload, useDefaultContentType, data, config, res, newAuth;
|
|
982
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
983
|
-
while (1) switch (_context.prev = _context.next) {
|
|
984
|
-
case 0:
|
|
985
|
-
_Object$fromEntries = Object.fromEntries(new URLSearchParams(window.location.search)), code = _Object$fromEntries.code, state = _Object$fromEntries.state;
|
|
986
|
-
isStateRequired = authConfig.GW_AUTH_LOGIN_URL.includes('&state=');
|
|
987
|
-
isPkceRequired = authConfig.GW_AUTH_LOGIN_URL.includes('&code_challenge=');
|
|
988
|
-
if (!isStateRequired) {
|
|
989
|
-
_context.next = 7;
|
|
990
|
-
break;
|
|
991
|
-
}
|
|
992
|
-
if (!(!state || state !== sessionStorageProvider.getOauthState())) {
|
|
993
|
-
_context.next = 7;
|
|
994
|
-
break;
|
|
995
|
-
}
|
|
996
|
-
setError(function () {
|
|
997
|
-
return {
|
|
998
|
-
message: 'Login failed',
|
|
999
|
-
stack: !state ? 'Missing state param' : 'State param does not match'
|
|
1000
|
-
};
|
|
1001
|
-
});
|
|
1002
|
-
return _context.abrupt("return");
|
|
1003
|
-
case 7:
|
|
1004
|
-
if (!isPkceRequired) {
|
|
1005
|
-
_context.next = 11;
|
|
1006
|
-
break;
|
|
1007
|
-
}
|
|
1008
|
-
if (!(!code || !sessionStorageProvider.getOauthCodeVerifier())) {
|
|
1009
|
-
_context.next = 11;
|
|
1010
|
-
break;
|
|
1011
|
-
}
|
|
1012
|
-
setError(function () {
|
|
1013
|
-
return {
|
|
1014
|
-
message: 'Login failed',
|
|
1015
|
-
stack: !code ? 'Missing code param' : 'Missing code verifier'
|
|
1016
|
-
};
|
|
1017
|
-
});
|
|
1018
|
-
return _context.abrupt("return");
|
|
1019
|
-
case 11:
|
|
1020
|
-
payload = Object.assign({
|
|
1021
|
-
client_id: authConfig.GW_AUTH_CLIENT_ID,
|
|
1022
|
-
code: code,
|
|
1023
|
-
redirect_uri: authConfig.GW_APP_URL + "/code",
|
|
1024
|
-
grant_type: 'authorization_code'
|
|
1025
|
-
}, isPkceRequired && {
|
|
1026
|
-
code_verifier: sessionStorageProvider.getOauthCodeVerifier()
|
|
1027
|
-
});
|
|
1028
|
-
/* Send data in the "application/x-www-form-urlencoded" format.
|
|
1029
|
-
If only JSON is supported, use Axios' default content type ("application/x-www-form-urlencoded"). */
|
|
1030
|
-
useDefaultContentType = authConfig.GW_AUTH_TOKEN_URL.includes('amazonaws.com');
|
|
1031
|
-
data = useDefaultContentType ? payload : new URLSearchParams(payload);
|
|
1032
|
-
config = {
|
|
1033
|
-
headers: {
|
|
1034
|
-
'content-type': useDefaultContentType ? 'application/json' : 'application/x-www-form-urlencoded'
|
|
1035
|
-
},
|
|
1036
|
-
timeout: 30000
|
|
1037
|
-
};
|
|
1038
|
-
_context.prev = 15;
|
|
1039
|
-
_context.next = 18;
|
|
1040
|
-
return axiosInstance.post(authConfig.GW_AUTH_TOKEN_URL, data, config);
|
|
1041
|
-
case 18:
|
|
1042
|
-
res = _context.sent;
|
|
1043
|
-
newAuth = makeCredentialsFromTokenResponse(res, authConfig);
|
|
1044
|
-
if (isMounted.current) {
|
|
1045
|
-
onSetAuth(newAuth);
|
|
1046
|
-
onLogin(true);
|
|
1047
|
-
sessionStorageProvider.setHasAuthenticated('true');
|
|
1048
|
-
if (sessionStorageProvider) {
|
|
1049
|
-
sessionStorageProvider.removeOauthState();
|
|
1050
|
-
sessionStorageProvider.removeOauthCodeVerifier();
|
|
1051
|
-
sessionStorageProvider.removeOauthCodeChallenge();
|
|
1052
|
-
}
|
|
1053
|
-
}
|
|
1054
|
-
_context.next = 26;
|
|
1055
|
-
break;
|
|
1056
|
-
case 23:
|
|
1057
|
-
_context.prev = 23;
|
|
1058
|
-
_context.t0 = _context["catch"](15);
|
|
1059
|
-
if (isMounted.current) {
|
|
1060
|
-
if (_context.t0 instanceof Error) {
|
|
1061
|
-
setError(function () {
|
|
1062
|
-
var _error$stack;
|
|
1063
|
-
return {
|
|
1064
|
-
message: _context.t0.message,
|
|
1065
|
-
stack: (_error$stack = _context.t0.stack) != null ? _error$stack : 'Error in HandleOAuth2Code'
|
|
1066
|
-
};
|
|
1067
|
-
});
|
|
1068
|
-
}
|
|
1069
|
-
if (sessionStorageProvider) {
|
|
1070
|
-
sessionStorageProvider.removeOauthState();
|
|
1071
|
-
sessionStorageProvider.removeOauthCodeVerifier();
|
|
1072
|
-
sessionStorageProvider.removeOauthCodeChallenge();
|
|
1073
|
-
sessionStorageProvider.removeHasAuthenticated();
|
|
1074
|
-
}
|
|
1075
|
-
}
|
|
1076
|
-
case 26:
|
|
1077
|
-
case "end":
|
|
1078
|
-
return _context.stop();
|
|
1079
|
-
}
|
|
1080
|
-
}, _callee, null, [[15, 23]]);
|
|
1081
|
-
})), [authConfig, isMounted, onLogin, onSetAuth, sessionStorageProvider]);
|
|
1082
|
-
React.useEffect(function () {
|
|
1083
|
-
var authenticateWithLock = /*#__PURE__*/function () {
|
|
1084
|
-
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
1085
|
-
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
1086
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
1087
|
-
case 0:
|
|
1088
|
-
if (!(!isLoggedIn && !loginInProgress.current)) {
|
|
1089
|
-
_context2.next = 5;
|
|
1090
|
-
break;
|
|
1091
|
-
}
|
|
1092
|
-
loginInProgress.current = true;
|
|
1093
|
-
_context2.next = 4;
|
|
1094
|
-
return authenticate();
|
|
1095
|
-
case 4:
|
|
1096
|
-
loginInProgress.current = false;
|
|
1097
|
-
case 5:
|
|
1098
|
-
case "end":
|
|
1099
|
-
return _context2.stop();
|
|
1100
|
-
}
|
|
1101
|
-
}, _callee2);
|
|
1102
|
-
}));
|
|
1103
|
-
return function authenticateWithLock() {
|
|
1104
|
-
return _ref2.apply(this, arguments);
|
|
1105
|
-
};
|
|
1106
|
-
}();
|
|
1107
|
-
authenticateWithLock()["catch"](function () {
|
|
1108
|
-
loginInProgress.current = false;
|
|
1109
|
-
});
|
|
1110
|
-
}, [authenticate, isLoggedIn]);
|
|
1111
|
-
return /*#__PURE__*/jsxs(Fragment, {
|
|
1112
|
-
children: [error ? /*#__PURE__*/jsx(Navigate, {
|
|
1113
|
-
replace: true,
|
|
1114
|
-
state: {
|
|
1115
|
-
error: {
|
|
1116
|
-
message: error.message,
|
|
1117
|
-
stack: error.stack
|
|
1118
|
-
}
|
|
1119
|
-
},
|
|
1120
|
-
to: "/error"
|
|
1121
|
-
}) : null, isLoggedIn ? /*#__PURE__*/jsx(Navigate, {
|
|
1122
|
-
replace: true,
|
|
1123
|
-
to: sessionStorageProvider.getCallbackUrl()
|
|
1124
|
-
}) : null]
|
|
1125
|
-
});
|
|
1126
|
-
};
|
|
1127
|
-
|
|
1128
|
-
/* *
|
|
1129
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1130
|
-
* you may not use this file except in compliance with the License.
|
|
1131
|
-
* You may obtain a copy of the License at
|
|
1132
|
-
*
|
|
1133
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1134
|
-
*
|
|
1135
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
1136
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1137
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1138
|
-
* See the License for the specific language governing permissions and
|
|
1139
|
-
* limitations under the License.
|
|
1140
|
-
*
|
|
1141
|
-
* Copyright 2024 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
|
|
1142
|
-
* Copyright 2024 - Finnish Meteorological Institute (FMI)
|
|
1143
|
-
* Copyright 2024 - The Norwegian Meteorological Institute (MET Norway)
|
|
1144
|
-
* */
|
|
1145
|
-
|
|
1146
|
-
var getCurrentUrlLocation = function getCurrentUrlLocation(url, appUrl) {
|
|
1147
|
-
return url ? url.replace(appUrl, '') : '/';
|
|
1148
|
-
};
|
|
1149
|
-
|
|
1150
|
-
/* *
|
|
1151
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1152
|
-
* you may not use this file except in compliance with the License.
|
|
1153
|
-
* You may obtain a copy of the License at
|
|
1154
|
-
*
|
|
1155
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1156
|
-
*
|
|
1157
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
1158
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1159
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1160
|
-
* See the License for the specific language governing permissions and
|
|
1161
|
-
* limitations under the License.
|
|
1162
|
-
*
|
|
1163
|
-
* Copyright 2021 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
|
|
1164
|
-
* Copyright 2021 - Finnish Meteorological Institute (FMI)
|
|
1165
|
-
* Copyright 2024 - The Norwegian Meteorological Institute (MET Norway)
|
|
1166
|
-
* */
|
|
1167
|
-
var OAuth2Login = function OAuth2Login() {
|
|
1168
|
-
var _useAuthenticationCon = useAuthenticationContext(),
|
|
1169
|
-
authConfig = _useAuthenticationCon.authConfig;
|
|
1170
|
-
React.useEffect(function () {
|
|
1171
|
-
var callbackUrl = getCurrentUrlLocation(sessionStorageProvider.getCallbackUrl(), authConfig.GW_APP_URL);
|
|
1172
|
-
sessionStorageProvider.setCallbackUrl(callbackUrl);
|
|
1173
|
-
window.location.assign(authConfig.GW_AUTH_LOGIN_URL);
|
|
1174
|
-
});
|
|
1175
|
-
return null;
|
|
1176
|
-
};
|
|
1177
|
-
|
|
1178
|
-
/* *
|
|
1179
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1180
|
-
* you may not use this file except in compliance with the License.
|
|
1181
|
-
* You may obtain a copy of the License at
|
|
1182
|
-
*
|
|
1183
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1184
|
-
*
|
|
1185
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
1186
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1187
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1188
|
-
* See the License for the specific language governing permissions and
|
|
1189
|
-
* limitations under the License.
|
|
1190
|
-
*
|
|
1191
|
-
* Copyright 2023 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
|
|
1192
|
-
* Copyright 2023 - Finnish Meteorological Institute (FMI)
|
|
1193
|
-
* Copyright 2024 - The Norwegian Meteorological Institute (MET Norway)
|
|
1194
|
-
* */
|
|
1195
|
-
|
|
1196
|
-
var API_NAMESPACE = 'api';
|
|
1197
|
-
var AUTH_NAMESPACE = 'auth';
|
|
1198
|
-
var ns = [AUTH_NAMESPACE, API_NAMESPACE, SHARED_NAMESPACE];
|
|
1199
|
-
var useAuthenticationTranslation = function useAuthenticationTranslation() {
|
|
1200
|
-
return useTranslation(ns);
|
|
1201
|
-
};
|
|
1202
|
-
|
|
1203
|
-
/* *
|
|
1204
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1205
|
-
* you may not use this file except in compliance with the License.
|
|
1206
|
-
* You may obtain a copy of the License at
|
|
1207
|
-
*
|
|
1208
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1209
|
-
*
|
|
1210
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
1211
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1212
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1213
|
-
* See the License for the specific language governing permissions and
|
|
1214
|
-
* limitations under the License.
|
|
1215
|
-
*
|
|
1216
|
-
* Copyright 2021 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
|
|
1217
|
-
* Copyright 2021 - Finnish Meteorological Institute (FMI)
|
|
1218
|
-
* Copyright 2024 - The Norwegian Meteorological Institute (MET Norway)
|
|
1219
|
-
* */
|
|
1220
|
-
var OAuth2Logout = function OAuth2Logout() {
|
|
1221
|
-
var _useAuthenticationCon = useAuthenticationContext(),
|
|
1222
|
-
onSetAuth = _useAuthenticationCon.onSetAuth,
|
|
1223
|
-
authConfig = _useAuthenticationCon.authConfig,
|
|
1224
|
-
isLoggedIn = _useAuthenticationCon.isLoggedIn,
|
|
1225
|
-
onLogin = _useAuthenticationCon.onLogin,
|
|
1226
|
-
sessionStorageProvider = _useAuthenticationCon.sessionStorageProvider;
|
|
1227
|
-
var _React$useState = React.useState(true),
|
|
1228
|
-
showAlert = _React$useState[0],
|
|
1229
|
-
setShowAlert = _React$useState[1];
|
|
1230
|
-
var _useAuthenticationTra = useAuthenticationTranslation(),
|
|
1231
|
-
t = _useAuthenticationTra.t;
|
|
1232
|
-
React.useEffect(function () {
|
|
1233
|
-
if (isLoggedIn) {
|
|
1234
|
-
setShowAlert(false);
|
|
1235
|
-
onSetAuth(null);
|
|
1236
|
-
onLogin(false);
|
|
1237
|
-
sessionStorageProvider.removeHasAuthenticated();
|
|
1238
|
-
window.location.assign(authConfig.GW_AUTH_LOGOUT_URL);
|
|
1239
|
-
}
|
|
1240
|
-
}, [isLoggedIn, onSetAuth, onLogin, sessionStorageProvider, authConfig.GW_AUTH_LOGOUT_URL]);
|
|
1241
|
-
return showAlert ? /*#__PURE__*/jsx(ThemeWrapper, {
|
|
1242
|
-
children: /*#__PURE__*/jsx(AlertBanner, {
|
|
1243
|
-
info: /*#__PURE__*/jsx("p", {
|
|
1244
|
-
children: /*#__PURE__*/jsxs(Trans, {
|
|
1245
|
-
i18nKey: "auth-logout-go-back-to-home-page",
|
|
1246
|
-
ns: AUTH_NAMESPACE,
|
|
1247
|
-
children: ["Go back to the ", /*#__PURE__*/jsx(Link, {
|
|
1248
|
-
to: "/",
|
|
1249
|
-
children: "Home Page"
|
|
1250
|
-
})]
|
|
1251
|
-
})
|
|
1252
|
-
}),
|
|
1253
|
-
severity: "info",
|
|
1254
|
-
title: t('auth-logout-you-are-logged-out')
|
|
1255
|
-
})
|
|
1256
|
-
}) : null;
|
|
1257
|
-
};
|
|
1258
|
-
|
|
1259
|
-
/* *
|
|
1260
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1261
|
-
* you may not use this file except in compliance with the License.
|
|
1262
|
-
* You may obtain a copy of the License at
|
|
1263
|
-
*
|
|
1264
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1265
|
-
*
|
|
1266
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
1267
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1268
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1269
|
-
* See the License for the specific language governing permissions and
|
|
1270
|
-
* limitations under the License.
|
|
1271
|
-
*
|
|
1272
|
-
* Copyright 2024 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
|
|
1273
|
-
* Copyright 2024 - Finnish Meteorological Institute (FMI)
|
|
1274
|
-
* Copyright 2024 - The Norwegian Meteorological Institute (MET Norway)
|
|
1275
|
-
* */
|
|
1276
|
-
var UserMenuRoles = function UserMenuRoles(_ref) {
|
|
1277
|
-
var currentRole = _ref.currentRole,
|
|
1278
|
-
onChangeRole = _ref.onChangeRole,
|
|
1279
|
-
roles = _ref.roles;
|
|
1280
|
-
var _useAuthenticationTra = useAuthenticationTranslation(),
|
|
1281
|
-
t = _useAuthenticationTra.t;
|
|
1282
|
-
var handleChangeRole = function handleChangeRole(event) {
|
|
1283
|
-
var selectedRole = roles == null ? void 0 : roles.find(function (role) {
|
|
1284
|
-
return role.name === event.target.value;
|
|
1285
|
-
});
|
|
1286
|
-
if (selectedRole) {
|
|
1287
|
-
onChangeRole == null || onChangeRole(selectedRole);
|
|
1288
|
-
}
|
|
1289
|
-
};
|
|
1290
|
-
return /*#__PURE__*/jsxs(FormControl, {
|
|
1291
|
-
children: [/*#__PURE__*/jsx(FormLabel, {
|
|
1292
|
-
component: "legend",
|
|
1293
|
-
sx: {
|
|
1294
|
-
fontSize: 14,
|
|
1295
|
-
fontWeight: 400,
|
|
1296
|
-
color: 'geowebColors.typographyAndIcons.text',
|
|
1297
|
-
opacity: 1
|
|
1298
|
-
},
|
|
1299
|
-
children: t('auth-role-title')
|
|
1300
|
-
}), /*#__PURE__*/jsx(RadioGroup, {
|
|
1301
|
-
"aria-labelledby": "user-menu-roles",
|
|
1302
|
-
name: "user-menu-roles",
|
|
1303
|
-
onChange: handleChangeRole,
|
|
1304
|
-
value: currentRole == null ? void 0 : currentRole.name,
|
|
1305
|
-
children: roles == null ? void 0 : roles.map(function (role) {
|
|
1306
|
-
return /*#__PURE__*/jsx(FormControlLabel, {
|
|
1307
|
-
control: /*#__PURE__*/jsx(Radio, {}),
|
|
1308
|
-
label: t(role.title),
|
|
1309
|
-
value: role.name
|
|
1310
|
-
}, role.name);
|
|
1311
|
-
})
|
|
1312
|
-
})]
|
|
1313
|
-
});
|
|
1314
|
-
};
|
|
1315
|
-
|
|
1316
|
-
/*
|
|
1317
|
-
Summary. Accepts a promise base apiCall with params, and returns an object with result
|
|
1318
|
-
|
|
1319
|
-
@param {Promise} apiCall: api request Promise
|
|
1320
|
-
@param {object} params: params for api request
|
|
1321
|
-
@return {isLoading: boolean, error: Error, results: any}
|
|
1322
|
-
|
|
1323
|
-
@example:
|
|
1324
|
-
const { isLoading, error, result } = useApi(api.getList, {
|
|
1325
|
-
id: 'xxxxx',
|
|
1326
|
-
});
|
|
1327
|
-
*/
|
|
1328
|
-
|
|
1329
|
-
var generateRandomId = function generateRandomId() {
|
|
1330
|
-
return "-" + Math.random().toString(36).substring(2, 11);
|
|
1331
|
-
};
|
|
1332
|
-
var useApi = function useApi(apiCall, params, callbacks) {
|
|
1333
|
-
var _useIsMounted = useIsMounted(),
|
|
1334
|
-
isMounted = _useIsMounted.isMounted;
|
|
1335
|
-
// eslint-disable-next-line react/hook-use-state
|
|
1336
|
-
var _useState = useState(generateRandomId()),
|
|
1337
|
-
id = _useState[0];
|
|
1338
|
-
var _useState2 = useState(true),
|
|
1339
|
-
isLoading = _useState2[0],
|
|
1340
|
-
setIsLoading = _useState2[1];
|
|
1341
|
-
var _useState3 = useState(null),
|
|
1342
|
-
error = _useState3[0],
|
|
1343
|
-
setError = _useState3[1];
|
|
1344
|
-
var _useState4 = useState(null),
|
|
1345
|
-
result = _useState4[0],
|
|
1346
|
-
setResult = _useState4[1];
|
|
1347
|
-
var debouncedParams = useDebounce(JSON.stringify(params), 300);
|
|
1348
|
-
|
|
1349
|
-
// trick so that we don't have to include this in the useEffect dependency array (as it is likely that callbacks changes on every render)
|
|
1350
|
-
var callbacksRef = useRef();
|
|
1351
|
-
callbacksRef.current = callbacks;
|
|
1352
|
-
var handleError = function handleError(newError) {
|
|
1353
|
-
if (isMounted.current) {
|
|
1354
|
-
if (!axios.isCancel(newError)) {
|
|
1355
|
-
var _callbacksRef$current;
|
|
1356
|
-
(_callbacksRef$current = callbacksRef.current) == null || _callbacksRef$current.onError == null || _callbacksRef$current.onError(newError);
|
|
1357
|
-
setError(newError);
|
|
1358
|
-
}
|
|
1359
|
-
}
|
|
1360
|
-
};
|
|
1361
|
-
var fetchApiData = /*#__PURE__*/function () {
|
|
1362
|
-
var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_params) {
|
|
1363
|
-
var response, _callbacksRef$current2, data;
|
|
1364
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
1365
|
-
while (1) switch (_context.prev = _context.next) {
|
|
1366
|
-
case 0:
|
|
1367
|
-
setIsLoading(true);
|
|
1368
|
-
setError(null);
|
|
1369
|
-
_context.prev = 2;
|
|
1370
|
-
_context.next = 5;
|
|
1371
|
-
return apiCall(_params, id);
|
|
1372
|
-
case 5:
|
|
1373
|
-
response = _context.sent;
|
|
1374
|
-
if (isMounted.current) {
|
|
1375
|
-
data = Array.isArray(response) ? response.map(function (dimension) {
|
|
1376
|
-
return dimension.data;
|
|
1377
|
-
}) : response.data;
|
|
1378
|
-
(_callbacksRef$current2 = callbacksRef.current) == null || _callbacksRef$current2.onSuccess == null || _callbacksRef$current2.onSuccess(data);
|
|
1379
|
-
setResult(data);
|
|
1380
|
-
}
|
|
1381
|
-
_context.next = 12;
|
|
1382
|
-
break;
|
|
1383
|
-
case 9:
|
|
1384
|
-
_context.prev = 9;
|
|
1385
|
-
_context.t0 = _context["catch"](2);
|
|
1386
|
-
if (_context.t0 instanceof Error) {
|
|
1387
|
-
handleError(_context.t0);
|
|
1388
|
-
}
|
|
1389
|
-
case 12:
|
|
1390
|
-
_context.prev = 12;
|
|
1391
|
-
setIsLoading(false);
|
|
1392
|
-
return _context.finish(12);
|
|
1393
|
-
case 15:
|
|
1394
|
-
case "end":
|
|
1395
|
-
return _context.stop();
|
|
1396
|
-
}
|
|
1397
|
-
}, _callee, null, [[2, 9, 12, 15]]);
|
|
1398
|
-
}));
|
|
1399
|
-
return function fetchApiData(_x) {
|
|
1400
|
-
return _ref.apply(this, arguments);
|
|
1401
|
-
};
|
|
1402
|
-
}();
|
|
1403
|
-
useEffect(function () {
|
|
1404
|
-
fetchApiData(params)["catch"](function (newError) {
|
|
1405
|
-
handleError(newError);
|
|
1406
|
-
});
|
|
1407
|
-
},
|
|
1408
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1409
|
-
[debouncedParams]);
|
|
1410
|
-
var clearResults = function clearResults() {
|
|
1411
|
-
setIsLoading(true);
|
|
1412
|
-
setResult(null);
|
|
1413
|
-
};
|
|
1414
|
-
return {
|
|
1415
|
-
isLoading: isLoading,
|
|
1416
|
-
error: error,
|
|
1417
|
-
result: result,
|
|
1418
|
-
clearResults: clearResults,
|
|
1419
|
-
fetchApiData: fetchApiData
|
|
1420
|
-
};
|
|
1421
|
-
};
|
|
1422
|
-
|
|
1423
|
-
export { AUTH_NAMESPACE, AuthenticationContext, AuthenticationProvider, HandleOAuth2Code as Code, GEOWEB_ROLE_PRESETS_ADMIN, GEOWEB_ROLE_USER, KEEP_ALIVE_POLLER_IN_SECONDS, OAuth2Login as Login, OAuth2Logout as Logout, MILLISECOND_TO_SECOND, REFRESH_TOKEN_WHEN_PCT_EXPIRED, UserMenuRoles, apiTranslations, authTranslations, createApiInstance, createFakeApiInstance, createNonAuthApiInstance, fakeApiRequest, getAuthConfig, getCodeChallenge, getCurrentTimeInSeconds, getCurrentUrlLocation, getRandomString, groupsToRoles, makeCredentialsFromTokenResponse, refreshAccessToken, refreshAccessTokenAndSetAuthContext, setAuthChangeListener, useApi, useAuthenticationContext, useAuthenticationDefaultProps };
|