cidaas-javascript-sdk 3.0.5 → 3.1.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.
@@ -1,6 +1,5 @@
1
1
  import { UserManager, UserManagerSettings } from "oidc-client-ts";
2
2
  import * as CryptoJS from 'crypto-js';
3
- import fingerprint from '@fingerprintjs/fingerprintjs';
4
3
 
5
4
  import { Authentication } from "../authentication";
6
5
  import { Helper, CustomException } from "./Helper";
@@ -35,13 +34,26 @@ import {
35
34
  AcceptResetPasswordEntity,
36
35
  LoginFormRequestAsyncEntity,
37
36
  PhysicalVerificationLoginRequest,
38
- IChangePasswordEntity
37
+ IChangePasswordEntity,
38
+ ICidaasSDKSettings
39
39
  } from "./Entities"
40
40
 
41
41
  export class WebAuth {
42
42
 
43
- constructor(settings: UserManagerSettings & { mode?: string, cidaas_version: number }) {
43
+ constructor(settings: ICidaasSDKSettings) {
44
44
  try {
45
+ if (!settings.response_type) {
46
+ settings.response_type = "code";
47
+ }
48
+ if (!settings.scope) {
49
+ settings.scope = "email openid profile mobile";
50
+ }
51
+ if (!settings.mode) {
52
+ settings.mode = 'redirect';
53
+ }
54
+ if (!settings.cidaas_version) {
55
+ settings.cidaas_version = 2;
56
+ }
45
57
  var usermanager = new UserManager(settings)
46
58
  window.webAuthSettings = settings;
47
59
  window.usermanager = usermanager;
@@ -50,9 +62,6 @@ export class WebAuth {
50
62
  window.usermanager.events.addSilentRenewError(function (error: any) {
51
63
  throw new CustomException("Error while renewing silent login", 500);
52
64
  });
53
- if (!settings.mode) {
54
- window.webAuthSettings.mode = 'redirect';
55
- }
56
65
  } catch (ex) {
57
66
  console.log(ex);
58
67
  }
@@ -225,27 +234,20 @@ export class WebAuth {
225
234
  * @returns
226
235
  */
227
236
  getLoginURL() {
228
- var settings = window.webAuthSettings;
229
- if (!settings.response_type) {
230
- settings.response_type = "code";
231
- }
232
- if (!settings.scope) {
233
- settings.scope = "email openid profile mobile";
234
- }
235
- var loginURL = "";
236
- window.usermanager._client.createSigninRequest(settings).then((signInRequest: any) => {
237
- loginURL = signInRequest.url;
238
- })
239
- var timeRemaining = 5000
240
- while(timeRemaining > 0) {
241
- if (loginURL) {
242
- break;
237
+ let loginUrl: string;
238
+ let finish: boolean = false;
239
+ (async () => {
240
+ try {
241
+ loginUrl = await window.usermanager._client.getSignInRedirectUrl();
243
242
  }
244
- setTimeout(() => {
245
- timeRemaining -= 100
246
- }, 100);
247
- }
248
- return loginURL;
243
+ catch (e) {
244
+ //TODO: define Error handling
245
+ console.log(e);
246
+ }
247
+ finish = true
248
+ })();
249
+ while (!finish) { } // A simple synchronous loop to wait async call is finish
250
+ return loginUrl;
249
251
  };
250
252
 
251
253
  /**
@@ -300,29 +302,8 @@ export class WebAuth {
300
302
  * @returns
301
303
  */
302
304
  getMissingFields(options: { requestId: string; trackId: string; }) {
303
- return new Promise((resolve, reject) => {
304
- try {
305
- var http = new XMLHttpRequest();
306
- var _serviceURL = window.webAuthSettings.authority + "/public-srv/public/trackinfo/" + options.requestId + "/" + options.trackId;
307
- http.onreadystatechange = function () {
308
- if (http.readyState == 4) {
309
- if (http.responseText) {
310
- resolve(JSON.parse(http.responseText));
311
- } else {
312
- resolve(false);
313
- }
314
- }
315
- };
316
- http.open("GET", _serviceURL, true);
317
- http.setRequestHeader("Content-type", "application/json");
318
- if (window.localeSettings) {
319
- http.setRequestHeader("accept-language", window.localeSettings);
320
- }
321
- http.send();
322
- } catch (ex) {
323
- reject(ex);
324
- }
325
- });
305
+ const _serviceURL = window.webAuthSettings.authority + "/public-srv/public/trackinfo/" + options.requestId + "/" + options.trackId;
306
+ return Helper.createPostPromise(undefined, _serviceURL,false, "GET");
326
307
  };
327
308
 
328
309
  /**
@@ -330,29 +311,8 @@ export class WebAuth {
330
311
  * @returns
331
312
  */
332
313
  getTenantInfo() {
333
- return new Promise((resolve, reject) => {
334
- try {
335
- var http = new XMLHttpRequest();
336
- var _serviceURL = window.webAuthSettings.authority + "/public-srv/tenantinfo/basic";
337
- http.onreadystatechange = function () {
338
- if (http.readyState == 4) {
339
- if (http.responseText) {
340
- resolve(JSON.parse(http.responseText));
341
- } else {
342
- resolve(false);
343
- }
344
- }
345
- };
346
- http.open("GET", _serviceURL, true);
347
- http.setRequestHeader("Content-type", "application/json");
348
- if (window.localeSettings) {
349
- http.setRequestHeader("accept-language", window.localeSettings);
350
- }
351
- http.send();
352
- } catch (ex) {
353
- reject(ex);
354
- }
355
- });
314
+ const _serviceURL = window.webAuthSettings.authority + "/public-srv/tenantinfo/basic";
315
+ return Helper.createPostPromise(undefined, _serviceURL,false, "GET");
356
316
  };
357
317
 
358
318
  /**
@@ -373,29 +333,8 @@ export class WebAuth {
373
333
  * @returns
374
334
  */
375
335
  getClientInfo(options: { requestId: string }) {
376
- return new Promise((resolve, reject) => {
377
- try {
378
- var http = new XMLHttpRequest();
379
- var _serviceURL = window.webAuthSettings.authority + "/public-srv/public/" + options.requestId;
380
- http.onreadystatechange = function () {
381
- if (http.readyState == 4) {
382
- if (http.responseText) {
383
- resolve(JSON.parse(http.responseText));
384
- } else {
385
- resolve(false);
386
- }
387
- }
388
- };
389
- http.open("GET", _serviceURL, true);
390
- http.setRequestHeader("Content-type", "application/json");
391
- if (window.localeSettings) {
392
- http.setRequestHeader("accept-language", window.localeSettings);
393
- }
394
- http.send();
395
- } catch (ex) {
396
- reject(ex);
397
- }
398
- });
336
+ const _serviceURL = window.webAuthSettings.authority + "/public-srv/public/" + options.requestId;
337
+ return Helper.createPostPromise(undefined, _serviceURL,false, "GET");
399
338
  };
400
339
 
401
340
  /**
@@ -404,33 +343,12 @@ export class WebAuth {
404
343
  * @returns
405
344
  */
406
345
  getDevicesInfo(options: any) {
407
- return new Promise((resolve, reject) => {
408
- try {
409
- var http = new XMLHttpRequest();
410
- var _serviceURL = window.webAuthSettings.authority + "/device-srv/devices";
411
- options.userAgent = window.navigator.userAgent
412
- http.onreadystatechange = function () {
413
- if (http.readyState == 4) {
414
- if (http.responseText) {
415
- resolve(JSON.parse(http.responseText));
416
- } else {
417
- resolve(false);
418
- }
419
- }
420
- };
421
- http.open("GET", _serviceURL, true);
422
- http.setRequestHeader("Content-type", "application/json");
423
- if (window.localeSettings) {
424
- http.setRequestHeader("accept-language", window.localeSettings);
425
- }
426
- if (window.navigator.userAgent) {
427
- http.send(JSON.stringify(options));
428
- }
429
- http.send();
430
- } catch (ex) {
431
- reject(ex);
432
- }
433
- });
346
+ options.userAgent = window.navigator.userAgent;
347
+ const _serviceURL = window.webAuthSettings.authority + "/device-srv/devices";
348
+ if (window.navigator.userAgent) {
349
+ return Helper.createPostPromise(options, _serviceURL,false, "GET");
350
+ }
351
+ return Helper.createPostPromise(undefined, _serviceURL,false, "GET");
434
352
  };
435
353
 
436
354
  /**
@@ -439,33 +357,12 @@ export class WebAuth {
439
357
  * @returns
440
358
  */
441
359
  deleteDevice(options: { device_id: string; userAgent?: string }) {
442
- return new Promise((resolve, reject) => {
443
- try {
444
- var http = new XMLHttpRequest();
445
- var _serviceURL = window.webAuthSettings.authority + "/device-srv/device/" + options.device_id;
446
- options.userAgent = window.navigator.userAgent
447
- http.onreadystatechange = function () {
448
- if (http.readyState == 4) {
449
- if (http.responseText) {
450
- resolve(JSON.parse(http.responseText));
451
- } else {
452
- resolve(false);
453
- }
454
- }
455
- };
456
- http.open("DELETE", _serviceURL, true);
457
- http.setRequestHeader("Content-type", "application/json");
458
- if (window.localeSettings) {
459
- http.setRequestHeader("accept-language", window.localeSettings);
460
- }
461
- if (window.navigator.userAgent) {
462
- http.send(JSON.stringify(options));
463
- }
464
- http.send();
465
- } catch (ex) {
466
- reject(ex);
467
- }
468
- });
360
+ const _serviceURL = window.webAuthSettings.authority + "/device-srv/device/" + options.device_id;
361
+ options.userAgent = window.navigator.userAgent;
362
+ if (window.navigator.userAgent) {
363
+ return Helper.createPostPromise(options, _serviceURL,false, "DELETE");
364
+ }
365
+ return Helper.createPostPromise(undefined, _serviceURL,false, "DELETE");
469
366
  };
470
367
 
471
368
  /**
@@ -510,30 +407,8 @@ export class WebAuth {
510
407
  * @returns
511
408
  */
512
409
  getUnreviewedDevices(access_token: string, sub: string) {
513
- return new Promise((resolve, reject) => {
514
- try {
515
- var http = new XMLHttpRequest();
516
- var _serviceURL = window.webAuthSettings.authority + "/reports-srv/device/unreviewlist/" + sub;
517
- http.onreadystatechange = function () {
518
- if (http.readyState == 4) {
519
- if (http.responseText) {
520
- resolve(JSON.parse(http.responseText));
521
- } else {
522
- resolve(false);
523
- }
524
- }
525
- };
526
- http.open("GET", _serviceURL, true);
527
- http.setRequestHeader("Content-type", "application/json");
528
- http.setRequestHeader("Authorization", `Bearer ${access_token}`);
529
- if (window.localeSettings) {
530
- http.setRequestHeader("accept-language", window.localeSettings);
531
- }
532
- http.send();
533
- } catch (ex) {
534
- throw new CustomException(ex, 417);
535
- }
536
- });
410
+ let _serviceURL = window.webAuthSettings.authority + "/reports-srv/device/unreviewlist/" + sub;
411
+ return Helper.createPostPromise(undefined, _serviceURL,false, "GET", access_token);
537
412
  };
538
413
 
539
414
  /**
@@ -543,30 +418,8 @@ export class WebAuth {
543
418
  * @returns
544
419
  */
545
420
  getReviewedDevices(access_token: string, sub: string) {
546
- return new Promise(function (resolve, reject) {
547
- try {
548
- var http = new XMLHttpRequest();
549
- var _serviceURL = window.webAuthSettings.authority + "/reports-srv/device/reviewlist/" + sub;
550
- http.onreadystatechange = function () {
551
- if (http.readyState == 4) {
552
- if (http.responseText) {
553
- resolve(JSON.parse(http.responseText));
554
- } else {
555
- resolve(false);
556
- }
557
- }
558
- };
559
- http.open("GET", _serviceURL, true);
560
- http.setRequestHeader("Content-type", "application/json");
561
- http.setRequestHeader("Authorization", `Bearer ${access_token}`);
562
- if (window.localeSettings) {
563
- http.setRequestHeader("accept-language", window.localeSettings);
564
- }
565
- http.send();
566
- } catch (ex) {
567
- throw new CustomException(ex, 417);
568
- }
569
- });
421
+ let _serviceURL = window.webAuthSettings.authority + "/reports-srv/device/reviewlist/" + sub;
422
+ return Helper.createPostPromise(undefined, _serviceURL,false, "GET", access_token);
570
423
  };
571
424
 
572
425
  /**
@@ -576,30 +429,8 @@ export class WebAuth {
576
429
  * @returns
577
430
  */
578
431
  reviewDevice(options: UpdateReviewDeviceEntity, access_token: string) {
579
- return new Promise((resolve, reject) => {
580
- try {
581
- var http = new XMLHttpRequest();
582
- var _serviceURL = window.webAuthSettings.authority + "/reports-srv/device/updatereview";
583
- http.onreadystatechange = function () {
584
- if (http.readyState == 4) {
585
- if (http.responseText) {
586
- resolve(JSON.parse(http.responseText));
587
- } else {
588
- resolve(false);
589
- }
590
- }
591
- };
592
- http.open("PUT", _serviceURL, true);
593
- http.setRequestHeader("Content-type", "application/json");
594
- http.setRequestHeader("Authorization", `Bearer ${access_token}`);
595
- if (window.localeSettings) {
596
- http.setRequestHeader("accept-language", window.localeSettings);
597
- }
598
- http.send(JSON.stringify(options));
599
- } catch (ex) {
600
- throw new CustomException(ex, 417);
601
- }
602
- });
432
+ let _serviceURL = window.webAuthSettings.authority + "/reports-srv/device/updatereview";
433
+ return Helper.createPostPromise(options, _serviceURL,false, "PUT", access_token);
603
434
  };
604
435
 
605
436
  /**
@@ -610,13 +441,9 @@ export class WebAuth {
610
441
  return new Promise((resolve, reject) => {
611
442
  try {
612
443
  var value = ('; ' + document.cookie).split(`; cidaas_dr=`).pop().split(';')[0];
613
- var fpPromise = fingerprint.load();
614
- var options = { fingerprint: "", userAgent: "" };
444
+ var options = { userAgent: "" };
615
445
  if (!value) {
616
446
  (async () => {
617
- var fp = await fpPromise;
618
- var result = await fp.get();
619
- options.fingerprint = result.visitorId
620
447
  options.userAgent = window.navigator.userAgent
621
448
  var http = new XMLHttpRequest();
622
449
  var _serviceURL = window.webAuthSettings.authority + "/device-srv/deviceinfo";
@@ -983,7 +810,7 @@ export class WebAuth {
983
810
  */
984
811
  getUserActivities(options: UserActivityEntity, access_token: string) {
985
812
  var _serviceURL = window.webAuthSettings.authority + "/useractivity-srv/latestactivity";
986
- return Helper.createPostPromise(options, _serviceURL, false, access_token);
813
+ return Helper.createPostPromise(options, _serviceURL, false,"POST", access_token);
987
814
  };
988
815
 
989
816
  /**
@@ -1042,7 +869,7 @@ export class WebAuth {
1042
869
  */
1043
870
  updateProfileImage(options: { image_key: string; }, access_token: string) {
1044
871
  var _serviceURL = window.webAuthSettings.authority + "/image-srv/profile/upload";
1045
- return Helper.createPostPromise(options, _serviceURL, false, access_token);
872
+ return Helper.createPostPromise(options, _serviceURL, false,"POST", access_token);
1046
873
  };
1047
874
 
1048
875
  /**
@@ -1660,7 +1487,7 @@ export class WebAuth {
1660
1487
  /**
1661
1488
  * @deprecated
1662
1489
  * authenticate ivr - v1
1663
- * @param options
1490
+ * @param options
1664
1491
  */
1665
1492
  authenticateIVR(options: any) {
1666
1493
  var verificationType = "IVR";
@@ -1669,21 +1496,21 @@ export class WebAuth {
1669
1496
 
1670
1497
  /**
1671
1498
  * @deprecated
1672
- * authenticate backupcode - v1
1673
- * @param options
1499
+ * authenticate totp - v1
1500
+ * @param options
1674
1501
  */
1675
- authenticateBackupcode(options: any) {
1676
- var verificationType = "BACKUPCODE";
1502
+ authenticateTOTP(options: any) {
1503
+ var verificationType = "TOTP";
1677
1504
  this.authenticateMfaV1(options, verificationType);
1678
1505
  };
1679
1506
 
1680
1507
  /**
1681
1508
  * @deprecated
1682
- * authenticate totp - v1
1683
- * @param options
1509
+ * authenticate backupcode - v1
1510
+ * @param options
1684
1511
  */
1685
- authenticateTOTP(options: any) {
1686
- var verificationType = "TOTP";
1512
+ authenticateBackupcode(options: any) {
1513
+ var verificationType = "BACKUPCODE";
1687
1514
  this.authenticateMfaV1(options, verificationType);
1688
1515
  };
1689
1516
  }
@@ -1,55 +0,0 @@
1
- import { UserManager, UserManagerSettings } from "oidc-client-ts";
2
- export declare class Authentication {
3
- webAuthSettings: UserManagerSettings;
4
- userManager: UserManager;
5
- constructor(webAuthSettings: UserManagerSettings, userManager: UserManager);
6
- /**
7
- * redirect sign in
8
- * @param view_type
9
- */
10
- redirectSignIn(view_type: string): void;
11
- /**
12
- * redirect sign in callback
13
- * @returns
14
- */
15
- redirectSignInCallback(): Promise<unknown>;
16
- /**
17
- * redirect sign out
18
- * @returns
19
- */
20
- redirectSignOut(): Promise<unknown>;
21
- /**
22
- * redirect sign out callback
23
- * @returns
24
- */
25
- redirectSignOutCallback(): Promise<unknown>;
26
- /**
27
- * pop up sign in
28
- */
29
- popupSignIn(): void;
30
- /**
31
- * pop up sign in callback
32
- */
33
- popupSignInCallback(): void;
34
- /**
35
- * pop up sign out
36
- */
37
- popupSignOut(): void;
38
- /**
39
- * silent sign in
40
- */
41
- silentSignIn(): void;
42
- /**
43
- * silent sign in callback
44
- */
45
- silentSignInCallback(): void;
46
- /**
47
- * silent sign in callback v2
48
- * @returns
49
- */
50
- silentSignInCallbackV2(): Promise<unknown>;
51
- /**
52
- * silent sign out callback
53
- */
54
- popupSignOutCallback(): void;
55
- }