@etsoo/appscript 1.1.75 → 1.1.76
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/lib/cjs/app/CoreApp.d.ts +12 -8
- package/lib/cjs/app/CoreApp.js +36 -24
- package/lib/mjs/app/CoreApp.d.ts +12 -8
- package/lib/mjs/app/CoreApp.js +36 -24
- package/package.json +1 -1
- package/src/app/CoreApp.ts +48 -43
package/lib/cjs/app/CoreApp.d.ts
CHANGED
|
@@ -105,9 +105,8 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
|
|
|
105
105
|
* Authorize
|
|
106
106
|
* @param token New token
|
|
107
107
|
* @param refreshToken Refresh token
|
|
108
|
-
* @param keep Keep in local storage or not
|
|
109
108
|
*/
|
|
110
|
-
authorize(token?: string, refreshToken?: string
|
|
109
|
+
authorize(token?: string, refreshToken?: string): void;
|
|
111
110
|
/**
|
|
112
111
|
* Change country or region
|
|
113
112
|
* @param region New country or region
|
|
@@ -118,6 +117,10 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
|
|
|
118
117
|
* @param culture New culture definition
|
|
119
118
|
*/
|
|
120
119
|
changeCulture(culture: DataTypes.CultureDefinition): void;
|
|
120
|
+
/**
|
|
121
|
+
* Clear cached token
|
|
122
|
+
*/
|
|
123
|
+
clearCacheToken(): void;
|
|
121
124
|
/**
|
|
122
125
|
* Decrypt message
|
|
123
126
|
* @param messageEncrypted Encrypted message
|
|
@@ -299,9 +302,8 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
|
|
|
299
302
|
* User login
|
|
300
303
|
* @param user User data
|
|
301
304
|
* @param refreshToken Refresh token
|
|
302
|
-
* @param keep Keep in local storage or not
|
|
303
305
|
*/
|
|
304
|
-
userLogin(user: IUserData, refreshToken: string
|
|
306
|
+
userLogin(user: IUserData, refreshToken: string): void;
|
|
305
307
|
/**
|
|
306
308
|
* User logout
|
|
307
309
|
* @param clearToken Clear refresh token or not
|
|
@@ -438,9 +440,8 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
|
|
|
438
440
|
* Authorize
|
|
439
441
|
* @param token New token
|
|
440
442
|
* @param refreshToken Refresh token
|
|
441
|
-
* @param keep Keep in local storage or not
|
|
442
443
|
*/
|
|
443
|
-
authorize(token?: string, refreshToken?: string
|
|
444
|
+
authorize(token?: string, refreshToken?: string): void;
|
|
444
445
|
/**
|
|
445
446
|
* Change country or region
|
|
446
447
|
* @param regionId New country or region
|
|
@@ -451,6 +452,10 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
|
|
|
451
452
|
* @param culture New culture definition
|
|
452
453
|
*/
|
|
453
454
|
changeCulture(culture: DataTypes.CultureDefinition): void;
|
|
455
|
+
/**
|
|
456
|
+
* Clear cached token
|
|
457
|
+
*/
|
|
458
|
+
clearCacheToken(): void;
|
|
454
459
|
/**
|
|
455
460
|
* Decrypt message
|
|
456
461
|
* @param messageEncrypted Encrypted message
|
|
@@ -644,9 +649,8 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
|
|
|
644
649
|
* User login
|
|
645
650
|
* @param user User data
|
|
646
651
|
* @param refreshToken Refresh token
|
|
647
|
-
* @param keep Keep in local storage or not
|
|
648
652
|
*/
|
|
649
|
-
userLogin(user: IUserData, refreshToken: string
|
|
653
|
+
userLogin(user: IUserData, refreshToken: string): void;
|
|
650
654
|
/**
|
|
651
655
|
* User logout
|
|
652
656
|
* @param clearToken Clear refresh token or not
|
package/lib/cjs/app/CoreApp.js
CHANGED
|
@@ -197,12 +197,21 @@ class CoreApp {
|
|
|
197
197
|
const fields = this.initCallUpdateFields();
|
|
198
198
|
for (const field of fields) {
|
|
199
199
|
const currentValue = shared_1.StorageUtils.getLocalData(field, '');
|
|
200
|
-
if (currentValue === ''
|
|
200
|
+
if (currentValue === '')
|
|
201
201
|
continue;
|
|
202
|
-
const
|
|
203
|
-
|
|
202
|
+
const enhanced = currentValue.indexOf('!') >= 8;
|
|
203
|
+
let newValueSource = null;
|
|
204
|
+
if (enhanced) {
|
|
205
|
+
newValueSource = this.decryptEnhanced(currentValue, prev, 12);
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
newValueSource = this.decrypt(currentValue, prev);
|
|
209
|
+
}
|
|
210
|
+
if (newValueSource == null || newValueSource === '')
|
|
204
211
|
continue;
|
|
205
|
-
const newValue =
|
|
212
|
+
const newValue = enhanced
|
|
213
|
+
? this.encryptEnhanced(newValueSource)
|
|
214
|
+
: this.encrypt(newValueSource);
|
|
206
215
|
shared_1.StorageUtils.setLocalData(field, newValue);
|
|
207
216
|
}
|
|
208
217
|
}
|
|
@@ -212,7 +221,7 @@ class CoreApp {
|
|
|
212
221
|
* @returns Fields
|
|
213
222
|
*/
|
|
214
223
|
initCallUpdateFields() {
|
|
215
|
-
return [];
|
|
224
|
+
return [this.headerTokenField];
|
|
216
225
|
}
|
|
217
226
|
/**
|
|
218
227
|
* Alert action result
|
|
@@ -226,17 +235,17 @@ class CoreApp {
|
|
|
226
235
|
* Authorize
|
|
227
236
|
* @param token New token
|
|
228
237
|
* @param refreshToken Refresh token
|
|
229
|
-
* @param keep Keep in local storage or not
|
|
230
238
|
*/
|
|
231
|
-
authorize(token, refreshToken
|
|
239
|
+
authorize(token, refreshToken) {
|
|
232
240
|
// State, when token is null, means logout
|
|
233
241
|
this.authorized = token != null;
|
|
234
242
|
// Token
|
|
235
243
|
this.api.authorize(this.settings.authScheme, token);
|
|
236
244
|
// Cover the current value
|
|
237
|
-
if (
|
|
238
|
-
|
|
239
|
-
|
|
245
|
+
if (refreshToken !== '') {
|
|
246
|
+
if (refreshToken != null)
|
|
247
|
+
refreshToken = this.encrypt(refreshToken);
|
|
248
|
+
shared_1.StorageUtils.setLocalData(this.headerTokenField, refreshToken);
|
|
240
249
|
}
|
|
241
250
|
// Reset tryLogin state
|
|
242
251
|
this._isTryingLogin = false;
|
|
@@ -302,6 +311,12 @@ class CoreApp {
|
|
|
302
311
|
region.name = AddressUtils_1.AddressUtils.getRegionLabel(id, this.labelDelegate);
|
|
303
312
|
});
|
|
304
313
|
}
|
|
314
|
+
/**
|
|
315
|
+
* Clear cached token
|
|
316
|
+
*/
|
|
317
|
+
clearCacheToken() {
|
|
318
|
+
shared_1.StorageUtils.setLocalData(this.headerTokenField, null);
|
|
319
|
+
}
|
|
305
320
|
/**
|
|
306
321
|
* Decrypt message
|
|
307
322
|
* @param messageEncrypted Encrypted message
|
|
@@ -321,14 +336,11 @@ class CoreApp {
|
|
|
321
336
|
hasher: crypto_js_1.algo.SHA256,
|
|
322
337
|
iterations: 1000 * iterations
|
|
323
338
|
});
|
|
324
|
-
|
|
339
|
+
return crypto_js_1.AES.decrypt(encrypted, key, {
|
|
325
340
|
iv,
|
|
326
341
|
padding: crypto_js_1.pad.Pkcs7,
|
|
327
342
|
mode: crypto_js_1.mode.CBC
|
|
328
|
-
});
|
|
329
|
-
if (bytes.words.length == 0)
|
|
330
|
-
return undefined;
|
|
331
|
-
return bytes.toString(crypto_js_1.enc.Utf8);
|
|
343
|
+
}).toString(crypto_js_1.enc.Utf8);
|
|
332
344
|
}
|
|
333
345
|
/**
|
|
334
346
|
* Enhanced decrypt message
|
|
@@ -548,12 +560,13 @@ class CoreApp {
|
|
|
548
560
|
* @returns Cached token
|
|
549
561
|
*/
|
|
550
562
|
getCacheToken() {
|
|
551
|
-
|
|
552
|
-
if (refreshToken === '')
|
|
553
|
-
refreshToken = shared_1.StorageUtils.getSessionData(this.headerTokenField, '');
|
|
563
|
+
const refreshToken = shared_1.StorageUtils.getLocalData(this.headerTokenField, '');
|
|
554
564
|
if (refreshToken === '')
|
|
555
565
|
return null;
|
|
556
|
-
|
|
566
|
+
const result = this.decrypt(refreshToken);
|
|
567
|
+
if (result == undefined)
|
|
568
|
+
return null;
|
|
569
|
+
return result;
|
|
557
570
|
}
|
|
558
571
|
/**
|
|
559
572
|
* Get all regions
|
|
@@ -751,24 +764,23 @@ class CoreApp {
|
|
|
751
764
|
* User login
|
|
752
765
|
* @param user User data
|
|
753
766
|
* @param refreshToken Refresh token
|
|
754
|
-
* @param keep Keep in local storage or not
|
|
755
767
|
*/
|
|
756
|
-
userLogin(user, refreshToken
|
|
768
|
+
userLogin(user, refreshToken) {
|
|
757
769
|
this.userData = user;
|
|
758
|
-
this.authorize(user.token, refreshToken
|
|
770
|
+
this.authorize(user.token, refreshToken);
|
|
759
771
|
}
|
|
760
772
|
/**
|
|
761
773
|
* User logout
|
|
762
774
|
* @param clearToken Clear refresh token or not
|
|
763
775
|
*/
|
|
764
776
|
userLogout(clearToken = true) {
|
|
765
|
-
this.authorize(undefined,
|
|
777
|
+
this.authorize(undefined, clearToken ? undefined : '');
|
|
766
778
|
}
|
|
767
779
|
/**
|
|
768
780
|
* User unauthorized
|
|
769
781
|
*/
|
|
770
782
|
userUnauthorized() {
|
|
771
|
-
this.authorize(undefined, undefined
|
|
783
|
+
this.authorize(undefined, undefined);
|
|
772
784
|
}
|
|
773
785
|
/**
|
|
774
786
|
* Show warning message
|
package/lib/mjs/app/CoreApp.d.ts
CHANGED
|
@@ -105,9 +105,8 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
|
|
|
105
105
|
* Authorize
|
|
106
106
|
* @param token New token
|
|
107
107
|
* @param refreshToken Refresh token
|
|
108
|
-
* @param keep Keep in local storage or not
|
|
109
108
|
*/
|
|
110
|
-
authorize(token?: string, refreshToken?: string
|
|
109
|
+
authorize(token?: string, refreshToken?: string): void;
|
|
111
110
|
/**
|
|
112
111
|
* Change country or region
|
|
113
112
|
* @param region New country or region
|
|
@@ -118,6 +117,10 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
|
|
|
118
117
|
* @param culture New culture definition
|
|
119
118
|
*/
|
|
120
119
|
changeCulture(culture: DataTypes.CultureDefinition): void;
|
|
120
|
+
/**
|
|
121
|
+
* Clear cached token
|
|
122
|
+
*/
|
|
123
|
+
clearCacheToken(): void;
|
|
121
124
|
/**
|
|
122
125
|
* Decrypt message
|
|
123
126
|
* @param messageEncrypted Encrypted message
|
|
@@ -299,9 +302,8 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
|
|
|
299
302
|
* User login
|
|
300
303
|
* @param user User data
|
|
301
304
|
* @param refreshToken Refresh token
|
|
302
|
-
* @param keep Keep in local storage or not
|
|
303
305
|
*/
|
|
304
|
-
userLogin(user: IUserData, refreshToken: string
|
|
306
|
+
userLogin(user: IUserData, refreshToken: string): void;
|
|
305
307
|
/**
|
|
306
308
|
* User logout
|
|
307
309
|
* @param clearToken Clear refresh token or not
|
|
@@ -438,9 +440,8 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
|
|
|
438
440
|
* Authorize
|
|
439
441
|
* @param token New token
|
|
440
442
|
* @param refreshToken Refresh token
|
|
441
|
-
* @param keep Keep in local storage or not
|
|
442
443
|
*/
|
|
443
|
-
authorize(token?: string, refreshToken?: string
|
|
444
|
+
authorize(token?: string, refreshToken?: string): void;
|
|
444
445
|
/**
|
|
445
446
|
* Change country or region
|
|
446
447
|
* @param regionId New country or region
|
|
@@ -451,6 +452,10 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
|
|
|
451
452
|
* @param culture New culture definition
|
|
452
453
|
*/
|
|
453
454
|
changeCulture(culture: DataTypes.CultureDefinition): void;
|
|
455
|
+
/**
|
|
456
|
+
* Clear cached token
|
|
457
|
+
*/
|
|
458
|
+
clearCacheToken(): void;
|
|
454
459
|
/**
|
|
455
460
|
* Decrypt message
|
|
456
461
|
* @param messageEncrypted Encrypted message
|
|
@@ -644,9 +649,8 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
|
|
|
644
649
|
* User login
|
|
645
650
|
* @param user User data
|
|
646
651
|
* @param refreshToken Refresh token
|
|
647
|
-
* @param keep Keep in local storage or not
|
|
648
652
|
*/
|
|
649
|
-
userLogin(user: IUserData, refreshToken: string
|
|
653
|
+
userLogin(user: IUserData, refreshToken: string): void;
|
|
650
654
|
/**
|
|
651
655
|
* User logout
|
|
652
656
|
* @param clearToken Clear refresh token or not
|
package/lib/mjs/app/CoreApp.js
CHANGED
|
@@ -194,12 +194,21 @@ export class CoreApp {
|
|
|
194
194
|
const fields = this.initCallUpdateFields();
|
|
195
195
|
for (const field of fields) {
|
|
196
196
|
const currentValue = StorageUtils.getLocalData(field, '');
|
|
197
|
-
if (currentValue === ''
|
|
197
|
+
if (currentValue === '')
|
|
198
198
|
continue;
|
|
199
|
-
const
|
|
200
|
-
|
|
199
|
+
const enhanced = currentValue.indexOf('!') >= 8;
|
|
200
|
+
let newValueSource = null;
|
|
201
|
+
if (enhanced) {
|
|
202
|
+
newValueSource = this.decryptEnhanced(currentValue, prev, 12);
|
|
203
|
+
}
|
|
204
|
+
else {
|
|
205
|
+
newValueSource = this.decrypt(currentValue, prev);
|
|
206
|
+
}
|
|
207
|
+
if (newValueSource == null || newValueSource === '')
|
|
201
208
|
continue;
|
|
202
|
-
const newValue =
|
|
209
|
+
const newValue = enhanced
|
|
210
|
+
? this.encryptEnhanced(newValueSource)
|
|
211
|
+
: this.encrypt(newValueSource);
|
|
203
212
|
StorageUtils.setLocalData(field, newValue);
|
|
204
213
|
}
|
|
205
214
|
}
|
|
@@ -209,7 +218,7 @@ export class CoreApp {
|
|
|
209
218
|
* @returns Fields
|
|
210
219
|
*/
|
|
211
220
|
initCallUpdateFields() {
|
|
212
|
-
return [];
|
|
221
|
+
return [this.headerTokenField];
|
|
213
222
|
}
|
|
214
223
|
/**
|
|
215
224
|
* Alert action result
|
|
@@ -223,17 +232,17 @@ export class CoreApp {
|
|
|
223
232
|
* Authorize
|
|
224
233
|
* @param token New token
|
|
225
234
|
* @param refreshToken Refresh token
|
|
226
|
-
* @param keep Keep in local storage or not
|
|
227
235
|
*/
|
|
228
|
-
authorize(token, refreshToken
|
|
236
|
+
authorize(token, refreshToken) {
|
|
229
237
|
// State, when token is null, means logout
|
|
230
238
|
this.authorized = token != null;
|
|
231
239
|
// Token
|
|
232
240
|
this.api.authorize(this.settings.authScheme, token);
|
|
233
241
|
// Cover the current value
|
|
234
|
-
if (
|
|
235
|
-
|
|
236
|
-
|
|
242
|
+
if (refreshToken !== '') {
|
|
243
|
+
if (refreshToken != null)
|
|
244
|
+
refreshToken = this.encrypt(refreshToken);
|
|
245
|
+
StorageUtils.setLocalData(this.headerTokenField, refreshToken);
|
|
237
246
|
}
|
|
238
247
|
// Reset tryLogin state
|
|
239
248
|
this._isTryingLogin = false;
|
|
@@ -299,6 +308,12 @@ export class CoreApp {
|
|
|
299
308
|
region.name = AddressUtils.getRegionLabel(id, this.labelDelegate);
|
|
300
309
|
});
|
|
301
310
|
}
|
|
311
|
+
/**
|
|
312
|
+
* Clear cached token
|
|
313
|
+
*/
|
|
314
|
+
clearCacheToken() {
|
|
315
|
+
StorageUtils.setLocalData(this.headerTokenField, null);
|
|
316
|
+
}
|
|
302
317
|
/**
|
|
303
318
|
* Decrypt message
|
|
304
319
|
* @param messageEncrypted Encrypted message
|
|
@@ -318,14 +333,11 @@ export class CoreApp {
|
|
|
318
333
|
hasher: algo.SHA256,
|
|
319
334
|
iterations: 1000 * iterations
|
|
320
335
|
});
|
|
321
|
-
|
|
336
|
+
return AES.decrypt(encrypted, key, {
|
|
322
337
|
iv,
|
|
323
338
|
padding: pad.Pkcs7,
|
|
324
339
|
mode: mode.CBC
|
|
325
|
-
});
|
|
326
|
-
if (bytes.words.length == 0)
|
|
327
|
-
return undefined;
|
|
328
|
-
return bytes.toString(enc.Utf8);
|
|
340
|
+
}).toString(enc.Utf8);
|
|
329
341
|
}
|
|
330
342
|
/**
|
|
331
343
|
* Enhanced decrypt message
|
|
@@ -545,12 +557,13 @@ export class CoreApp {
|
|
|
545
557
|
* @returns Cached token
|
|
546
558
|
*/
|
|
547
559
|
getCacheToken() {
|
|
548
|
-
|
|
549
|
-
if (refreshToken === '')
|
|
550
|
-
refreshToken = StorageUtils.getSessionData(this.headerTokenField, '');
|
|
560
|
+
const refreshToken = StorageUtils.getLocalData(this.headerTokenField, '');
|
|
551
561
|
if (refreshToken === '')
|
|
552
562
|
return null;
|
|
553
|
-
|
|
563
|
+
const result = this.decrypt(refreshToken);
|
|
564
|
+
if (result == undefined)
|
|
565
|
+
return null;
|
|
566
|
+
return result;
|
|
554
567
|
}
|
|
555
568
|
/**
|
|
556
569
|
* Get all regions
|
|
@@ -748,24 +761,23 @@ export class CoreApp {
|
|
|
748
761
|
* User login
|
|
749
762
|
* @param user User data
|
|
750
763
|
* @param refreshToken Refresh token
|
|
751
|
-
* @param keep Keep in local storage or not
|
|
752
764
|
*/
|
|
753
|
-
userLogin(user, refreshToken
|
|
765
|
+
userLogin(user, refreshToken) {
|
|
754
766
|
this.userData = user;
|
|
755
|
-
this.authorize(user.token, refreshToken
|
|
767
|
+
this.authorize(user.token, refreshToken);
|
|
756
768
|
}
|
|
757
769
|
/**
|
|
758
770
|
* User logout
|
|
759
771
|
* @param clearToken Clear refresh token or not
|
|
760
772
|
*/
|
|
761
773
|
userLogout(clearToken = true) {
|
|
762
|
-
this.authorize(undefined,
|
|
774
|
+
this.authorize(undefined, clearToken ? undefined : '');
|
|
763
775
|
}
|
|
764
776
|
/**
|
|
765
777
|
* User unauthorized
|
|
766
778
|
*/
|
|
767
779
|
userUnauthorized() {
|
|
768
|
-
this.authorize(undefined, undefined
|
|
780
|
+
this.authorize(undefined, undefined);
|
|
769
781
|
}
|
|
770
782
|
/**
|
|
771
783
|
* Show warning message
|
package/package.json
CHANGED
package/src/app/CoreApp.ts
CHANGED
|
@@ -162,9 +162,8 @@ export interface ICoreApp<
|
|
|
162
162
|
* Authorize
|
|
163
163
|
* @param token New token
|
|
164
164
|
* @param refreshToken Refresh token
|
|
165
|
-
* @param keep Keep in local storage or not
|
|
166
165
|
*/
|
|
167
|
-
authorize(token?: string, refreshToken?: string
|
|
166
|
+
authorize(token?: string, refreshToken?: string): void;
|
|
168
167
|
|
|
169
168
|
/**
|
|
170
169
|
* Change country or region
|
|
@@ -178,6 +177,11 @@ export interface ICoreApp<
|
|
|
178
177
|
*/
|
|
179
178
|
changeCulture(culture: DataTypes.CultureDefinition): void;
|
|
180
179
|
|
|
180
|
+
/**
|
|
181
|
+
* Clear cached token
|
|
182
|
+
*/
|
|
183
|
+
clearCacheToken(): void;
|
|
184
|
+
|
|
181
185
|
/**
|
|
182
186
|
* Decrypt message
|
|
183
187
|
* @param messageEncrypted Encrypted message
|
|
@@ -407,9 +411,8 @@ export interface ICoreApp<
|
|
|
407
411
|
* User login
|
|
408
412
|
* @param user User data
|
|
409
413
|
* @param refreshToken Refresh token
|
|
410
|
-
* @param keep Keep in local storage or not
|
|
411
414
|
*/
|
|
412
|
-
userLogin(user: IUserData, refreshToken: string
|
|
415
|
+
userLogin(user: IUserData, refreshToken: string): void;
|
|
413
416
|
|
|
414
417
|
/**
|
|
415
418
|
* User logout
|
|
@@ -714,17 +717,27 @@ export abstract class CoreApp<
|
|
|
714
717
|
field,
|
|
715
718
|
''
|
|
716
719
|
);
|
|
717
|
-
if (currentValue === ''
|
|
718
|
-
continue;
|
|
720
|
+
if (currentValue === '') continue;
|
|
719
721
|
|
|
720
|
-
const
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
722
|
+
const enhanced = currentValue.indexOf('!') >= 8;
|
|
723
|
+
let newValueSource = null;
|
|
724
|
+
|
|
725
|
+
if (enhanced) {
|
|
726
|
+
newValueSource = this.decryptEnhanced(
|
|
727
|
+
currentValue,
|
|
728
|
+
prev,
|
|
729
|
+
12
|
|
730
|
+
);
|
|
731
|
+
} else {
|
|
732
|
+
newValueSource = this.decrypt(currentValue, prev);
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
if (newValueSource == null || newValueSource === '') continue;
|
|
736
|
+
|
|
737
|
+
const newValue = enhanced
|
|
738
|
+
? this.encryptEnhanced(newValueSource)
|
|
739
|
+
: this.encrypt(newValueSource);
|
|
726
740
|
|
|
727
|
-
const newValue = this.encryptEnhanced(newValueSource);
|
|
728
741
|
StorageUtils.setLocalData(field, newValue);
|
|
729
742
|
}
|
|
730
743
|
}
|
|
@@ -735,7 +748,7 @@ export abstract class CoreApp<
|
|
|
735
748
|
* @returns Fields
|
|
736
749
|
*/
|
|
737
750
|
protected initCallUpdateFields(): string[] {
|
|
738
|
-
return [];
|
|
751
|
+
return [this.headerTokenField];
|
|
739
752
|
}
|
|
740
753
|
|
|
741
754
|
/**
|
|
@@ -751,9 +764,8 @@ export abstract class CoreApp<
|
|
|
751
764
|
* Authorize
|
|
752
765
|
* @param token New token
|
|
753
766
|
* @param refreshToken Refresh token
|
|
754
|
-
* @param keep Keep in local storage or not
|
|
755
767
|
*/
|
|
756
|
-
authorize(token?: string, refreshToken?: string
|
|
768
|
+
authorize(token?: string, refreshToken?: string) {
|
|
757
769
|
// State, when token is null, means logout
|
|
758
770
|
this.authorized = token != null;
|
|
759
771
|
|
|
@@ -761,17 +773,10 @@ export abstract class CoreApp<
|
|
|
761
773
|
this.api.authorize(this.settings.authScheme, token);
|
|
762
774
|
|
|
763
775
|
// Cover the current value
|
|
764
|
-
if (
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
keep ? refreshToken : undefined
|
|
768
|
-
);
|
|
769
|
-
StorageUtils.setSessionData(
|
|
770
|
-
this.headerTokenField,
|
|
771
|
-
keep ? undefined : refreshToken
|
|
772
|
-
);
|
|
776
|
+
if (refreshToken !== '') {
|
|
777
|
+
if (refreshToken != null) refreshToken = this.encrypt(refreshToken);
|
|
778
|
+
StorageUtils.setLocalData(this.headerTokenField, refreshToken);
|
|
773
779
|
}
|
|
774
|
-
|
|
775
780
|
// Reset tryLogin state
|
|
776
781
|
this._isTryingLogin = false;
|
|
777
782
|
|
|
@@ -849,6 +854,13 @@ export abstract class CoreApp<
|
|
|
849
854
|
});
|
|
850
855
|
}
|
|
851
856
|
|
|
857
|
+
/**
|
|
858
|
+
* Clear cached token
|
|
859
|
+
*/
|
|
860
|
+
clearCacheToken() {
|
|
861
|
+
StorageUtils.setLocalData(this.headerTokenField, null);
|
|
862
|
+
}
|
|
863
|
+
|
|
852
864
|
/**
|
|
853
865
|
* Decrypt message
|
|
854
866
|
* @param messageEncrypted Encrypted message
|
|
@@ -870,14 +882,11 @@ export abstract class CoreApp<
|
|
|
870
882
|
iterations: 1000 * iterations
|
|
871
883
|
});
|
|
872
884
|
|
|
873
|
-
|
|
885
|
+
return AES.decrypt(encrypted, key, {
|
|
874
886
|
iv,
|
|
875
887
|
padding: pad.Pkcs7,
|
|
876
888
|
mode: mode.CBC
|
|
877
|
-
});
|
|
878
|
-
if (bytes.words.length == 0) return undefined;
|
|
879
|
-
|
|
880
|
-
return bytes.toString(enc.Utf8);
|
|
889
|
+
}).toString(enc.Utf8);
|
|
881
890
|
}
|
|
882
891
|
|
|
883
892
|
/**
|
|
@@ -1153,19 +1162,16 @@ export abstract class CoreApp<
|
|
|
1153
1162
|
* @returns Cached token
|
|
1154
1163
|
*/
|
|
1155
1164
|
getCacheToken(): string | null {
|
|
1156
|
-
|
|
1165
|
+
const refreshToken = StorageUtils.getLocalData<string>(
|
|
1157
1166
|
this.headerTokenField,
|
|
1158
1167
|
''
|
|
1159
1168
|
);
|
|
1160
|
-
if (refreshToken === '')
|
|
1161
|
-
refreshToken = StorageUtils.getSessionData(
|
|
1162
|
-
this.headerTokenField,
|
|
1163
|
-
''
|
|
1164
|
-
);
|
|
1165
1169
|
|
|
1166
1170
|
if (refreshToken === '') return null;
|
|
1167
1171
|
|
|
1168
|
-
|
|
1172
|
+
const result = this.decrypt(refreshToken);
|
|
1173
|
+
if (result == undefined) return null;
|
|
1174
|
+
return result;
|
|
1169
1175
|
}
|
|
1170
1176
|
|
|
1171
1177
|
/**
|
|
@@ -1385,11 +1391,10 @@ export abstract class CoreApp<
|
|
|
1385
1391
|
* User login
|
|
1386
1392
|
* @param user User data
|
|
1387
1393
|
* @param refreshToken Refresh token
|
|
1388
|
-
* @param keep Keep in local storage or not
|
|
1389
1394
|
*/
|
|
1390
|
-
userLogin(user: IUserData, refreshToken: string
|
|
1395
|
+
userLogin(user: IUserData, refreshToken: string) {
|
|
1391
1396
|
this.userData = user;
|
|
1392
|
-
this.authorize(user.token, refreshToken
|
|
1397
|
+
this.authorize(user.token, refreshToken);
|
|
1393
1398
|
}
|
|
1394
1399
|
|
|
1395
1400
|
/**
|
|
@@ -1397,14 +1402,14 @@ export abstract class CoreApp<
|
|
|
1397
1402
|
* @param clearToken Clear refresh token or not
|
|
1398
1403
|
*/
|
|
1399
1404
|
userLogout(clearToken: boolean = true) {
|
|
1400
|
-
this.authorize(undefined,
|
|
1405
|
+
this.authorize(undefined, clearToken ? undefined : '');
|
|
1401
1406
|
}
|
|
1402
1407
|
|
|
1403
1408
|
/**
|
|
1404
1409
|
* User unauthorized
|
|
1405
1410
|
*/
|
|
1406
1411
|
userUnauthorized() {
|
|
1407
|
-
this.authorize(undefined, undefined
|
|
1412
|
+
this.authorize(undefined, undefined);
|
|
1408
1413
|
}
|
|
1409
1414
|
|
|
1410
1415
|
private lastWarning?: INotification<N, C>;
|