ssi-security-commons 0.16.0 → 0.16.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/esm2022/lib/alert/alert.component.mjs +7 -8
- package/esm2022/lib/services/auth-interceptor.service.mjs +37 -37
- package/esm2022/lib/services/crypto.service.mjs +7 -1
- package/esm2022/lib/services/jwt.service.mjs +29 -0
- package/esm2022/lib/services/messages.service.mjs +1 -1
- package/esm2022/lib/services/session.service.mjs +111 -51
- package/esm2022/lib/shared/constants.mjs +5 -0
- package/esm2022/lib/ssi-security-commons.module.mjs +6 -3
- package/esm2022/lib/user.model.mjs +1 -1
- package/esm2022/public-api.mjs +3 -1
- package/fesm2022/ssi-security-commons.mjs +193 -99
- package/fesm2022/ssi-security-commons.mjs.map +1 -1
- package/lib/alert/alert.component.d.ts +1 -1
- package/lib/services/auth-interceptor.service.d.ts +2 -1
- package/lib/services/jwt.service.d.ts +6 -0
- package/lib/services/session.service.d.ts +14 -6
- package/lib/shared/constants.d.ts +4 -0
- package/lib/user.model.d.ts +13 -1
- package/package.json +1 -1
- package/public-api.d.ts +2 -0
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
2
|
import { Injectable, Component, Inject, NgModule } from '@angular/core';
|
|
3
|
-
import * as
|
|
4
|
-
import { MatDialogModule } from '@angular/material/dialog';
|
|
3
|
+
import * as i1 from '@angular/material/dialog';
|
|
4
|
+
import { MAT_DIALOG_DATA, MatDialogModule } from '@angular/material/dialog';
|
|
5
5
|
import * as i2$1 from '@angular/material/snack-bar';
|
|
6
6
|
import { MatSnackBarModule } from '@angular/material/snack-bar';
|
|
7
7
|
import * as CryptoJS from 'crypto-js';
|
|
8
|
-
import * as
|
|
9
|
-
import { MAT_LEGACY_DIALOG_DATA } from '@angular/material/legacy-dialog';
|
|
10
|
-
import * as i3 from '@angular/material/button';
|
|
8
|
+
import * as i2 from '@angular/material/button';
|
|
11
9
|
import { MatButtonModule } from '@angular/material/button';
|
|
12
10
|
import * as i1$1 from '@angular/common/http';
|
|
13
11
|
import { HttpHeaders, HttpResponse, HttpErrorResponse } from '@angular/common/http';
|
|
@@ -48,9 +46,15 @@ class CryptoService {
|
|
|
48
46
|
this.key = CryptoJS.lib.WordArray.create(hash.words.slice(0, 16 / 4));
|
|
49
47
|
}
|
|
50
48
|
encrypt(text) {
|
|
49
|
+
if (!text) {
|
|
50
|
+
return '';
|
|
51
|
+
}
|
|
51
52
|
return CryptoJS.AES.encrypt(text, this.key, this.configuration).toString();
|
|
52
53
|
}
|
|
53
54
|
decrypt(text) {
|
|
55
|
+
if (!text) {
|
|
56
|
+
return '';
|
|
57
|
+
}
|
|
54
58
|
return CryptoJS.AES.decrypt(text, this.key, this.configuration).toString(CryptoJS.enc.Utf8);
|
|
55
59
|
}
|
|
56
60
|
encryptWithSecret(text, secret) {
|
|
@@ -81,27 +85,62 @@ class AlertComponent {
|
|
|
81
85
|
onCancel() {
|
|
82
86
|
this.dialogRef.close(null);
|
|
83
87
|
}
|
|
84
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.0.3", ngImport: i0, type: AlertComponent, deps: [{ token: i1.
|
|
85
|
-
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.0.3", type: AlertComponent, selector: "lib-app-alert", ngImport: i0, template: "<h1 mat-dialog-title>{{data.title?data.title:'Alert'}}</h1>\n<div mat-dialog-content class=\"alert-min-width\">\n <div>\n {{data.message}}\n </div>\n</div>\n<div mat-dialog-actions align=\"end\">\n <button *ngIf=\"data?.cancelText\" mat-button (click)=\"onCancel()\">{{data.cancelText ? data.cancelText : 'Cancel'}}</button>\n <button mat-button color=\"primary\" (click)=\"onConfirm()\">{{data.okText ? data.okText : 'OK'}}</button>\n</div>\n", styles: [""], dependencies: [{ kind: "directive", type:
|
|
88
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.0.3", ngImport: i0, type: AlertComponent, deps: [{ token: i1.MatDialogRef }, { token: MAT_DIALOG_DATA }], target: i0.ɵɵFactoryTarget.Component }); }
|
|
89
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.0.3", type: AlertComponent, selector: "lib-app-alert", ngImport: i0, template: "<h1 mat-dialog-title>{{data.title?data.title:'Alert'}}</h1>\n<div mat-dialog-content class=\"alert-min-width\">\n <div>\n {{data.message}}\n </div>\n</div>\n<div mat-dialog-actions align=\"end\">\n <button *ngIf=\"data?.cancelText\" mat-button (click)=\"onCancel()\">{{data.cancelText ? data.cancelText : 'Cancel'}}</button>\n <button mat-button color=\"primary\" (click)=\"onConfirm()\">{{data.okText ? data.okText : 'OK'}}</button>\n</div>\n", styles: [""], dependencies: [{ kind: "directive", type: i1.MatDialogTitle, selector: "[mat-dialog-title], [matDialogTitle]", inputs: ["id"], exportAs: ["matDialogTitle"] }, { kind: "directive", type: i1.MatDialogContent, selector: "[mat-dialog-content], mat-dialog-content, [matDialogContent]" }, { kind: "directive", type: i1.MatDialogActions, selector: "[mat-dialog-actions], mat-dialog-actions, [matDialogActions]", inputs: ["align"] }, { kind: "component", type: i2.MatButton, selector: " button[mat-button], button[mat-raised-button], button[mat-flat-button], button[mat-stroked-button] ", inputs: ["disabled", "disableRipple", "color"], exportAs: ["matButton"] }] }); }
|
|
86
90
|
}
|
|
87
91
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.0.3", ngImport: i0, type: AlertComponent, decorators: [{
|
|
88
92
|
type: Component,
|
|
89
93
|
args: [{ selector: 'lib-app-alert', template: "<h1 mat-dialog-title>{{data.title?data.title:'Alert'}}</h1>\n<div mat-dialog-content class=\"alert-min-width\">\n <div>\n {{data.message}}\n </div>\n</div>\n<div mat-dialog-actions align=\"end\">\n <button *ngIf=\"data?.cancelText\" mat-button (click)=\"onCancel()\">{{data.cancelText ? data.cancelText : 'Cancel'}}</button>\n <button mat-button color=\"primary\" (click)=\"onConfirm()\">{{data.okText ? data.okText : 'OK'}}</button>\n</div>\n" }]
|
|
90
|
-
}], ctorParameters: function () { return [{ type: i1.
|
|
94
|
+
}], ctorParameters: function () { return [{ type: i1.MatDialogRef }, { type: undefined, decorators: [{
|
|
91
95
|
type: Inject,
|
|
92
|
-
args: [
|
|
96
|
+
args: [MAT_DIALOG_DATA]
|
|
93
97
|
}] }]; } });
|
|
94
98
|
|
|
99
|
+
const TOKEN = 'TOKEN';
|
|
100
|
+
const REFRESH_TOKEN = 'REFRESH_TOKEN';
|
|
101
|
+
const USERDATA = 'USERDATA';
|
|
102
|
+
const LANG = 'LANG';
|
|
103
|
+
|
|
104
|
+
/* eslint-disable */
|
|
105
|
+
class JwtService {
|
|
106
|
+
decodeToken(token) {
|
|
107
|
+
const _decodeToken = (token) => {
|
|
108
|
+
try {
|
|
109
|
+
return JSON.parse(atob(token));
|
|
110
|
+
}
|
|
111
|
+
catch {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
return token
|
|
116
|
+
.split('.')
|
|
117
|
+
.map(token => _decodeToken(token))
|
|
118
|
+
.reduce((acc, curr) => {
|
|
119
|
+
if (!!curr)
|
|
120
|
+
acc = { ...acc, ...curr };
|
|
121
|
+
return acc;
|
|
122
|
+
}, Object.create(null));
|
|
123
|
+
}
|
|
124
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.0.3", ngImport: i0, type: JwtService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
125
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.0.3", ngImport: i0, type: JwtService }); }
|
|
126
|
+
}
|
|
127
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.0.3", ngImport: i0, type: JwtService, decorators: [{
|
|
128
|
+
type: Injectable
|
|
129
|
+
}] });
|
|
130
|
+
|
|
95
131
|
/* eslint-disable max-lines-per-function */
|
|
96
132
|
/* eslint-disable arrow-body-style */
|
|
97
133
|
/* eslint-disable @typescript-eslint/naming-convention */
|
|
98
134
|
class SessionService {
|
|
99
|
-
constructor(http, environment) {
|
|
135
|
+
constructor(http, environment, cryptoService, jwtService) {
|
|
100
136
|
this.http = http;
|
|
137
|
+
this.cryptoService = cryptoService;
|
|
138
|
+
this.jwtService = jwtService;
|
|
101
139
|
this.loginUrl = 'http://localhost:4200/login';
|
|
102
140
|
this.endPoint = environment.endPoint;
|
|
103
141
|
this.applicationId = environment.applicationId;
|
|
104
142
|
const urlHub = environment.sessionHub;
|
|
143
|
+
this.environment = environment;
|
|
105
144
|
console.log(urlHub);
|
|
106
145
|
this.storage = new CrossStorageClient(urlHub, { timeout: 5000 });
|
|
107
146
|
}
|
|
@@ -110,18 +149,32 @@ class SessionService {
|
|
|
110
149
|
let data;
|
|
111
150
|
let token;
|
|
112
151
|
let refreshToken;
|
|
152
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
113
153
|
const self = this;
|
|
114
154
|
this.storage.onConnect().then(function () {
|
|
115
|
-
|
|
155
|
+
if (self.environment.production) {
|
|
156
|
+
const u = self.cryptoService.encrypt(USERDATA);
|
|
157
|
+
const t = self.cryptoService.encrypt(TOKEN);
|
|
158
|
+
const r = self.cryptoService.encrypt(REFRESH_TOKEN);
|
|
159
|
+
return self.storage.get(u, t, r);
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
return self.storage.get(USERDATA, TOKEN, REFRESH_TOKEN);
|
|
163
|
+
}
|
|
116
164
|
}).then(function (res) {
|
|
117
165
|
console.log(res);
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
166
|
+
if (self.environment.production) {
|
|
167
|
+
data = self.cryptoService.decrypt(res[0]);
|
|
168
|
+
token = self.cryptoService.decrypt(res[1]);
|
|
169
|
+
refreshToken = self.cryptoService.decrypt(res[2]);
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
data = res[0];
|
|
173
|
+
token = res[1];
|
|
174
|
+
refreshToken = res[2];
|
|
175
|
+
}
|
|
121
176
|
if (data && token && refreshToken) {
|
|
122
|
-
const user = JSON.parse(data);
|
|
123
177
|
self.saveCredentials(token, refreshToken);
|
|
124
|
-
self.saveUserData(user);
|
|
125
178
|
self.checkAppPermissions().then((res1) => {
|
|
126
179
|
console.log(res1);
|
|
127
180
|
resolve('OK');
|
|
@@ -153,6 +206,20 @@ class SessionService {
|
|
|
153
206
|
});
|
|
154
207
|
return promise;
|
|
155
208
|
}
|
|
209
|
+
buildUserdataFromToken(token) {
|
|
210
|
+
const tokenData = this.jwtService.decodeToken(token);
|
|
211
|
+
const userData = {
|
|
212
|
+
givenName: tokenData.given_name,
|
|
213
|
+
familyName: tokenData.family_name,
|
|
214
|
+
name: tokenData.name,
|
|
215
|
+
roles: tokenData.realm_access.roles,
|
|
216
|
+
userId: tokenData.sub,
|
|
217
|
+
username: tokenData.preferred_username,
|
|
218
|
+
email: tokenData.email,
|
|
219
|
+
emailVerified: tokenData.email_verified
|
|
220
|
+
};
|
|
221
|
+
return userData;
|
|
222
|
+
}
|
|
156
223
|
async reviewSessionData() {
|
|
157
224
|
const value = await this.checkSessionData();
|
|
158
225
|
console.log(`async result: ${value}`);
|
|
@@ -170,20 +237,14 @@ class SessionService {
|
|
|
170
237
|
}
|
|
171
238
|
setRefreshToken(refreshToken) {
|
|
172
239
|
this.refreshToken = refreshToken;
|
|
173
|
-
|
|
174
|
-
this.storage.onConnect().then(() => {
|
|
175
|
-
return this.storage.set('REFRESH_TOKEN', refreshToken);
|
|
176
|
-
});
|
|
240
|
+
this.saveStorageData(REFRESH_TOKEN, refreshToken);
|
|
177
241
|
}
|
|
178
242
|
getRefreshToken() {
|
|
179
243
|
return this.refreshToken;
|
|
180
244
|
}
|
|
181
245
|
setToken(token) {
|
|
182
246
|
this.token = token;
|
|
183
|
-
|
|
184
|
-
this.storage.onConnect().then(() => {
|
|
185
|
-
return this.storage.set('TOKEN', token);
|
|
186
|
-
});
|
|
247
|
+
this.saveStorageData(TOKEN, token);
|
|
187
248
|
}
|
|
188
249
|
getToken() {
|
|
189
250
|
return this.token;
|
|
@@ -191,44 +252,30 @@ class SessionService {
|
|
|
191
252
|
destroyCredentials() {
|
|
192
253
|
this.token = undefined;
|
|
193
254
|
this.refreshToken = undefined;
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
this.storage.onConnect().then(() => {
|
|
197
|
-
return this.storage.del('TOKEN', 'REFRESH_TOKEN');
|
|
198
|
-
});
|
|
255
|
+
this.deleteStorageData(TOKEN);
|
|
256
|
+
this.deleteStorageData(REFRESH_TOKEN);
|
|
199
257
|
}
|
|
200
258
|
destroyUserData() {
|
|
201
259
|
this.userdata = undefined;
|
|
202
|
-
|
|
203
|
-
this.storage.onConnect().then(() => {
|
|
204
|
-
return this.storage.del('USERDATA');
|
|
205
|
-
});
|
|
260
|
+
this.deleteStorageData(USERDATA);
|
|
206
261
|
}
|
|
207
262
|
saveCredentials(token, refreshToken) {
|
|
208
263
|
this.token = token;
|
|
209
264
|
this.refreshToken = refreshToken;
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
this.
|
|
213
|
-
return this.storage.set('TOKEN', token);
|
|
214
|
-
});
|
|
215
|
-
this.storage.onConnect().then(() => {
|
|
216
|
-
return this.storage.set('REFRESH_TOKEN', refreshToken);
|
|
217
|
-
});
|
|
265
|
+
this.saveStorageData(TOKEN, token);
|
|
266
|
+
this.saveStorageData(REFRESH_TOKEN, refreshToken);
|
|
267
|
+
this.saveUserData(this.buildUserdataFromToken(token));
|
|
218
268
|
}
|
|
219
|
-
saveUserData(
|
|
220
|
-
this.userdata =
|
|
221
|
-
|
|
222
|
-
this.storage.onConnect().then(() => {
|
|
223
|
-
return this.storage.set('USERDATA', JSON.stringify(this.userdata));
|
|
224
|
-
});
|
|
269
|
+
saveUserData(userData) {
|
|
270
|
+
this.userdata = userData;
|
|
271
|
+
this.saveStorageData(USERDATA, JSON.stringify(userData));
|
|
225
272
|
}
|
|
226
273
|
isLoggedIn() {
|
|
227
274
|
return !!this.userdata;
|
|
228
275
|
}
|
|
229
276
|
logout() {
|
|
230
277
|
return new Promise((resolve, reject) => {
|
|
231
|
-
this.logoutApi(
|
|
278
|
+
this.logoutApi().subscribe(res => {
|
|
232
279
|
console.log(res);
|
|
233
280
|
this.destroyCredentials();
|
|
234
281
|
this.destroyUserData();
|
|
@@ -244,10 +291,10 @@ class SessionService {
|
|
|
244
291
|
}
|
|
245
292
|
getNewToken(refreshToken) {
|
|
246
293
|
console.log('getNewToken');
|
|
247
|
-
const
|
|
248
|
-
|
|
249
|
-
}
|
|
250
|
-
|
|
294
|
+
const body = 'grant_type=refresh_token' + '&refresh_token=' + refreshToken + '&client_id=' + this.environment.authClient;
|
|
295
|
+
const headers = new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded');
|
|
296
|
+
return this.http.post(`${this.environment.authEndPoint}/realms/${this.environment.authRealm}/protocol/openid-connect/token`, body, { headers })
|
|
297
|
+
.pipe(map(res => res));
|
|
251
298
|
}
|
|
252
299
|
getLoginUrl() {
|
|
253
300
|
return this.http.get(this.endPoint + '/auth/login/url')
|
|
@@ -257,8 +304,10 @@ class SessionService {
|
|
|
257
304
|
return this.http.get(this.endPoint + '/auth/home/url')
|
|
258
305
|
.pipe(map(res => res));
|
|
259
306
|
}
|
|
260
|
-
logoutApi(
|
|
261
|
-
|
|
307
|
+
logoutApi() {
|
|
308
|
+
const body = 'refresh_token=' + this.refreshToken + '&client_id=' + this.environment.authClient;
|
|
309
|
+
const headers = new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded');
|
|
310
|
+
return this.http.post(`${this.environment.authEndPoint}/realms/${this.environment.authRealm}/protocol/openid-connect/logout`, body, { headers })
|
|
262
311
|
.pipe(map(res => res));
|
|
263
312
|
}
|
|
264
313
|
goToLogin() {
|
|
@@ -271,9 +320,22 @@ class SessionService {
|
|
|
271
320
|
});
|
|
272
321
|
}
|
|
273
322
|
loadSessionData() {
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
323
|
+
let data;
|
|
324
|
+
let token;
|
|
325
|
+
let refreshToken;
|
|
326
|
+
if (this.environment.production) {
|
|
327
|
+
const u = this.cryptoService.encrypt(USERDATA);
|
|
328
|
+
const t = this.cryptoService.encrypt(TOKEN);
|
|
329
|
+
const r = this.cryptoService.encrypt(REFRESH_TOKEN);
|
|
330
|
+
data = window.localStorage.getItem(u);
|
|
331
|
+
token = window.localStorage.getItem(t);
|
|
332
|
+
refreshToken = window.localStorage.getItem(r);
|
|
333
|
+
}
|
|
334
|
+
else {
|
|
335
|
+
data = window.localStorage.getItem(USERDATA);
|
|
336
|
+
token = window.localStorage.getItem(TOKEN);
|
|
337
|
+
refreshToken = window.localStorage.getItem(REFRESH_TOKEN);
|
|
338
|
+
}
|
|
277
339
|
if (data && token && refreshToken) {
|
|
278
340
|
const user = JSON.parse(data);
|
|
279
341
|
this.setTokens(token, refreshToken);
|
|
@@ -334,7 +396,38 @@ class SessionService {
|
|
|
334
396
|
return this.http.post(this.endPoint + '/auth/exception/log', param, { headers })
|
|
335
397
|
.pipe(map(res => res));
|
|
336
398
|
}
|
|
337
|
-
|
|
399
|
+
saveStorageData(key, value) {
|
|
400
|
+
if (this.environment.production) {
|
|
401
|
+
const k = this.cryptoService.encrypt(key);
|
|
402
|
+
const v = this.cryptoService.encrypt(value);
|
|
403
|
+
window.localStorage.setItem(k, v);
|
|
404
|
+
this.storage.onConnect().then(() => {
|
|
405
|
+
return this.storage.set(k, v);
|
|
406
|
+
});
|
|
407
|
+
}
|
|
408
|
+
else {
|
|
409
|
+
window.localStorage.setItem(key, value);
|
|
410
|
+
this.storage.onConnect().then(() => {
|
|
411
|
+
return this.storage.set(key, value);
|
|
412
|
+
});
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
deleteStorageData(key) {
|
|
416
|
+
if (this.environment.production) {
|
|
417
|
+
const k = this.cryptoService.encrypt(key);
|
|
418
|
+
window.localStorage.removeItem(k);
|
|
419
|
+
this.storage.onConnect().then(() => {
|
|
420
|
+
return this.storage.del(k);
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
else {
|
|
424
|
+
window.localStorage.removeItem(key);
|
|
425
|
+
this.storage.onConnect().then(() => {
|
|
426
|
+
return this.storage.del(key);
|
|
427
|
+
});
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.0.3", ngImport: i0, type: SessionService, deps: [{ token: i1$1.HttpClient }, { token: 'environment' }, { token: CryptoService }, { token: JwtService }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
338
431
|
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.0.3", ngImport: i0, type: SessionService }); }
|
|
339
432
|
}
|
|
340
433
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.0.3", ngImport: i0, type: SessionService, decorators: [{
|
|
@@ -342,7 +435,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.0.3", ngImpor
|
|
|
342
435
|
}], ctorParameters: function () { return [{ type: i1$1.HttpClient }, { type: undefined, decorators: [{
|
|
343
436
|
type: Inject,
|
|
344
437
|
args: ['environment']
|
|
345
|
-
}] }]; } });
|
|
438
|
+
}] }, { type: CryptoService }, { type: JwtService }]; } });
|
|
346
439
|
|
|
347
440
|
class MessagesService {
|
|
348
441
|
constructor(auth,
|
|
@@ -536,12 +629,12 @@ class MessagesService {
|
|
|
536
629
|
}
|
|
537
630
|
});
|
|
538
631
|
}
|
|
539
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.0.3", ngImport: i0, type: MessagesService, deps: [{ token: SessionService }, { token: i2$1.MatSnackBar }, { token:
|
|
632
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.0.3", ngImport: i0, type: MessagesService, deps: [{ token: SessionService }, { token: i2$1.MatSnackBar }, { token: i1.MatDialog }, { token: 'environment' }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
540
633
|
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.0.3", ngImport: i0, type: MessagesService }); }
|
|
541
634
|
}
|
|
542
635
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.0.3", ngImport: i0, type: MessagesService, decorators: [{
|
|
543
636
|
type: Injectable
|
|
544
|
-
}], ctorParameters: function () { return [{ type: SessionService }, { type: i2$1.MatSnackBar }, { type:
|
|
637
|
+
}], ctorParameters: function () { return [{ type: SessionService }, { type: i2$1.MatSnackBar }, { type: i1.MatDialog }, { type: undefined, decorators: [{
|
|
545
638
|
type: Inject,
|
|
546
639
|
args: ['environment']
|
|
547
640
|
}] }]; } });
|
|
@@ -561,7 +654,8 @@ class SsiSecurityCommonsModule {
|
|
|
561
654
|
static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "16.0.3", ngImport: i0, type: SsiSecurityCommonsModule, providers: [
|
|
562
655
|
MessagesService,
|
|
563
656
|
SessionService,
|
|
564
|
-
CryptoService
|
|
657
|
+
CryptoService,
|
|
658
|
+
JwtService
|
|
565
659
|
], imports: [MatSnackBarModule,
|
|
566
660
|
MatDialogModule,
|
|
567
661
|
MatButtonModule] }); }
|
|
@@ -584,22 +678,31 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.0.3", ngImpor
|
|
|
584
678
|
providers: [
|
|
585
679
|
MessagesService,
|
|
586
680
|
SessionService,
|
|
587
|
-
CryptoService
|
|
681
|
+
CryptoService,
|
|
682
|
+
JwtService
|
|
588
683
|
]
|
|
589
684
|
}]
|
|
590
685
|
}] });
|
|
591
686
|
|
|
592
687
|
/* eslint-disable */
|
|
593
688
|
class AuthInterceptor {
|
|
594
|
-
constructor(cryptoService) {
|
|
689
|
+
constructor(cryptoService, environment) {
|
|
595
690
|
this.cryptoService = cryptoService;
|
|
596
691
|
console.log('AuthInterceptor constructor');
|
|
692
|
+
this.environment = environment;
|
|
597
693
|
}
|
|
598
694
|
intercept(request, next) {
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
695
|
+
let token;
|
|
696
|
+
if (this.environment.production) {
|
|
697
|
+
const t = this.cryptoService.encrypt(TOKEN);
|
|
698
|
+
const to = window.localStorage.getItem(t);
|
|
699
|
+
if (to) {
|
|
700
|
+
token = this.cryptoService.decrypt(to);
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
else {
|
|
704
|
+
token = window.localStorage.getItem(TOKEN);
|
|
705
|
+
}
|
|
603
706
|
let encrypt = request.headers.get('encrypted');
|
|
604
707
|
if (encrypt && encrypt === 'true') {
|
|
605
708
|
let body = request.body;
|
|
@@ -618,14 +721,23 @@ class AuthInterceptor {
|
|
|
618
721
|
}
|
|
619
722
|
});
|
|
620
723
|
}
|
|
724
|
+
const l = window.localStorage.getItem(LANG);
|
|
725
|
+
if (l && request.url.indexOf(this.environment.authEndPoint) < 0) {
|
|
726
|
+
request = request.clone({
|
|
727
|
+
headers: request.headers.append('Language', l)
|
|
728
|
+
});
|
|
729
|
+
}
|
|
621
730
|
return next.handle(request);
|
|
622
731
|
}
|
|
623
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.0.3", ngImport: i0, type: AuthInterceptor, deps: [{ token: CryptoService }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
732
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.0.3", ngImport: i0, type: AuthInterceptor, deps: [{ token: CryptoService }, { token: 'environment' }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
624
733
|
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.0.3", ngImport: i0, type: AuthInterceptor }); }
|
|
625
734
|
}
|
|
626
735
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.0.3", ngImport: i0, type: AuthInterceptor, decorators: [{
|
|
627
736
|
type: Injectable
|
|
628
|
-
}], ctorParameters: function () { return [{ type: CryptoService }
|
|
737
|
+
}], ctorParameters: function () { return [{ type: CryptoService }, { type: undefined, decorators: [{
|
|
738
|
+
type: Inject,
|
|
739
|
+
args: ['environment']
|
|
740
|
+
}] }]; } });
|
|
629
741
|
class ResponseInterceptor {
|
|
630
742
|
constructor(injector, router, cryptoService, sessionService) {
|
|
631
743
|
this.injector = injector;
|
|
@@ -634,7 +746,6 @@ class ResponseInterceptor {
|
|
|
634
746
|
this.sessionService = sessionService;
|
|
635
747
|
this.isRefreshing = false;
|
|
636
748
|
this.refreshTokenSubject = new BehaviorSubject(null);
|
|
637
|
-
//console.log('ResponseInterceptor constructor');
|
|
638
749
|
setTimeout(() => {
|
|
639
750
|
this.messages = this.injector.get(MessagesService);
|
|
640
751
|
});
|
|
@@ -642,7 +753,6 @@ class ResponseInterceptor {
|
|
|
642
753
|
intercept(request, next) {
|
|
643
754
|
return next.handle(request).pipe(map((event) => {
|
|
644
755
|
if (event instanceof HttpResponse) {
|
|
645
|
-
//console.log(request.headers.get('encrypted'));
|
|
646
756
|
let encrypt = request.headers.get('encrypted');
|
|
647
757
|
if (encrypt && encrypt === 'true' && event.body.encrypted) {
|
|
648
758
|
event = event.clone({ body: this.decryptBody(event.body) });
|
|
@@ -653,34 +763,22 @@ class ResponseInterceptor {
|
|
|
653
763
|
if (error instanceof HttpErrorResponse) {
|
|
654
764
|
console.error(error);
|
|
655
765
|
let nerror = error;
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
nerror = new HttpErrorResponse({
|
|
659
|
-
error: this.decryptBody(error.error),
|
|
660
|
-
headers: error.headers,
|
|
661
|
-
status: error.status,
|
|
662
|
-
statusText: error.statusText,
|
|
663
|
-
url: error.url || request.urlWithParams || undefined,
|
|
664
|
-
});
|
|
665
|
-
}*/
|
|
666
|
-
if (nerror.status === 401) {
|
|
667
|
-
console.log(this.router.url);
|
|
668
|
-
if (this.router.url != '/login' && this.router.url.indexOf('/login') < 0) {
|
|
669
|
-
console.log('401--->' + request.url);
|
|
766
|
+
if (this.router.url != '/login' && this.router.url.indexOf('/login') < 0) {
|
|
767
|
+
if (nerror.status === 401) {
|
|
670
768
|
return this.handle401Error(request, next);
|
|
671
769
|
}
|
|
672
770
|
else {
|
|
673
|
-
|
|
771
|
+
let skipError = request.headers.get('skipError');
|
|
772
|
+
if (skipError && skipError === 'true') {
|
|
773
|
+
return throwError(nerror);
|
|
774
|
+
}
|
|
775
|
+
else {
|
|
776
|
+
this.messages?.showErrorMessage(nerror, request);
|
|
777
|
+
}
|
|
674
778
|
}
|
|
675
779
|
}
|
|
676
780
|
else {
|
|
677
|
-
|
|
678
|
-
if (skipError && skipError === 'true') {
|
|
679
|
-
return throwError(nerror);
|
|
680
|
-
}
|
|
681
|
-
else {
|
|
682
|
-
this.messages?.showErrorMessage(nerror, request);
|
|
683
|
-
}
|
|
781
|
+
return throwError(nerror);
|
|
684
782
|
}
|
|
685
783
|
}
|
|
686
784
|
}));
|
|
@@ -691,13 +789,10 @@ class ResponseInterceptor {
|
|
|
691
789
|
return JSON.parse(strJson);
|
|
692
790
|
}
|
|
693
791
|
handle401Error(request, next) {
|
|
694
|
-
//console.log('handle401Error');
|
|
695
|
-
//console.log(this.isRefreshing);
|
|
696
792
|
if (!this.isRefreshing) {
|
|
697
793
|
this.isRefreshing = true;
|
|
698
794
|
this.refreshTokenSubject.next(null);
|
|
699
795
|
const refreshToken = this.sessionService.getRefreshToken();
|
|
700
|
-
//console.log(refreshToken);
|
|
701
796
|
if (refreshToken) {
|
|
702
797
|
return this.sessionService.getNewToken(refreshToken).pipe(switchMap((res) => {
|
|
703
798
|
console.log('refresh token response');
|
|
@@ -710,7 +805,6 @@ class ResponseInterceptor {
|
|
|
710
805
|
}), catchError((err) => {
|
|
711
806
|
this.isRefreshing = false;
|
|
712
807
|
this.sessionService.logout();
|
|
713
|
-
//this.router.navigate(['/login']);
|
|
714
808
|
this.goToLogin();
|
|
715
809
|
return throwError(err);
|
|
716
810
|
}));
|
|
@@ -750,5 +844,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.0.3", ngImpor
|
|
|
750
844
|
* Generated bundle index. Do not edit.
|
|
751
845
|
*/
|
|
752
846
|
|
|
753
|
-
export { AuthInterceptor, CryptoService, MessagesService, ResponseInterceptor, SessionService, SsiSecurityCommonsComponent, SsiSecurityCommonsModule, SsiSecurityCommonsService };
|
|
847
|
+
export { AuthInterceptor, CryptoService, JwtService, LANG, MessagesService, REFRESH_TOKEN, ResponseInterceptor, SessionService, SsiSecurityCommonsComponent, SsiSecurityCommonsModule, SsiSecurityCommonsService, TOKEN, USERDATA };
|
|
754
848
|
//# sourceMappingURL=ssi-security-commons.mjs.map
|