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