@arkitektbedriftene/fe-lib 7.2.0 → 7.3.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/oidc/AuthManager.d.ts +4 -3
- package/dist/oidc.es.js +106 -100
- 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, n) => e in t ? E(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n;
|
|
3
|
+
var f = (t, e, n) => v(t, typeof e != "symbol" ? e + "" : e, n);
|
|
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,
|
|
22
|
+
const [e, n] = 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
|
+
n({ 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:
|
|
34
|
+
h(() => {
|
|
35
|
+
const { search: n } = window.location, s = new URLSearchParams(n).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, n) {
|
|
74
|
+
f(this, "userManager");
|
|
75
|
+
f(this, "storageKey", "impersonationState");
|
|
76
|
+
f(this, "meEndpoint");
|
|
77
|
+
this.userManager = new L(e), this.meEndpoint = n;
|
|
77
78
|
}
|
|
78
79
|
/**
|
|
79
80
|
* Get impersonation user from localStorage
|
|
@@ -82,11 +83,11 @@ class W {
|
|
|
82
83
|
try {
|
|
83
84
|
const e = localStorage.getItem(this.storageKey);
|
|
84
85
|
if (e) {
|
|
85
|
-
const
|
|
86
|
-
if (
|
|
87
|
-
if (Math.floor(Date.now() / 1e3) >=
|
|
86
|
+
const n = JSON.parse(e);
|
|
87
|
+
if (n.impersonationToken && n.impersonatedUser) {
|
|
88
|
+
if (Math.floor(Date.now() / 1e3) >= n.impersonatedUser.exp)
|
|
88
89
|
throw new Error("Impersonation token has expired");
|
|
89
|
-
return
|
|
90
|
+
return n;
|
|
90
91
|
}
|
|
91
92
|
}
|
|
92
93
|
} catch (e) {
|
|
@@ -105,10 +106,10 @@ class W {
|
|
|
105
106
|
profile: e.impersonatedUser,
|
|
106
107
|
impersonating: !0
|
|
107
108
|
};
|
|
108
|
-
const
|
|
109
|
-
return !
|
|
110
|
-
access_token:
|
|
111
|
-
profile:
|
|
109
|
+
const n = await this.userManager.getUser();
|
|
110
|
+
return !n || n.expired ? null : {
|
|
111
|
+
access_token: n.access_token,
|
|
112
|
+
profile: n.profile,
|
|
112
113
|
impersonating: !1
|
|
113
114
|
};
|
|
114
115
|
}
|
|
@@ -132,15 +133,20 @@ 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
|
+
"Content-Type": "application/json",
|
|
142
|
+
Authorization: `Bearer ${e}`
|
|
143
|
+
}
|
|
144
|
+
})).json(),
|
|
139
145
|
impersonationToken: e
|
|
140
146
|
};
|
|
141
|
-
localStorage.setItem(this.storageKey, JSON.stringify(
|
|
142
|
-
} catch (
|
|
143
|
-
console.error("Failed to
|
|
147
|
+
localStorage.setItem(this.storageKey, JSON.stringify(o));
|
|
148
|
+
} catch (n) {
|
|
149
|
+
console.error("Failed to set impersonation token:", n);
|
|
144
150
|
}
|
|
145
151
|
}
|
|
146
152
|
/**
|
|
@@ -152,48 +158,48 @@ class W {
|
|
|
152
158
|
/**
|
|
153
159
|
* Handle impersonation callback from URL parameters
|
|
154
160
|
*/
|
|
155
|
-
handleImpersonationCallback(e) {
|
|
156
|
-
const
|
|
157
|
-
if (!
|
|
161
|
+
async handleImpersonationCallback(e) {
|
|
162
|
+
const s = new URL(e).searchParams.get("impersonateAccessToken");
|
|
163
|
+
if (!s)
|
|
158
164
|
throw new Error("Missing url param 'impersonateAccessToken'");
|
|
159
|
-
this.setImpersonation(
|
|
165
|
+
return this.setImpersonation(s);
|
|
160
166
|
}
|
|
161
167
|
}
|
|
162
168
|
const O = ({
|
|
163
169
|
userManager: t,
|
|
164
170
|
context: e,
|
|
165
|
-
children:
|
|
171
|
+
children: n
|
|
166
172
|
}) => {
|
|
167
|
-
const [
|
|
173
|
+
const [s, o] = R({
|
|
168
174
|
user: null,
|
|
169
175
|
isLoading: !0,
|
|
170
176
|
isAuthenticated: !1,
|
|
171
177
|
isError: !1,
|
|
172
178
|
error: null
|
|
173
179
|
}), i = x(!1);
|
|
174
|
-
|
|
180
|
+
h(() => {
|
|
175
181
|
i.current || (i.current = !0, (async () => {
|
|
176
182
|
try {
|
|
177
|
-
const
|
|
183
|
+
const r = await t.getUser();
|
|
178
184
|
o({
|
|
179
|
-
user:
|
|
185
|
+
user: r,
|
|
180
186
|
isLoading: !1,
|
|
181
|
-
isAuthenticated:
|
|
187
|
+
isAuthenticated: r ? !r.expired : !1,
|
|
182
188
|
isError: !1,
|
|
183
189
|
error: null
|
|
184
190
|
});
|
|
185
|
-
} catch (
|
|
191
|
+
} catch (r) {
|
|
186
192
|
o({
|
|
187
193
|
user: null,
|
|
188
194
|
isLoading: !1,
|
|
189
195
|
isAuthenticated: !1,
|
|
190
196
|
isError: !0,
|
|
191
|
-
error:
|
|
197
|
+
error: r instanceof Error ? r : new Error("Unknown error during auth")
|
|
192
198
|
});
|
|
193
199
|
}
|
|
194
200
|
})());
|
|
195
|
-
}, [t]),
|
|
196
|
-
const
|
|
201
|
+
}, [t]), h(() => {
|
|
202
|
+
const r = (p) => {
|
|
197
203
|
o({
|
|
198
204
|
user: p,
|
|
199
205
|
isLoading: !1,
|
|
@@ -202,10 +208,10 @@ const O = ({
|
|
|
202
208
|
error: null
|
|
203
209
|
});
|
|
204
210
|
};
|
|
205
|
-
t.events.addUserLoaded(
|
|
211
|
+
t.events.addUserLoaded(r);
|
|
206
212
|
const c = () => {
|
|
207
213
|
o({
|
|
208
|
-
...
|
|
214
|
+
...s,
|
|
209
215
|
user: null,
|
|
210
216
|
isAuthenticated: !1
|
|
211
217
|
});
|
|
@@ -213,41 +219,41 @@ const O = ({
|
|
|
213
219
|
t.events.addUserUnloaded(c);
|
|
214
220
|
const S = (p) => {
|
|
215
221
|
o({
|
|
216
|
-
...
|
|
222
|
+
...s,
|
|
217
223
|
isLoading: !1,
|
|
218
224
|
isError: !0,
|
|
219
225
|
error: p
|
|
220
226
|
});
|
|
221
227
|
};
|
|
222
228
|
return t.events.addSilentRenewError(S), () => {
|
|
223
|
-
t.events.removeUserLoaded(
|
|
229
|
+
t.events.removeUserLoaded(r), t.events.removeUserUnloaded(c), t.events.removeSilentRenewError(S);
|
|
224
230
|
};
|
|
225
231
|
}, [t]);
|
|
226
|
-
const u =
|
|
227
|
-
const
|
|
232
|
+
const u = m(async () => {
|
|
233
|
+
const r = await t.signinCallback();
|
|
228
234
|
return o({
|
|
229
|
-
user:
|
|
235
|
+
user: r ?? null,
|
|
230
236
|
isLoading: !1,
|
|
231
|
-
isAuthenticated:
|
|
237
|
+
isAuthenticated: r ? !r.expired : !1,
|
|
232
238
|
isError: !1,
|
|
233
239
|
error: null
|
|
234
|
-
}),
|
|
235
|
-
}, [t]), a =
|
|
236
|
-
async (
|
|
240
|
+
}), r ?? void 0;
|
|
241
|
+
}, [t]), a = m(
|
|
242
|
+
async (r) => {
|
|
237
243
|
try {
|
|
238
|
-
await t.signinRedirect(
|
|
244
|
+
await t.signinRedirect(r);
|
|
239
245
|
} catch (c) {
|
|
240
246
|
console.error(c);
|
|
241
247
|
}
|
|
242
248
|
},
|
|
243
249
|
[t]
|
|
244
|
-
), l =
|
|
245
|
-
async (
|
|
250
|
+
), l = m(
|
|
251
|
+
async (r) => await t.signinPopup(r),
|
|
246
252
|
[t]
|
|
247
|
-
),
|
|
248
|
-
async (
|
|
253
|
+
), d = m(
|
|
254
|
+
async (r) => {
|
|
249
255
|
try {
|
|
250
|
-
return await t.signinSilent(
|
|
256
|
+
return await t.signinSilent(r);
|
|
251
257
|
} catch (c) {
|
|
252
258
|
return o({
|
|
253
259
|
user: null,
|
|
@@ -259,36 +265,36 @@ const O = ({
|
|
|
259
265
|
}
|
|
260
266
|
},
|
|
261
267
|
[t]
|
|
262
|
-
),
|
|
263
|
-
async (
|
|
268
|
+
), g = m(
|
|
269
|
+
async (r) => {
|
|
264
270
|
try {
|
|
265
|
-
await t.signoutRedirect(
|
|
271
|
+
await t.signoutRedirect(r);
|
|
266
272
|
} catch (c) {
|
|
267
273
|
console.error(c);
|
|
268
274
|
}
|
|
269
275
|
},
|
|
270
276
|
[t]
|
|
271
|
-
), C =
|
|
277
|
+
), C = k(
|
|
272
278
|
() => ({
|
|
273
|
-
state:
|
|
279
|
+
state: s,
|
|
274
280
|
handleSigninCallback: u,
|
|
275
281
|
redirectToSignin: a,
|
|
276
|
-
signinSilent:
|
|
282
|
+
signinSilent: d,
|
|
277
283
|
signinPopup: l,
|
|
278
|
-
logout:
|
|
284
|
+
logout: g
|
|
279
285
|
}),
|
|
280
286
|
[
|
|
281
|
-
|
|
287
|
+
s,
|
|
282
288
|
u,
|
|
283
289
|
a,
|
|
284
|
-
|
|
290
|
+
d,
|
|
285
291
|
l,
|
|
286
|
-
|
|
292
|
+
g
|
|
287
293
|
]
|
|
288
294
|
);
|
|
289
|
-
return /* @__PURE__ */ w(e.Provider, { value: C, children:
|
|
295
|
+
return /* @__PURE__ */ w(e.Provider, { value: C, children: n });
|
|
290
296
|
}, A = (t) => {
|
|
291
|
-
const e =
|
|
297
|
+
const e = U(t);
|
|
292
298
|
if (!e)
|
|
293
299
|
throw new Error("useAuthContext must be used within an AuthProvider");
|
|
294
300
|
return e;
|
|
@@ -296,15 +302,15 @@ const O = ({
|
|
|
296
302
|
const { state: e } = A(t);
|
|
297
303
|
return e;
|
|
298
304
|
}, K = (t, e) => {
|
|
299
|
-
const { state:
|
|
300
|
-
return
|
|
301
|
-
o.current || (o.current = !0,
|
|
305
|
+
const { state: n, handleSigninCallback: s } = A(t), o = x(!1);
|
|
306
|
+
return h(() => {
|
|
307
|
+
o.current || (o.current = !0, s().then(
|
|
302
308
|
(i) => new Promise(
|
|
303
309
|
(u) => setTimeout(() => u(i), 0)
|
|
304
310
|
)
|
|
305
311
|
).then((i) => e == null ? void 0 : e(i)));
|
|
306
|
-
}, [
|
|
307
|
-
},
|
|
312
|
+
}, [s]), n;
|
|
313
|
+
}, W = (t) => {
|
|
308
314
|
const e = I(null);
|
|
309
315
|
return {
|
|
310
316
|
AuthContext: e,
|
|
@@ -319,13 +325,13 @@ const O = ({
|
|
|
319
325
|
};
|
|
320
326
|
};
|
|
321
327
|
export {
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
+
Q as AuthManager,
|
|
329
|
+
q as ImpersonationContextProvider,
|
|
330
|
+
$ as ROLESAdminInCompany,
|
|
331
|
+
H as ROLESAnsatt,
|
|
332
|
+
G as ROLESMAKSAdministrator,
|
|
333
|
+
W as createAuthContext,
|
|
328
334
|
B as parseUserProfileFCString,
|
|
329
|
-
|
|
335
|
+
V as useImpersonationCallback,
|
|
330
336
|
b as useImpersonationContext
|
|
331
337
|
};
|