ssi-security-commons 0.0.21 → 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/{esm2020 → esm2022}/lib/alert/alert.component.mjs +5 -5
- package/esm2022/lib/services/auth-interceptor.service.mjs +162 -0
- package/esm2022/lib/services/crypto.service.mjs +41 -0
- package/esm2022/lib/services/jwt.service.mjs +29 -0
- package/{esm2020 → esm2022}/lib/services/messages.service.mjs +4 -4
- package/esm2022/lib/services/session.service.mjs +318 -0
- package/esm2022/lib/shared/constants.mjs +5 -0
- package/esm2022/lib/ssi-security-commons.component.mjs +13 -0
- package/esm2022/lib/ssi-security-commons.module.mjs +56 -0
- package/{esm2020 → esm2022}/lib/ssi-security-commons.service.mjs +4 -4
- package/{esm2020 → esm2022}/lib/user.model.mjs +1 -1
- package/esm2022/public-api.mjs +14 -0
- package/{fesm2020 → fesm2022}/ssi-security-commons.mjs +224 -132
- package/fesm2022/ssi-security-commons.mjs.map +1 -0
- 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/ssi-security-commons.component.d.ts +1 -1
- package/lib/user.model.d.ts +13 -1
- package/package.json +10 -16
- package/public-api.d.ts +2 -0
- package/esm2020/lib/services/auth-interceptor.service.mjs +0 -162
- package/esm2020/lib/services/crypto.service.mjs +0 -35
- package/esm2020/lib/services/session.service.mjs +0 -258
- package/esm2020/lib/ssi-security-commons.component.mjs +0 -17
- package/esm2020/lib/ssi-security-commons.module.mjs +0 -55
- package/esm2020/public-api.mjs +0 -12
- package/fesm2015/ssi-security-commons.mjs +0 -768
- package/fesm2015/ssi-security-commons.mjs.map +0 -1
- package/fesm2020/ssi-security-commons.mjs.map +0 -1
- /package/{esm2020 → esm2022}/ssi-security-commons.mjs +0 -0
- /package/{ssi-security-commons.d.ts → index.d.ts} +0 -0
|
@@ -15,10 +15,10 @@ import { BehaviorSubject, throwError } from 'rxjs';
|
|
|
15
15
|
import * as i2$2 from '@angular/router';
|
|
16
16
|
|
|
17
17
|
class SsiSecurityCommonsService {
|
|
18
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.0.3", ngImport: i0, type: SsiSecurityCommonsService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
19
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.0.3", ngImport: i0, type: SsiSecurityCommonsService, providedIn: 'root' }); }
|
|
18
20
|
}
|
|
19
|
-
|
|
20
|
-
SsiSecurityCommonsService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.3.3", ngImport: i0, type: SsiSecurityCommonsService, providedIn: 'root' });
|
|
21
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.3", ngImport: i0, type: SsiSecurityCommonsService, decorators: [{
|
|
21
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.0.3", ngImport: i0, type: SsiSecurityCommonsService, decorators: [{
|
|
22
22
|
type: Injectable,
|
|
23
23
|
args: [{
|
|
24
24
|
providedIn: 'root'
|
|
@@ -26,18 +26,14 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.3", ngImpor
|
|
|
26
26
|
}] });
|
|
27
27
|
|
|
28
28
|
class SsiSecurityCommonsComponent {
|
|
29
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.0.3", ngImport: i0, type: SsiSecurityCommonsComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
|
|
30
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.0.3", type: SsiSecurityCommonsComponent, selector: "lib-ssi-security-commons", ngImport: i0, template: ` <p>ssi-security-commons works!</p>
|
|
31
|
+
`, isInline: true }); }
|
|
29
32
|
}
|
|
30
|
-
|
|
31
|
-
SsiSecurityCommonsComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.3.3", type: SsiSecurityCommonsComponent, selector: "lib-ssi-security-commons", ngImport: i0, template: ` <p>ssi-security-commons works!</p>
|
|
32
|
-
`, isInline: true });
|
|
33
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.3", ngImport: i0, type: SsiSecurityCommonsComponent, decorators: [{
|
|
33
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.0.3", ngImport: i0, type: SsiSecurityCommonsComponent, decorators: [{
|
|
34
34
|
type: Component,
|
|
35
|
-
args: [{
|
|
36
|
-
|
|
37
|
-
template: ` <p>ssi-security-commons works!</p>
|
|
38
|
-
`,
|
|
39
|
-
styles: []
|
|
40
|
-
}]
|
|
35
|
+
args: [{ selector: 'lib-ssi-security-commons', template: ` <p>ssi-security-commons works!</p>
|
|
36
|
+
` }]
|
|
41
37
|
}] });
|
|
42
38
|
|
|
43
39
|
class CryptoService {
|
|
@@ -50,9 +46,15 @@ class CryptoService {
|
|
|
50
46
|
this.key = CryptoJS.lib.WordArray.create(hash.words.slice(0, 16 / 4));
|
|
51
47
|
}
|
|
52
48
|
encrypt(text) {
|
|
49
|
+
if (!text) {
|
|
50
|
+
return '';
|
|
51
|
+
}
|
|
53
52
|
return CryptoJS.AES.encrypt(text, this.key, this.configuration).toString();
|
|
54
53
|
}
|
|
55
54
|
decrypt(text) {
|
|
55
|
+
if (!text) {
|
|
56
|
+
return '';
|
|
57
|
+
}
|
|
56
58
|
return CryptoJS.AES.decrypt(text, this.key, this.configuration).toString(CryptoJS.enc.Utf8);
|
|
57
59
|
}
|
|
58
60
|
encryptWithSecret(text, secret) {
|
|
@@ -65,10 +67,10 @@ class CryptoService {
|
|
|
65
67
|
const key = CryptoJS.lib.WordArray.create(hash.words.slice(0, 16 / 4));
|
|
66
68
|
return CryptoJS.AES.decrypt(text, key, this.configuration).toString(CryptoJS.enc.Utf8);
|
|
67
69
|
}
|
|
70
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.0.3", ngImport: i0, type: CryptoService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
71
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.0.3", ngImport: i0, type: CryptoService }); }
|
|
68
72
|
}
|
|
69
|
-
|
|
70
|
-
CryptoService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.3.3", ngImport: i0, type: CryptoService });
|
|
71
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.3", ngImport: i0, type: CryptoService, decorators: [{
|
|
73
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.0.3", ngImport: i0, type: CryptoService, decorators: [{
|
|
72
74
|
type: Injectable
|
|
73
75
|
}], ctorParameters: function () { return []; } });
|
|
74
76
|
|
|
@@ -83,25 +85,62 @@ class AlertComponent {
|
|
|
83
85
|
onCancel() {
|
|
84
86
|
this.dialogRef.close(null);
|
|
85
87
|
}
|
|
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
|
-
|
|
88
|
-
AlertComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.3.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: [""], components: [{ type: i2.MatButton, selector: "button[mat-button], button[mat-raised-button], button[mat-icon-button], button[mat-fab], button[mat-mini-fab], button[mat-stroked-button], button[mat-flat-button]", inputs: ["disabled", "disableRipple", "color"], exportAs: ["matButton"] }], directives: [{ type: i1.MatDialogTitle, selector: "[mat-dialog-title], [matDialogTitle]", inputs: ["id"], exportAs: ["matDialogTitle"] }, { type: i1.MatDialogContent, selector: "[mat-dialog-content], mat-dialog-content, [matDialogContent]" }, { type: i1.MatDialogActions, selector: "[mat-dialog-actions], mat-dialog-actions, [matDialogActions]" }] });
|
|
89
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.3", ngImport: i0, type: AlertComponent, decorators: [{
|
|
91
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.0.3", ngImport: i0, type: AlertComponent, decorators: [{
|
|
90
92
|
type: Component,
|
|
91
|
-
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"
|
|
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" }]
|
|
92
94
|
}], ctorParameters: function () { return [{ type: i1.MatDialogRef }, { type: undefined, decorators: [{
|
|
93
95
|
type: Inject,
|
|
94
96
|
args: [MAT_DIALOG_DATA]
|
|
95
97
|
}] }]; } });
|
|
96
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
|
+
|
|
97
131
|
/* eslint-disable max-lines-per-function */
|
|
132
|
+
/* eslint-disable arrow-body-style */
|
|
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,15 +396,46 @@ class SessionService {
|
|
|
334
396
|
return this.http.post(this.endPoint + '/auth/exception/log', param, { headers })
|
|
335
397
|
.pipe(map(res => res));
|
|
336
398
|
}
|
|
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 }); }
|
|
431
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.0.3", ngImport: i0, type: SessionService }); }
|
|
337
432
|
}
|
|
338
|
-
|
|
339
|
-
SessionService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.3.3", ngImport: i0, type: SessionService });
|
|
340
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.3", ngImport: i0, type: SessionService, decorators: [{
|
|
433
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.0.3", ngImport: i0, type: SessionService, decorators: [{
|
|
341
434
|
type: Injectable
|
|
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,10 +629,10 @@ class MessagesService {
|
|
|
536
629
|
}
|
|
537
630
|
});
|
|
538
631
|
}
|
|
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 }); }
|
|
633
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.0.3", ngImport: i0, type: MessagesService }); }
|
|
539
634
|
}
|
|
540
|
-
|
|
541
|
-
MessagesService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.3.3", ngImport: i0, type: MessagesService });
|
|
542
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.3", ngImport: i0, type: MessagesService, decorators: [{
|
|
635
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.0.3", ngImport: i0, type: MessagesService, decorators: [{
|
|
543
636
|
type: Injectable
|
|
544
637
|
}], ctorParameters: function () { return [{ type: SessionService }, { type: i2$1.MatSnackBar }, { type: i1.MatDialog }, { type: undefined, decorators: [{
|
|
545
638
|
type: Inject,
|
|
@@ -553,22 +646,21 @@ class SsiSecurityCommonsModule {
|
|
|
553
646
|
providers: [{ provide: 'environment', useValue: environment }]
|
|
554
647
|
};
|
|
555
648
|
}
|
|
556
|
-
}
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
MatSnackBarModule,
|
|
649
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.0.3", ngImport: i0, type: SsiSecurityCommonsModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
|
|
650
|
+
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "16.0.3", ngImport: i0, type: SsiSecurityCommonsModule, declarations: [SsiSecurityCommonsComponent,
|
|
651
|
+
AlertComponent], imports: [MatSnackBarModule,
|
|
652
|
+
MatDialogModule,
|
|
653
|
+
MatButtonModule], exports: [SsiSecurityCommonsComponent] }); }
|
|
654
|
+
static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "16.0.3", ngImport: i0, type: SsiSecurityCommonsModule, providers: [
|
|
655
|
+
MessagesService,
|
|
656
|
+
SessionService,
|
|
657
|
+
CryptoService,
|
|
658
|
+
JwtService
|
|
659
|
+
], imports: [MatSnackBarModule,
|
|
568
660
|
MatDialogModule,
|
|
569
|
-
MatButtonModule
|
|
570
|
-
|
|
571
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
661
|
+
MatButtonModule] }); }
|
|
662
|
+
}
|
|
663
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.0.3", ngImport: i0, type: SsiSecurityCommonsModule, decorators: [{
|
|
572
664
|
type: NgModule,
|
|
573
665
|
args: [{
|
|
574
666
|
declarations: [
|
|
@@ -586,22 +678,31 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.3", ngImpor
|
|
|
586
678
|
providers: [
|
|
587
679
|
MessagesService,
|
|
588
680
|
SessionService,
|
|
589
|
-
CryptoService
|
|
681
|
+
CryptoService,
|
|
682
|
+
JwtService
|
|
590
683
|
]
|
|
591
684
|
}]
|
|
592
685
|
}] });
|
|
593
686
|
|
|
594
687
|
/* eslint-disable */
|
|
595
688
|
class AuthInterceptor {
|
|
596
|
-
constructor(cryptoService) {
|
|
689
|
+
constructor(cryptoService, environment) {
|
|
597
690
|
this.cryptoService = cryptoService;
|
|
598
691
|
console.log('AuthInterceptor constructor');
|
|
692
|
+
this.environment = environment;
|
|
599
693
|
}
|
|
600
694
|
intercept(request, next) {
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
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
|
+
}
|
|
605
706
|
let encrypt = request.headers.get('encrypted');
|
|
606
707
|
if (encrypt && encrypt === 'true') {
|
|
607
708
|
let body = request.body;
|
|
@@ -620,14 +721,23 @@ class AuthInterceptor {
|
|
|
620
721
|
}
|
|
621
722
|
});
|
|
622
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
|
+
}
|
|
623
730
|
return next.handle(request);
|
|
624
731
|
}
|
|
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 }); }
|
|
733
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.0.3", ngImport: i0, type: AuthInterceptor }); }
|
|
625
734
|
}
|
|
626
|
-
|
|
627
|
-
AuthInterceptor.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.3.3", ngImport: i0, type: AuthInterceptor });
|
|
628
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.3", ngImport: i0, type: AuthInterceptor, decorators: [{
|
|
735
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.0.3", ngImport: i0, type: AuthInterceptor, decorators: [{
|
|
629
736
|
type: Injectable
|
|
630
|
-
}], ctorParameters: function () { return [{ type: CryptoService }
|
|
737
|
+
}], ctorParameters: function () { return [{ type: CryptoService }, { type: undefined, decorators: [{
|
|
738
|
+
type: Inject,
|
|
739
|
+
args: ['environment']
|
|
740
|
+
}] }]; } });
|
|
631
741
|
class ResponseInterceptor {
|
|
632
742
|
constructor(injector, router, cryptoService, sessionService) {
|
|
633
743
|
this.injector = injector;
|
|
@@ -636,7 +746,6 @@ class ResponseInterceptor {
|
|
|
636
746
|
this.sessionService = sessionService;
|
|
637
747
|
this.isRefreshing = false;
|
|
638
748
|
this.refreshTokenSubject = new BehaviorSubject(null);
|
|
639
|
-
//console.log('ResponseInterceptor constructor');
|
|
640
749
|
setTimeout(() => {
|
|
641
750
|
this.messages = this.injector.get(MessagesService);
|
|
642
751
|
});
|
|
@@ -644,7 +753,6 @@ class ResponseInterceptor {
|
|
|
644
753
|
intercept(request, next) {
|
|
645
754
|
return next.handle(request).pipe(map((event) => {
|
|
646
755
|
if (event instanceof HttpResponse) {
|
|
647
|
-
//console.log(request.headers.get('encrypted'));
|
|
648
756
|
let encrypt = request.headers.get('encrypted');
|
|
649
757
|
if (encrypt && encrypt === 'true' && event.body.encrypted) {
|
|
650
758
|
event = event.clone({ body: this.decryptBody(event.body) });
|
|
@@ -655,34 +763,22 @@ class ResponseInterceptor {
|
|
|
655
763
|
if (error instanceof HttpErrorResponse) {
|
|
656
764
|
console.error(error);
|
|
657
765
|
let nerror = error;
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
nerror = new HttpErrorResponse({
|
|
661
|
-
error: this.decryptBody(error.error),
|
|
662
|
-
headers: error.headers,
|
|
663
|
-
status: error.status,
|
|
664
|
-
statusText: error.statusText,
|
|
665
|
-
url: error.url || request.urlWithParams || undefined,
|
|
666
|
-
});
|
|
667
|
-
}*/
|
|
668
|
-
if (nerror.status === 401) {
|
|
669
|
-
console.log(this.router.url);
|
|
670
|
-
if (this.router.url != '/login' && this.router.url.indexOf('/login') < 0) {
|
|
671
|
-
console.log('401--->' + request.url);
|
|
766
|
+
if (this.router.url != '/login' && this.router.url.indexOf('/login') < 0) {
|
|
767
|
+
if (nerror.status === 401) {
|
|
672
768
|
return this.handle401Error(request, next);
|
|
673
769
|
}
|
|
674
770
|
else {
|
|
675
|
-
|
|
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
|
+
}
|
|
676
778
|
}
|
|
677
779
|
}
|
|
678
780
|
else {
|
|
679
|
-
|
|
680
|
-
if (skipError && skipError === 'true') {
|
|
681
|
-
return throwError(nerror);
|
|
682
|
-
}
|
|
683
|
-
else {
|
|
684
|
-
this.messages?.showErrorMessage(nerror, request);
|
|
685
|
-
}
|
|
781
|
+
return throwError(nerror);
|
|
686
782
|
}
|
|
687
783
|
}
|
|
688
784
|
}));
|
|
@@ -693,13 +789,10 @@ class ResponseInterceptor {
|
|
|
693
789
|
return JSON.parse(strJson);
|
|
694
790
|
}
|
|
695
791
|
handle401Error(request, next) {
|
|
696
|
-
//console.log('handle401Error');
|
|
697
|
-
//console.log(this.isRefreshing);
|
|
698
792
|
if (!this.isRefreshing) {
|
|
699
793
|
this.isRefreshing = true;
|
|
700
794
|
this.refreshTokenSubject.next(null);
|
|
701
795
|
const refreshToken = this.sessionService.getRefreshToken();
|
|
702
|
-
//console.log(refreshToken);
|
|
703
796
|
if (refreshToken) {
|
|
704
797
|
return this.sessionService.getNewToken(refreshToken).pipe(switchMap((res) => {
|
|
705
798
|
console.log('refresh token response');
|
|
@@ -712,7 +805,6 @@ class ResponseInterceptor {
|
|
|
712
805
|
}), catchError((err) => {
|
|
713
806
|
this.isRefreshing = false;
|
|
714
807
|
this.sessionService.logout();
|
|
715
|
-
//this.router.navigate(['/login']);
|
|
716
808
|
this.goToLogin();
|
|
717
809
|
return throwError(err);
|
|
718
810
|
}));
|
|
@@ -737,10 +829,10 @@ class ResponseInterceptor {
|
|
|
737
829
|
console.error(err);
|
|
738
830
|
});
|
|
739
831
|
}
|
|
832
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.0.3", ngImport: i0, type: ResponseInterceptor, deps: [{ token: i0.Injector }, { token: i2$2.Router }, { token: CryptoService }, { token: SessionService }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
833
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.0.3", ngImport: i0, type: ResponseInterceptor }); }
|
|
740
834
|
}
|
|
741
|
-
|
|
742
|
-
ResponseInterceptor.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.3.3", ngImport: i0, type: ResponseInterceptor });
|
|
743
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.3", ngImport: i0, type: ResponseInterceptor, decorators: [{
|
|
835
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.0.3", ngImport: i0, type: ResponseInterceptor, decorators: [{
|
|
744
836
|
type: Injectable
|
|
745
837
|
}], ctorParameters: function () { return [{ type: i0.Injector }, { type: i2$2.Router }, { type: CryptoService }, { type: SessionService }]; } });
|
|
746
838
|
|
|
@@ -752,5 +844,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.3", ngImpor
|
|
|
752
844
|
* Generated bundle index. Do not edit.
|
|
753
845
|
*/
|
|
754
846
|
|
|
755
|
-
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 };
|
|
756
848
|
//# sourceMappingURL=ssi-security-commons.mjs.map
|