@leapdev/auth-agent 2.0.0-alpha.0

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.
@@ -0,0 +1,68 @@
1
+ import { AccountLink, HookName, Hooks, InitOptions, UserInfo } from './types';
2
+ export declare class Authentication {
3
+ #private;
4
+ constructor(options: InitOptions);
5
+ initNotification: () => void;
6
+ destroyNotification: () => void;
7
+ login: () => Promise<string | undefined>;
8
+ logout: (force?: boolean, redirectUrl?: string | undefined) => void;
9
+ getAccessToken: () => string;
10
+ getDecodedAccessToken: () => any;
11
+ getHooks: () => Hooks | undefined;
12
+ setHook: (params: {
13
+ name: HookName;
14
+ callback: (params?: any) => any;
15
+ }) => void;
16
+ autoLogin: () => boolean;
17
+ autoLogout: () => boolean;
18
+ idleTimeoutInMinutes: () => number;
19
+ createCodeVerifier: (size: number) => string;
20
+ createCodeChallenge: (verifier: string) => string;
21
+ checkAuthCode: () => Promise<boolean>;
22
+ exchangeAuthCodeForAccessToken: (params: {
23
+ code: string;
24
+ verifier: string;
25
+ redirectUri: string;
26
+ }) => Promise<{
27
+ ok: boolean;
28
+ value: any;
29
+ }>;
30
+ getUserInfo: () => Promise<UserInfo>;
31
+ linkUser: (params: {
32
+ redirectUrl?: string;
33
+ newWindow?: boolean;
34
+ callback?: any;
35
+ }) => void;
36
+ unlinkUser: (params: {
37
+ redirectUrl?: string;
38
+ newWindow?: boolean;
39
+ callback?: any;
40
+ }) => void;
41
+ getCloudProviderToken: (jti?: string | undefined) => Promise<any>;
42
+ cloudProviderUserInfo: () => Promise<any>;
43
+ cloudProviderReauthenticate: (params: {
44
+ redirectUrl?: string;
45
+ nonce?: string;
46
+ newWindow?: boolean;
47
+ callback?: any;
48
+ }) => Promise<void>;
49
+ statusAdminConsent: () => Promise<boolean>;
50
+ getAdminConsent: (params: {
51
+ domain?: string;
52
+ redirectUrl?: string;
53
+ newWindow?: boolean;
54
+ callback?: any;
55
+ }) => void;
56
+ revokeAdminConsent: () => Promise<boolean>;
57
+ getLinkMap: (allUsers?: boolean) => Promise<AccountLink[]>;
58
+ setLinkMap: (linkMap: Array<AccountLink>) => Promise<void>;
59
+ authoriseSupport: (params: {
60
+ code: string;
61
+ duration: number;
62
+ }) => Promise<string>;
63
+ changePassword: (params: {
64
+ redirectUrl?: string;
65
+ newWindow?: boolean;
66
+ callback?: any;
67
+ }) => void;
68
+ }
@@ -0,0 +1,289 @@
1
+ "use strict";
2
+ var _Authentication_accessToken, _Authentication_config, _Authentication_leapAuthService, _Authentication_notification;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.Authentication = void 0;
5
+ const tslib_1 = require("tslib");
6
+ const crypto_random_string_1 = require("crypto-random-string");
7
+ const js_sha256_1 = require("js-sha256");
8
+ const lodash_1 = require("lodash");
9
+ const config_1 = require("./config");
10
+ const auth_service_1 = require("./auth.service");
11
+ const notification_1 = require("./notification");
12
+ const hookNames = ['afterLogin', 'beforeLogout'];
13
+ class Authentication {
14
+ constructor(options) {
15
+ _Authentication_accessToken.set(this, void 0);
16
+ _Authentication_config.set(this, void 0);
17
+ _Authentication_leapAuthService.set(this, void 0);
18
+ _Authentication_notification.set(this, void 0);
19
+ this.initNotification = () => {
20
+ const decodedToken = this.getDecodedAccessToken();
21
+ tslib_1.__classPrivateFieldGet(this, _Authentication_notification, "f").init({
22
+ authHost: tslib_1.__classPrivateFieldGet(this, _Authentication_config, "f").authHost,
23
+ clientId: tslib_1.__classPrivateFieldGet(this, _Authentication_config, "f").clientId,
24
+ firmId: decodedToken.firmId,
25
+ userId: decodedToken.userId,
26
+ uniqueSession: !!tslib_1.__classPrivateFieldGet(this, _Authentication_config, "f").uniqueSession,
27
+ });
28
+ };
29
+ this.destroyNotification = () => {
30
+ tslib_1.__classPrivateFieldGet(this, _Authentication_notification, "f").destroy();
31
+ };
32
+ this.login = () => tslib_1.__awaiter(this, void 0, void 0, function* () {
33
+ const done = yield this.checkAuthCode();
34
+ if (done && !!tslib_1.__classPrivateFieldGet(this, _Authentication_accessToken, "f")) {
35
+ return tslib_1.__classPrivateFieldGet(this, _Authentication_accessToken, "f");
36
+ }
37
+ else {
38
+ const code_verifier = this.createCodeVerifier(64);
39
+ const state = (0, crypto_random_string_1.default)({ length: 6, type: 'alphanumeric' });
40
+ //* store verifier into browser session for later auth-code exchange
41
+ window.sessionStorage.setItem(state, code_verifier);
42
+ const code_challenge = this.createCodeChallenge(code_verifier);
43
+ const scope = tslib_1.__classPrivateFieldGet(this, _Authentication_config, "f").scopes.join(',');
44
+ const url = `${tslib_1.__classPrivateFieldGet(this, _Authentication_config, "f").authHost}/oauth/authorize?response_type=code&scope=${scope}&client_id=${tslib_1.__classPrivateFieldGet(this, _Authentication_config, "f").clientId}&redirect_uri=${encodeURIComponent(window.location.href)}&code_challenge=${encodeURIComponent(code_challenge)}&code_challenge_method=SH256&state=${state}`;
45
+ window.location.assign(url);
46
+ return;
47
+ }
48
+ });
49
+ this.logout = (force = false, redirectUrl) => {
50
+ tslib_1.__classPrivateFieldSet(this, _Authentication_accessToken, undefined, "f");
51
+ const redirectUri = encodeURIComponent(redirectUrl || window.location.href);
52
+ window.location.href = `${tslib_1.__classPrivateFieldGet(this, _Authentication_config, "f").authHost}/oauth/logout?force=${force}&redirect_uri=${redirectUri}`;
53
+ };
54
+ this.getAccessToken = () => {
55
+ if (tslib_1.__classPrivateFieldGet(this, _Authentication_accessToken, "f") === undefined || !tslib_1.__classPrivateFieldGet(this, _Authentication_accessToken, "f")) {
56
+ this.login();
57
+ return '';
58
+ }
59
+ else {
60
+ return tslib_1.__classPrivateFieldGet(this, _Authentication_accessToken, "f");
61
+ }
62
+ };
63
+ //todo: need to replace the return type "any"
64
+ this.getDecodedAccessToken = () => {
65
+ if (!tslib_1.__classPrivateFieldGet(this, _Authentication_accessToken, "f")) {
66
+ return undefined;
67
+ }
68
+ const payload = tslib_1.__classPrivateFieldGet(this, _Authentication_accessToken, "f").split('.')[1];
69
+ if (payload) {
70
+ try {
71
+ const result = window.atob(payload);
72
+ return JSON.parse(result);
73
+ }
74
+ catch (e) {
75
+ throw Error('Fail to decode access token.');
76
+ }
77
+ }
78
+ return undefined;
79
+ };
80
+ this.getHooks = () => {
81
+ if (tslib_1.__classPrivateFieldGet(this, _Authentication_config, "f")) {
82
+ return tslib_1.__classPrivateFieldGet(this, _Authentication_config, "f").hooks;
83
+ }
84
+ else {
85
+ return undefined;
86
+ }
87
+ };
88
+ this.setHook = (params) => {
89
+ const { name, callback } = params;
90
+ if (hookNames.indexOf(name) < 0) {
91
+ throw Error('Unimplemented hook : ' + name);
92
+ }
93
+ if ((0, lodash_1.isFunction)(callback)) {
94
+ throw Error('hook must be a function: ' + name);
95
+ }
96
+ tslib_1.__classPrivateFieldSet(this, _Authentication_config, Object.assign(Object.assign({}, tslib_1.__classPrivateFieldGet(this, _Authentication_config, "f")), { hooks: Object.assign(Object.assign({}, tslib_1.__classPrivateFieldGet(this, _Authentication_config, "f").hooks), { [name]: callback }) }), "f");
97
+ return;
98
+ };
99
+ this.autoLogin = () => {
100
+ return tslib_1.__classPrivateFieldGet(this, _Authentication_config, "f") ? tslib_1.__classPrivateFieldGet(this, _Authentication_config, "f").autoLogin || false : false;
101
+ };
102
+ this.autoLogout = () => {
103
+ return tslib_1.__classPrivateFieldGet(this, _Authentication_config, "f") ? tslib_1.__classPrivateFieldGet(this, _Authentication_config, "f").autoLogin || false : false;
104
+ };
105
+ this.idleTimeoutInMinutes = () => {
106
+ return tslib_1.__classPrivateFieldGet(this, _Authentication_config, "f") ? tslib_1.__classPrivateFieldGet(this, _Authentication_config, "f").idleTimeoutInMinutes || 30 : 30;
107
+ };
108
+ this.createCodeVerifier = (size) => {
109
+ return (0, crypto_random_string_1.default)({
110
+ length: size,
111
+ type: 'alphanumeric',
112
+ });
113
+ };
114
+ this.createCodeChallenge = (verifier) => {
115
+ return btoa((0, js_sha256_1.sha256)(verifier).toLowerCase());
116
+ };
117
+ this.checkAuthCode = () => tslib_1.__awaiter(this, void 0, void 0, function* () {
118
+ const search = window.location.search;
119
+ const queryParams = new URLSearchParams(search);
120
+ const code = queryParams.get('code');
121
+ const state = queryParams.get('state');
122
+ //* check if "AuthCode" comes back from AuthServer
123
+ if (!!code && !!state) {
124
+ const verifier = window.sessionStorage.getItem(state);
125
+ window.sessionStorage.removeItem(state);
126
+ queryParams.delete('code');
127
+ queryParams.delete('state');
128
+ const newUrl = window.location.origin + '/' + queryParams.toString();
129
+ window.history.replaceState(null, '', newUrl);
130
+ //* use the Verifier and AuthCode to exchange for AccessToken
131
+ if (verifier) {
132
+ const data = yield this.exchangeAuthCodeForAccessToken({
133
+ code,
134
+ verifier,
135
+ redirectUri: newUrl,
136
+ });
137
+ //* store access token for later use. It should be stored in Agent's memory
138
+ tslib_1.__classPrivateFieldSet(this, _Authentication_accessToken, data.value.access_token, "f");
139
+ return true;
140
+ }
141
+ return false;
142
+ }
143
+ else {
144
+ return false;
145
+ }
146
+ });
147
+ this.exchangeAuthCodeForAccessToken = (params) => tslib_1.__awaiter(this, void 0, void 0, function* () {
148
+ const { code, verifier, redirectUri } = params;
149
+ const url = `${tslib_1.__classPrivateFieldGet(this, _Authentication_config, "f").authHost}/oauth/token`;
150
+ const body = `grant_type=authorization_code&code=${code}&redirect_uri=${redirectUri}&client_id=${tslib_1.__classPrivateFieldGet(this, _Authentication_config, "f").clientId}&code_verifier=${verifier}`;
151
+ const response = yield fetch(url, {
152
+ method: 'POST',
153
+ headers: {
154
+ Accept: 'application/json',
155
+ 'Content-Type': 'application/x-www-form-urlencoded',
156
+ },
157
+ body: body,
158
+ });
159
+ const { ok } = response;
160
+ if (!ok) {
161
+ throw new Error('Unable to get access token');
162
+ }
163
+ const resBody = yield response.json();
164
+ if (!!resBody && !!resBody.Error) {
165
+ throw new Error(resBody.Error);
166
+ }
167
+ return Promise.resolve({
168
+ ok: true,
169
+ value: Object.assign({}, resBody),
170
+ });
171
+ });
172
+ this.getUserInfo = () => {
173
+ return tslib_1.__classPrivateFieldGet(this, _Authentication_leapAuthService, "f").userInfo(tslib_1.__classPrivateFieldGet(this, _Authentication_accessToken, "f"));
174
+ };
175
+ this.linkUser = (params) => {
176
+ const decodeToken = this.getDecodedAccessToken();
177
+ if (!decodeToken) {
178
+ return;
179
+ }
180
+ const redirectUrl = params.redirectUrl || window.location.href;
181
+ tslib_1.__classPrivateFieldGet(this, _Authentication_leapAuthService, "f").linkUser({
182
+ redirectUrl,
183
+ jti: decodeToken.jti,
184
+ newWindow: params.newWindow,
185
+ callback: params.callback,
186
+ });
187
+ };
188
+ this.unlinkUser = (params) => {
189
+ const decodeToken = this.getDecodedAccessToken();
190
+ if (!decodeToken) {
191
+ return;
192
+ }
193
+ const redirectUrl = params.redirectUrl || window.location.href;
194
+ tslib_1.__classPrivateFieldGet(this, _Authentication_leapAuthService, "f").unlinkUser({
195
+ redirectUrl,
196
+ jti: decodeToken.jti,
197
+ newWindow: params.newWindow,
198
+ callback: params.callback,
199
+ });
200
+ };
201
+ this.getCloudProviderToken = (jti) => {
202
+ if (!tslib_1.__classPrivateFieldGet(this, _Authentication_accessToken, "f")) {
203
+ throw Error('Not authenticated yet');
204
+ }
205
+ return tslib_1.__classPrivateFieldGet(this, _Authentication_leapAuthService, "f").getCloudProviderToken(tslib_1.__classPrivateFieldGet(this, _Authentication_accessToken, "f"), jti);
206
+ };
207
+ this.cloudProviderUserInfo = () => {
208
+ if (!tslib_1.__classPrivateFieldGet(this, _Authentication_accessToken, "f")) {
209
+ throw Error('Not authenticated yet');
210
+ }
211
+ return tslib_1.__classPrivateFieldGet(this, _Authentication_leapAuthService, "f").cloudProviderUserInfo(tslib_1.__classPrivateFieldGet(this, _Authentication_accessToken, "f"));
212
+ };
213
+ this.cloudProviderReauthenticate = (params) => tslib_1.__awaiter(this, void 0, void 0, function* () {
214
+ if (!tslib_1.__classPrivateFieldGet(this, _Authentication_accessToken, "f")) {
215
+ throw Error('Not authenticated yet');
216
+ }
217
+ let { nonce, redirectUrl } = params;
218
+ const { newWindow, callback } = params;
219
+ redirectUrl = redirectUrl || window.location.href;
220
+ if (!nonce) {
221
+ const reauthticateLink = yield tslib_1.__classPrivateFieldGet(this, _Authentication_leapAuthService, "f").cloudProviderReauthenticateLink(tslib_1.__classPrivateFieldGet(this, _Authentication_accessToken, "f"));
222
+ nonce = reauthticateLink.nonce;
223
+ }
224
+ return tslib_1.__classPrivateFieldGet(this, _Authentication_leapAuthService, "f").cloudProviderReauthenticate({
225
+ redirectUrl,
226
+ nonce,
227
+ newWindow,
228
+ callback,
229
+ });
230
+ });
231
+ this.statusAdminConsent = () => {
232
+ if (!tslib_1.__classPrivateFieldGet(this, _Authentication_accessToken, "f")) {
233
+ throw Error('Not authenticated yet');
234
+ }
235
+ return tslib_1.__classPrivateFieldGet(this, _Authentication_leapAuthService, "f").statusAdminConsent(tslib_1.__classPrivateFieldGet(this, _Authentication_accessToken, "f"));
236
+ };
237
+ this.getAdminConsent = (params) => {
238
+ const redirectUrl = params.redirectUrl || window.location.href;
239
+ tslib_1.__classPrivateFieldGet(this, _Authentication_leapAuthService, "f").getAdminConsent(Object.assign(Object.assign({}, params), { redirectUrl }));
240
+ };
241
+ this.revokeAdminConsent = () => {
242
+ if (!tslib_1.__classPrivateFieldGet(this, _Authentication_accessToken, "f")) {
243
+ throw Error('Not authenticated yet');
244
+ }
245
+ return tslib_1.__classPrivateFieldGet(this, _Authentication_leapAuthService, "f").revokeAdminConsent(tslib_1.__classPrivateFieldGet(this, _Authentication_accessToken, "f"));
246
+ };
247
+ this.getLinkMap = (allUsers = false) => {
248
+ if (!tslib_1.__classPrivateFieldGet(this, _Authentication_accessToken, "f")) {
249
+ throw Error('Not authenticated yet');
250
+ }
251
+ return tslib_1.__classPrivateFieldGet(this, _Authentication_leapAuthService, "f").getLinkMap(tslib_1.__classPrivateFieldGet(this, _Authentication_accessToken, "f"), allUsers);
252
+ };
253
+ this.setLinkMap = (linkMap) => {
254
+ if (!tslib_1.__classPrivateFieldGet(this, _Authentication_accessToken, "f")) {
255
+ throw Error('Not authenticated yet');
256
+ }
257
+ const verifyFormat = () => {
258
+ if (Array.isArray(linkMap)) {
259
+ for (const link of linkMap) {
260
+ if (!(link.internalUser && link.externalUser && link.externalUser.id))
261
+ return false;
262
+ }
263
+ return true;
264
+ }
265
+ return false;
266
+ };
267
+ if (!verifyFormat())
268
+ throw Error('linkmap in wrong format');
269
+ return tslib_1.__classPrivateFieldGet(this, _Authentication_leapAuthService, "f").setLinkMap(tslib_1.__classPrivateFieldGet(this, _Authentication_accessToken, "f"), linkMap);
270
+ };
271
+ this.authoriseSupport = (params) => {
272
+ if (!tslib_1.__classPrivateFieldGet(this, _Authentication_accessToken, "f")) {
273
+ throw Error('Not authenticated yet');
274
+ }
275
+ return tslib_1.__classPrivateFieldGet(this, _Authentication_leapAuthService, "f").authoriseSupport(tslib_1.__classPrivateFieldGet(this, _Authentication_accessToken, "f"), params);
276
+ };
277
+ this.changePassword = (params) => {
278
+ const redirectUrl = params.redirectUrl || window.location.href;
279
+ tslib_1.__classPrivateFieldGet(this, _Authentication_leapAuthService, "f").changePassword(Object.assign(Object.assign({}, params), { redirectUrl }));
280
+ };
281
+ tslib_1.__classPrivateFieldSet(this, _Authentication_accessToken, undefined, "f");
282
+ tslib_1.__classPrivateFieldSet(this, _Authentication_config, (0, config_1.init)(options), "f");
283
+ tslib_1.__classPrivateFieldSet(this, _Authentication_leapAuthService, new auth_service_1.LeapAuthService(tslib_1.__classPrivateFieldGet(this, _Authentication_config, "f").authHost, tslib_1.__classPrivateFieldGet(this, _Authentication_config, "f").clientId), "f");
284
+ tslib_1.__classPrivateFieldSet(this, _Authentication_notification, new notification_1.Notification(), "f");
285
+ }
286
+ }
287
+ exports.Authentication = Authentication;
288
+ _Authentication_accessToken = new WeakMap(), _Authentication_config = new WeakMap(), _Authentication_leapAuthService = new WeakMap(), _Authentication_notification = new WeakMap();
289
+ //# sourceMappingURL=authentication.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authentication.js","sourceRoot":"","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AAA,IAAI,mCAAoB,IAAI,8BAAe,CACzC,+BAAA,IAAI,8BAAQ,CAAC,QAAQ,EACrB,+BAAA,IAAI,8BAAQ,CAAC,QAAQ,CACtB,MAAA,CAAC;QACF,+BAAA,IAAI,gCAAiB,IAAI,2BAAY,EAAE,MAAA,CAAC;IAC1C,CAAC;CA+WF;AA7XD,wCA6XC"}
@@ -0,0 +1,3 @@
1
+ import { Complete, InitOptions } from './types';
2
+ export declare type Config = Complete<InitOptions>;
3
+ export declare const init: (options: InitOptions) => Config;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.init = void 0;
4
+ const lodash_1 = require("lodash");
5
+ const DEFAULT_CONFIG = {
6
+ autoLogin: true,
7
+ autoLogout: true,
8
+ idleTimeoutInMinutes: 30,
9
+ uniqueSession: true,
10
+ hooks: {},
11
+ };
12
+ const requiredParams = ['authHost', 'clientId', 'scopes'];
13
+ const init = (options) => {
14
+ (0, lodash_1.forEach)(requiredParams, (p) => {
15
+ if (!(0, lodash_1.has)(options, p)) {
16
+ throw Error('Missing config parameter : ' + p);
17
+ }
18
+ });
19
+ if (!(0, lodash_1.isArray)(options.scopes)) {
20
+ throw Error('Scopes must be an array with string values');
21
+ }
22
+ const config = Object.assign(Object.assign({}, DEFAULT_CONFIG), options);
23
+ return config;
24
+ };
25
+ exports.init = init;
26
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../../../../packages/auth-agent/src/lib/config.ts"],"names":[],"mappings":";;;AACA,mCAA+C;AAI/C,MAAM,cAAc,GAAG;IACrB,SAAS,EAAE,IAAI;IACf,UAAU,EAAE,IAAI;IAChB,oBAAoB,EAAE,EAAE;IACxB,aAAa,EAAE,IAAI;IACnB,KAAK,EAAE,EAAE;CACV,CAAC;AAEF,MAAM,cAAc,GAAG,CAAC,UAAU,EAAE,UAAU,EAAE,QAAQ,CAAC,CAAC;AAEnD,MAAM,IAAI,GAAG,CAAC,OAAoB,EAAU,EAAE;IACnD,IAAA,gBAAO,EAAC,cAAc,EAAE,CAAC,CAAC,EAAE,EAAE;QAC5B,IAAI,CAAC,IAAA,YAAG,EAAC,OAAO,EAAE,CAAC,CAAC,EAAE;YACpB,MAAM,KAAK,CAAC,6BAA6B,GAAG,CAAC,CAAC,CAAC;SAChD;IACH,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,IAAA,gBAAO,EAAC,OAAO,CAAC,MAAM,CAAC,EAAE;QAC5B,MAAM,KAAK,CAAC,4CAA4C,CAAC,CAAC;KAC3D;IAED,MAAM,MAAM,mCACP,cAAc,GACd,OAAO,CACX,CAAC;IAEF,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAjBW,QAAA,IAAI,QAiBf"}
@@ -0,0 +1,8 @@
1
+ export declare class IdleTimer {
2
+ #private;
3
+ constructor(params: {
4
+ timeoutInMinutes: number;
5
+ onTimeout: () => void;
6
+ });
7
+ tracker: () => void;
8
+ }
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ var _IdleTimer_timeoutInMinutes, _IdleTimer_timer, _IdleTimer_onTimeout, _IdleTimer_cleanUpTracker, _IdleTimer_clearTimeout, _IdleTimer_resetTimer;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.IdleTimer = void 0;
5
+ const tslib_1 = require("tslib");
6
+ class IdleTimer {
7
+ constructor(params) {
8
+ _IdleTimer_timeoutInMinutes.set(this, void 0);
9
+ _IdleTimer_timer.set(this, void 0);
10
+ _IdleTimer_onTimeout.set(this, void 0);
11
+ this.tracker = () => {
12
+ window.addEventListener('onload', tslib_1.__classPrivateFieldGet(this, _IdleTimer_resetTimer, "f"), true);
13
+ window.addEventListener('mousemove', tslib_1.__classPrivateFieldGet(this, _IdleTimer_resetTimer, "f"), true);
14
+ window.addEventListener('onmousedown', tslib_1.__classPrivateFieldGet(this, _IdleTimer_resetTimer, "f"), true);
15
+ window.addEventListener('onscroll', tslib_1.__classPrivateFieldGet(this, _IdleTimer_resetTimer, "f"), true);
16
+ window.addEventListener('onkeypress', tslib_1.__classPrivateFieldGet(this, _IdleTimer_resetTimer, "f"), true);
17
+ };
18
+ _IdleTimer_cleanUpTracker.set(this, () => {
19
+ window.removeEventListener('onload', tslib_1.__classPrivateFieldGet(this, _IdleTimer_resetTimer, "f"), true);
20
+ window.removeEventListener('mousemove', tslib_1.__classPrivateFieldGet(this, _IdleTimer_resetTimer, "f"), true);
21
+ window.removeEventListener('onmousedown', tslib_1.__classPrivateFieldGet(this, _IdleTimer_resetTimer, "f"), true);
22
+ window.removeEventListener('onscroll', tslib_1.__classPrivateFieldGet(this, _IdleTimer_resetTimer, "f"), true);
23
+ window.removeEventListener('onkeypress', tslib_1.__classPrivateFieldGet(this, _IdleTimer_resetTimer, "f"), true);
24
+ });
25
+ _IdleTimer_clearTimeout.set(this, () => {
26
+ if (tslib_1.__classPrivateFieldGet(this, _IdleTimer_timer, "f")) {
27
+ clearTimeout(tslib_1.__classPrivateFieldGet(this, _IdleTimer_timer, "f"));
28
+ }
29
+ });
30
+ _IdleTimer_resetTimer.set(this, () => {
31
+ tslib_1.__classPrivateFieldGet(this, _IdleTimer_clearTimeout, "f").call(this);
32
+ tslib_1.__classPrivateFieldSet(this, _IdleTimer_timer, setTimeout(() => {
33
+ tslib_1.__classPrivateFieldGet(this, _IdleTimer_clearTimeout, "f").call(this);
34
+ tslib_1.__classPrivateFieldGet(this, _IdleTimer_cleanUpTracker, "f").call(this);
35
+ tslib_1.__classPrivateFieldGet(this, _IdleTimer_onTimeout, "f").call(this);
36
+ }, tslib_1.__classPrivateFieldGet(this, _IdleTimer_timeoutInMinutes, "f") * 60 * 1000), "f");
37
+ });
38
+ const { timeoutInMinutes, onTimeout: onTimeout } = params;
39
+ tslib_1.__classPrivateFieldSet(this, _IdleTimer_timeoutInMinutes, timeoutInMinutes, "f");
40
+ tslib_1.__classPrivateFieldSet(this, _IdleTimer_onTimeout, onTimeout, "f");
41
+ }
42
+ }
43
+ exports.IdleTimer = IdleTimer;
44
+ _IdleTimer_timeoutInMinutes = new WeakMap(), _IdleTimer_timer = new WeakMap(), _IdleTimer_onTimeout = new WeakMap(), _IdleTimer_cleanUpTracker = new WeakMap(), _IdleTimer_clearTimeout = new WeakMap(), _IdleTimer_resetTimer = new WeakMap();
45
+ //# sourceMappingURL=idle-timer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"idle-timer.js","sourceRoot":"","sources":["../../../../../packages/auth-agent/src/lib/idle-timer.ts"],"names":[],"mappings":";;;;;AACA,MAAa,SAAS;IAKpB,YAAY,MAA2D;QAJvE,8CAA0B;QAC1B,mCAAmC;QACnC,uCAAuB;QAQvB,YAAO,GAAG,GAAG,EAAE;YACb,MAAM,CAAC,gBAAgB,CAAC,QAAQ,EAAE,+BAAA,IAAI,6BAAY,EAAE,IAAI,CAAC,CAAC;YAC1D,MAAM,CAAC,gBAAgB,CAAC,WAAW,EAAE,+BAAA,IAAI,6BAAY,EAAE,IAAI,CAAC,CAAC;YAC7D,MAAM,CAAC,gBAAgB,CAAC,aAAa,EAAE,+BAAA,IAAI,6BAAY,EAAE,IAAI,CAAC,CAAC;YAC/D,MAAM,CAAC,gBAAgB,CAAC,UAAU,EAAE,+BAAA,IAAI,6BAAY,EAAE,IAAI,CAAC,CAAC;YAC5D,MAAM,CAAC,gBAAgB,CAAC,YAAY,EAAE,+BAAA,IAAI,6BAAY,EAAE,IAAI,CAAC,CAAC;QAChE,CAAC,CAAC;QAEF,oCAAkB,GAAG,EAAE;YACrB,MAAM,CAAC,mBAAmB,CAAC,QAAQ,EAAE,+BAAA,IAAI,6BAAY,EAAE,IAAI,CAAC,CAAC;YAC7D,MAAM,CAAC,mBAAmB,CAAC,WAAW,EAAE,+BAAA,IAAI,6BAAY,EAAE,IAAI,CAAC,CAAC;YAChE,MAAM,CAAC,mBAAmB,CAAC,aAAa,EAAE,+BAAA,IAAI,6BAAY,EAAE,IAAI,CAAC,CAAC;YAClE,MAAM,CAAC,mBAAmB,CAAC,UAAU,EAAE,+BAAA,IAAI,6BAAY,EAAE,IAAI,CAAC,CAAC;YAC/D,MAAM,CAAC,mBAAmB,CAAC,YAAY,EAAE,+BAAA,IAAI,6BAAY,EAAE,IAAI,CAAC,CAAC;QACnE,CAAC,EAAC;QAEF,kCAAgB,GAAG,EAAE;YACnB,IAAI,+BAAA,IAAI,wBAAO,EAAE;gBACf,YAAY,CAAC,+BAAA,IAAI,wBAAO,CAAC,CAAC;aAC3B;QACH,CAAC,EAAC;QAEF,gCAAc,GAAG,EAAE;YACjB,+BAAA,IAAI,+BAAc,MAAlB,IAAI,CAAgB,CAAC;YAErB,+BAAA,IAAI,oBAAU,UAAU,CAAC,GAAG,EAAE;gBAC5B,+BAAA,IAAI,+BAAc,MAAlB,IAAI,CAAgB,CAAC;gBACrB,+BAAA,IAAI,iCAAgB,MAApB,IAAI,CAAkB,CAAC;gBACvB,+BAAA,IAAI,4BAAW,MAAf,IAAI,CAAa,CAAC;YACpB,CAAC,EAAE,+BAAA,IAAI,mCAAkB,GAAG,EAAE,GAAG,IAAI,CAAC,MAAA,CAAC;QACzC,CAAC,EAAC;QAnCA,MAAM,EAAE,gBAAgB,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,MAAM,CAAC;QAC1D,+BAAA,IAAI,+BAAqB,gBAAgB,MAAA,CAAC;QAC1C,+BAAA,IAAI,wBAAc,SAAS,MAAA,CAAC;IAC9B,CAAC;CAiCF;AA1CD,8BA0CC"}
@@ -0,0 +1,17 @@
1
+ export declare class Notification {
2
+ #private;
3
+ constructor();
4
+ init: (params: {
5
+ authHost: string;
6
+ clientId: string;
7
+ firmId: string;
8
+ userId: string;
9
+ uniqueSession: boolean;
10
+ }) => void;
11
+ destroy: () => void;
12
+ registerEventListenerForUserChannel: (params: {
13
+ topic: string;
14
+ messageType: string;
15
+ callback: any;
16
+ }) => void;
17
+ }
@@ -0,0 +1,158 @@
1
+ "use strict";
2
+ var _Notification_pubnubKeys, _Notification_pubnub, _Notification_eventListeners, _Notification_initFirmChannel, _Notification_initUserChannel, _Notification_initUniqueSessionChannel;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.Notification = void 0;
5
+ const tslib_1 = require("tslib");
6
+ const uuid_1 = require("uuid");
7
+ const Pubnub = require("pubnub");
8
+ const auth_agent_1 = require("./auth-agent");
9
+ const lodash_1 = require("lodash");
10
+ const EMPTY_GUID = '00000000-0000-0000-0000-000000000000';
11
+ const USER_ACTION = {
12
+ USERNAME_CHANGED: '1',
13
+ PASSWORD_CHANGED: '2',
14
+ USER_DISABLED: '3', // 3 - User has been disabled
15
+ };
16
+ class Notification {
17
+ constructor() {
18
+ _Notification_pubnubKeys.set(this, void 0);
19
+ _Notification_pubnub.set(this, void 0);
20
+ _Notification_eventListeners.set(this, []);
21
+ this.init = (params) => {
22
+ const { authHost, clientId, firmId, userId, uniqueSession } = params;
23
+ tslib_1.__classPrivateFieldGet(this, _Notification_initFirmChannel, "f").call(this, firmId, userId);
24
+ tslib_1.__classPrivateFieldGet(this, _Notification_initUserChannel, "f").call(this, userId);
25
+ if (uniqueSession) {
26
+ tslib_1.__classPrivateFieldGet(this, _Notification_initUniqueSessionChannel, "f").call(this, { authHost, clientId });
27
+ }
28
+ };
29
+ this.destroy = () => {
30
+ if (tslib_1.__classPrivateFieldGet(this, _Notification_pubnub, "f")) {
31
+ tslib_1.__classPrivateFieldGet(this, _Notification_pubnub, "f").unsubscribeAll();
32
+ tslib_1.__classPrivateFieldSet(this, _Notification_eventListeners, [], "f");
33
+ }
34
+ };
35
+ this.registerEventListenerForUserChannel = (params) => {
36
+ const { topic, messageType, callback } = params;
37
+ if (!(0, lodash_1.isFunction)(callback)) {
38
+ throw Error(`Registering Event Listener ${topic} ${messageType}: callback needs to be a function`);
39
+ }
40
+ tslib_1.__classPrivateFieldGet(this, _Notification_eventListeners, "f").push({ topic, messageType, callback });
41
+ };
42
+ _Notification_initFirmChannel.set(this, (firmId, userId) => {
43
+ tslib_1.__classPrivateFieldGet(this, _Notification_pubnub, "f").addListener({
44
+ presence: (presenceEvent) => {
45
+ //* handle presence
46
+ const { action, uuid } = presenceEvent;
47
+ //* the message was sent from the current pubnub instance
48
+ if (uuid === tslib_1.__classPrivateFieldGet(this, _Notification_pubnubKeys, "f").uuid) {
49
+ return;
50
+ }
51
+ //* handle action 'leave' and 'timeout'
52
+ if (action === 'leave' || action === 'timeout') {
53
+ const valuesUUID = uuid.split('~');
54
+ const userIdFromPresence = valuesUUID[0] || '';
55
+ const instanceGuidFromPresence = valuesUUID[1] || '';
56
+ const userActionFromPresence = valuesUUID[2] || '';
57
+ const isUserActionRequiredLogout = userActionFromPresence === USER_ACTION.USERNAME_CHANGED ||
58
+ userActionFromPresence === USER_ACTION.PASSWORD_CHANGED ||
59
+ userActionFromPresence === USER_ACTION.USER_DISABLED;
60
+ if (userIdFromPresence === userId &&
61
+ instanceGuidFromPresence === EMPTY_GUID &&
62
+ isUserActionRequiredLogout) {
63
+ //* User Information has been changed, force user to logout
64
+ auth_agent_1.AuthAgent.logout(true); // call logout with force=true (because the logout is forced)
65
+ }
66
+ }
67
+ },
68
+ });
69
+ tslib_1.__classPrivateFieldGet(this, _Notification_pubnub, "f").subscribe({
70
+ channels: [firmId],
71
+ withPresence: true,
72
+ });
73
+ });
74
+ _Notification_initUserChannel.set(this, (userId) => {
75
+ tslib_1.__classPrivateFieldGet(this, _Notification_pubnub, "f").addListener({
76
+ message: (data) => {
77
+ const { content } = data.message;
78
+ if (content && content.topic && content.messageType && content.data) {
79
+ for (const eventListener of tslib_1.__classPrivateFieldGet(this, _Notification_eventListeners, "f")) {
80
+ if (eventListener.topic === content.topic &&
81
+ eventListener.messageType === content.messageType &&
82
+ eventListener.callback &&
83
+ (0, lodash_1.isFunction)(eventListener.callback)) {
84
+ return eventListener.callback(content.data);
85
+ }
86
+ }
87
+ }
88
+ },
89
+ });
90
+ tslib_1.__classPrivateFieldGet(this, _Notification_pubnub, "f").subscribe({
91
+ channels: [`user_${userId}`],
92
+ withPresence: false,
93
+ });
94
+ });
95
+ _Notification_initUniqueSessionChannel.set(this, (params) => {
96
+ const decodedToken = auth_agent_1.AuthAgent.getDecodedAccessToken();
97
+ const { authHost: myAuthHost, clientId: myClientId } = params;
98
+ const { userId: myUserId, sessionId: mySessionId, impersonatorId: myImpersonatorId, } = decodedToken;
99
+ if (!decodedToken) {
100
+ return;
101
+ }
102
+ const channel = `auth-session-${myUserId}`;
103
+ tslib_1.__classPrivateFieldGet(this, _Notification_pubnub, "f").addListener({
104
+ message: (data) => {
105
+ const decodedToken = auth_agent_1.AuthAgent.getDecodedAccessToken();
106
+ if (!decodedToken) {
107
+ auth_agent_1.AuthAgent.logout(true); // call logout with force=true (because the logout is forced)
108
+ }
109
+ const { sessionId: mySessionId, impersonatorId: myImpersonatorId, userId: myUserId, } = decodedToken;
110
+ if (mySessionId && data && data.message) {
111
+ const sessionId = data.message.sessionId, authHost = data.message.authHost, clientId = data.message.clientId, logout = data.message.logout, impersonatorId = myImpersonatorId
112
+ ? myImpersonatorId
113
+ : data.message.impersonatorId;
114
+ if (authHost === myAuthHost) {
115
+ if ((clientId === myClientId && sessionId !== mySessionId) || // same application, different browser => logout (unique session feature)
116
+ (clientId !== myClientId && sessionId === mySessionId && logout) // different application, same browser, logout asked by user => logout (unique logout feature)
117
+ ) {
118
+ if (impersonatorId !== undefined && impersonatorId !== '') {
119
+ // I'm impersonating someone who is being logged in or out so I don't want to be logged out
120
+ console.log('user ' + impersonatorId + ' impersonating user ' + myUserId);
121
+ }
122
+ else {
123
+ auth_agent_1.AuthAgent.logout(true); // call logout with force=true (because the logout is forced)
124
+ }
125
+ }
126
+ }
127
+ }
128
+ },
129
+ });
130
+ tslib_1.__classPrivateFieldGet(this, _Notification_pubnub, "f").subscribe({
131
+ channels: [channel],
132
+ withPresence: true,
133
+ });
134
+ tslib_1.__classPrivateFieldGet(this, _Notification_pubnub, "f").publish({
135
+ message: {
136
+ authHost: myAuthHost,
137
+ clientId: myClientId,
138
+ sessionId: mySessionId,
139
+ impersonatorId: myImpersonatorId,
140
+ },
141
+ channel: channel,
142
+ }, (status) => {
143
+ if (status.error) {
144
+ console.log('pubnub error');
145
+ }
146
+ });
147
+ });
148
+ tslib_1.__classPrivateFieldSet(this, _Notification_pubnubKeys, {
149
+ publishKey: 'pub-13f5288e-cd88-4ef9-9e68-0c11cd03ddb8',
150
+ subscribeKey: 'sub-a456f002-0095-11e2-9638-9581afc33ebf',
151
+ uuid: (0, uuid_1.v4)(),
152
+ }, "f");
153
+ tslib_1.__classPrivateFieldSet(this, _Notification_pubnub, new Pubnub(tslib_1.__classPrivateFieldGet(this, _Notification_pubnubKeys, "f")), "f");
154
+ }
155
+ }
156
+ exports.Notification = Notification;
157
+ _Notification_pubnubKeys = new WeakMap(), _Notification_pubnub = new WeakMap(), _Notification_eventListeners = new WeakMap(), _Notification_initFirmChannel = new WeakMap(), _Notification_initUserChannel = new WeakMap(), _Notification_initUniqueSessionChannel = new WeakMap();
158
+ //# sourceMappingURL=notification.js.map