@gandalan/weblibs 0.0.39 → 0.0.41
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 +24 -0
- package/package.json +1 -1
package/api/IDAS.js
CHANGED
|
@@ -2,12 +2,14 @@ import { RESTClient } from './RESTClient';
|
|
|
2
2
|
|
|
3
3
|
let appToken = localStorage.getItem('IDAS_AppToken') || '66B70E0B-F7C4-4829-B12A-18AD309E3970';
|
|
4
4
|
let authToken = localStorage.getItem('IDAS_AuthToken');
|
|
5
|
+
let authJwtToken = localStorage.getItem('IDAS_AuthJwtToken');
|
|
5
6
|
let apiBaseUrl = localStorage.getItem('IDAS_ApiBaseUrl') || 'https://api.dev.idas-cloudservices.net/api/';
|
|
6
7
|
|
|
7
8
|
let restClient = new RESTClient(apiBaseUrl, authToken);
|
|
8
9
|
restClient.onError = (error, message) => {
|
|
9
10
|
if (message.indexOf("401") != -1 || message.indexOf("403") != -1) {
|
|
10
11
|
localStorage.removeItem('IDAS_AuthToken');
|
|
12
|
+
localStorage.removeItem('IDAS_AuthJwtToken');
|
|
11
13
|
new IDAS().authenticateWithSSO(true);
|
|
12
14
|
}
|
|
13
15
|
}
|
|
@@ -24,6 +26,11 @@ export class IDAS {
|
|
|
24
26
|
return data;
|
|
25
27
|
}
|
|
26
28
|
|
|
29
|
+
authorizeWithJwt(jwtToken) {
|
|
30
|
+
localStorage.setItem('IDAS_AuthJwtToken', jwtToken);
|
|
31
|
+
restClient = new RESTClient(apiBaseUrl, jwtToken, true);
|
|
32
|
+
}
|
|
33
|
+
|
|
27
34
|
async authenticateWithSSO(forceRenew = false) {
|
|
28
35
|
if (!authToken)
|
|
29
36
|
{
|
|
@@ -40,6 +47,23 @@ export class IDAS {
|
|
|
40
47
|
}
|
|
41
48
|
}
|
|
42
49
|
|
|
50
|
+
async authenticateWithJwt(authPath) {
|
|
51
|
+
if (!authJwtToken) {
|
|
52
|
+
const authEndpoint = (new URL(window.location.href).origin) + authPath;
|
|
53
|
+
let authUrlCallback = `${authEndpoint}?r=%target%&t=%jwt%`;
|
|
54
|
+
authUrlCallback = authUrlCallback.replace('%target%', encodeURIComponent(window.location.href));
|
|
55
|
+
|
|
56
|
+
const url = new URL(apiBaseUrl);
|
|
57
|
+
url.pathname = "/Session";
|
|
58
|
+
url.search = `?a=${appToken}&r=${encodeURIComponent(authUrlCallback)}`;
|
|
59
|
+
let jwtUrl = url.toString();
|
|
60
|
+
|
|
61
|
+
window.location = jwtUrl;
|
|
62
|
+
} else {
|
|
63
|
+
restClient = new RESTClient(apiBaseUrl, authJwtToken, true);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
43
67
|
mandantGuid = localStorage.getItem('IDAS_MandantGuid');
|
|
44
68
|
|
|
45
69
|
auth = {
|