@gandalan/weblibs 1.0.20 → 1.0.22
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/api/IDAS.js +1 -0
- package/api/authUtils.js +14 -14
- package/package.json +1 -1
package/api/IDAS.js
CHANGED
|
@@ -6,6 +6,7 @@ export function IDASFactory(settings = {
|
|
|
6
6
|
appToken : localStorage.getItem("IDAS_AppToken"),
|
|
7
7
|
mandantGuid : localStorage.getItem("IDAS_MandantGuid"),
|
|
8
8
|
apiBaseurl : localStorage.getItem("IDAS_ApiBaseUrl"),
|
|
9
|
+
authUrl : localStorage.getItem("IDAS_ApiBaseUrl"),
|
|
9
10
|
jwtRefreshToken : localStorage.getItem("IDAS_AuthJwtRefreshToken"),
|
|
10
11
|
jwtCallbackPath : localStorage.getItem("IDAS_AuthJwtCallbackPath")
|
|
11
12
|
})
|
package/api/authUtils.js
CHANGED
|
@@ -9,22 +9,20 @@ export async function setup(settings)
|
|
|
9
9
|
|
|
10
10
|
if (settings.jwtRefreshToken && jwtTokenInvalid(settings))
|
|
11
11
|
{
|
|
12
|
-
|
|
13
|
-
// Fetch Token from IDAS API
|
|
14
|
-
let api = new RESTClient(settings);
|
|
15
|
-
const response = await api.put("Login/Update", payload);
|
|
16
|
-
const iat = response.data;
|
|
17
|
-
console.log("Got IDAS token: ", iat);
|
|
18
|
-
|
|
19
|
-
// If valid, check roles and authenticate against JWT API
|
|
20
|
-
if (iat)
|
|
21
|
-
await jwtTokenRenew(settings);
|
|
22
|
-
|
|
12
|
+
await jwtTokenRenew(settings);
|
|
23
13
|
if (jwtTokenInvalid(settings))
|
|
24
|
-
console.log("
|
|
14
|
+
console.log("Refresh failed, invalid JWT token!");
|
|
25
15
|
|
|
26
16
|
} else {
|
|
27
17
|
console.log("Settings already have a valid JWT token, nothing to do");
|
|
18
|
+
let decoded = jwt_decode(settings.jwtToken);
|
|
19
|
+
let refreshToken = decoded["refreshToken"] || "";
|
|
20
|
+
if (refreshToken)
|
|
21
|
+
{
|
|
22
|
+
console.log("Got new refresh token:", refreshToken);
|
|
23
|
+
settings.jwtRefreshToken = refreshToken;
|
|
24
|
+
localStorage.setItem("IDAS_AuthJwtRefreshToken", refreshToken);
|
|
25
|
+
}
|
|
28
26
|
}
|
|
29
27
|
console.log("Setup finished", settings);
|
|
30
28
|
}
|
|
@@ -42,7 +40,8 @@ export function jwtTokenInvalid(settings)
|
|
|
42
40
|
|
|
43
41
|
export async function jwtTokenRenew(settings)
|
|
44
42
|
{
|
|
45
|
-
|
|
43
|
+
console.log("try to refresh");
|
|
44
|
+
const renewSettings = { ...settings, jwtToken : undefined, apiBaseurl : settings.authUrl || settings.apiBaseurl };
|
|
46
45
|
let api = new RESTClient(renewSettings);
|
|
47
46
|
const payload = { "Token" : settings.jwtRefreshToken };
|
|
48
47
|
const response = await api.put("LoginJwt/Refresh", payload);
|
|
@@ -55,6 +54,7 @@ export async function jwtTokenRenew(settings)
|
|
|
55
54
|
{
|
|
56
55
|
console.log("Got new refresh token:", refreshToken);
|
|
57
56
|
settings.jwtRefreshToken = refreshToken;
|
|
57
|
+
localStorage.setItem("IDAS_AuthJwtRefreshToken", refreshToken);
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
if (jwtTokenInvalid(settings))
|
|
@@ -68,7 +68,7 @@ export function jwtAuthenticateOnBackend(settings, authPath)
|
|
|
68
68
|
let authUrlCallback = `${authEndpoint}?r=%target%&j=%jwt%&m=%mandant%`;
|
|
69
69
|
authUrlCallback = authUrlCallback.replace("%target%", encodeURIComponent(window.location.href));
|
|
70
70
|
|
|
71
|
-
const url = new URL(settings.apiBaseurl);
|
|
71
|
+
const url = new URL(settings.authUrl || settings.apiBaseurl);
|
|
72
72
|
url.pathname = "/Session";
|
|
73
73
|
url.search = `?a=${settings.appToken}&r=${encodeURIComponent(authUrlCallback)}`;
|
|
74
74
|
let jwtUrl = url.toString();
|