@leapdev/auth-agent 2.6.0 → 2.6.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/README.md +15 -0
- package/package.json +1 -1
- package/src/index.umd.js +99 -55
- package/src/lib/auth-agent.d.ts +2 -0
- package/src/lib/auth-agent.js +19 -7
- package/src/lib/authentication.d.ts +2 -0
- package/src/lib/authentication.js +30 -2
- package/src/lib/idle-timer.d.ts +1 -0
- package/src/lib/idle-timer.js +5 -0
package/README.md
CHANGED
|
@@ -285,6 +285,21 @@ In order to be able get a refreshToken for an App, app needs to
|
|
|
285
285
|
- `clientId` **[string][36]** clientId of the app (requried)
|
|
286
286
|
- `scopes` **[Array<string>][37]** requested scopes
|
|
287
287
|
|
|
288
|
+
## setAutoLogout
|
|
289
|
+
|
|
290
|
+
Enable or Disable autoLogout
|
|
291
|
+
|
|
292
|
+
### Parameters
|
|
293
|
+
|
|
294
|
+
- `enable` **[boolean][36]** enable or disable autoLogout
|
|
295
|
+
|
|
296
|
+
## setIdleTimeoutInMinutes
|
|
297
|
+
|
|
298
|
+
In minutes, the time interval after which the user is automatically logged out if no activity detected. In order to have this value working, user have to enable "AutoLogout"
|
|
299
|
+
|
|
300
|
+
### Parameters
|
|
301
|
+
|
|
302
|
+
- `minutes` **[number][36]** number of minute to allow application to be in Idle time (no activity)
|
|
288
303
|
|
|
289
304
|
[1]: #init
|
|
290
305
|
|
package/package.json
CHANGED
package/src/index.umd.js
CHANGED
|
@@ -6788,7 +6788,55 @@
|
|
|
6788
6788
|
return list.find(appName => app.startsWith(`http://${appName}`) || app.startsWith(`https://${appName}`));
|
|
6789
6789
|
};
|
|
6790
6790
|
|
|
6791
|
-
var
|
|
6791
|
+
var _IdleTimer_timeoutInMinutes, _IdleTimer_timer, _IdleTimer_onTimeout, _IdleTimer_cleanUpTracker, _IdleTimer_clearTimeout, _IdleTimer_resetTimer;
|
|
6792
|
+
class IdleTimer {
|
|
6793
|
+
constructor(params) {
|
|
6794
|
+
_IdleTimer_timeoutInMinutes.set(this, void 0);
|
|
6795
|
+
_IdleTimer_timer.set(this, void 0);
|
|
6796
|
+
_IdleTimer_onTimeout.set(this, void 0);
|
|
6797
|
+
this.tracker = () => {
|
|
6798
|
+
window.addEventListener('onload', __classPrivateFieldGet(this, _IdleTimer_resetTimer, "f"), true);
|
|
6799
|
+
window.addEventListener('mousemove', __classPrivateFieldGet(this, _IdleTimer_resetTimer, "f"), true);
|
|
6800
|
+
window.addEventListener('onmousedown', __classPrivateFieldGet(this, _IdleTimer_resetTimer, "f"), true);
|
|
6801
|
+
window.addEventListener('onscroll', __classPrivateFieldGet(this, _IdleTimer_resetTimer, "f"), true);
|
|
6802
|
+
window.addEventListener('onkeypress', __classPrivateFieldGet(this, _IdleTimer_resetTimer, "f"), true);
|
|
6803
|
+
};
|
|
6804
|
+
this.resetTracker = () => {
|
|
6805
|
+
__classPrivateFieldGet(this, _IdleTimer_clearTimeout, "f").call(this);
|
|
6806
|
+
__classPrivateFieldSet(this, _IdleTimer_timer, undefined, "f");
|
|
6807
|
+
__classPrivateFieldGet(this, _IdleTimer_cleanUpTracker, "f").call(this);
|
|
6808
|
+
};
|
|
6809
|
+
_IdleTimer_cleanUpTracker.set(this, () => {
|
|
6810
|
+
window.removeEventListener('onload', __classPrivateFieldGet(this, _IdleTimer_resetTimer, "f"), true);
|
|
6811
|
+
window.removeEventListener('mousemove', __classPrivateFieldGet(this, _IdleTimer_resetTimer, "f"), true);
|
|
6812
|
+
window.removeEventListener('onmousedown', __classPrivateFieldGet(this, _IdleTimer_resetTimer, "f"), true);
|
|
6813
|
+
window.removeEventListener('onscroll', __classPrivateFieldGet(this, _IdleTimer_resetTimer, "f"), true);
|
|
6814
|
+
window.removeEventListener('onkeypress', __classPrivateFieldGet(this, _IdleTimer_resetTimer, "f"), true);
|
|
6815
|
+
});
|
|
6816
|
+
_IdleTimer_clearTimeout.set(this, () => {
|
|
6817
|
+
if (__classPrivateFieldGet(this, _IdleTimer_timer, "f")) {
|
|
6818
|
+
clearTimeout(__classPrivateFieldGet(this, _IdleTimer_timer, "f"));
|
|
6819
|
+
}
|
|
6820
|
+
});
|
|
6821
|
+
_IdleTimer_resetTimer.set(this, () => {
|
|
6822
|
+
__classPrivateFieldGet(this, _IdleTimer_clearTimeout, "f").call(this);
|
|
6823
|
+
__classPrivateFieldSet(this, _IdleTimer_timer, setTimeout(() => {
|
|
6824
|
+
__classPrivateFieldGet(this, _IdleTimer_clearTimeout, "f").call(this);
|
|
6825
|
+
__classPrivateFieldGet(this, _IdleTimer_cleanUpTracker, "f").call(this);
|
|
6826
|
+
__classPrivateFieldGet(this, _IdleTimer_onTimeout, "f").call(this);
|
|
6827
|
+
}, __classPrivateFieldGet(this, _IdleTimer_timeoutInMinutes, "f") * 60 * 1000), "f");
|
|
6828
|
+
});
|
|
6829
|
+
const {
|
|
6830
|
+
timeoutInMinutes,
|
|
6831
|
+
onTimeout: onTimeout
|
|
6832
|
+
} = params;
|
|
6833
|
+
__classPrivateFieldSet(this, _IdleTimer_timeoutInMinutes, timeoutInMinutes, "f");
|
|
6834
|
+
__classPrivateFieldSet(this, _IdleTimer_onTimeout, onTimeout, "f");
|
|
6835
|
+
}
|
|
6836
|
+
}
|
|
6837
|
+
_IdleTimer_timeoutInMinutes = new WeakMap(), _IdleTimer_timer = new WeakMap(), _IdleTimer_onTimeout = new WeakMap(), _IdleTimer_cleanUpTracker = new WeakMap(), _IdleTimer_clearTimeout = new WeakMap(), _IdleTimer_resetTimer = new WeakMap();
|
|
6838
|
+
|
|
6839
|
+
var _Authentication_accessToken, _Authentication_config, _Authentication_leapAuthService, _Authentication_notification, _Authentication_idleTimer, _Authentication_refreshInfo, _Authentication_dedupeAccessTokenFetch, _Authentication_dedupeUserInfoFetch, _Authentication_startIdleTimer, _Authentication_exchangeAuthCodeForAccessToken, _Authentication_verifyAndPerformRedirections, _Authentication_startRefreshAccessTokenProcess, _Authentication_destroyRefreshAccessTokenProcess, _Authentication_decodeAccessToken, _Authentication_getRefreshedAccessTokenFactory, _Authentication_getUserInfoFactory;
|
|
6792
6840
|
const SECONDS_BEFORE_EXPIRE = 30;
|
|
6793
6841
|
const MAX_SETTIME_OUT = 2147483647;
|
|
6794
6842
|
const DEFAULT_AUTHORIZE_TIMEOUT_IN_SECONDS = 60;
|
|
@@ -6800,6 +6848,7 @@
|
|
|
6800
6848
|
_Authentication_config.set(this, void 0);
|
|
6801
6849
|
_Authentication_leapAuthService.set(this, void 0);
|
|
6802
6850
|
_Authentication_notification.set(this, void 0);
|
|
6851
|
+
_Authentication_idleTimer.set(this, void 0);
|
|
6803
6852
|
_Authentication_refreshInfo.set(this, void 0);
|
|
6804
6853
|
_Authentication_dedupeAccessTokenFetch.set(this, void 0);
|
|
6805
6854
|
_Authentication_dedupeUserInfoFetch.set(this, void 0);
|
|
@@ -7200,6 +7249,7 @@
|
|
|
7200
7249
|
this.afterAuthenticated = () => {
|
|
7201
7250
|
return this.triggerHooks(HookName.afterLogin).then(() => __awaiter(this, void 0, void 0, function* () {
|
|
7202
7251
|
yield this.initNotification();
|
|
7252
|
+
__classPrivateFieldGet(this, _Authentication_startIdleTimer, "f").call(this);
|
|
7203
7253
|
return __classPrivateFieldGet(this, _Authentication_accessToken, "f");
|
|
7204
7254
|
}));
|
|
7205
7255
|
};
|
|
@@ -7315,6 +7365,33 @@
|
|
|
7315
7365
|
window.addEventListener('message', windowEventHandler);
|
|
7316
7366
|
});
|
|
7317
7367
|
});
|
|
7368
|
+
this.setIdleTimeoutInMinutes = timeoutInMinutes => {
|
|
7369
|
+
__classPrivateFieldGet(this, _Authentication_config, "f").idleTimeoutInMinutes = timeoutInMinutes;
|
|
7370
|
+
__classPrivateFieldGet(this, _Authentication_startIdleTimer, "f").call(this);
|
|
7371
|
+
};
|
|
7372
|
+
this.setAutoLogout = autoLogout => {
|
|
7373
|
+
__classPrivateFieldGet(this, _Authentication_config, "f").autoLogout = autoLogout;
|
|
7374
|
+
if (autoLogout) {
|
|
7375
|
+
__classPrivateFieldGet(this, _Authentication_startIdleTimer, "f").call(this);
|
|
7376
|
+
} else {
|
|
7377
|
+
if (__classPrivateFieldGet(this, _Authentication_idleTimer, "f")) {
|
|
7378
|
+
__classPrivateFieldGet(this, _Authentication_idleTimer, "f").resetTracker();
|
|
7379
|
+
}
|
|
7380
|
+
}
|
|
7381
|
+
};
|
|
7382
|
+
_Authentication_startIdleTimer.set(this, () => {
|
|
7383
|
+
if (this.autoLogout()) {
|
|
7384
|
+
if (__classPrivateFieldGet(this, _Authentication_idleTimer, "f")) {
|
|
7385
|
+
__classPrivateFieldGet(this, _Authentication_idleTimer, "f").resetTracker();
|
|
7386
|
+
}
|
|
7387
|
+
const timeoutInMinutes = this.idleTimeoutInMinutes();
|
|
7388
|
+
__classPrivateFieldSet(this, _Authentication_idleTimer, new IdleTimer({
|
|
7389
|
+
timeoutInMinutes,
|
|
7390
|
+
onTimeout: this.logout
|
|
7391
|
+
}), "f");
|
|
7392
|
+
__classPrivateFieldGet(this, _Authentication_idleTimer, "f").tracker();
|
|
7393
|
+
}
|
|
7394
|
+
});
|
|
7318
7395
|
_Authentication_exchangeAuthCodeForAccessToken.set(this, params => __awaiter(this, void 0, void 0, function* () {
|
|
7319
7396
|
const {
|
|
7320
7397
|
verifier,
|
|
@@ -7458,50 +7535,7 @@
|
|
|
7458
7535
|
__classPrivateFieldSet(this, _Authentication_dedupeUserInfoFetch, createInFlightDedupe(), "f");
|
|
7459
7536
|
}
|
|
7460
7537
|
}
|
|
7461
|
-
_Authentication_accessToken = new WeakMap(), _Authentication_config = new WeakMap(), _Authentication_leapAuthService = new WeakMap(), _Authentication_notification = new WeakMap(), _Authentication_refreshInfo = new WeakMap(), _Authentication_dedupeAccessTokenFetch = new WeakMap(), _Authentication_dedupeUserInfoFetch = new WeakMap(), _Authentication_exchangeAuthCodeForAccessToken = new WeakMap(), _Authentication_verifyAndPerformRedirections = new WeakMap(), _Authentication_startRefreshAccessTokenProcess = new WeakMap(), _Authentication_destroyRefreshAccessTokenProcess = new WeakMap(), _Authentication_decodeAccessToken = new WeakMap(), _Authentication_getRefreshedAccessTokenFactory = new WeakMap(), _Authentication_getUserInfoFactory = new WeakMap();
|
|
7462
|
-
|
|
7463
|
-
var _IdleTimer_timeoutInMinutes, _IdleTimer_timer, _IdleTimer_onTimeout, _IdleTimer_cleanUpTracker, _IdleTimer_clearTimeout, _IdleTimer_resetTimer;
|
|
7464
|
-
class IdleTimer {
|
|
7465
|
-
constructor(params) {
|
|
7466
|
-
_IdleTimer_timeoutInMinutes.set(this, void 0);
|
|
7467
|
-
_IdleTimer_timer.set(this, void 0);
|
|
7468
|
-
_IdleTimer_onTimeout.set(this, void 0);
|
|
7469
|
-
this.tracker = () => {
|
|
7470
|
-
window.addEventListener('onload', __classPrivateFieldGet(this, _IdleTimer_resetTimer, "f"), true);
|
|
7471
|
-
window.addEventListener('mousemove', __classPrivateFieldGet(this, _IdleTimer_resetTimer, "f"), true);
|
|
7472
|
-
window.addEventListener('onmousedown', __classPrivateFieldGet(this, _IdleTimer_resetTimer, "f"), true);
|
|
7473
|
-
window.addEventListener('onscroll', __classPrivateFieldGet(this, _IdleTimer_resetTimer, "f"), true);
|
|
7474
|
-
window.addEventListener('onkeypress', __classPrivateFieldGet(this, _IdleTimer_resetTimer, "f"), true);
|
|
7475
|
-
};
|
|
7476
|
-
_IdleTimer_cleanUpTracker.set(this, () => {
|
|
7477
|
-
window.removeEventListener('onload', __classPrivateFieldGet(this, _IdleTimer_resetTimer, "f"), true);
|
|
7478
|
-
window.removeEventListener('mousemove', __classPrivateFieldGet(this, _IdleTimer_resetTimer, "f"), true);
|
|
7479
|
-
window.removeEventListener('onmousedown', __classPrivateFieldGet(this, _IdleTimer_resetTimer, "f"), true);
|
|
7480
|
-
window.removeEventListener('onscroll', __classPrivateFieldGet(this, _IdleTimer_resetTimer, "f"), true);
|
|
7481
|
-
window.removeEventListener('onkeypress', __classPrivateFieldGet(this, _IdleTimer_resetTimer, "f"), true);
|
|
7482
|
-
});
|
|
7483
|
-
_IdleTimer_clearTimeout.set(this, () => {
|
|
7484
|
-
if (__classPrivateFieldGet(this, _IdleTimer_timer, "f")) {
|
|
7485
|
-
clearTimeout(__classPrivateFieldGet(this, _IdleTimer_timer, "f"));
|
|
7486
|
-
}
|
|
7487
|
-
});
|
|
7488
|
-
_IdleTimer_resetTimer.set(this, () => {
|
|
7489
|
-
__classPrivateFieldGet(this, _IdleTimer_clearTimeout, "f").call(this);
|
|
7490
|
-
__classPrivateFieldSet(this, _IdleTimer_timer, setTimeout(() => {
|
|
7491
|
-
__classPrivateFieldGet(this, _IdleTimer_clearTimeout, "f").call(this);
|
|
7492
|
-
__classPrivateFieldGet(this, _IdleTimer_cleanUpTracker, "f").call(this);
|
|
7493
|
-
__classPrivateFieldGet(this, _IdleTimer_onTimeout, "f").call(this);
|
|
7494
|
-
}, __classPrivateFieldGet(this, _IdleTimer_timeoutInMinutes, "f") * 60 * 1000), "f");
|
|
7495
|
-
});
|
|
7496
|
-
const {
|
|
7497
|
-
timeoutInMinutes,
|
|
7498
|
-
onTimeout: onTimeout
|
|
7499
|
-
} = params;
|
|
7500
|
-
__classPrivateFieldSet(this, _IdleTimer_timeoutInMinutes, timeoutInMinutes, "f");
|
|
7501
|
-
__classPrivateFieldSet(this, _IdleTimer_onTimeout, onTimeout, "f");
|
|
7502
|
-
}
|
|
7503
|
-
}
|
|
7504
|
-
_IdleTimer_timeoutInMinutes = new WeakMap(), _IdleTimer_timer = new WeakMap(), _IdleTimer_onTimeout = new WeakMap(), _IdleTimer_cleanUpTracker = new WeakMap(), _IdleTimer_clearTimeout = new WeakMap(), _IdleTimer_resetTimer = new WeakMap();
|
|
7538
|
+
_Authentication_accessToken = new WeakMap(), _Authentication_config = new WeakMap(), _Authentication_leapAuthService = new WeakMap(), _Authentication_notification = new WeakMap(), _Authentication_idleTimer = new WeakMap(), _Authentication_refreshInfo = new WeakMap(), _Authentication_dedupeAccessTokenFetch = new WeakMap(), _Authentication_dedupeUserInfoFetch = new WeakMap(), _Authentication_startIdleTimer = new WeakMap(), _Authentication_exchangeAuthCodeForAccessToken = new WeakMap(), _Authentication_verifyAndPerformRedirections = new WeakMap(), _Authentication_startRefreshAccessTokenProcess = new WeakMap(), _Authentication_destroyRefreshAccessTokenProcess = new WeakMap(), _Authentication_decodeAccessToken = new WeakMap(), _Authentication_getRefreshedAccessTokenFactory = new WeakMap(), _Authentication_getUserInfoFactory = new WeakMap();
|
|
7505
7539
|
|
|
7506
7540
|
let auth;
|
|
7507
7541
|
const init = options => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -7509,15 +7543,6 @@
|
|
|
7509
7543
|
if (!auth) {
|
|
7510
7544
|
return false;
|
|
7511
7545
|
}
|
|
7512
|
-
const autoLogout = auth.autoLogout();
|
|
7513
|
-
if (autoLogout) {
|
|
7514
|
-
const timeoutInMinutes = auth.idleTimeoutInMinutes();
|
|
7515
|
-
const idleTimer = new IdleTimer({
|
|
7516
|
-
timeoutInMinutes,
|
|
7517
|
-
onTimeout: logout
|
|
7518
|
-
});
|
|
7519
|
-
idleTimer.tracker();
|
|
7520
|
-
}
|
|
7521
7546
|
const done = yield auth.checkAuthCode();
|
|
7522
7547
|
if (done) {
|
|
7523
7548
|
return auth.afterAuthenticated();
|
|
@@ -7746,6 +7771,23 @@
|
|
|
7746
7771
|
scopes
|
|
7747
7772
|
});
|
|
7748
7773
|
});
|
|
7774
|
+
const setIdleTimeoutInMinutes = timeoutInMinutes => {
|
|
7775
|
+
if (!auth) {
|
|
7776
|
+
throw Error('Not init yet');
|
|
7777
|
+
}
|
|
7778
|
+
if (typeof timeoutInMinutes !== "number") {
|
|
7779
|
+
throw Error('timeoutInMinutes must be a number');
|
|
7780
|
+
}
|
|
7781
|
+
auth.setIdleTimeoutInMinutes(timeoutInMinutes);
|
|
7782
|
+
return true;
|
|
7783
|
+
};
|
|
7784
|
+
const setAutoLogout = autoLogout => {
|
|
7785
|
+
if (!auth) {
|
|
7786
|
+
throw Error('Not init yet');
|
|
7787
|
+
}
|
|
7788
|
+
auth.setAutoLogout(autoLogout);
|
|
7789
|
+
return true;
|
|
7790
|
+
};
|
|
7749
7791
|
const AuthAgent = {
|
|
7750
7792
|
init,
|
|
7751
7793
|
registerHook,
|
|
@@ -7771,7 +7813,9 @@
|
|
|
7771
7813
|
changePassword,
|
|
7772
7814
|
registerEventListener,
|
|
7773
7815
|
passthrough,
|
|
7774
|
-
getRefreshTokenForApp
|
|
7816
|
+
getRefreshTokenForApp,
|
|
7817
|
+
setIdleTimeoutInMinutes,
|
|
7818
|
+
setAutoLogout
|
|
7775
7819
|
};
|
|
7776
7820
|
|
|
7777
7821
|
exports.AuthAgent = AuthAgent;
|
package/src/lib/auth-agent.d.ts
CHANGED
package/src/lib/auth-agent.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { __awaiter } from "tslib";
|
|
2
2
|
import { Authentication } from './authentication';
|
|
3
|
-
import { IdleTimer } from './idle-timer';
|
|
4
3
|
import { HookName } from './types';
|
|
5
4
|
let auth;
|
|
6
5
|
const init = (options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -8,12 +7,6 @@ const init = (options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
8
7
|
if (!auth) {
|
|
9
8
|
return false;
|
|
10
9
|
}
|
|
11
|
-
const autoLogout = auth.autoLogout();
|
|
12
|
-
if (autoLogout) {
|
|
13
|
-
const timeoutInMinutes = auth.idleTimeoutInMinutes();
|
|
14
|
-
const idleTimer = new IdleTimer({ timeoutInMinutes, onTimeout: logout });
|
|
15
|
-
idleTimer.tracker();
|
|
16
|
-
}
|
|
17
10
|
const done = yield auth.checkAuthCode();
|
|
18
11
|
if (done) {
|
|
19
12
|
return auth.afterAuthenticated();
|
|
@@ -202,6 +195,23 @@ const getRefreshTokenForApp = (params) => __awaiter(void 0, void 0, void 0, func
|
|
|
202
195
|
}
|
|
203
196
|
return auth.getRefreshTokenForApp({ clientId, scopes });
|
|
204
197
|
});
|
|
198
|
+
const setIdleTimeoutInMinutes = (timeoutInMinutes) => {
|
|
199
|
+
if (!auth) {
|
|
200
|
+
throw Error('Not init yet');
|
|
201
|
+
}
|
|
202
|
+
if (typeof timeoutInMinutes !== "number") {
|
|
203
|
+
throw Error('timeoutInMinutes must be a number');
|
|
204
|
+
}
|
|
205
|
+
auth.setIdleTimeoutInMinutes(timeoutInMinutes);
|
|
206
|
+
return true;
|
|
207
|
+
};
|
|
208
|
+
const setAutoLogout = (autoLogout) => {
|
|
209
|
+
if (!auth) {
|
|
210
|
+
throw Error('Not init yet');
|
|
211
|
+
}
|
|
212
|
+
auth.setAutoLogout(autoLogout);
|
|
213
|
+
return true;
|
|
214
|
+
};
|
|
205
215
|
export const AuthAgent = {
|
|
206
216
|
init,
|
|
207
217
|
registerHook,
|
|
@@ -228,4 +238,6 @@ export const AuthAgent = {
|
|
|
228
238
|
registerEventListener,
|
|
229
239
|
passthrough,
|
|
230
240
|
getRefreshTokenForApp,
|
|
241
|
+
setIdleTimeoutInMinutes,
|
|
242
|
+
setAutoLogout,
|
|
231
243
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var _Authentication_accessToken, _Authentication_config, _Authentication_leapAuthService, _Authentication_notification, _Authentication_refreshInfo, _Authentication_dedupeAccessTokenFetch, _Authentication_dedupeUserInfoFetch, _Authentication_exchangeAuthCodeForAccessToken, _Authentication_verifyAndPerformRedirections, _Authentication_startRefreshAccessTokenProcess, _Authentication_destroyRefreshAccessTokenProcess, _Authentication_decodeAccessToken, _Authentication_getRefreshedAccessTokenFactory, _Authentication_getUserInfoFactory;
|
|
1
|
+
var _Authentication_accessToken, _Authentication_config, _Authentication_leapAuthService, _Authentication_notification, _Authentication_idleTimer, _Authentication_refreshInfo, _Authentication_dedupeAccessTokenFetch, _Authentication_dedupeUserInfoFetch, _Authentication_startIdleTimer, _Authentication_exchangeAuthCodeForAccessToken, _Authentication_verifyAndPerformRedirections, _Authentication_startRefreshAccessTokenProcess, _Authentication_destroyRefreshAccessTokenProcess, _Authentication_decodeAccessToken, _Authentication_getRefreshedAccessTokenFactory, _Authentication_getUserInfoFactory;
|
|
2
2
|
import { __awaiter, __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
|
|
3
3
|
import { isFunction } from 'lodash';
|
|
4
4
|
import { init } from './config';
|
|
@@ -7,6 +7,7 @@ import { HookName, } from './types';
|
|
|
7
7
|
import { Notification } from './notification';
|
|
8
8
|
import { createCodeChallenge, createInFlightDedupe, createLoginUrl, createRandomString, deleteQueryParameter, getQueryParameter } from './utils';
|
|
9
9
|
import { getRedirectUri } from './redirections';
|
|
10
|
+
import { IdleTimer } from './idle-timer';
|
|
10
11
|
const SECONDS_BEFORE_EXPIRE = 30;
|
|
11
12
|
const MAX_SETTIME_OUT = 2147483647;
|
|
12
13
|
const DEFAULT_AUTHORIZE_TIMEOUT_IN_SECONDS = 60;
|
|
@@ -18,6 +19,7 @@ export class Authentication {
|
|
|
18
19
|
_Authentication_config.set(this, void 0);
|
|
19
20
|
_Authentication_leapAuthService.set(this, void 0);
|
|
20
21
|
_Authentication_notification.set(this, void 0);
|
|
22
|
+
_Authentication_idleTimer.set(this, void 0);
|
|
21
23
|
_Authentication_refreshInfo.set(this, void 0);
|
|
22
24
|
_Authentication_dedupeAccessTokenFetch.set(this, void 0);
|
|
23
25
|
_Authentication_dedupeUserInfoFetch.set(this, void 0);
|
|
@@ -381,6 +383,7 @@ export class Authentication {
|
|
|
381
383
|
this.afterAuthenticated = () => {
|
|
382
384
|
return this.triggerHooks(HookName.afterLogin).then(() => __awaiter(this, void 0, void 0, function* () {
|
|
383
385
|
yield this.initNotification();
|
|
386
|
+
__classPrivateFieldGet(this, _Authentication_startIdleTimer, "f").call(this);
|
|
384
387
|
return __classPrivateFieldGet(this, _Authentication_accessToken, "f");
|
|
385
388
|
}));
|
|
386
389
|
};
|
|
@@ -484,6 +487,31 @@ export class Authentication {
|
|
|
484
487
|
window.addEventListener('message', windowEventHandler);
|
|
485
488
|
});
|
|
486
489
|
});
|
|
490
|
+
this.setIdleTimeoutInMinutes = (timeoutInMinutes) => {
|
|
491
|
+
__classPrivateFieldGet(this, _Authentication_config, "f").idleTimeoutInMinutes = timeoutInMinutes;
|
|
492
|
+
__classPrivateFieldGet(this, _Authentication_startIdleTimer, "f").call(this);
|
|
493
|
+
};
|
|
494
|
+
this.setAutoLogout = (autoLogout) => {
|
|
495
|
+
__classPrivateFieldGet(this, _Authentication_config, "f").autoLogout = autoLogout;
|
|
496
|
+
if (autoLogout) {
|
|
497
|
+
__classPrivateFieldGet(this, _Authentication_startIdleTimer, "f").call(this);
|
|
498
|
+
}
|
|
499
|
+
else {
|
|
500
|
+
if (__classPrivateFieldGet(this, _Authentication_idleTimer, "f")) {
|
|
501
|
+
__classPrivateFieldGet(this, _Authentication_idleTimer, "f").resetTracker();
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
};
|
|
505
|
+
_Authentication_startIdleTimer.set(this, () => {
|
|
506
|
+
if (this.autoLogout()) {
|
|
507
|
+
if (__classPrivateFieldGet(this, _Authentication_idleTimer, "f")) {
|
|
508
|
+
__classPrivateFieldGet(this, _Authentication_idleTimer, "f").resetTracker();
|
|
509
|
+
}
|
|
510
|
+
const timeoutInMinutes = this.idleTimeoutInMinutes();
|
|
511
|
+
__classPrivateFieldSet(this, _Authentication_idleTimer, new IdleTimer({ timeoutInMinutes, onTimeout: this.logout }), "f");
|
|
512
|
+
__classPrivateFieldGet(this, _Authentication_idleTimer, "f").tracker();
|
|
513
|
+
}
|
|
514
|
+
});
|
|
487
515
|
_Authentication_exchangeAuthCodeForAccessToken.set(this, (params) => __awaiter(this, void 0, void 0, function* () {
|
|
488
516
|
const { verifier, code, redirectUri } = params;
|
|
489
517
|
if (verifier) {
|
|
@@ -616,4 +644,4 @@ export class Authentication {
|
|
|
616
644
|
__classPrivateFieldSet(this, _Authentication_dedupeUserInfoFetch, createInFlightDedupe(), "f");
|
|
617
645
|
}
|
|
618
646
|
}
|
|
619
|
-
_Authentication_accessToken = new WeakMap(), _Authentication_config = new WeakMap(), _Authentication_leapAuthService = new WeakMap(), _Authentication_notification = new WeakMap(), _Authentication_refreshInfo = new WeakMap(), _Authentication_dedupeAccessTokenFetch = new WeakMap(), _Authentication_dedupeUserInfoFetch = new WeakMap(), _Authentication_exchangeAuthCodeForAccessToken = new WeakMap(), _Authentication_verifyAndPerformRedirections = new WeakMap(), _Authentication_startRefreshAccessTokenProcess = new WeakMap(), _Authentication_destroyRefreshAccessTokenProcess = new WeakMap(), _Authentication_decodeAccessToken = new WeakMap(), _Authentication_getRefreshedAccessTokenFactory = new WeakMap(), _Authentication_getUserInfoFactory = new WeakMap();
|
|
647
|
+
_Authentication_accessToken = new WeakMap(), _Authentication_config = new WeakMap(), _Authentication_leapAuthService = new WeakMap(), _Authentication_notification = new WeakMap(), _Authentication_idleTimer = new WeakMap(), _Authentication_refreshInfo = new WeakMap(), _Authentication_dedupeAccessTokenFetch = new WeakMap(), _Authentication_dedupeUserInfoFetch = new WeakMap(), _Authentication_startIdleTimer = new WeakMap(), _Authentication_exchangeAuthCodeForAccessToken = new WeakMap(), _Authentication_verifyAndPerformRedirections = new WeakMap(), _Authentication_startRefreshAccessTokenProcess = new WeakMap(), _Authentication_destroyRefreshAccessTokenProcess = new WeakMap(), _Authentication_decodeAccessToken = new WeakMap(), _Authentication_getRefreshedAccessTokenFactory = new WeakMap(), _Authentication_getUserInfoFactory = new WeakMap();
|
package/src/lib/idle-timer.d.ts
CHANGED
package/src/lib/idle-timer.js
CHANGED
|
@@ -12,6 +12,11 @@ export class IdleTimer {
|
|
|
12
12
|
window.addEventListener('onscroll', __classPrivateFieldGet(this, _IdleTimer_resetTimer, "f"), true);
|
|
13
13
|
window.addEventListener('onkeypress', __classPrivateFieldGet(this, _IdleTimer_resetTimer, "f"), true);
|
|
14
14
|
};
|
|
15
|
+
this.resetTracker = () => {
|
|
16
|
+
__classPrivateFieldGet(this, _IdleTimer_clearTimeout, "f").call(this);
|
|
17
|
+
__classPrivateFieldSet(this, _IdleTimer_timer, undefined, "f");
|
|
18
|
+
__classPrivateFieldGet(this, _IdleTimer_cleanUpTracker, "f").call(this);
|
|
19
|
+
};
|
|
15
20
|
_IdleTimer_cleanUpTracker.set(this, () => {
|
|
16
21
|
window.removeEventListener('onload', __classPrivateFieldGet(this, _IdleTimer_resetTimer, "f"), true);
|
|
17
22
|
window.removeEventListener('mousemove', __classPrivateFieldGet(this, _IdleTimer_resetTimer, "f"), true);
|