@prove-identity/prove-auth 2.3.2 → 2.3.5

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.
@@ -4,7 +4,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.MobileAuthImplementation = exports.DeviceRole = void 0;
7
- const primary_authenticator_1 = __importDefault(require("./internal/primary-authenticator"));
8
7
  const web_platform_1 = require("./internal/web-platform");
9
8
  const device_passive_register_step_1 = __importDefault(require("./internal/device-passive-register-step"));
10
9
  const device_passive_step_1 = __importDefault(require("./internal/device-passive-step"));
@@ -14,9 +13,9 @@ const mobile_instantlink_step_1 = __importDefault(require("./internal/mobile-ins
14
13
  const mobile_otp_step_1 = __importDefault(require("./internal/mobile-otp-step"));
15
14
  const scan_message_step_1 = __importDefault(require("./internal/scan-message-step"));
16
15
  const user_mobileactive_step_1 = __importDefault(require("./internal/user-mobileactive-step"));
17
- const secondary_authenticator_1 = __importDefault(require("./internal/secondary-authenticator"));
18
16
  const device_passive_silent_step_1 = __importDefault(require("./internal/device-passive-silent-step"));
19
17
  const device_passive_stepup_step_1 = __importDefault(require("./internal/device-passive-stepup-step"));
18
+ const main_authenticator_1 = __importDefault(require("./internal/main-authenticator"));
20
19
  var DeviceRole;
21
20
  (function (DeviceRole) {
22
21
  DeviceRole[DeviceRole["Primary"] = 0] = "Primary";
@@ -102,20 +101,21 @@ class AuthenticatorBuilder {
102
101
  }
103
102
  build() {
104
103
  if (this.role === DeviceRole.Primary) {
105
- return new primary_authenticator_1.default(this.platform, this.storage, this.authFinishStep, [
104
+ return new main_authenticator_1.default(this.platform, this.storage, this.authFinishStep, [
106
105
  new device_passive_step_1.default(this.getDisplayName, this.role),
107
106
  new device_passive_stepup_step_1.default(this.getDisplayName),
108
107
  new device_passive_silent_step_1.default(),
109
108
  new device_passive_register_step_1.default(),
110
109
  new device_passive_verify_step_1.default(),
111
110
  new mobile_instant_step_1.default(this.mobileAuthImplementation, this.getDeviceIp),
111
+ new mobile_instantlink_step_1.default(this.instantLinkStartStep, this.getDeviceIp),
112
112
  new mobile_otp_step_1.default(this.otpStartStep, this.otpFinishStep),
113
113
  new user_mobileactive_step_1.default(),
114
114
  new scan_message_step_1.default(this.authMessageHandler),
115
115
  ]);
116
116
  }
117
117
  else {
118
- return new secondary_authenticator_1.default(this.platform, this.storage, this.authFinishStep, [
118
+ return new main_authenticator_1.default(this.platform, this.storage, this.authFinishStep, [
119
119
  new device_passive_step_1.default(this.getDisplayName, this.role),
120
120
  new mobile_instant_step_1.default(this.mobileAuthImplementation, this.getDeviceIp),
121
121
  new mobile_instantlink_step_1.default(this.instantLinkStartStep, this.getDeviceIp),
@@ -12,6 +12,7 @@ export default class AuthSession implements AuthSessionIntegration {
12
12
  readonly claims?: AuthTokenClaims;
13
13
  readonly settings: Settings;
14
14
  readonly requestSigner: RequestSigner;
15
+ readonly channels: Set<MessageChannel>;
15
16
  lastStep: string | null;
16
17
  credential: CredentialType | null;
17
18
  authMessage: AuthMessage | null;
@@ -25,6 +26,7 @@ export default class AuthSession implements AuthSessionIntegration {
25
26
  constructor(settings: Settings, platform: Platform, authToken?: string);
26
27
  fetchFromBackend(query: string, body: AuthRequest): Promise<AuthResponse>;
27
28
  createMessageChannel(endpointPath: string, onClose: () => void, onError: (message: string) => void, onMessage: (data: string) => void): MessageChannel;
29
+ closeAllMessageChannels(): void;
28
30
  getDeviceRegistration(): Promise<DeviceRegistration | null>;
29
31
  private parseJwt;
30
32
  }
@@ -30,6 +30,7 @@ class AuthSession {
30
30
  }
31
31
  constructor(settings, platform, authToken) {
32
32
  var _a, _b;
33
+ this.channels = new Set();
33
34
  this.lastStep = null;
34
35
  this.credential = null;
35
36
  this.authMessage = null;
@@ -99,11 +100,10 @@ class AuthSession {
99
100
  }
100
101
  const KEEP_ALIVE_INTERVAL = 30000;
101
102
  const endpoint = this.backendUrl.replace(/^http/, 'ws');
102
- const encodedAuthToken = encodeURIComponent(this.authToken);
103
- const channel = this.platform.createMessageChannel(endpoint + endpointPath + '?token=' + encodedAuthToken);
103
+ const channel = this.platform.createMessageChannel(endpoint + endpointPath);
104
104
  const log = logger_1.LoggerFactory.getLogger('web-message-channel');
105
105
  const keepAlive = setInterval(() => {
106
- log.debug('Sending keep-alive message');
106
+ log.trace('Sending keep-alive message');
107
107
  channel.send('');
108
108
  }, KEEP_ALIVE_INTERVAL);
109
109
  channel.addEventListener('close', (_) => {
@@ -111,6 +111,7 @@ class AuthSession {
111
111
  clearInterval(keepAlive);
112
112
  }
113
113
  onClose();
114
+ this.channels.delete(channel);
114
115
  });
115
116
  channel.addEventListener('error', (event) => {
116
117
  if ('message' in event) {
@@ -134,8 +135,15 @@ class AuthSession {
134
135
  }
135
136
  }
136
137
  });
138
+ this.channels.add(channel);
137
139
  return channel;
138
140
  }
141
+ closeAllMessageChannels() {
142
+ const channelsCopy = new Set(this.channels);
143
+ channelsCopy.forEach((channel) => channel.close());
144
+ channelsCopy.clear();
145
+ this.channels.clear();
146
+ }
139
147
  getDeviceRegistration() {
140
148
  return new Promise((resolve, reject) => {
141
149
  this.platform.deviceAuth
@@ -0,0 +1,5 @@
1
+ import AuthSession from './auth-session';
2
+ export declare class AuthStatusActions {
3
+ protected log: import("../common/logger").Logger;
4
+ protected waitForStatus(session: AuthSession): Promise<string>;
5
+ }
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.AuthStatusActions = void 0;
7
+ const logger_1 = require("../common/logger");
8
+ const auth_error_1 = __importDefault(require("./auth-error"));
9
+ class AuthStatusActions {
10
+ constructor() {
11
+ this.log = logger_1.LoggerFactory.getLogger('auth-status-actions');
12
+ }
13
+ waitForStatus(session) {
14
+ var gotResponse = false;
15
+ this.log.trace('Waiting for auth status');
16
+ return new Promise((resolve, reject) => {
17
+ const channel = session.createMessageChannel('/v1/client/status?token=' + encodeURIComponent(session.authToken), () => {
18
+ if (!gotResponse) {
19
+ reject(new auth_error_1.default('Failed to receive secondary authentication status, no response'));
20
+ }
21
+ }, (errorMessage) => {
22
+ gotResponse = true;
23
+ this.log.error('Failed: ' + errorMessage);
24
+ reject(new auth_error_1.default('Failed to receive secondary authentication status: ' + errorMessage));
25
+ }, (data) => {
26
+ gotResponse = true;
27
+ try {
28
+ this.log.debug(('Secondary authentication status: ' + data));
29
+ const response = JSON.parse(data);
30
+ if (response.error) {
31
+ reject(new auth_error_1.default(response.error.message, response.error.code, response.next));
32
+ }
33
+ else {
34
+ session.lastStep = response.next;
35
+ resolve(response.next);
36
+ }
37
+ }
38
+ catch (e) {
39
+ reject(e);
40
+ }
41
+ finally {
42
+ channel.close();
43
+ }
44
+ });
45
+ });
46
+ }
47
+ }
48
+ exports.AuthStatusActions = AuthStatusActions;
@@ -1,7 +1,8 @@
1
1
  import AuthSession from './auth-session';
2
2
  import AuthStep from './auth-step';
3
3
  import { DeviceRole } from '../authenticator-builder';
4
- export declare class DevicePassiveActions {
4
+ import { AuthStatusActions } from './auth-status-actions';
5
+ export declare class DevicePassiveActions extends AuthStatusActions {
5
6
  protected log: import("../common/logger").Logger;
6
7
  private readonly getDisplayName;
7
8
  protected constructor(getDisplayName?: () => string | null);
@@ -10,9 +10,10 @@ const device_passive_silent_step_1 = __importDefault(require("./device-passive-s
10
10
  const auth_token_claims_1 = require("./auth-token-claims");
11
11
  const auth_error_1 = __importDefault(require("./auth-error"));
12
12
  const authenticator_builder_1 = require("../authenticator-builder");
13
- const base_authenticator_1 = __importDefault(require("./base-authenticator"));
14
- class DevicePassiveActions {
13
+ const auth_status_actions_1 = require("./auth-status-actions");
14
+ class DevicePassiveActions extends auth_status_actions_1.AuthStatusActions {
15
15
  constructor(getDisplayName) {
16
+ super();
16
17
  this.log = logger_1.LoggerFactory.getLogger('device-passive-actions');
17
18
  this.getDisplayName = getDisplayName ? getDisplayName : () => null;
18
19
  }
@@ -114,7 +115,7 @@ class DevicePassiveStep extends DevicePassiveActions {
114
115
  }
115
116
  execute(session) {
116
117
  if (this.role == authenticator_builder_1.DeviceRole.Secondary) {
117
- return Promise.resolve(base_authenticator_1.default.AUTH_DONE);
118
+ return this.waitForStatus(session);
118
119
  }
119
120
  if (!session.platform.isFidoSupported() ||
120
121
  session.uvLevel === auth_token_claims_1.UserVerificationLevel.Discouraged) {
@@ -5,15 +5,17 @@ import { Logger } from '../common/logger';
5
5
  import Platform from './platform';
6
6
  import CancelablePromise from '../common/cancelable-promise';
7
7
  import AuthSession from './auth-session';
8
- export default abstract class BaseAuthenticator implements Authenticator {
8
+ import AuthStep from './auth-step';
9
+ export default class MainAuthenticator implements Authenticator {
9
10
  static readonly AUTH_DONE = "done";
10
11
  static readonly AUTH_EMPTY = "";
11
12
  static readonly MAX_ATTEMPTS = 50;
13
+ private readonly steps;
12
14
  protected log: Logger;
13
15
  protected readonly platform: Platform;
14
16
  protected readonly settings: Settings;
15
17
  protected readonly authFinishStep?: AuthFinishStep;
16
- constructor(platform?: Platform, storage?: Storage, finishStep?: AuthFinishStep);
18
+ constructor(platform?: Platform, storage?: Storage, finishStep?: AuthFinishStep, steps?: Array<AuthStep>);
17
19
  isPasskeyRegistered(): boolean;
18
20
  isFidoSupported(): boolean;
19
21
  isDeviceRegistered(): boolean;
@@ -24,5 +26,7 @@ export default abstract class BaseAuthenticator implements Authenticator {
24
26
  unregisterDevice(): Promise<void>;
25
27
  unregisterPasskey(): Promise<void>;
26
28
  private unregister;
27
- abstract process(session: AuthSession): CancelablePromise<void>;
29
+ process(session: AuthSession): CancelablePromise<void>;
30
+ private nextStep;
31
+ private getNextStep;
28
32
  }
@@ -8,18 +8,26 @@ const logger_1 = require("../common/logger");
8
8
  const cancelable_promise_1 = __importDefault(require("../common/cancelable-promise"));
9
9
  const auth_session_1 = __importDefault(require("./auth-session"));
10
10
  const auth_error_1 = __importDefault(require("./auth-error"));
11
- class BaseAuthenticator {
12
- constructor(platform, storage, finishStep) {
11
+ const report_error_step_1 = __importDefault(require("./report-error-step"));
12
+ const error_code_1 = __importDefault(require("./error-code"));
13
+ class MainAuthenticator {
14
+ constructor(platform, storage, finishStep, steps) {
15
+ this.steps = new Map();
13
16
  if (!platform) {
14
17
  throw new Error('Implementation of Platform is required');
15
18
  }
16
19
  if (!storage) {
17
20
  throw new Error('Implementation of Storage is required');
18
21
  }
19
- this.log = logger_1.LoggerFactory.getLogger('base-authenticator');
22
+ this.log = logger_1.LoggerFactory.getLogger('main-authenticator');
20
23
  this.platform = platform;
21
24
  this.authFinishStep = finishStep;
22
25
  this.settings = new settings_1.default(storage);
26
+ if (steps) {
27
+ for (let step of steps) {
28
+ this.steps.set(step.name, step);
29
+ }
30
+ }
23
31
  }
24
32
  isPasskeyRegistered() {
25
33
  return this.settings.fidoPasskeyRegistered;
@@ -56,7 +64,7 @@ class BaseAuthenticator {
56
64
  processing
57
65
  .then(() => {
58
66
  var _a;
59
- if (session.lastStep !== BaseAuthenticator.AUTH_EMPTY) {
67
+ if (session.lastStep !== MainAuthenticator.AUTH_EMPTY) {
60
68
  this.log.info('Authentication flow has been completed.');
61
69
  return (_a = this.authFinishStep) === null || _a === void 0 ? void 0 : _a.execute({ authId: session.authId });
62
70
  }
@@ -122,8 +130,48 @@ class BaseAuthenticator {
122
130
  }
123
131
  });
124
132
  }
133
+ process(session) {
134
+ return new cancelable_promise_1.default((resolve, reject, onCancel) => {
135
+ onCancel(() => {
136
+ this.log.info('Canceled');
137
+ session.closeAllMessageChannels();
138
+ resolve();
139
+ });
140
+ this.nextStep(session, session.next, 1).then(resolve).catch(reject);
141
+ });
142
+ }
143
+ nextStep(session, step, attempt) {
144
+ this.log.debug(`Authentication attempt ${attempt}, next step: ${step}`);
145
+ session.lastStep = step;
146
+ return new Promise((resolve, reject) => {
147
+ if ([MainAuthenticator.AUTH_DONE, MainAuthenticator.AUTH_EMPTY].includes(step)) {
148
+ resolve();
149
+ }
150
+ else if (attempt > MainAuthenticator.MAX_ATTEMPTS) {
151
+ reject(new auth_error_1.default('Too many authentication steps', error_code_1.default.ERROR_MAX_ATTEMPTS));
152
+ }
153
+ else {
154
+ this.getNextStep(step)
155
+ .execute(session)
156
+ .then((next) => this.nextStep(session, next, attempt + 1))
157
+ .then(resolve)
158
+ .catch((e) => new report_error_step_1.default(e)
159
+ .execute(session)
160
+ .then((next) => this.nextStep(session, next, attempt + 1))
161
+ .then(resolve)
162
+ .catch(reject));
163
+ }
164
+ });
165
+ }
166
+ getNextStep(step) {
167
+ var nextStep = this.steps.get(step);
168
+ if (nextStep) {
169
+ return nextStep;
170
+ }
171
+ return new report_error_step_1.default('Unknown authentication step: ' + step);
172
+ }
125
173
  }
126
- BaseAuthenticator.AUTH_DONE = 'done';
127
- BaseAuthenticator.AUTH_EMPTY = '';
128
- BaseAuthenticator.MAX_ATTEMPTS = 50;
129
- exports.default = BaseAuthenticator;
174
+ MainAuthenticator.AUTH_DONE = 'done';
175
+ MainAuthenticator.AUTH_EMPTY = '';
176
+ MainAuthenticator.MAX_ATTEMPTS = 50;
177
+ exports.default = MainAuthenticator;
@@ -1,7 +1,8 @@
1
1
  import AuthSession from './auth-session';
2
2
  import AuthStep from './auth-step';
3
3
  import { InstantLinkStartStep } from '../instantlink';
4
- export default class MobileInstantLinkStep implements AuthStep {
4
+ import { AuthStatusActions } from './auth-status-actions';
5
+ export default class MobileInstantLinkStep extends AuthStatusActions implements AuthStep {
5
6
  static readonly NAME = "mobile/instantlink";
6
7
  readonly name = "mobile/instantlink";
7
8
  protected log: import("../common/logger").Logger;
@@ -6,15 +6,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const logger_1 = require("../common/logger");
7
7
  const phone_number_input_1 = require("./phone-number-input");
8
8
  const auth_error_1 = __importDefault(require("./auth-error"));
9
+ const auth_status_actions_1 = require("./auth-status-actions");
9
10
  const SIMULATED_LINK_CLICK_DELAY = 100;
10
- class MobileInstantLinkStep {
11
+ class MobileInstantLinkStep extends auth_status_actions_1.AuthStatusActions {
11
12
  constructor(startStep, getDeviceIp) {
13
+ super();
12
14
  this.name = MobileInstantLinkStep.NAME;
13
15
  this.log = logger_1.LoggerFactory.getLogger('mobile-instantlink-step');
14
16
  this.startStep = startStep;
15
17
  this.getDeviceIp = getDeviceIp !== null && getDeviceIp !== void 0 ? getDeviceIp : (() => null);
16
18
  }
17
19
  execute(session) {
20
+ this.log.trace('Executing');
18
21
  return new Promise((resolve, reject) => {
19
22
  var _a, _b, _c, _d, _e, _f;
20
23
  var phoneNumberNeeded = true;
@@ -26,9 +29,10 @@ class MobileInstantLinkStep {
26
29
  testMode = true;
27
30
  }
28
31
  this.runStartStep(session, phoneNumberNeeded)
29
- .then((next) => {
32
+ .then((_) => {
30
33
  this.runFinishStep(session, testMode)
31
- .then(() => resolve(next))
34
+ .then(() => this.waitForStatus(session))
35
+ .then((next) => resolve(next))
32
36
  .catch(reject);
33
37
  })
34
38
  .catch(reject);
@@ -89,7 +93,7 @@ class MobileInstantLinkStep {
89
93
  session.platform
90
94
  .fetch(session.backendUrl +
91
95
  '/v1/client/mobile/instantlink/finish?token=' +
92
- session.authToken +
96
+ encodeURIComponent(session.authToken) +
93
97
  '&vfp=test-vfp', {
94
98
  mode: 'cors',
95
99
  method: 'GET',
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const logger_1 = require("../common/logger");
7
7
  const auth_error_1 = __importDefault(require("./auth-error"));
8
- const base_authenticator_1 = __importDefault(require("./base-authenticator"));
8
+ const main_authenticator_1 = __importDefault(require("./main-authenticator"));
9
9
  const device_passive_register_step_1 = __importDefault(require("./device-passive-register-step"));
10
10
  const device_passive_silent_step_1 = __importDefault(require("./device-passive-silent-step"));
11
11
  const device_passive_step_1 = __importDefault(require("./device-passive-step"));
@@ -49,8 +49,8 @@ class ReportErrorStep {
49
49
  logMessage = logMessage + ', message: ' + this._message;
50
50
  }
51
51
  this.logger.error(logMessage);
52
- if (this.nextStep === base_authenticator_1.default.AUTH_DONE) {
53
- return Promise.resolve(base_authenticator_1.default.AUTH_DONE);
52
+ if (this.nextStep === main_authenticator_1.default.AUTH_DONE) {
53
+ return Promise.resolve(main_authenticator_1.default.AUTH_DONE);
54
54
  }
55
55
  else if (!this.nextStep || this.reportable) {
56
56
  return new Promise((resolve, reject) => {
@@ -1,3 +1,3 @@
1
- export declare const VERSION = "2.3.2";
1
+ export declare const VERSION = "2.3.5";
2
2
  export declare const API_CONTRACT_VERSION = "2.7.0";
3
3
  export declare const USER_AGENT_VERSIONS: string;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.USER_AGENT_VERSIONS = exports.API_CONTRACT_VERSION = exports.VERSION = void 0;
4
- exports.VERSION = '2.3.2';
4
+ exports.VERSION = '2.3.5';
5
5
  exports.API_CONTRACT_VERSION = '2.7.0';
6
6
  exports.USER_AGENT_VERSIONS = `ProveAuth/${exports.VERSION} Contract/${exports.API_CONTRACT_VERSION} WEB/1`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prove-identity/prove-auth",
3
- "version": "2.3.2",
3
+ "version": "2.3.5",
4
4
  "description": "Prove Auth SDK for Web",
5
5
  "main": "build/lib/index.js",
6
6
  "files": [
@@ -1,14 +0,0 @@
1
- import AuthFinishStep from '../auth-finish-step';
2
- import AuthStep from './auth-step';
3
- import AuthSession from './auth-session';
4
- import Platform from './platform';
5
- import CancelablePromise from '../common/cancelable-promise';
6
- import BaseAuthenticator from './base-authenticator';
7
- export default class PrimaryAuthenticator extends BaseAuthenticator {
8
- static readonly MAX_ATTEMPTS = 50;
9
- private readonly steps;
10
- constructor(platform?: Platform, storage?: Storage, finishStep?: AuthFinishStep, steps?: Array<AuthStep>);
11
- process(session: AuthSession): CancelablePromise<void>;
12
- private nextStep;
13
- private getNextStep;
14
- }
@@ -1,64 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const report_error_step_1 = __importDefault(require("./report-error-step"));
7
- const logger_1 = require("../common/logger");
8
- const cancelable_promise_1 = __importDefault(require("../common/cancelable-promise"));
9
- const base_authenticator_1 = __importDefault(require("./base-authenticator"));
10
- const auth_error_1 = __importDefault(require("./auth-error"));
11
- const error_code_1 = __importDefault(require("./error-code"));
12
- class PrimaryAuthenticator extends base_authenticator_1.default {
13
- constructor(platform, storage, finishStep, steps) {
14
- super(platform, storage, finishStep);
15
- this.steps = new Map();
16
- this.log = logger_1.LoggerFactory.getLogger('primary-authenticator');
17
- if (steps) {
18
- for (let step of steps) {
19
- this.steps.set(step.name, step);
20
- }
21
- }
22
- }
23
- process(session) {
24
- return new cancelable_promise_1.default((resolve, reject, onCancel) => {
25
- onCancel(() => {
26
- this.log.info('Canceled');
27
- resolve();
28
- });
29
- this.nextStep(session, session.next, 1).then(resolve).catch(reject);
30
- });
31
- }
32
- nextStep(session, step, attempt) {
33
- this.log.debug(`Authentication attempt ${attempt}, next step: ${step}`);
34
- session.lastStep = step;
35
- return new Promise((resolve, reject) => {
36
- if ([base_authenticator_1.default.AUTH_DONE, base_authenticator_1.default.AUTH_EMPTY].includes(step)) {
37
- resolve();
38
- }
39
- else if (attempt > PrimaryAuthenticator.MAX_ATTEMPTS) {
40
- reject(new auth_error_1.default('Too many authentication steps', error_code_1.default.ERROR_MAX_ATTEMPTS));
41
- }
42
- else {
43
- this.getNextStep(step)
44
- .execute(session)
45
- .then((next) => this.nextStep(session, next, attempt + 1))
46
- .then(resolve)
47
- .catch((e) => new report_error_step_1.default(e)
48
- .execute(session)
49
- .then((next) => this.nextStep(session, next, attempt + 1))
50
- .then(resolve)
51
- .catch(reject));
52
- }
53
- });
54
- }
55
- getNextStep(step) {
56
- var nextStep = this.steps.get(step);
57
- if (nextStep) {
58
- return nextStep;
59
- }
60
- return new report_error_step_1.default('Unknown authentication step: ' + step);
61
- }
62
- }
63
- PrimaryAuthenticator.MAX_ATTEMPTS = 50;
64
- exports.default = PrimaryAuthenticator;
@@ -1,10 +0,0 @@
1
- import AuthFinishStep from '../auth-finish-step';
2
- import AuthSession from './auth-session';
3
- import Platform from './platform';
4
- import CancelablePromise from '../common/cancelable-promise';
5
- import AuthStep from './auth-step';
6
- import PrimaryAuthenticator from './primary-authenticator';
7
- export default class SecondaryAuthenticator extends PrimaryAuthenticator {
8
- constructor(platform?: Platform, storage?: Storage, finishStep?: AuthFinishStep, steps?: Array<AuthStep>);
9
- process(session: AuthSession): CancelablePromise<void>;
10
- }
@@ -1,65 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const logger_1 = require("../common/logger");
7
- const cancelable_promise_1 = __importDefault(require("../common/cancelable-promise"));
8
- const auth_error_1 = __importDefault(require("./auth-error"));
9
- const primary_authenticator_1 = __importDefault(require("./primary-authenticator"));
10
- class SecondaryAuthenticator extends primary_authenticator_1.default {
11
- constructor(platform, storage, finishStep, steps) {
12
- super(platform, storage, finishStep, steps);
13
- this.log = logger_1.LoggerFactory.getLogger('secondary-authenticator');
14
- }
15
- process(session) {
16
- return new cancelable_promise_1.default((resolve, reject, onCancel) => {
17
- var gotResponse = false;
18
- var channel;
19
- var runSteps = super.process(session);
20
- runSteps
21
- .then(() => {
22
- channel = session.createMessageChannel('/v1/client/status', () => {
23
- if (!gotResponse) {
24
- reject(new auth_error_1.default('Failed to receive secondary authentication status, no response'));
25
- }
26
- }, (errorMessage) => {
27
- gotResponse = true;
28
- this.log.error('Failed: ' + errorMessage);
29
- reject(new auth_error_1.default('Failed to receive secondary authentication status: ' + errorMessage));
30
- }, (data) => {
31
- gotResponse = true;
32
- try {
33
- this.log.debug(('Secondary authentication status: ' + data));
34
- const response = JSON.parse(data);
35
- if (response.error) {
36
- reject(new auth_error_1.default(response.error.message, response.error.code, response.next));
37
- }
38
- else {
39
- session.lastStep = response.next;
40
- resolve();
41
- }
42
- }
43
- catch (e) {
44
- reject(e);
45
- }
46
- finally {
47
- channel.close();
48
- }
49
- });
50
- })
51
- .catch(reject);
52
- onCancel(() => {
53
- gotResponse = true;
54
- if (runSteps) {
55
- runSteps.cancel();
56
- }
57
- if (channel) {
58
- channel.close();
59
- }
60
- resolve();
61
- });
62
- });
63
- }
64
- }
65
- exports.default = SecondaryAuthenticator;