@factset/frontgate-js-sdk 6.11.1 → 7.0.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/CHANGELOG.md +97 -40
- package/dist/lib/esnext/FrontgateClient.js +0 -3
- package/dist/lib/esnext/authentication/index.js +3 -4
- package/dist/lib/esnext/common/errors.js +0 -35
- package/dist/lib/esnext/common/functions.js +0 -84
- package/dist/lib/esnext/common/interfaces/index.js +0 -1
- package/dist/lib/esnext/compat/index.js +0 -3
- package/dist/lib/esnext/connection/index.js +19 -6
- package/dist/lib/esnext/connection/util/functions.js +0 -56
- package/dist/lib/esnext/index.js +0 -1
- package/dist/lib/esnext/message/index.js +1 -1
- package/dist/lib/esnext/message/interfaces/index.js +0 -1
- package/dist/lib/esnext/message/request/TransportLayerClientRequestHeader.js +1 -1
- package/dist/lib/esnext/message/request/raw/example/CreateNotationSearchRequest.js +1 -1
- package/dist/lib/esnext/message/request/raw/index.js +0 -1
- package/dist/lib/esnext/message/response/index.js +0 -5
- package/dist/lib/esnext/message/update/index.js +0 -1
- package/dist/lib/esnext/mixins/EndpointRequestMixin.js +1 -1
- package/dist/lib/esnext/mixins/RemoteLoggerMixin.js +29 -0
- package/dist/lib/esnext/mixins/auth/AppAuthMixin.js +79 -11
- package/dist/lib/esnext/mixins/auth/SessionAuthMixin.js +76 -36
- package/dist/lib/esnext/mixins/auth/UserCredentialAuthMixin.js +82 -12
- package/dist/lib/esnext/mixins/auth/UserPasswordAuthMixin.js +80 -13
- package/dist/lib/esnext/mixins/auth/index.js +0 -31
- package/dist/lib/esnext/mixins/index.js +1 -0
- package/dist/lib/esnext/mixins/subscription/EndpointSubscriptionMixin.js +149 -122
- package/dist/lib/esnext/version.js +1 -1
- package/dist/lib/node/FrontgateClient.js +0 -3
- package/dist/lib/node/authentication/index.js +4 -4
- package/dist/lib/node/common/errors.js +1 -41
- package/dist/lib/node/common/functions.js +0 -92
- package/dist/lib/node/common/interfaces/index.js +0 -1
- package/dist/lib/node/compat/index.js +0 -3
- package/dist/lib/node/connection/index.js +20 -6
- package/dist/lib/node/connection/util/functions.js +0 -63
- package/dist/lib/node/index.js +1 -3
- package/dist/lib/node/message/index.js +2 -1
- package/dist/lib/node/message/interfaces/index.js +0 -1
- package/dist/lib/node/message/request/TransportLayerClientRequestHeader.js +3 -3
- package/dist/lib/node/message/request/raw/example/CreateNotationSearchRequest.js +3 -3
- package/dist/lib/node/message/request/raw/index.js +0 -1
- package/dist/lib/node/message/response/index.js +0 -5
- package/dist/lib/node/message/update/index.js +0 -1
- package/dist/lib/node/mixins/EndpointRequestMixin.js +2 -2
- package/dist/lib/node/mixins/RemoteLoggerMixin.js +33 -0
- package/dist/lib/node/mixins/auth/AppAuthMixin.js +78 -10
- package/dist/lib/node/mixins/auth/SessionAuthMixin.js +75 -35
- package/dist/lib/node/mixins/auth/UserCredentialAuthMixin.js +80 -10
- package/dist/lib/node/mixins/auth/UserPasswordAuthMixin.js +78 -11
- package/dist/lib/node/mixins/auth/index.js +0 -33
- package/dist/lib/node/mixins/index.js +1 -0
- package/dist/lib/node/mixins/subscription/EndpointSubscriptionMixin.js +149 -122
- package/dist/lib/node/version.js +1 -1
- package/dist/lib/types/FrontgateClient.d.ts +0 -1
- package/dist/lib/types/authentication/index.d.ts +3 -4
- package/dist/lib/types/authentication/util/ChallengeResolver.d.ts +2 -1
- package/dist/lib/types/common/errors.d.ts +0 -21
- package/dist/lib/types/common/functions.d.ts +0 -8
- package/dist/lib/types/common/interfaces/index.d.ts +0 -1
- package/dist/lib/types/compat/index.d.ts +0 -3
- package/dist/lib/types/connection/index.d.ts +16 -6
- package/dist/lib/types/connection/util/functions.d.ts +0 -18
- package/dist/lib/types/index.d.ts +0 -1
- package/dist/lib/types/message/index.d.ts +1 -1
- package/dist/lib/types/message/interfaces/index.d.ts +0 -1
- package/dist/lib/types/message/request/TransportLayerClientRequestHeader.d.ts +1 -0
- package/dist/lib/types/message/request/raw/index.d.ts +0 -1
- package/dist/lib/types/message/response/index.d.ts +0 -5
- package/dist/lib/types/message/update/index.d.ts +0 -1
- package/dist/lib/types/mixins/AuthTokenRequestMixin.d.ts +1 -2
- package/dist/lib/types/mixins/EndpointRequestMixin.d.ts +1 -2
- package/dist/lib/types/mixins/HTTPProxyRequestMixin.d.ts +1 -4
- package/dist/lib/types/mixins/LoggerMixin.d.ts +1 -2
- package/dist/lib/types/mixins/MessageCompressorMixin.d.ts +1 -2
- package/dist/lib/types/mixins/OpenTelemetryMixin.d.ts +1 -2
- package/dist/lib/types/mixins/PingMixin.d.ts +1 -2
- package/dist/lib/types/mixins/ReconnectMixin.d.ts +1 -2
- package/dist/lib/types/mixins/RemoteLoggerMixin.d.ts +16 -0
- package/dist/lib/types/mixins/RequestMixin.d.ts +1 -2
- package/dist/lib/types/mixins/auth/AppAuthMixin.d.ts +15 -8
- package/dist/lib/types/mixins/auth/CookieTokenAuthMixin.d.ts +1 -2
- package/dist/lib/types/mixins/auth/FetchAuthenticationMixin.d.ts +1 -2
- package/dist/lib/types/mixins/auth/SessionAuthMixin.d.ts +10 -5
- package/dist/lib/types/mixins/auth/TokenAuthMixin.d.ts +1 -2
- package/dist/lib/types/mixins/auth/UserCredentialAuthMixin.d.ts +15 -8
- package/dist/lib/types/mixins/auth/UserPasswordAuthMixin.d.ts +15 -8
- package/dist/lib/types/mixins/auth/index.d.ts +0 -8
- package/dist/lib/types/mixins/connection/FrontgateWSMixin.d.ts +1 -2
- package/dist/lib/types/mixins/index.d.ts +2 -1
- package/dist/lib/types/mixins/subscription/EndpointSubscriptionMixin.d.ts +4 -6
- package/dist/lib/types/mixins/subscription/RawSubscriptionMixin.d.ts +1 -2
- package/dist/lib/umd/mdg2.client.min.umd.js +1 -12
- package/dist/lib/umd/mdg2.client.umd.js +4061 -8138
- package/package.json +25 -28
- package/dist/lib/esnext/Mdg2Client.js +0 -185
- package/dist/lib/esnext/authentication/AbstractAuthentication.js +0 -49
- package/dist/lib/esnext/authentication/AppAuthentication.js +0 -70
- package/dist/lib/esnext/authentication/AuthenticationInterface.js +0 -1
- package/dist/lib/esnext/authentication/CookieTokenAuthentication.js +0 -18
- package/dist/lib/esnext/authentication/TokenAuthentication.js +0 -42
- package/dist/lib/esnext/authentication/UserCredentialAuthentication.js +0 -73
- package/dist/lib/esnext/authentication/UserPasswordAuthentication.js +0 -71
- package/dist/lib/esnext/common/Mdg2ClientOptions.js +0 -1
- package/dist/lib/esnext/common/constants.js +0 -10
- package/dist/lib/esnext/common/interfaces/observe/ObserveOptions.js +0 -1
- package/dist/lib/esnext/connection/AbstractFrontgateConnection.js +0 -324
- package/dist/lib/esnext/connection/ConnectionInterface.js +0 -1
- package/dist/lib/esnext/connection/FrontgateWSConnection.js +0 -281
- package/dist/lib/esnext/connection/JobPromise.js +0 -2
- package/dist/lib/esnext/connection/LatencyHandler.js +0 -1
- package/dist/lib/esnext/connection/LatencyTracker.js +0 -47
- package/dist/lib/esnext/connection/MessageProcessor.js +0 -1
- package/dist/lib/esnext/connection/util/Encoding.js +0 -14
- package/dist/lib/esnext/core/RequestModule.js +0 -349
- package/dist/lib/esnext/core/SubscriptionModule.js +0 -104
- package/dist/lib/esnext/core/subscription/EndpointHandler.js +0 -121
- package/dist/lib/esnext/core/subscription/SubjectManager.js +0 -39
- package/dist/lib/esnext/message/MessageFactory.js +0 -36
- package/dist/lib/esnext/message/guards.js +0 -21
- package/dist/lib/esnext/message/interfaces/JobObservable.js +0 -1
- package/dist/lib/esnext/message/request/raw/RawRequestFactory.js +0 -18
- package/dist/lib/esnext/message/response/AuthenticationByTokenResponse.js +0 -1
- package/dist/lib/esnext/message/response/CancelSubscriptionResponse.js +0 -3
- package/dist/lib/esnext/message/response/LoadNotificationMessage.js +0 -1
- package/dist/lib/esnext/message/response/PermissionDeniedResponse.js +0 -6
- package/dist/lib/esnext/message/response/RejectResponse.js +0 -9
- package/dist/lib/esnext/message/update/SubscriptionLossMessage.js +0 -10
- package/dist/lib/esnext/util/TimeOutWrapper.js +0 -51
- package/dist/lib/node/Mdg2Client.js +0 -189
- package/dist/lib/node/authentication/AbstractAuthentication.js +0 -53
- package/dist/lib/node/authentication/AppAuthentication.js +0 -74
- package/dist/lib/node/authentication/AuthenticationInterface.js +0 -2
- package/dist/lib/node/authentication/CookieTokenAuthentication.js +0 -22
- package/dist/lib/node/authentication/TokenAuthentication.js +0 -46
- package/dist/lib/node/authentication/UserCredentialAuthentication.js +0 -77
- package/dist/lib/node/authentication/UserPasswordAuthentication.js +0 -75
- package/dist/lib/node/common/Mdg2ClientOptions.js +0 -2
- package/dist/lib/node/common/constants.js +0 -13
- package/dist/lib/node/common/interfaces/observe/ObserveOptions.js +0 -2
- package/dist/lib/node/connection/AbstractFrontgateConnection.js +0 -328
- package/dist/lib/node/connection/ConnectionInterface.js +0 -2
- package/dist/lib/node/connection/FrontgateWSConnection.js +0 -288
- package/dist/lib/node/connection/JobPromise.js +0 -6
- package/dist/lib/node/connection/LatencyHandler.js +0 -2
- package/dist/lib/node/connection/LatencyTracker.js +0 -51
- package/dist/lib/node/connection/MessageProcessor.js +0 -2
- package/dist/lib/node/connection/util/Encoding.js +0 -18
- package/dist/lib/node/core/RequestModule.js +0 -353
- package/dist/lib/node/core/SubscriptionModule.js +0 -108
- package/dist/lib/node/core/subscription/EndpointHandler.js +0 -125
- package/dist/lib/node/core/subscription/SubjectManager.js +0 -43
- package/dist/lib/node/message/MessageFactory.js +0 -73
- package/dist/lib/node/message/guards.js +0 -30
- package/dist/lib/node/message/interfaces/JobObservable.js +0 -2
- package/dist/lib/node/message/request/raw/RawRequestFactory.js +0 -22
- package/dist/lib/node/message/response/AuthenticationByTokenResponse.js +0 -2
- package/dist/lib/node/message/response/CancelSubscriptionResponse.js +0 -7
- package/dist/lib/node/message/response/LoadNotificationMessage.js +0 -2
- package/dist/lib/node/message/response/PermissionDeniedResponse.js +0 -10
- package/dist/lib/node/message/response/RejectResponse.js +0 -13
- package/dist/lib/node/message/update/SubscriptionLossMessage.js +0 -14
- package/dist/lib/node/util/TimeOutWrapper.js +0 -55
- package/dist/lib/types/Mdg2Client.d.ts +0 -52
- package/dist/lib/types/authentication/AbstractAuthentication.d.ts +0 -17
- package/dist/lib/types/authentication/AppAuthentication.d.ts +0 -12
- package/dist/lib/types/authentication/AuthenticationInterface.d.ts +0 -9
- package/dist/lib/types/authentication/CookieTokenAuthentication.d.ts +0 -6
- package/dist/lib/types/authentication/TokenAuthentication.d.ts +0 -14
- package/dist/lib/types/authentication/UserCredentialAuthentication.d.ts +0 -13
- package/dist/lib/types/authentication/UserPasswordAuthentication.d.ts +0 -14
- package/dist/lib/types/common/Mdg2ClientOptions.d.ts +0 -12
- package/dist/lib/types/common/constants.d.ts +0 -11
- package/dist/lib/types/common/interfaces/observe/ObserveOptions.d.ts +0 -5
- package/dist/lib/types/connection/AbstractFrontgateConnection.d.ts +0 -116
- package/dist/lib/types/connection/ConnectionInterface.d.ts +0 -53
- package/dist/lib/types/connection/FrontgateWSConnection.d.ts +0 -23
- package/dist/lib/types/connection/JobPromise.d.ts +0 -3
- package/dist/lib/types/connection/LatencyHandler.d.ts +0 -1
- package/dist/lib/types/connection/LatencyTracker.d.ts +0 -13
- package/dist/lib/types/connection/MessageProcessor.d.ts +0 -2
- package/dist/lib/types/connection/util/Encoding.d.ts +0 -9
- package/dist/lib/types/core/RequestModule.d.ts +0 -78
- package/dist/lib/types/core/SubscriptionModule.d.ts +0 -24
- package/dist/lib/types/core/subscription/EndpointHandler.d.ts +0 -37
- package/dist/lib/types/core/subscription/SubjectManager.d.ts +0 -21
- package/dist/lib/types/message/MessageFactory.d.ts +0 -29
- package/dist/lib/types/message/guards.d.ts +0 -11
- package/dist/lib/types/message/interfaces/JobObservable.d.ts +0 -4
- package/dist/lib/types/message/request/raw/RawRequestFactory.d.ts +0 -4
- package/dist/lib/types/message/response/AuthenticationByTokenResponse.d.ts +0 -20
- package/dist/lib/types/message/response/CancelSubscriptionResponse.d.ts +0 -3
- package/dist/lib/types/message/response/LoadNotificationMessage.d.ts +0 -8
- package/dist/lib/types/message/response/PermissionDeniedResponse.d.ts +0 -4
- package/dist/lib/types/message/response/RejectResponse.d.ts +0 -5
- package/dist/lib/types/message/update/SubscriptionLossMessage.d.ts +0 -17
- package/dist/lib/types/util/TimeOutWrapper.d.ts +0 -12
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { RawRequest } from './RawRequest';
|
|
2
|
-
export class RawRequestFactory {
|
|
3
|
-
static createFromString(json) {
|
|
4
|
-
return RawRequestFactory.createFromObject(JSON.parse(json));
|
|
5
|
-
}
|
|
6
|
-
static createFromObject(json) {
|
|
7
|
-
const { header } = json;
|
|
8
|
-
if (header) {
|
|
9
|
-
if (header.id_job) {
|
|
10
|
-
delete header.id_job;
|
|
11
|
-
}
|
|
12
|
-
if (header.resend_counter) {
|
|
13
|
-
delete header.resend_counter;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
return new RawRequest(json);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { TimeoutError } from '../common/errors';
|
|
2
|
-
export class TimeoutWrapper {
|
|
3
|
-
static async wrap(promise, delay, rejectReason = '') {
|
|
4
|
-
return new TimeoutWrapper().wrap(promise, delay, rejectReason);
|
|
5
|
-
}
|
|
6
|
-
constructor() {
|
|
7
|
-
this.promiseFinally = async (promise, fn) => {
|
|
8
|
-
const success = (result) => {
|
|
9
|
-
fn();
|
|
10
|
-
return result;
|
|
11
|
-
};
|
|
12
|
-
const error = async (e) => {
|
|
13
|
-
fn();
|
|
14
|
-
return Promise.reject(e);
|
|
15
|
-
};
|
|
16
|
-
return Promise.resolve(promise).then(success, error);
|
|
17
|
-
};
|
|
18
|
-
this._id = null;
|
|
19
|
-
this._delay = null;
|
|
20
|
-
}
|
|
21
|
-
get id() {
|
|
22
|
-
return this._id;
|
|
23
|
-
}
|
|
24
|
-
get delay() {
|
|
25
|
-
return this._delay;
|
|
26
|
-
}
|
|
27
|
-
async set(delay, rejectReason = '') {
|
|
28
|
-
return new Promise((resolve, reject) => {
|
|
29
|
-
this.clear();
|
|
30
|
-
const fn = rejectReason
|
|
31
|
-
? () => {
|
|
32
|
-
reject(new TimeoutError(rejectReason));
|
|
33
|
-
}
|
|
34
|
-
: resolve;
|
|
35
|
-
this._id = setTimeout(fn, delay);
|
|
36
|
-
this._delay = delay;
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
async wrap(promise, delay, rejectReason = '') {
|
|
40
|
-
const wrappedPromise = this.promiseFinally(promise, () => {
|
|
41
|
-
this.clear();
|
|
42
|
-
});
|
|
43
|
-
const timer = this.set(delay, rejectReason);
|
|
44
|
-
return Promise.race([wrappedPromise, timer]);
|
|
45
|
-
}
|
|
46
|
-
clear() {
|
|
47
|
-
if (this._id) {
|
|
48
|
-
clearTimeout(this._id);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
@@ -1,189 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Mdg2Client = void 0;
|
|
4
|
-
const constants_1 = require("./common/constants");
|
|
5
|
-
const connection_1 = require("./connection");
|
|
6
|
-
const RequestModule_1 = require("./core/RequestModule");
|
|
7
|
-
const SubscriptionModule_1 = require("./core/SubscriptionModule");
|
|
8
|
-
const logger_1 = require("./logger");
|
|
9
|
-
const authentication_1 = require("./authentication");
|
|
10
|
-
const message_1 = require("./message");
|
|
11
|
-
class Mdg2Client {
|
|
12
|
-
constructor(connection, options = {}) {
|
|
13
|
-
this.options = options;
|
|
14
|
-
this.flagPermissionDenied = options.flagPermissionDenied ?? constants_1.DEFAULT_FLAG_PERMISSION_DENIED;
|
|
15
|
-
this.shouldRestartSubscriptions = options.shouldRestartSubscriptions ?? true;
|
|
16
|
-
this.defaultTimeoutInMs = options.defaultTimeoutInMs ?? constants_1.DEFAULT_TIMEOUT_IN_MS;
|
|
17
|
-
this.defaultTimeoutTokenInMs = options.defaultTimeoutTokenInMs ?? constants_1.DEFAULT_TIMEOUT_TOKEN_IN_MS;
|
|
18
|
-
this.maxTimeoutsBeforeReconnect = options.maxTimeoutsBeforeReconnect ?? constants_1.DEFAULT_MAX_TIMEOUTS_BEFORE_RECONNECT;
|
|
19
|
-
this.enableSessionHandling = options.enableSessionHandling ?? constants_1.DEFAULT_ENABLE_SESSION_HANDLING;
|
|
20
|
-
this.replaySubjectBufferSize = options.replaySubjectBufferSize ?? constants_1.DEFAULT_REPLAY_SUBJECT_BUFFER_SIZE;
|
|
21
|
-
this.requestModule = new RequestModule_1.RequestModule(this.getConnection.bind(this), this.logger, {
|
|
22
|
-
defaultTimeoutInMs: this.defaultTimeoutInMs,
|
|
23
|
-
defaultTimeoutTokenInMs: this.defaultTimeoutTokenInMs,
|
|
24
|
-
flagPermissionDenied: this.flagPermissionDenied,
|
|
25
|
-
maxTimeoutsBeforeReconnect: this.maxTimeoutsBeforeReconnect,
|
|
26
|
-
replaySubjectBufferSize: this.replaySubjectBufferSize,
|
|
27
|
-
});
|
|
28
|
-
this.subscriptionModule = new SubscriptionModule_1.SubscriptionModule(this.requestModule, this.logger, { shouldRestartSubscriptions: this.shouldRestartSubscriptions });
|
|
29
|
-
this.sessionConnect = false;
|
|
30
|
-
if (options.onConnectCallback)
|
|
31
|
-
this.onConnectCallback = options.onConnectCallback;
|
|
32
|
-
if (connection) {
|
|
33
|
-
this.setConnection(connection);
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
this.logger = new logger_1.NullLogger();
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
async connect() {
|
|
40
|
-
if (!this.connection) {
|
|
41
|
-
throw new Error('No connection defined. please set a connection before trying to connect.');
|
|
42
|
-
}
|
|
43
|
-
if (this.sessionConnect) {
|
|
44
|
-
return Promise.resolve();
|
|
45
|
-
}
|
|
46
|
-
return this.connection.open();
|
|
47
|
-
}
|
|
48
|
-
async connectSession(shouldThrow = false) {
|
|
49
|
-
if (!this.connection) {
|
|
50
|
-
throw new Error('No connection defined. please set a connection before trying to connect.');
|
|
51
|
-
}
|
|
52
|
-
const { connection: previousConnection } = this;
|
|
53
|
-
const tokenAuth = new authentication_1.CookieTokenAuthentication();
|
|
54
|
-
const tokenConnection = new connection_1.FrontgateWSConnection(tokenAuth, {
|
|
55
|
-
...this.connection.options,
|
|
56
|
-
sessionHandling: true,
|
|
57
|
-
});
|
|
58
|
-
this.setConnection(tokenConnection);
|
|
59
|
-
try {
|
|
60
|
-
await this.connection.open();
|
|
61
|
-
}
|
|
62
|
-
catch (error) {
|
|
63
|
-
this.setConnection(previousConnection);
|
|
64
|
-
if (shouldThrow) {
|
|
65
|
-
throw error;
|
|
66
|
-
}
|
|
67
|
-
return false;
|
|
68
|
-
}
|
|
69
|
-
return true;
|
|
70
|
-
}
|
|
71
|
-
async disconnect(logout = false) {
|
|
72
|
-
if (!this.connection) {
|
|
73
|
-
throw new Error('No connection defined. please set a connection before trying to disconnect.');
|
|
74
|
-
}
|
|
75
|
-
await this.connection.close(false, logout);
|
|
76
|
-
}
|
|
77
|
-
async request(msg, timeOutInMs = this.defaultTimeoutInMs) {
|
|
78
|
-
return this.requestModule.request(msg, timeOutInMs);
|
|
79
|
-
}
|
|
80
|
-
restartSubscriptions() {
|
|
81
|
-
this.subscriptionModule.restartSubscriptions();
|
|
82
|
-
}
|
|
83
|
-
async requestWithQuality(msg, quality = constants_1.DEFAULT_QUALITY, timeOutInMs = this.defaultTimeoutInMs) {
|
|
84
|
-
return this.requestModule.requestWithQuality(msg, quality, timeOutInMs);
|
|
85
|
-
}
|
|
86
|
-
async requestEndpoint(method, path, data, options, timeOutInMs = this.defaultTimeoutInMs) {
|
|
87
|
-
return this.requestModule.requestEndpoint(method, path, data, options, timeOutInMs);
|
|
88
|
-
}
|
|
89
|
-
async requestProxyEndpoint(method, path, body, options, timeOutInMs = this.defaultTimeoutInMs) {
|
|
90
|
-
return this.requestModule.requestProxyEndpoint(method, path, body, options, timeOutInMs);
|
|
91
|
-
}
|
|
92
|
-
async requestAuthenticationToken(lifetimeSeconds, idUser, idApplication, timeOutInMs = this.defaultTimeoutTokenInMs) {
|
|
93
|
-
return this.requestModule.requestAuthenticationToken(lifetimeSeconds, idUser, idApplication, timeOutInMs);
|
|
94
|
-
}
|
|
95
|
-
async requestAuthenticationTokenExpiry(lifetimeSeconds, idUser, idApplication, timeOutInMs = this.defaultTimeoutTokenInMs, otp = false) {
|
|
96
|
-
return this.requestModule.requestAuthenticationTokenExpiry(lifetimeSeconds, idUser, idApplication, timeOutInMs, otp);
|
|
97
|
-
}
|
|
98
|
-
async requestOtpAuthenticationTokenForSessionHandling(lifetimeSeconds = message_1.AuthenticationTokenRequest.LIFETIME_SECONDS_MAXIMUM, idUser = authentication_1.ID_USER_AUTHENTICATED, idApplication = authentication_1.ID_APP_AUTHENTICATED, timeOutInMs = this.defaultTimeoutTokenInMs) {
|
|
99
|
-
const { token, expiry } = await this.requestModule.requestAuthenticationTokenExpiry(lifetimeSeconds, idUser, idApplication, timeOutInMs, true);
|
|
100
|
-
this.options.otpToken = token;
|
|
101
|
-
this.options.otpTokenExpiry = expiry;
|
|
102
|
-
}
|
|
103
|
-
async requestAuthenticationTokenForCookieTokenAuthentication(lifetimeSeconds, idUser, idApplication, timeOutInMs = this.defaultTimeoutTokenInMs) {
|
|
104
|
-
return this.requestModule.requestAuthenticationTokenFactorsForCookieAuthentication(lifetimeSeconds, idUser, idApplication, timeOutInMs);
|
|
105
|
-
}
|
|
106
|
-
observeEndpoint(method, path, data, options, requestOptions) {
|
|
107
|
-
return this.subscriptionModule.observeEndpoint(method, path, data, options, requestOptions);
|
|
108
|
-
}
|
|
109
|
-
async unobserveEndpoint(idJob) {
|
|
110
|
-
return this.subscriptionModule.unobserveEndpoint(idJob);
|
|
111
|
-
}
|
|
112
|
-
setConnection(connection) {
|
|
113
|
-
if (connection.options.logger) {
|
|
114
|
-
this.setLogger(connection.options.logger);
|
|
115
|
-
}
|
|
116
|
-
if (this.isConnected) {
|
|
117
|
-
this.logger.warn('Cannot modify an open connection. Disconnect first, before trying to set the connection.');
|
|
118
|
-
}
|
|
119
|
-
this.connection = connection;
|
|
120
|
-
this.connection.clientOptions = this.options;
|
|
121
|
-
this.connection.shouldRestartSubscriptions = this.shouldRestartSubscriptions;
|
|
122
|
-
this.connection.onAuthentication = this.requestModule.onConnection.bind(this.requestModule);
|
|
123
|
-
this.connection.onCleanupRequests = this.requestModule.clearPendingRequests.bind(this.requestModule);
|
|
124
|
-
this.connection.onCleanupSubscriptions = this.subscriptionModule.clearPendingSubscriptions.bind(this.subscriptionModule);
|
|
125
|
-
this.connection.onClearPendingSubscription = (jobId) => {
|
|
126
|
-
this.subscriptionModule.clearPendingSubscription(jobId);
|
|
127
|
-
};
|
|
128
|
-
this.connection.restartSubscriptions = this.subscriptionModule.restartSubscriptions.bind(this.subscriptionModule);
|
|
129
|
-
this.connection.onConnect = this.onConnectCallback;
|
|
130
|
-
}
|
|
131
|
-
getConnection() {
|
|
132
|
-
return this.connection;
|
|
133
|
-
}
|
|
134
|
-
async setConnectionFromFetchConfiguration(input, init, shouldReconnectOnConnectionLoss) {
|
|
135
|
-
if (this.enableSessionHandling) {
|
|
136
|
-
if (this.setConnectionFromSavedConfig() && (await this.connectSession())) {
|
|
137
|
-
this.sessionConnect = true;
|
|
138
|
-
return Promise.resolve();
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
const { config, response } = await (0, connection_1.fetchConnectionConfiguration)(input, init);
|
|
142
|
-
if (this.enableSessionHandling) {
|
|
143
|
-
(0, connection_1.setConnectionConfiguration)(config);
|
|
144
|
-
}
|
|
145
|
-
this.setConnection(Mdg2Client.createConnection({
|
|
146
|
-
...config,
|
|
147
|
-
logger: this.logger,
|
|
148
|
-
loglevel: this.logger.getLevel(),
|
|
149
|
-
shouldReconnectOnConnectionLoss,
|
|
150
|
-
}, input, init));
|
|
151
|
-
return response;
|
|
152
|
-
}
|
|
153
|
-
static createConnection(config, input, init) {
|
|
154
|
-
return (0, connection_1.createConnection)(config, input, init);
|
|
155
|
-
}
|
|
156
|
-
setLogger(logger) {
|
|
157
|
-
this.logger = logger;
|
|
158
|
-
this.requestModule.setLogger(logger);
|
|
159
|
-
this.subscriptionModule.setLogger(logger);
|
|
160
|
-
if (this.connection) {
|
|
161
|
-
this.connection.setLogger(logger);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
getLogger() {
|
|
165
|
-
return this.logger;
|
|
166
|
-
}
|
|
167
|
-
get isConnected() {
|
|
168
|
-
return this.connection?.isAuthenticated() ?? false;
|
|
169
|
-
}
|
|
170
|
-
get isConnecting() {
|
|
171
|
-
return this.connection?.isConnecting() ?? false;
|
|
172
|
-
}
|
|
173
|
-
getServerInfo() {
|
|
174
|
-
return this.connection?.auth.getServerInfo();
|
|
175
|
-
}
|
|
176
|
-
setConnectionFromSavedConfig() {
|
|
177
|
-
const savedConfig = (0, connection_1.getConnectionConfiguration)();
|
|
178
|
-
if (savedConfig) {
|
|
179
|
-
this.setConnection(Mdg2Client.createConnection({
|
|
180
|
-
...savedConfig,
|
|
181
|
-
logger: this.logger,
|
|
182
|
-
loglevel: this.logger.getLevel(),
|
|
183
|
-
}));
|
|
184
|
-
return true;
|
|
185
|
-
}
|
|
186
|
-
return false;
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
exports.Mdg2Client = Mdg2Client;
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AbstractAuthentication = exports.ID_USER_NONE = exports.ID_USER_AUTHENTICATED = exports.ID_APP_AUTHENTICATED = void 0;
|
|
4
|
-
exports.ID_APP_AUTHENTICATED = -2;
|
|
5
|
-
exports.ID_USER_AUTHENTICATED = -2;
|
|
6
|
-
exports.ID_USER_NONE = -1;
|
|
7
|
-
class AbstractAuthentication {
|
|
8
|
-
constructor(idApplication, idUser = exports.ID_USER_NONE) {
|
|
9
|
-
if (!Number.isInteger(idApplication)) {
|
|
10
|
-
throw new TypeError(`idApplication is not an integer number. Given: ${idApplication} (${typeof idApplication})`);
|
|
11
|
-
}
|
|
12
|
-
this.idApplication = idApplication;
|
|
13
|
-
if (!Number.isInteger(idUser)) {
|
|
14
|
-
throw new TypeError(`idUser is not an integer number. Given: ${idUser} (${typeof idUser})`);
|
|
15
|
-
}
|
|
16
|
-
this.idUser = idUser;
|
|
17
|
-
}
|
|
18
|
-
peerInfoFromMessage(msg) {
|
|
19
|
-
if (msg.Message === 'Foundation::DisconnectionMessage') {
|
|
20
|
-
const disconnectMessage = msg;
|
|
21
|
-
throw new Error(`Disconnection Message: ${disconnectMessage.details}`);
|
|
22
|
-
}
|
|
23
|
-
if (msg.Message === 'Foundation::AuthenticationByTokenResponse' || msg.Message === 'Foundation::ConfigurationResponse') {
|
|
24
|
-
const message = msg;
|
|
25
|
-
this.serverInfo = this.parseServerInfo(message);
|
|
26
|
-
return {
|
|
27
|
-
uuid: message.server_info.uuid,
|
|
28
|
-
description: message.server_info.description,
|
|
29
|
-
software: message.server_info.software,
|
|
30
|
-
os: message.server_info.os,
|
|
31
|
-
maximumIdleInterval: parseInt(message.maximum_idle_interval, 10),
|
|
32
|
-
maximumReceivableMessageSize: message.maximum_receivable_message_size,
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
throw new Error('Could not extract server_info from unknown message type.');
|
|
36
|
-
}
|
|
37
|
-
parseServerInfo(msg) {
|
|
38
|
-
const message = msg;
|
|
39
|
-
const timeInMs = Number(BigInt(message.time_at_server.microseconds)) / 1000;
|
|
40
|
-
const offsetInMs = Math.ceil(Date.now() - timeInMs);
|
|
41
|
-
return {
|
|
42
|
-
description: message.server_info.description,
|
|
43
|
-
software: message.server_info.software,
|
|
44
|
-
os: message.server_info.os,
|
|
45
|
-
time: new Date(timeInMs),
|
|
46
|
-
offsetInMs,
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
getServerInfo() {
|
|
50
|
-
return this.serverInfo;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
exports.AbstractAuthentication = AbstractAuthentication;
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AppAuthentication = void 0;
|
|
4
|
-
const functions_1 = require("../connection/util/functions");
|
|
5
|
-
const util_1 = require("./util");
|
|
6
|
-
const AbstractAuthentication_1 = require("./AbstractAuthentication");
|
|
7
|
-
const AuthenticationRequest_1 = require("../message/request/AuthenticationRequest");
|
|
8
|
-
const ConfigurationRequest_1 = require("../message/request/ConfigurationRequest");
|
|
9
|
-
const crypto_1 = require("crypto");
|
|
10
|
-
class AppAuthentication extends AbstractAuthentication_1.AbstractAuthentication {
|
|
11
|
-
constructor(idApplication, idUser, clientCredentials) {
|
|
12
|
-
super(idApplication, idUser);
|
|
13
|
-
this.reconnectable = true;
|
|
14
|
-
if (typeof clientCredentials !== 'string') {
|
|
15
|
-
throw new Error('clientCredentials not provided or not a string. Client credentials must have the form "{server_secret}-{shared_secret}-{client_secret}".');
|
|
16
|
-
}
|
|
17
|
-
const secrets = clientCredentials.split('-');
|
|
18
|
-
if (secrets.length !== 3) {
|
|
19
|
-
throw new Error('Invalid clientCredentials. Client credentials must have the form "{server_secret}-{shared_secret}-{client_secret}".');
|
|
20
|
-
}
|
|
21
|
-
if (secrets[0] === '*') {
|
|
22
|
-
throw new Error('Invalid clientCredentials. Client credentials first part must be a hashed server secret.');
|
|
23
|
-
}
|
|
24
|
-
this.sharedSecret = Buffer.from(secrets[1], 'base64');
|
|
25
|
-
this.clientSecret = Buffer.from(secrets[2], 'base64');
|
|
26
|
-
}
|
|
27
|
-
async authenticate(connection) {
|
|
28
|
-
this.connection = connection;
|
|
29
|
-
const authenticationResponse = await this.sendAuthenticationRequest();
|
|
30
|
-
const configurationResponse = await this.sendConfigurationRequest(authenticationResponse);
|
|
31
|
-
const peerInfo = this.peerInfoFromMessage(configurationResponse);
|
|
32
|
-
this.connection.setPeerInfo(peerInfo);
|
|
33
|
-
await this.sendTransportLayerRequestHeaderConfigurationRequest(configurationResponse);
|
|
34
|
-
}
|
|
35
|
-
async sendAuthenticationRequest() {
|
|
36
|
-
const salt = (0, crypto_1.randomBytes)(16);
|
|
37
|
-
const options = {
|
|
38
|
-
idApplication: this.idApplication,
|
|
39
|
-
salt: (0, functions_1.getBytesFromBuffer)(salt),
|
|
40
|
-
challenge: (0, functions_1.getBytesFromBuffer)((0, crypto_1.randomBytes)(16)),
|
|
41
|
-
encryptedSecrets: [{ encrypted_secret: util_1.SecretGenerator.createEncryptedSecret(salt, this.sharedSecret, this.clientSecret) }],
|
|
42
|
-
};
|
|
43
|
-
const request = new AuthenticationRequest_1.AuthenticationRequest(options);
|
|
44
|
-
return (await this.connection.submit(request.toJson()));
|
|
45
|
-
}
|
|
46
|
-
async sendConfigurationRequest(msg) {
|
|
47
|
-
const expectedMessage = 'Foundation::AuthenticationResponse';
|
|
48
|
-
if (msg.Message !== expectedMessage) {
|
|
49
|
-
throw new Error(`Expected message "${expectedMessage}" but received "${msg.Message}"`);
|
|
50
|
-
}
|
|
51
|
-
const { challenge } = msg.challenge;
|
|
52
|
-
const options = {
|
|
53
|
-
shared_secret: this.sharedSecret,
|
|
54
|
-
payload_content: this.connection.options.payload_content,
|
|
55
|
-
deployment_stage: this.connection.options.deployment_stage,
|
|
56
|
-
maximum_idle_interval: this.connection.options.maximum_idle_interval,
|
|
57
|
-
};
|
|
58
|
-
const configRequest = new ConfigurationRequest_1.ConfigurationRequest(challenge, options);
|
|
59
|
-
return (await this.connection.submit(configRequest.toJson()));
|
|
60
|
-
}
|
|
61
|
-
async sendTransportLayerRequestHeaderConfigurationRequest(msg) {
|
|
62
|
-
const expectedMessage = 'Foundation::ConfigurationResponse';
|
|
63
|
-
if (msg.Message !== expectedMessage) {
|
|
64
|
-
throw new Error(`Expected message "${expectedMessage}" but received "${msg.Message}"`);
|
|
65
|
-
}
|
|
66
|
-
const request = {
|
|
67
|
-
Message: 'TransportLayerClientConfigurationRequest',
|
|
68
|
-
Version: 1,
|
|
69
|
-
flags: 0,
|
|
70
|
-
};
|
|
71
|
-
return this.connection.submit(request);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
exports.AppAuthentication = AppAuthentication;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CookieTokenAuthentication = void 0;
|
|
4
|
-
const functions_1 = require("../connection/util/functions");
|
|
5
|
-
const TokenAuthentication_1 = require("./TokenAuthentication");
|
|
6
|
-
class CookieTokenAuthentication extends TokenAuthentication_1.TokenAuthentication {
|
|
7
|
-
constructor() {
|
|
8
|
-
super('', false);
|
|
9
|
-
}
|
|
10
|
-
getEncodedToken() {
|
|
11
|
-
return [];
|
|
12
|
-
}
|
|
13
|
-
async onReconnect() {
|
|
14
|
-
if (this.fetchConfigurationInput) {
|
|
15
|
-
const { config } = await (0, functions_1.fetchConnectionConfiguration)(this.fetchConfigurationInput, this.fetchConfigurationConfig);
|
|
16
|
-
if (config.frontgateSplitAuthenticationTokenSecondFactor) {
|
|
17
|
-
this.connection.options.frontgateSplitAuthenticationTokenSecondFactor = config.frontgateSplitAuthenticationTokenSecondFactor;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
exports.CookieTokenAuthentication = CookieTokenAuthentication;
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TokenAuthentication = void 0;
|
|
4
|
-
const functions_1 = require("../connection/util/functions");
|
|
5
|
-
const AbstractAuthentication_1 = require("./AbstractAuthentication");
|
|
6
|
-
const message_1 = require("../message");
|
|
7
|
-
const functions_2 = require("../common/functions");
|
|
8
|
-
class TokenAuthentication extends AbstractAuthentication_1.AbstractAuthentication {
|
|
9
|
-
constructor(token, validate = true) {
|
|
10
|
-
super(AbstractAuthentication_1.ID_APP_AUTHENTICATED, AbstractAuthentication_1.ID_USER_AUTHENTICATED);
|
|
11
|
-
if (validate && (!token || token.length < 80)) {
|
|
12
|
-
throw new Error('Invalid token passed to TokenAuthentication');
|
|
13
|
-
}
|
|
14
|
-
this.setToken(token);
|
|
15
|
-
}
|
|
16
|
-
setToken(token) {
|
|
17
|
-
this.token = (0, functions_2.isBase64Url)(token) ? (0, functions_2.base64UrlToBase64)(token) : token;
|
|
18
|
-
}
|
|
19
|
-
setFetchConfiguration(input, config) {
|
|
20
|
-
this.fetchConfigurationInput = input;
|
|
21
|
-
this.fetchConfigurationConfig = config;
|
|
22
|
-
}
|
|
23
|
-
async authenticate(connection) {
|
|
24
|
-
this.connection = connection;
|
|
25
|
-
const authenticationByTokenResponse = await this.sendAuthenticationByTokenRequest();
|
|
26
|
-
const peerInfo = this.peerInfoFromMessage(authenticationByTokenResponse);
|
|
27
|
-
this.connection.setPeerInfo(peerInfo);
|
|
28
|
-
}
|
|
29
|
-
async sendAuthenticationByTokenRequest() {
|
|
30
|
-
const token = { b64: this.token };
|
|
31
|
-
const request = new message_1.AuthenticationByTokenRequest(token, this.connection.options.maximum_idle_interval);
|
|
32
|
-
return (await this.connection.submit(request.toJson()));
|
|
33
|
-
}
|
|
34
|
-
get reconnectable() {
|
|
35
|
-
return !!this.fetchConfigurationInput;
|
|
36
|
-
}
|
|
37
|
-
async onReconnect() {
|
|
38
|
-
if (this.fetchConfigurationInput) {
|
|
39
|
-
const { config } = await (0, functions_1.fetchConnectionConfiguration)(this.fetchConfigurationInput, this.fetchConfigurationConfig);
|
|
40
|
-
if (config.frontgateAuthenticationType === 'token' && config.frontgateAuthenticationToken) {
|
|
41
|
-
this.setToken(config.frontgateAuthenticationToken);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
exports.TokenAuthentication = TokenAuthentication;
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.UserCredentialAuthentication = void 0;
|
|
4
|
-
const functions_1 = require("../connection/util/functions");
|
|
5
|
-
const AbstractAuthentication_1 = require("./AbstractAuthentication");
|
|
6
|
-
const util_1 = require("./util");
|
|
7
|
-
const AuthenticationRequest_1 = require("../message/request/AuthenticationRequest");
|
|
8
|
-
const ConfigurationRequest_1 = require("../message/request/ConfigurationRequest");
|
|
9
|
-
const crypto_1 = require("crypto");
|
|
10
|
-
class UserCredentialAuthentication extends AbstractAuthentication_1.AbstractAuthentication {
|
|
11
|
-
constructor(idApplication, username, credentials) {
|
|
12
|
-
super(idApplication);
|
|
13
|
-
this.reconnectable = true;
|
|
14
|
-
const secrets = credentials.split('-');
|
|
15
|
-
if (secrets.length !== 3) {
|
|
16
|
-
throw new Error('Invalid clientCredentials. Client credentials must have the form "{server_secret}-{shared_secret}-{client_secret}".');
|
|
17
|
-
}
|
|
18
|
-
if (secrets[0] === '*') {
|
|
19
|
-
throw new Error('Invalid clientCredentials. Client credentials first part must be a hashed server secret.');
|
|
20
|
-
}
|
|
21
|
-
this.username = username;
|
|
22
|
-
this.sharedSecret = Buffer.from(secrets[1], 'base64');
|
|
23
|
-
this.clientSecret = Buffer.from(secrets[2], 'base64');
|
|
24
|
-
}
|
|
25
|
-
async authenticate(connection) {
|
|
26
|
-
this.connection = connection;
|
|
27
|
-
const authenticationResponse = await this.sendAuthenticationRequest();
|
|
28
|
-
const configurationResponse = await this.sendConfigurationRequest(authenticationResponse);
|
|
29
|
-
const peerInfo = this.peerInfoFromMessage(configurationResponse);
|
|
30
|
-
this.connection.setPeerInfo(peerInfo);
|
|
31
|
-
await this.sendTransportLayerRequestHeaderConfigurationRequest(configurationResponse);
|
|
32
|
-
}
|
|
33
|
-
async sendAuthenticationRequest() {
|
|
34
|
-
const salt = (0, crypto_1.randomBytes)(16);
|
|
35
|
-
const options = {
|
|
36
|
-
idApplication: this.idApplication,
|
|
37
|
-
username: this.username,
|
|
38
|
-
salt: (0, functions_1.getBytesFromBuffer)(salt),
|
|
39
|
-
challenge: (0, functions_1.getBytesFromBuffer)((0, crypto_1.randomBytes)(16)),
|
|
40
|
-
encryptedSecrets: [{ encrypted_secret: util_1.SecretGenerator.createEncryptedSecret(salt, this.sharedSecret, this.clientSecret) }],
|
|
41
|
-
};
|
|
42
|
-
const request = new AuthenticationRequest_1.AuthenticationRequest(options);
|
|
43
|
-
return (await this.connection.submit(request.toJson()));
|
|
44
|
-
}
|
|
45
|
-
async sendConfigurationRequest(msg) {
|
|
46
|
-
const expectedMessage = 'Foundation::AuthenticationResponse';
|
|
47
|
-
if (msg.Message !== expectedMessage) {
|
|
48
|
-
throw new Error(`Expected message "${expectedMessage}" but received "${msg.Message}"`);
|
|
49
|
-
}
|
|
50
|
-
if (msg.id_user === AbstractAuthentication_1.ID_USER_AUTHENTICATED) {
|
|
51
|
-
this.connection.auth.idUser = AbstractAuthentication_1.ID_USER_AUTHENTICATED;
|
|
52
|
-
this.connection.auth.idApplication = AbstractAuthentication_1.ID_APP_AUTHENTICATED;
|
|
53
|
-
}
|
|
54
|
-
const { challenge } = msg.challenge;
|
|
55
|
-
const options = {
|
|
56
|
-
shared_secret: this.sharedSecret,
|
|
57
|
-
payload_content: this.connection.options.payload_content,
|
|
58
|
-
deployment_stage: this.connection.options.deployment_stage,
|
|
59
|
-
maximum_idle_interval: this.connection.options.maximum_idle_interval,
|
|
60
|
-
};
|
|
61
|
-
const configRequest = new ConfigurationRequest_1.ConfigurationRequest(challenge, options);
|
|
62
|
-
return (await this.connection.submit(configRequest.toJson()));
|
|
63
|
-
}
|
|
64
|
-
async sendTransportLayerRequestHeaderConfigurationRequest(msg) {
|
|
65
|
-
const expectedMessage = 'Foundation::ConfigurationResponse';
|
|
66
|
-
if (msg.Message !== expectedMessage) {
|
|
67
|
-
throw new Error(`Expected message "${expectedMessage}" but received "${msg.Message}"`);
|
|
68
|
-
}
|
|
69
|
-
const request = {
|
|
70
|
-
Message: 'TransportLayerClientConfigurationRequest',
|
|
71
|
-
Version: 1,
|
|
72
|
-
flags: 0,
|
|
73
|
-
};
|
|
74
|
-
return this.connection.submit(request);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
exports.UserCredentialAuthentication = UserCredentialAuthentication;
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.UserPasswordAuthentication = void 0;
|
|
4
|
-
const functions_1 = require("../connection/util/functions");
|
|
5
|
-
const AbstractAuthentication_1 = require("./AbstractAuthentication");
|
|
6
|
-
const util_1 = require("./util");
|
|
7
|
-
const AuthenticationRequest_1 = require("../message/request/AuthenticationRequest");
|
|
8
|
-
const ConfigurationRequest_1 = require("../message/request/ConfigurationRequest");
|
|
9
|
-
const crypto_1 = require("crypto");
|
|
10
|
-
class UserPasswordAuthentication extends AbstractAuthentication_1.AbstractAuthentication {
|
|
11
|
-
constructor(idApplication, username, password) {
|
|
12
|
-
super(idApplication);
|
|
13
|
-
this.reconnectable = true;
|
|
14
|
-
this.username = username;
|
|
15
|
-
this.password = password;
|
|
16
|
-
const plainSharedSecret = util_1.SecretGenerator.generateSharedSecret(username, password);
|
|
17
|
-
const plainClientSecret = util_1.SecretGenerator.generateClientSecret(username, password);
|
|
18
|
-
if (plainSharedSecret && plainClientSecret) {
|
|
19
|
-
this.sharedSecret = Buffer.from(plainSharedSecret);
|
|
20
|
-
this.clientSecret = Buffer.from(plainClientSecret);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
async authenticate(connection) {
|
|
24
|
-
this.connection = connection;
|
|
25
|
-
const authenticationResponse = await this.sendAuthenticationRequest();
|
|
26
|
-
const configurationResponse = await this.sendConfigurationRequest(authenticationResponse);
|
|
27
|
-
const peerInfo = this.peerInfoFromMessage(configurationResponse);
|
|
28
|
-
this.connection.setPeerInfo(peerInfo);
|
|
29
|
-
await this.sendTransportLayerRequestHeaderConfigurationRequest(configurationResponse);
|
|
30
|
-
}
|
|
31
|
-
async sendAuthenticationRequest() {
|
|
32
|
-
const salt = (0, crypto_1.randomBytes)(16);
|
|
33
|
-
const options = {
|
|
34
|
-
idApplication: this.idApplication,
|
|
35
|
-
username: this.username,
|
|
36
|
-
salt: (0, functions_1.getBytesFromBuffer)(salt),
|
|
37
|
-
challenge: (0, functions_1.getBytesFromBuffer)((0, crypto_1.randomBytes)(16)),
|
|
38
|
-
encryptedSecrets: [{ encrypted_secret: util_1.SecretGenerator.createEncryptedSecret(salt, this.sharedSecret, this.clientSecret) }],
|
|
39
|
-
};
|
|
40
|
-
const request = new AuthenticationRequest_1.AuthenticationRequest(options);
|
|
41
|
-
return (await this.connection.submit(request.toJson()));
|
|
42
|
-
}
|
|
43
|
-
async sendConfigurationRequest(msg) {
|
|
44
|
-
const expectedMessage = 'Foundation::AuthenticationResponse';
|
|
45
|
-
if (msg.Message !== expectedMessage) {
|
|
46
|
-
throw new Error(`Expected message "${expectedMessage}" but received "${msg.Message}"`);
|
|
47
|
-
}
|
|
48
|
-
if (msg.id_user === AbstractAuthentication_1.ID_USER_AUTHENTICATED) {
|
|
49
|
-
this.connection.auth.idApplication = AbstractAuthentication_1.ID_APP_AUTHENTICATED;
|
|
50
|
-
this.connection.auth.idUser = AbstractAuthentication_1.ID_USER_AUTHENTICATED;
|
|
51
|
-
}
|
|
52
|
-
const { challenge } = msg.challenge;
|
|
53
|
-
const options = {
|
|
54
|
-
shared_secret: this.sharedSecret,
|
|
55
|
-
payload_content: this.connection.options.payload_content,
|
|
56
|
-
deployment_stage: this.connection.options.deployment_stage,
|
|
57
|
-
maximum_idle_interval: this.connection.options.maximum_idle_interval,
|
|
58
|
-
};
|
|
59
|
-
const configRequest = new ConfigurationRequest_1.ConfigurationRequest(challenge, options);
|
|
60
|
-
return (await this.connection.submit(configRequest.toJson()));
|
|
61
|
-
}
|
|
62
|
-
async sendTransportLayerRequestHeaderConfigurationRequest(msg) {
|
|
63
|
-
const expectedMessage = 'Foundation::ConfigurationResponse';
|
|
64
|
-
if (msg.Message !== expectedMessage) {
|
|
65
|
-
throw new Error(`Expected message "${expectedMessage}" but received "${msg.Message}"`);
|
|
66
|
-
}
|
|
67
|
-
const request = {
|
|
68
|
-
Message: 'TransportLayerClientConfigurationRequest',
|
|
69
|
-
Version: 1,
|
|
70
|
-
flags: 0,
|
|
71
|
-
};
|
|
72
|
-
return this.connection.submit(request);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
exports.UserPasswordAuthentication = UserPasswordAuthentication;
|