@arkitektbedriftene/fe-lib 7.2.0 → 7.3.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/dist/oidc/AuthManager.d.ts +4 -3
- package/dist/oidc.es.js +93 -88
- package/package.json +1 -1
|
@@ -22,7 +22,8 @@ export type ImpersonationData = {
|
|
|
22
22
|
export declare class AuthManager {
|
|
23
23
|
private userManager;
|
|
24
24
|
private storageKey;
|
|
25
|
-
|
|
25
|
+
private meEndpoint;
|
|
26
|
+
constructor(settings: UserManagerSettings, meEndpoint: string);
|
|
26
27
|
/**
|
|
27
28
|
* Get impersonation user from localStorage
|
|
28
29
|
*/
|
|
@@ -43,7 +44,7 @@ export declare class AuthManager {
|
|
|
43
44
|
/**
|
|
44
45
|
* Set impersonation with access token
|
|
45
46
|
*/
|
|
46
|
-
setImpersonation(accessToken: string): void
|
|
47
|
+
setImpersonation(accessToken: string): Promise<void>;
|
|
47
48
|
/**
|
|
48
49
|
* Clear impersonation and return to normal user
|
|
49
50
|
*/
|
|
@@ -51,5 +52,5 @@ export declare class AuthManager {
|
|
|
51
52
|
/**
|
|
52
53
|
* Handle impersonation callback from URL parameters
|
|
53
54
|
*/
|
|
54
|
-
handleImpersonationCallback(urlStr: string): void
|
|
55
|
+
handleImpersonationCallback(urlStr: string): Promise<void>;
|
|
55
56
|
}
|
package/dist/oidc.es.js
CHANGED
|
@@ -1,79 +1,80 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
1
|
+
var E = Object.defineProperty;
|
|
2
|
+
var v = (t, e, r) => e in t ? E(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r;
|
|
3
|
+
var f = (t, e, r) => v(t, typeof e != "symbol" ? e + "" : e, r);
|
|
4
4
|
import { jsx as w } from "react/jsx-runtime";
|
|
5
|
-
import { createContext as I, useContext as
|
|
6
|
-
import { UserManager as
|
|
5
|
+
import { createContext as I, useContext as U, useMemo as k, useEffect as h, useState as R, useRef as x, useCallback as m } from "react";
|
|
6
|
+
import { UserManager as L } from "oidc-client-ts";
|
|
7
7
|
export * from "oidc-client-ts";
|
|
8
|
-
import
|
|
9
|
-
import { jwtDecode as
|
|
10
|
-
const
|
|
8
|
+
import P from "use-local-storage-state";
|
|
9
|
+
import { jwtDecode as T } from "jwt-decode";
|
|
10
|
+
const y = I(
|
|
11
11
|
null
|
|
12
12
|
), b = () => {
|
|
13
|
-
const t =
|
|
13
|
+
const t = U(y);
|
|
14
14
|
if (!t)
|
|
15
15
|
throw new Error(
|
|
16
16
|
"useImpersonationContext must be used within a ImpersonationContextProvider"
|
|
17
17
|
);
|
|
18
18
|
return t;
|
|
19
|
-
},
|
|
19
|
+
}, q = ({
|
|
20
20
|
children: t
|
|
21
21
|
}) => {
|
|
22
|
-
const [e, r] =
|
|
22
|
+
const [e, r] = P("impersonationState", {
|
|
23
23
|
defaultValue: {}
|
|
24
|
-
}),
|
|
24
|
+
}), s = k(() => ({
|
|
25
25
|
accessToken: e == null ? void 0 : e.accessToken,
|
|
26
26
|
userInfo: e == null ? void 0 : e.userInfo,
|
|
27
27
|
setImpersonation: (o, i) => {
|
|
28
28
|
r({ accessToken: o, userInfo: i });
|
|
29
29
|
}
|
|
30
30
|
}), []);
|
|
31
|
-
return /* @__PURE__ */ w(
|
|
32
|
-
},
|
|
31
|
+
return /* @__PURE__ */ w(y.Provider, { value: s, children: t });
|
|
32
|
+
}, V = (t) => {
|
|
33
33
|
const { setImpersonation: e } = b();
|
|
34
|
-
|
|
35
|
-
const { search: r } = window.location,
|
|
34
|
+
h(() => {
|
|
35
|
+
const { search: r } = window.location, s = new URLSearchParams(r).get(
|
|
36
36
|
"impersonateAccessToken"
|
|
37
37
|
);
|
|
38
|
-
if (
|
|
39
|
-
const o =
|
|
40
|
-
e(
|
|
38
|
+
if (s && e) {
|
|
39
|
+
const o = T(s);
|
|
40
|
+
e(s, o), t();
|
|
41
41
|
}
|
|
42
42
|
}, []);
|
|
43
43
|
};
|
|
44
44
|
function B(t) {
|
|
45
|
-
return JSON.parse(t).map((
|
|
45
|
+
return JSON.parse(t).map((s) => {
|
|
46
46
|
const [
|
|
47
47
|
o,
|
|
48
48
|
i,
|
|
49
49
|
u,
|
|
50
50
|
a,
|
|
51
51
|
l
|
|
52
|
-
] =
|
|
52
|
+
] = s.split("|"), d = a.split(",");
|
|
53
53
|
return {
|
|
54
54
|
CustomerExternalId: o,
|
|
55
55
|
CustomerFirmId: i,
|
|
56
56
|
CustomerFirmName: u,
|
|
57
|
-
CustomerUserRoles:
|
|
57
|
+
CustomerUserRoles: d,
|
|
58
58
|
CustomerUserIsAdmin: l === "True" || l === "1"
|
|
59
59
|
};
|
|
60
60
|
});
|
|
61
61
|
}
|
|
62
|
-
const
|
|
62
|
+
const $ = [
|
|
63
63
|
"97",
|
|
64
64
|
"131",
|
|
65
65
|
"132",
|
|
66
66
|
"141"
|
|
67
|
-
],
|
|
67
|
+
], G = [
|
|
68
68
|
"3"
|
|
69
|
-
],
|
|
69
|
+
], H = [
|
|
70
70
|
"0"
|
|
71
71
|
];
|
|
72
|
-
class
|
|
73
|
-
constructor(e) {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
this
|
|
72
|
+
class Q {
|
|
73
|
+
constructor(e, r) {
|
|
74
|
+
f(this, "userManager");
|
|
75
|
+
f(this, "storageKey", "impersonationState");
|
|
76
|
+
f(this, "meEndpoint");
|
|
77
|
+
this.userManager = new L(e), this.meEndpoint = r;
|
|
77
78
|
}
|
|
78
79
|
/**
|
|
79
80
|
* Get impersonation user from localStorage
|
|
@@ -132,15 +133,19 @@ class W {
|
|
|
132
133
|
/**
|
|
133
134
|
* Set impersonation with access token
|
|
134
135
|
*/
|
|
135
|
-
setImpersonation(e) {
|
|
136
|
+
async setImpersonation(e) {
|
|
136
137
|
try {
|
|
137
|
-
const
|
|
138
|
-
impersonatedUser:
|
|
138
|
+
const o = {
|
|
139
|
+
impersonatedUser: await (await fetch(this.meEndpoint, {
|
|
140
|
+
headers: {
|
|
141
|
+
Authorization: `Bearer ${e}`
|
|
142
|
+
}
|
|
143
|
+
})).json(),
|
|
139
144
|
impersonationToken: e
|
|
140
145
|
};
|
|
141
|
-
localStorage.setItem(this.storageKey, JSON.stringify(
|
|
146
|
+
localStorage.setItem(this.storageKey, JSON.stringify(o));
|
|
142
147
|
} catch (r) {
|
|
143
|
-
console.error("Failed to
|
|
148
|
+
console.error("Failed to set impersonation token:", r);
|
|
144
149
|
}
|
|
145
150
|
}
|
|
146
151
|
/**
|
|
@@ -152,11 +157,11 @@ class W {
|
|
|
152
157
|
/**
|
|
153
158
|
* Handle impersonation callback from URL parameters
|
|
154
159
|
*/
|
|
155
|
-
handleImpersonationCallback(e) {
|
|
156
|
-
const
|
|
157
|
-
if (!
|
|
160
|
+
async handleImpersonationCallback(e) {
|
|
161
|
+
const s = new URL(e).searchParams.get("impersonateAccessToken");
|
|
162
|
+
if (!s)
|
|
158
163
|
throw new Error("Missing url param 'impersonateAccessToken'");
|
|
159
|
-
this.setImpersonation(
|
|
164
|
+
return this.setImpersonation(s);
|
|
160
165
|
}
|
|
161
166
|
}
|
|
162
167
|
const O = ({
|
|
@@ -164,36 +169,36 @@ const O = ({
|
|
|
164
169
|
context: e,
|
|
165
170
|
children: r
|
|
166
171
|
}) => {
|
|
167
|
-
const [
|
|
172
|
+
const [s, o] = R({
|
|
168
173
|
user: null,
|
|
169
174
|
isLoading: !0,
|
|
170
175
|
isAuthenticated: !1,
|
|
171
176
|
isError: !1,
|
|
172
177
|
error: null
|
|
173
178
|
}), i = x(!1);
|
|
174
|
-
|
|
179
|
+
h(() => {
|
|
175
180
|
i.current || (i.current = !0, (async () => {
|
|
176
181
|
try {
|
|
177
|
-
const
|
|
182
|
+
const n = await t.getUser();
|
|
178
183
|
o({
|
|
179
|
-
user:
|
|
184
|
+
user: n,
|
|
180
185
|
isLoading: !1,
|
|
181
|
-
isAuthenticated:
|
|
186
|
+
isAuthenticated: n ? !n.expired : !1,
|
|
182
187
|
isError: !1,
|
|
183
188
|
error: null
|
|
184
189
|
});
|
|
185
|
-
} catch (
|
|
190
|
+
} catch (n) {
|
|
186
191
|
o({
|
|
187
192
|
user: null,
|
|
188
193
|
isLoading: !1,
|
|
189
194
|
isAuthenticated: !1,
|
|
190
195
|
isError: !0,
|
|
191
|
-
error:
|
|
196
|
+
error: n instanceof Error ? n : new Error("Unknown error during auth")
|
|
192
197
|
});
|
|
193
198
|
}
|
|
194
199
|
})());
|
|
195
|
-
}, [t]),
|
|
196
|
-
const
|
|
200
|
+
}, [t]), h(() => {
|
|
201
|
+
const n = (p) => {
|
|
197
202
|
o({
|
|
198
203
|
user: p,
|
|
199
204
|
isLoading: !1,
|
|
@@ -202,10 +207,10 @@ const O = ({
|
|
|
202
207
|
error: null
|
|
203
208
|
});
|
|
204
209
|
};
|
|
205
|
-
t.events.addUserLoaded(
|
|
210
|
+
t.events.addUserLoaded(n);
|
|
206
211
|
const c = () => {
|
|
207
212
|
o({
|
|
208
|
-
...
|
|
213
|
+
...s,
|
|
209
214
|
user: null,
|
|
210
215
|
isAuthenticated: !1
|
|
211
216
|
});
|
|
@@ -213,41 +218,41 @@ const O = ({
|
|
|
213
218
|
t.events.addUserUnloaded(c);
|
|
214
219
|
const S = (p) => {
|
|
215
220
|
o({
|
|
216
|
-
...
|
|
221
|
+
...s,
|
|
217
222
|
isLoading: !1,
|
|
218
223
|
isError: !0,
|
|
219
224
|
error: p
|
|
220
225
|
});
|
|
221
226
|
};
|
|
222
227
|
return t.events.addSilentRenewError(S), () => {
|
|
223
|
-
t.events.removeUserLoaded(
|
|
228
|
+
t.events.removeUserLoaded(n), t.events.removeUserUnloaded(c), t.events.removeSilentRenewError(S);
|
|
224
229
|
};
|
|
225
230
|
}, [t]);
|
|
226
|
-
const u =
|
|
227
|
-
const
|
|
231
|
+
const u = m(async () => {
|
|
232
|
+
const n = await t.signinCallback();
|
|
228
233
|
return o({
|
|
229
|
-
user:
|
|
234
|
+
user: n ?? null,
|
|
230
235
|
isLoading: !1,
|
|
231
|
-
isAuthenticated:
|
|
236
|
+
isAuthenticated: n ? !n.expired : !1,
|
|
232
237
|
isError: !1,
|
|
233
238
|
error: null
|
|
234
|
-
}),
|
|
235
|
-
}, [t]), a =
|
|
236
|
-
async (
|
|
239
|
+
}), n ?? void 0;
|
|
240
|
+
}, [t]), a = m(
|
|
241
|
+
async (n) => {
|
|
237
242
|
try {
|
|
238
|
-
await t.signinRedirect(
|
|
243
|
+
await t.signinRedirect(n);
|
|
239
244
|
} catch (c) {
|
|
240
245
|
console.error(c);
|
|
241
246
|
}
|
|
242
247
|
},
|
|
243
248
|
[t]
|
|
244
|
-
), l =
|
|
245
|
-
async (
|
|
249
|
+
), l = m(
|
|
250
|
+
async (n) => await t.signinPopup(n),
|
|
246
251
|
[t]
|
|
247
|
-
),
|
|
248
|
-
async (
|
|
252
|
+
), d = m(
|
|
253
|
+
async (n) => {
|
|
249
254
|
try {
|
|
250
|
-
return await t.signinSilent(
|
|
255
|
+
return await t.signinSilent(n);
|
|
251
256
|
} catch (c) {
|
|
252
257
|
return o({
|
|
253
258
|
user: null,
|
|
@@ -259,36 +264,36 @@ const O = ({
|
|
|
259
264
|
}
|
|
260
265
|
},
|
|
261
266
|
[t]
|
|
262
|
-
),
|
|
263
|
-
async (
|
|
267
|
+
), g = m(
|
|
268
|
+
async (n) => {
|
|
264
269
|
try {
|
|
265
|
-
await t.signoutRedirect(
|
|
270
|
+
await t.signoutRedirect(n);
|
|
266
271
|
} catch (c) {
|
|
267
272
|
console.error(c);
|
|
268
273
|
}
|
|
269
274
|
},
|
|
270
275
|
[t]
|
|
271
|
-
), C =
|
|
276
|
+
), C = k(
|
|
272
277
|
() => ({
|
|
273
|
-
state:
|
|
278
|
+
state: s,
|
|
274
279
|
handleSigninCallback: u,
|
|
275
280
|
redirectToSignin: a,
|
|
276
|
-
signinSilent:
|
|
281
|
+
signinSilent: d,
|
|
277
282
|
signinPopup: l,
|
|
278
|
-
logout:
|
|
283
|
+
logout: g
|
|
279
284
|
}),
|
|
280
285
|
[
|
|
281
|
-
|
|
286
|
+
s,
|
|
282
287
|
u,
|
|
283
288
|
a,
|
|
284
|
-
|
|
289
|
+
d,
|
|
285
290
|
l,
|
|
286
|
-
|
|
291
|
+
g
|
|
287
292
|
]
|
|
288
293
|
);
|
|
289
294
|
return /* @__PURE__ */ w(e.Provider, { value: C, children: r });
|
|
290
295
|
}, A = (t) => {
|
|
291
|
-
const e =
|
|
296
|
+
const e = U(t);
|
|
292
297
|
if (!e)
|
|
293
298
|
throw new Error("useAuthContext must be used within an AuthProvider");
|
|
294
299
|
return e;
|
|
@@ -296,15 +301,15 @@ const O = ({
|
|
|
296
301
|
const { state: e } = A(t);
|
|
297
302
|
return e;
|
|
298
303
|
}, K = (t, e) => {
|
|
299
|
-
const { state: r, handleSigninCallback:
|
|
300
|
-
return
|
|
301
|
-
o.current || (o.current = !0,
|
|
304
|
+
const { state: r, handleSigninCallback: s } = A(t), o = x(!1);
|
|
305
|
+
return h(() => {
|
|
306
|
+
o.current || (o.current = !0, s().then(
|
|
302
307
|
(i) => new Promise(
|
|
303
308
|
(u) => setTimeout(() => u(i), 0)
|
|
304
309
|
)
|
|
305
310
|
).then((i) => e == null ? void 0 : e(i)));
|
|
306
|
-
}, [
|
|
307
|
-
},
|
|
311
|
+
}, [s]), r;
|
|
312
|
+
}, W = (t) => {
|
|
308
313
|
const e = I(null);
|
|
309
314
|
return {
|
|
310
315
|
AuthContext: e,
|
|
@@ -319,13 +324,13 @@ const O = ({
|
|
|
319
324
|
};
|
|
320
325
|
};
|
|
321
326
|
export {
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
327
|
+
Q as AuthManager,
|
|
328
|
+
q as ImpersonationContextProvider,
|
|
329
|
+
$ as ROLESAdminInCompany,
|
|
330
|
+
H as ROLESAnsatt,
|
|
331
|
+
G as ROLESMAKSAdministrator,
|
|
332
|
+
W as createAuthContext,
|
|
328
333
|
B as parseUserProfileFCString,
|
|
329
|
-
|
|
334
|
+
V as useImpersonationCallback,
|
|
330
335
|
b as useImpersonationContext
|
|
331
336
|
};
|