@gandalan/weblibs 0.0.38 → 0.0.40
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 +15 -0
- package/api/RESTClient.js +16 -24
- 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
|
}
|
|
@@ -40,6 +42,19 @@ export class IDAS {
|
|
|
40
42
|
}
|
|
41
43
|
}
|
|
42
44
|
|
|
45
|
+
async authenticateWithJwt() {
|
|
46
|
+
if (!authJwtToken) {
|
|
47
|
+
const url = new URL(apiBaseUrl);
|
|
48
|
+
url.pathname = "/Session";
|
|
49
|
+
url.search = "?a=" + appToken;
|
|
50
|
+
url.search = url.search + "&r=%target%";
|
|
51
|
+
let jwtAuthUrl = url.toString();
|
|
52
|
+
|
|
53
|
+
var jwtUrl = jwtAuthUrl.replace("%target%", encodeURIComponent(window.location.href));
|
|
54
|
+
window.location = jwtUrl;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
43
58
|
mandantGuid = localStorage.getItem('IDAS_MandantGuid');
|
|
44
59
|
|
|
45
60
|
auth = {
|
package/api/RESTClient.js
CHANGED
|
@@ -31,12 +31,16 @@ export class RESTClient {
|
|
|
31
31
|
this.token = token;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
+
getUrlOptions(noJWT = false) {
|
|
35
|
+
let options = { withCredentials: false }
|
|
36
|
+
if (this.isJWT && !noJWT)
|
|
37
|
+
options.headers = { Authorization: `Bearer ${this.token}` }
|
|
38
|
+
return options
|
|
39
|
+
}
|
|
40
|
+
|
|
34
41
|
async get(uri, noJWT = false) {
|
|
35
42
|
try {
|
|
36
|
-
|
|
37
|
-
if (this.isJWT && !noJWT)
|
|
38
|
-
options.headers = { Authorization: `Bearer ${this.token}` }
|
|
39
|
-
const response = await axios.get(this.baseurl + uri, options);
|
|
43
|
+
const response = await axios.get(this.baseurl + uri, this.getUrlOptions(noJWT));
|
|
40
44
|
this.lastError = '';
|
|
41
45
|
return response.data;
|
|
42
46
|
} catch (error) {
|
|
@@ -60,13 +64,10 @@ export class RESTClient {
|
|
|
60
64
|
}
|
|
61
65
|
}
|
|
62
66
|
|
|
63
|
-
async getRaw(uri) {
|
|
67
|
+
async getRaw(uri, noJWT = false) {
|
|
64
68
|
let response = {};
|
|
65
69
|
try {
|
|
66
|
-
|
|
67
|
-
if (this.isJWT)
|
|
68
|
-
options.headers = { Authorization: `Bearer ${this.token}` }
|
|
69
|
-
response = await axios.get(this.baseurl + uri, options)
|
|
70
|
+
response = await axios.get(this.baseurl + uri, this.getUrlOptions(noJWT))
|
|
70
71
|
this.lastError = '';
|
|
71
72
|
} catch (error) {
|
|
72
73
|
this.handleError(error);
|
|
@@ -74,12 +75,9 @@ export class RESTClient {
|
|
|
74
75
|
return response;
|
|
75
76
|
}
|
|
76
77
|
|
|
77
|
-
async post(uri, formData) {
|
|
78
|
+
async post(uri, formData, noJWT = false) {
|
|
78
79
|
try {
|
|
79
|
-
|
|
80
|
-
if (this.isJWT)
|
|
81
|
-
options.headers = { Authorization: `Bearer ${this.token}` }
|
|
82
|
-
const response = await axios.post(this.baseurl + uri, formData, options);
|
|
80
|
+
const response = await axios.post(this.baseurl + uri, formData, this.getUrlOptions(noJWT));
|
|
83
81
|
this.lastError = '';
|
|
84
82
|
return response;
|
|
85
83
|
} catch (error) {
|
|
@@ -87,12 +85,9 @@ export class RESTClient {
|
|
|
87
85
|
}
|
|
88
86
|
}
|
|
89
87
|
|
|
90
|
-
async put(uri, formData) {
|
|
88
|
+
async put(uri, formData, noJWT = false) {
|
|
91
89
|
try {
|
|
92
|
-
|
|
93
|
-
if (this.isJWT)
|
|
94
|
-
options.headers = { Authorization: `Bearer ${this.token}` }
|
|
95
|
-
const response = await axios.put(this.baseurl + uri, formData, options);
|
|
90
|
+
const response = await axios.put(this.baseurl + uri, formData, this.getUrlOptions(noJWT));
|
|
96
91
|
this.lastError = '';
|
|
97
92
|
return response;
|
|
98
93
|
} catch (error) {
|
|
@@ -100,12 +95,9 @@ export class RESTClient {
|
|
|
100
95
|
}
|
|
101
96
|
}
|
|
102
97
|
|
|
103
|
-
async delete(uri) {
|
|
98
|
+
async delete(uri, noJWT = false) {
|
|
104
99
|
try {
|
|
105
|
-
|
|
106
|
-
if (this.isJWT)
|
|
107
|
-
options.headers = { Authorization: `Bearer ${this.token}` }
|
|
108
|
-
const response = await axios.delete(this.baseurl + uri, options);
|
|
100
|
+
const response = await axios.delete(this.baseurl + uri, this.getUrlOptions(noJWT));
|
|
109
101
|
this.lastError = '';
|
|
110
102
|
return response;
|
|
111
103
|
} catch (error) {
|