@etsoo/appscript 1.1.74 → 1.1.78
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 +13 -6
- package/lib/cjs/app/CoreApp.js +49 -21
- package/lib/cjs/state/User.d.ts +4 -0
- package/lib/mjs/app/CoreApp.d.ts +13 -6
- package/lib/mjs/app/CoreApp.js +49 -21
- package/lib/mjs/state/User.d.ts +4 -0
- package/package.json +1 -1
- package/src/app/CoreApp.ts +64 -38
- package/src/state/User.ts +5 -0
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,7 +302,7 @@ 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
|
|
305
|
+
* @param keep Keep login or not
|
|
303
306
|
*/
|
|
304
307
|
userLogin(user: IUserData, refreshToken: string, keep?: boolean): void;
|
|
305
308
|
/**
|
|
@@ -403,6 +406,7 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
|
|
|
403
406
|
* Passphrase for encryption
|
|
404
407
|
*/
|
|
405
408
|
protected passphrase: string;
|
|
409
|
+
private cachedRefreshToken?;
|
|
406
410
|
/**
|
|
407
411
|
* Protected constructor
|
|
408
412
|
* @param settings Settings
|
|
@@ -438,9 +442,8 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
|
|
|
438
442
|
* Authorize
|
|
439
443
|
* @param token New token
|
|
440
444
|
* @param refreshToken Refresh token
|
|
441
|
-
* @param keep Keep in local storage or not
|
|
442
445
|
*/
|
|
443
|
-
authorize(token?: string, refreshToken?: string
|
|
446
|
+
authorize(token?: string, refreshToken?: string): void;
|
|
444
447
|
/**
|
|
445
448
|
* Change country or region
|
|
446
449
|
* @param regionId New country or region
|
|
@@ -451,6 +454,10 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
|
|
|
451
454
|
* @param culture New culture definition
|
|
452
455
|
*/
|
|
453
456
|
changeCulture(culture: DataTypes.CultureDefinition): void;
|
|
457
|
+
/**
|
|
458
|
+
* Clear cached token
|
|
459
|
+
*/
|
|
460
|
+
clearCacheToken(): void;
|
|
454
461
|
/**
|
|
455
462
|
* Decrypt message
|
|
456
463
|
* @param messageEncrypted Encrypted message
|
|
@@ -644,7 +651,7 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
|
|
|
644
651
|
* User login
|
|
645
652
|
* @param user User data
|
|
646
653
|
* @param refreshToken Refresh token
|
|
647
|
-
* @param keep Keep
|
|
654
|
+
* @param keep Keep login or not
|
|
648
655
|
*/
|
|
649
656
|
userLogin(user: IUserData, refreshToken: string, keep?: boolean): void;
|
|
650
657
|
/**
|
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,25 +235,27 @@ 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;
|
|
243
252
|
// Token countdown
|
|
244
253
|
if (this.authorized)
|
|
245
254
|
this.refreshCountdown(this.userData.seconds);
|
|
246
|
-
else
|
|
255
|
+
else {
|
|
256
|
+
this.cachedRefreshToken = undefined;
|
|
247
257
|
this.refreshCountdownClear();
|
|
258
|
+
}
|
|
248
259
|
}
|
|
249
260
|
/**
|
|
250
261
|
* Change country or region
|
|
@@ -302,6 +313,13 @@ class CoreApp {
|
|
|
302
313
|
region.name = AddressUtils_1.AddressUtils.getRegionLabel(id, this.labelDelegate);
|
|
303
314
|
});
|
|
304
315
|
}
|
|
316
|
+
/**
|
|
317
|
+
* Clear cached token
|
|
318
|
+
*/
|
|
319
|
+
clearCacheToken() {
|
|
320
|
+
this.cachedRefreshToken = undefined;
|
|
321
|
+
shared_1.StorageUtils.setLocalData(this.headerTokenField, undefined);
|
|
322
|
+
}
|
|
305
323
|
/**
|
|
306
324
|
* Decrypt message
|
|
307
325
|
* @param messageEncrypted Encrypted message
|
|
@@ -545,12 +563,16 @@ class CoreApp {
|
|
|
545
563
|
* @returns Cached token
|
|
546
564
|
*/
|
|
547
565
|
getCacheToken() {
|
|
548
|
-
|
|
549
|
-
if (
|
|
550
|
-
|
|
566
|
+
// Temp refresh token
|
|
567
|
+
if (this.cachedRefreshToken)
|
|
568
|
+
return this.cachedRefreshToken;
|
|
569
|
+
const refreshToken = shared_1.StorageUtils.getLocalData(this.headerTokenField, '');
|
|
551
570
|
if (refreshToken === '')
|
|
552
571
|
return null;
|
|
553
|
-
|
|
572
|
+
const result = this.decrypt(refreshToken);
|
|
573
|
+
if (result == undefined)
|
|
574
|
+
return null;
|
|
575
|
+
return result;
|
|
554
576
|
}
|
|
555
577
|
/**
|
|
556
578
|
* Get all regions
|
|
@@ -724,7 +746,7 @@ class CoreApp {
|
|
|
724
746
|
return url;
|
|
725
747
|
// From relative root, like home:/react/, url: /about => /react/about
|
|
726
748
|
if (url.startsWith('/'))
|
|
727
|
-
return home + url.
|
|
749
|
+
return home + url.substring(1);
|
|
728
750
|
const pathname = window.location.pathname;
|
|
729
751
|
// Relative
|
|
730
752
|
const pos = pathname.indexOf(home);
|
|
@@ -748,24 +770,30 @@ class CoreApp {
|
|
|
748
770
|
* User login
|
|
749
771
|
* @param user User data
|
|
750
772
|
* @param refreshToken Refresh token
|
|
751
|
-
* @param keep Keep
|
|
773
|
+
* @param keep Keep login or not
|
|
752
774
|
*/
|
|
753
|
-
userLogin(user, refreshToken, keep
|
|
775
|
+
userLogin(user, refreshToken, keep) {
|
|
754
776
|
this.userData = user;
|
|
755
|
-
|
|
777
|
+
if (keep) {
|
|
778
|
+
this.authorize(user.token, refreshToken);
|
|
779
|
+
}
|
|
780
|
+
else {
|
|
781
|
+
this.cachedRefreshToken = refreshToken;
|
|
782
|
+
this.authorize(user.token, undefined);
|
|
783
|
+
}
|
|
756
784
|
}
|
|
757
785
|
/**
|
|
758
786
|
* User logout
|
|
759
787
|
* @param clearToken Clear refresh token or not
|
|
760
788
|
*/
|
|
761
789
|
userLogout(clearToken = true) {
|
|
762
|
-
this.authorize(undefined,
|
|
790
|
+
this.authorize(undefined, clearToken ? undefined : '');
|
|
763
791
|
}
|
|
764
792
|
/**
|
|
765
793
|
* User unauthorized
|
|
766
794
|
*/
|
|
767
795
|
userUnauthorized() {
|
|
768
|
-
this.authorize(undefined, undefined
|
|
796
|
+
this.authorize(undefined, undefined);
|
|
769
797
|
}
|
|
770
798
|
/**
|
|
771
799
|
* Show warning message
|
package/lib/cjs/state/User.d.ts
CHANGED
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,7 +302,7 @@ 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
|
|
305
|
+
* @param keep Keep login or not
|
|
303
306
|
*/
|
|
304
307
|
userLogin(user: IUserData, refreshToken: string, keep?: boolean): void;
|
|
305
308
|
/**
|
|
@@ -403,6 +406,7 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
|
|
|
403
406
|
* Passphrase for encryption
|
|
404
407
|
*/
|
|
405
408
|
protected passphrase: string;
|
|
409
|
+
private cachedRefreshToken?;
|
|
406
410
|
/**
|
|
407
411
|
* Protected constructor
|
|
408
412
|
* @param settings Settings
|
|
@@ -438,9 +442,8 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
|
|
|
438
442
|
* Authorize
|
|
439
443
|
* @param token New token
|
|
440
444
|
* @param refreshToken Refresh token
|
|
441
|
-
* @param keep Keep in local storage or not
|
|
442
445
|
*/
|
|
443
|
-
authorize(token?: string, refreshToken?: string
|
|
446
|
+
authorize(token?: string, refreshToken?: string): void;
|
|
444
447
|
/**
|
|
445
448
|
* Change country or region
|
|
446
449
|
* @param regionId New country or region
|
|
@@ -451,6 +454,10 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
|
|
|
451
454
|
* @param culture New culture definition
|
|
452
455
|
*/
|
|
453
456
|
changeCulture(culture: DataTypes.CultureDefinition): void;
|
|
457
|
+
/**
|
|
458
|
+
* Clear cached token
|
|
459
|
+
*/
|
|
460
|
+
clearCacheToken(): void;
|
|
454
461
|
/**
|
|
455
462
|
* Decrypt message
|
|
456
463
|
* @param messageEncrypted Encrypted message
|
|
@@ -644,7 +651,7 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
|
|
|
644
651
|
* User login
|
|
645
652
|
* @param user User data
|
|
646
653
|
* @param refreshToken Refresh token
|
|
647
|
-
* @param keep Keep
|
|
654
|
+
* @param keep Keep login or not
|
|
648
655
|
*/
|
|
649
656
|
userLogin(user: IUserData, refreshToken: string, keep?: boolean): void;
|
|
650
657
|
/**
|
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,25 +232,27 @@ 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;
|
|
240
249
|
// Token countdown
|
|
241
250
|
if (this.authorized)
|
|
242
251
|
this.refreshCountdown(this.userData.seconds);
|
|
243
|
-
else
|
|
252
|
+
else {
|
|
253
|
+
this.cachedRefreshToken = undefined;
|
|
244
254
|
this.refreshCountdownClear();
|
|
255
|
+
}
|
|
245
256
|
}
|
|
246
257
|
/**
|
|
247
258
|
* Change country or region
|
|
@@ -299,6 +310,13 @@ export class CoreApp {
|
|
|
299
310
|
region.name = AddressUtils.getRegionLabel(id, this.labelDelegate);
|
|
300
311
|
});
|
|
301
312
|
}
|
|
313
|
+
/**
|
|
314
|
+
* Clear cached token
|
|
315
|
+
*/
|
|
316
|
+
clearCacheToken() {
|
|
317
|
+
this.cachedRefreshToken = undefined;
|
|
318
|
+
StorageUtils.setLocalData(this.headerTokenField, undefined);
|
|
319
|
+
}
|
|
302
320
|
/**
|
|
303
321
|
* Decrypt message
|
|
304
322
|
* @param messageEncrypted Encrypted message
|
|
@@ -542,12 +560,16 @@ export class CoreApp {
|
|
|
542
560
|
* @returns Cached token
|
|
543
561
|
*/
|
|
544
562
|
getCacheToken() {
|
|
545
|
-
|
|
546
|
-
if (
|
|
547
|
-
|
|
563
|
+
// Temp refresh token
|
|
564
|
+
if (this.cachedRefreshToken)
|
|
565
|
+
return this.cachedRefreshToken;
|
|
566
|
+
const refreshToken = StorageUtils.getLocalData(this.headerTokenField, '');
|
|
548
567
|
if (refreshToken === '')
|
|
549
568
|
return null;
|
|
550
|
-
|
|
569
|
+
const result = this.decrypt(refreshToken);
|
|
570
|
+
if (result == undefined)
|
|
571
|
+
return null;
|
|
572
|
+
return result;
|
|
551
573
|
}
|
|
552
574
|
/**
|
|
553
575
|
* Get all regions
|
|
@@ -721,7 +743,7 @@ export class CoreApp {
|
|
|
721
743
|
return url;
|
|
722
744
|
// From relative root, like home:/react/, url: /about => /react/about
|
|
723
745
|
if (url.startsWith('/'))
|
|
724
|
-
return home + url.
|
|
746
|
+
return home + url.substring(1);
|
|
725
747
|
const pathname = window.location.pathname;
|
|
726
748
|
// Relative
|
|
727
749
|
const pos = pathname.indexOf(home);
|
|
@@ -745,24 +767,30 @@ export class CoreApp {
|
|
|
745
767
|
* User login
|
|
746
768
|
* @param user User data
|
|
747
769
|
* @param refreshToken Refresh token
|
|
748
|
-
* @param keep Keep
|
|
770
|
+
* @param keep Keep login or not
|
|
749
771
|
*/
|
|
750
|
-
userLogin(user, refreshToken, keep
|
|
772
|
+
userLogin(user, refreshToken, keep) {
|
|
751
773
|
this.userData = user;
|
|
752
|
-
|
|
774
|
+
if (keep) {
|
|
775
|
+
this.authorize(user.token, refreshToken);
|
|
776
|
+
}
|
|
777
|
+
else {
|
|
778
|
+
this.cachedRefreshToken = refreshToken;
|
|
779
|
+
this.authorize(user.token, undefined);
|
|
780
|
+
}
|
|
753
781
|
}
|
|
754
782
|
/**
|
|
755
783
|
* User logout
|
|
756
784
|
* @param clearToken Clear refresh token or not
|
|
757
785
|
*/
|
|
758
786
|
userLogout(clearToken = true) {
|
|
759
|
-
this.authorize(undefined,
|
|
787
|
+
this.authorize(undefined, clearToken ? undefined : '');
|
|
760
788
|
}
|
|
761
789
|
/**
|
|
762
790
|
* User unauthorized
|
|
763
791
|
*/
|
|
764
792
|
userUnauthorized() {
|
|
765
|
-
this.authorize(undefined, undefined
|
|
793
|
+
this.authorize(undefined, undefined);
|
|
766
794
|
}
|
|
767
795
|
/**
|
|
768
796
|
* Show warning message
|
package/lib/mjs/state/User.d.ts
CHANGED
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,7 +411,7 @@ export interface ICoreApp<
|
|
|
407
411
|
* User login
|
|
408
412
|
* @param user User data
|
|
409
413
|
* @param refreshToken Refresh token
|
|
410
|
-
* @param keep Keep
|
|
414
|
+
* @param keep Keep login or not
|
|
411
415
|
*/
|
|
412
416
|
userLogin(user: IUserData, refreshToken: string, keep?: boolean): void;
|
|
413
417
|
|
|
@@ -558,6 +562,8 @@ export abstract class CoreApp<
|
|
|
558
562
|
*/
|
|
559
563
|
protected passphrase: string = '***';
|
|
560
564
|
|
|
565
|
+
private cachedRefreshToken?: string;
|
|
566
|
+
|
|
561
567
|
/**
|
|
562
568
|
* Protected constructor
|
|
563
569
|
* @param settings Settings
|
|
@@ -714,17 +720,27 @@ export abstract class CoreApp<
|
|
|
714
720
|
field,
|
|
715
721
|
''
|
|
716
722
|
);
|
|
717
|
-
if (currentValue === ''
|
|
718
|
-
continue;
|
|
723
|
+
if (currentValue === '') continue;
|
|
719
724
|
|
|
720
|
-
const
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
725
|
+
const enhanced = currentValue.indexOf('!') >= 8;
|
|
726
|
+
let newValueSource = null;
|
|
727
|
+
|
|
728
|
+
if (enhanced) {
|
|
729
|
+
newValueSource = this.decryptEnhanced(
|
|
730
|
+
currentValue,
|
|
731
|
+
prev,
|
|
732
|
+
12
|
|
733
|
+
);
|
|
734
|
+
} else {
|
|
735
|
+
newValueSource = this.decrypt(currentValue, prev);
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
if (newValueSource == null || newValueSource === '') continue;
|
|
739
|
+
|
|
740
|
+
const newValue = enhanced
|
|
741
|
+
? this.encryptEnhanced(newValueSource)
|
|
742
|
+
: this.encrypt(newValueSource);
|
|
726
743
|
|
|
727
|
-
const newValue = this.encryptEnhanced(newValueSource);
|
|
728
744
|
StorageUtils.setLocalData(field, newValue);
|
|
729
745
|
}
|
|
730
746
|
}
|
|
@@ -735,7 +751,7 @@ export abstract class CoreApp<
|
|
|
735
751
|
* @returns Fields
|
|
736
752
|
*/
|
|
737
753
|
protected initCallUpdateFields(): string[] {
|
|
738
|
-
return [];
|
|
754
|
+
return [this.headerTokenField];
|
|
739
755
|
}
|
|
740
756
|
|
|
741
757
|
/**
|
|
@@ -751,9 +767,8 @@ export abstract class CoreApp<
|
|
|
751
767
|
* Authorize
|
|
752
768
|
* @param token New token
|
|
753
769
|
* @param refreshToken Refresh token
|
|
754
|
-
* @param keep Keep in local storage or not
|
|
755
770
|
*/
|
|
756
|
-
authorize(token?: string, refreshToken?: string
|
|
771
|
+
authorize(token?: string, refreshToken?: string) {
|
|
757
772
|
// State, when token is null, means logout
|
|
758
773
|
this.authorized = token != null;
|
|
759
774
|
|
|
@@ -761,15 +776,9 @@ export abstract class CoreApp<
|
|
|
761
776
|
this.api.authorize(this.settings.authScheme, token);
|
|
762
777
|
|
|
763
778
|
// Cover the current value
|
|
764
|
-
if (
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
keep ? refreshToken : undefined
|
|
768
|
-
);
|
|
769
|
-
StorageUtils.setSessionData(
|
|
770
|
-
this.headerTokenField,
|
|
771
|
-
keep ? undefined : refreshToken
|
|
772
|
-
);
|
|
779
|
+
if (refreshToken !== '') {
|
|
780
|
+
if (refreshToken != null) refreshToken = this.encrypt(refreshToken);
|
|
781
|
+
StorageUtils.setLocalData(this.headerTokenField, refreshToken);
|
|
773
782
|
}
|
|
774
783
|
|
|
775
784
|
// Reset tryLogin state
|
|
@@ -777,7 +786,10 @@ export abstract class CoreApp<
|
|
|
777
786
|
|
|
778
787
|
// Token countdown
|
|
779
788
|
if (this.authorized) this.refreshCountdown(this.userData!.seconds);
|
|
780
|
-
else
|
|
789
|
+
else {
|
|
790
|
+
this.cachedRefreshToken = undefined;
|
|
791
|
+
this.refreshCountdownClear();
|
|
792
|
+
}
|
|
781
793
|
}
|
|
782
794
|
|
|
783
795
|
/**
|
|
@@ -849,6 +861,14 @@ export abstract class CoreApp<
|
|
|
849
861
|
});
|
|
850
862
|
}
|
|
851
863
|
|
|
864
|
+
/**
|
|
865
|
+
* Clear cached token
|
|
866
|
+
*/
|
|
867
|
+
clearCacheToken() {
|
|
868
|
+
this.cachedRefreshToken = undefined;
|
|
869
|
+
StorageUtils.setLocalData(this.headerTokenField, undefined);
|
|
870
|
+
}
|
|
871
|
+
|
|
852
872
|
/**
|
|
853
873
|
* Decrypt message
|
|
854
874
|
* @param messageEncrypted Encrypted message
|
|
@@ -1150,19 +1170,19 @@ export abstract class CoreApp<
|
|
|
1150
1170
|
* @returns Cached token
|
|
1151
1171
|
*/
|
|
1152
1172
|
getCacheToken(): string | null {
|
|
1153
|
-
|
|
1173
|
+
// Temp refresh token
|
|
1174
|
+
if (this.cachedRefreshToken) return this.cachedRefreshToken;
|
|
1175
|
+
|
|
1176
|
+
const refreshToken = StorageUtils.getLocalData<string>(
|
|
1154
1177
|
this.headerTokenField,
|
|
1155
1178
|
''
|
|
1156
1179
|
);
|
|
1157
|
-
if (refreshToken === '')
|
|
1158
|
-
refreshToken = StorageUtils.getSessionData(
|
|
1159
|
-
this.headerTokenField,
|
|
1160
|
-
''
|
|
1161
|
-
);
|
|
1162
1180
|
|
|
1163
1181
|
if (refreshToken === '') return null;
|
|
1164
1182
|
|
|
1165
|
-
|
|
1183
|
+
const result = this.decrypt(refreshToken);
|
|
1184
|
+
if (result == undefined) return null;
|
|
1185
|
+
return result;
|
|
1166
1186
|
}
|
|
1167
1187
|
|
|
1168
1188
|
/**
|
|
@@ -1355,7 +1375,7 @@ export abstract class CoreApp<
|
|
|
1355
1375
|
if (home === '') return url;
|
|
1356
1376
|
|
|
1357
1377
|
// From relative root, like home:/react/, url: /about => /react/about
|
|
1358
|
-
if (url.startsWith('/')) return home + url.
|
|
1378
|
+
if (url.startsWith('/')) return home + url.substring(1);
|
|
1359
1379
|
|
|
1360
1380
|
const pathname = window.location.pathname;
|
|
1361
1381
|
|
|
@@ -1382,11 +1402,17 @@ export abstract class CoreApp<
|
|
|
1382
1402
|
* User login
|
|
1383
1403
|
* @param user User data
|
|
1384
1404
|
* @param refreshToken Refresh token
|
|
1385
|
-
* @param keep Keep
|
|
1405
|
+
* @param keep Keep login or not
|
|
1386
1406
|
*/
|
|
1387
|
-
userLogin(user: IUserData, refreshToken: string, keep
|
|
1407
|
+
userLogin(user: IUserData, refreshToken: string, keep?: boolean) {
|
|
1388
1408
|
this.userData = user;
|
|
1389
|
-
|
|
1409
|
+
|
|
1410
|
+
if (keep) {
|
|
1411
|
+
this.authorize(user.token, refreshToken);
|
|
1412
|
+
} else {
|
|
1413
|
+
this.cachedRefreshToken = refreshToken;
|
|
1414
|
+
this.authorize(user.token, undefined);
|
|
1415
|
+
}
|
|
1390
1416
|
}
|
|
1391
1417
|
|
|
1392
1418
|
/**
|
|
@@ -1394,14 +1420,14 @@ export abstract class CoreApp<
|
|
|
1394
1420
|
* @param clearToken Clear refresh token or not
|
|
1395
1421
|
*/
|
|
1396
1422
|
userLogout(clearToken: boolean = true) {
|
|
1397
|
-
this.authorize(undefined,
|
|
1423
|
+
this.authorize(undefined, clearToken ? undefined : '');
|
|
1398
1424
|
}
|
|
1399
1425
|
|
|
1400
1426
|
/**
|
|
1401
1427
|
* User unauthorized
|
|
1402
1428
|
*/
|
|
1403
1429
|
userUnauthorized() {
|
|
1404
|
-
this.authorize(undefined, undefined
|
|
1430
|
+
this.authorize(undefined, undefined);
|
|
1405
1431
|
}
|
|
1406
1432
|
|
|
1407
1433
|
private lastWarning?: INotification<N, C>;
|