@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
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@factset/frontgate-js-sdk",
|
|
3
3
|
"author": "Factset GmbH",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "7.0.1",
|
|
5
5
|
"description": "Typescript based client to request and subscribe values from mdg2 (frontgate)",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"main": "./dist/lib/node/index.js",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
},
|
|
28
28
|
"scripts": {
|
|
29
29
|
"prebuild": "rimraf ./dist",
|
|
30
|
-
"build": "yarn prebuild && yarn typecheck &&
|
|
30
|
+
"build": "yarn prebuild && yarn typecheck && concurrently 'yarn build:node' 'yarn build:esnext' 'yarn build:umd'",
|
|
31
31
|
"build:vite:umd": "cross-env BUILD_TYPE=umd MINIFY=false vite build --outDir dist/lib/umd",
|
|
32
32
|
"build:vite:umd:min": "cross-env BUILD_TYPE=umd MINIFY=true vite build --outDir dist/lib/umd",
|
|
33
33
|
"build:node": "tsc -p tsconfig_node.json",
|
|
@@ -44,52 +44,49 @@
|
|
|
44
44
|
"prepublishOnly": "node ./scripts/prepublish.mjs",
|
|
45
45
|
"prettier": "prettier --check .",
|
|
46
46
|
"prettier:fix": "prettier --write .",
|
|
47
|
-
"changelog": "conventional-changelog -r 0 -f"
|
|
47
|
+
"changelog": "conventional-changelog -r 0 -f",
|
|
48
|
+
"changelog:help": "conventional-changelog --help"
|
|
48
49
|
},
|
|
49
50
|
"repository": {
|
|
50
51
|
"type": "git",
|
|
51
52
|
"url": "https://github.com/factset/frontgate-js-sdk"
|
|
52
53
|
},
|
|
53
54
|
"dependencies": {
|
|
54
|
-
"@opentelemetry/api": "^1.
|
|
55
|
+
"@opentelemetry/api": "^1.9.0",
|
|
55
56
|
"bcryptjs": "^3.0.2",
|
|
56
57
|
"big-integer": "^1.6.52",
|
|
57
58
|
"buffer": "^6.0.3",
|
|
58
|
-
"core-js": "^3.
|
|
59
|
-
"crypto-browserify": "^3.12.1",
|
|
59
|
+
"core-js": "^3.44.0",
|
|
60
60
|
"deepmerge": "^4.3.1",
|
|
61
61
|
"fast-json-patch": "^3.1.1",
|
|
62
62
|
"fb-tiger-hash": "^1.0.0",
|
|
63
63
|
"fflate": "^0.8.2",
|
|
64
64
|
"hookable": "^5.5.3",
|
|
65
65
|
"isomorphic-ws": "^5.0.0",
|
|
66
|
-
"
|
|
67
|
-
"
|
|
68
|
-
"winston": "^3.11.0",
|
|
69
|
-
"ws": "^8.16.0"
|
|
66
|
+
"winston": "^3.17.0",
|
|
67
|
+
"ws": "^8.18.3"
|
|
70
68
|
},
|
|
71
69
|
"devDependencies": {
|
|
72
70
|
"@types/bcryptjs": "^3.0.0",
|
|
73
|
-
"@types/ws": "^8.
|
|
74
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
75
|
-
"@vitest/coverage-v8": "^3.
|
|
71
|
+
"@types/ws": "^8.18.1",
|
|
72
|
+
"@typescript-eslint/eslint-plugin": "^8.38.0",
|
|
73
|
+
"@vitest/coverage-v8": "^3.2.4",
|
|
74
|
+
"concurrently": "^9.2.0",
|
|
76
75
|
"conventional-changelog": "^7.1.1",
|
|
77
|
-
"conventional-changelog-cli": "^
|
|
78
|
-
"cross-env": "^
|
|
79
|
-
"eslint": "^9.
|
|
80
|
-
"eslint-config-prettier": "^10.1.
|
|
81
|
-
"globals": "^16.
|
|
82
|
-
"happy-dom": "^
|
|
76
|
+
"conventional-changelog-cli": "^5.0.0",
|
|
77
|
+
"cross-env": "^10.0.0",
|
|
78
|
+
"eslint": "^9.31.0",
|
|
79
|
+
"eslint-config-prettier": "^10.1.8",
|
|
80
|
+
"globals": "^16.3.0",
|
|
81
|
+
"happy-dom": "^18.0.1",
|
|
83
82
|
"mock-socket": "^9.3.1",
|
|
84
|
-
"
|
|
85
|
-
"prettier": "^3.2.5",
|
|
83
|
+
"prettier": "^3.6.2",
|
|
86
84
|
"replace": "^1.2.2",
|
|
87
|
-
"rimraf": "^
|
|
88
|
-
"typedoc": "^0.
|
|
89
|
-
"typescript": "^5.
|
|
90
|
-
"vite": "^
|
|
91
|
-
"
|
|
92
|
-
"vitest": "^3.1.1"
|
|
85
|
+
"rimraf": "^6.0.1",
|
|
86
|
+
"typedoc": "^0.28.7",
|
|
87
|
+
"typescript": "^5.8.3",
|
|
88
|
+
"vite": "^7.0.5",
|
|
89
|
+
"vitest": "^3.2.4"
|
|
93
90
|
},
|
|
94
|
-
"packageManager": "yarn@4.
|
|
91
|
+
"packageManager": "yarn@4.9.4"
|
|
95
92
|
}
|
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
import { DEFAULT_ENABLE_SESSION_HANDLING, DEFAULT_FLAG_PERMISSION_DENIED, DEFAULT_MAX_TIMEOUTS_BEFORE_RECONNECT, DEFAULT_QUALITY, DEFAULT_REPLAY_SUBJECT_BUFFER_SIZE, DEFAULT_TIMEOUT_IN_MS, DEFAULT_TIMEOUT_TOKEN_IN_MS, } from './common/constants';
|
|
2
|
-
import { createConnection, fetchConnectionConfiguration, FrontgateWSConnection, getConnectionConfiguration, setConnectionConfiguration } from './connection';
|
|
3
|
-
import { RequestModule } from './core/RequestModule';
|
|
4
|
-
import { SubscriptionModule } from './core/SubscriptionModule';
|
|
5
|
-
import { NullLogger } from './logger';
|
|
6
|
-
import { CookieTokenAuthentication, ID_APP_AUTHENTICATED, ID_USER_AUTHENTICATED } from './authentication';
|
|
7
|
-
import { AuthenticationTokenRequest } from './message';
|
|
8
|
-
export class Mdg2Client {
|
|
9
|
-
constructor(connection, options = {}) {
|
|
10
|
-
this.options = options;
|
|
11
|
-
this.flagPermissionDenied = options.flagPermissionDenied ?? DEFAULT_FLAG_PERMISSION_DENIED;
|
|
12
|
-
this.shouldRestartSubscriptions = options.shouldRestartSubscriptions ?? true;
|
|
13
|
-
this.defaultTimeoutInMs = options.defaultTimeoutInMs ?? DEFAULT_TIMEOUT_IN_MS;
|
|
14
|
-
this.defaultTimeoutTokenInMs = options.defaultTimeoutTokenInMs ?? DEFAULT_TIMEOUT_TOKEN_IN_MS;
|
|
15
|
-
this.maxTimeoutsBeforeReconnect = options.maxTimeoutsBeforeReconnect ?? DEFAULT_MAX_TIMEOUTS_BEFORE_RECONNECT;
|
|
16
|
-
this.enableSessionHandling = options.enableSessionHandling ?? DEFAULT_ENABLE_SESSION_HANDLING;
|
|
17
|
-
this.replaySubjectBufferSize = options.replaySubjectBufferSize ?? DEFAULT_REPLAY_SUBJECT_BUFFER_SIZE;
|
|
18
|
-
this.requestModule = new RequestModule(this.getConnection.bind(this), this.logger, {
|
|
19
|
-
defaultTimeoutInMs: this.defaultTimeoutInMs,
|
|
20
|
-
defaultTimeoutTokenInMs: this.defaultTimeoutTokenInMs,
|
|
21
|
-
flagPermissionDenied: this.flagPermissionDenied,
|
|
22
|
-
maxTimeoutsBeforeReconnect: this.maxTimeoutsBeforeReconnect,
|
|
23
|
-
replaySubjectBufferSize: this.replaySubjectBufferSize,
|
|
24
|
-
});
|
|
25
|
-
this.subscriptionModule = new SubscriptionModule(this.requestModule, this.logger, { shouldRestartSubscriptions: this.shouldRestartSubscriptions });
|
|
26
|
-
this.sessionConnect = false;
|
|
27
|
-
if (options.onConnectCallback)
|
|
28
|
-
this.onConnectCallback = options.onConnectCallback;
|
|
29
|
-
if (connection) {
|
|
30
|
-
this.setConnection(connection);
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
33
|
-
this.logger = new NullLogger();
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
async connect() {
|
|
37
|
-
if (!this.connection) {
|
|
38
|
-
throw new Error('No connection defined. please set a connection before trying to connect.');
|
|
39
|
-
}
|
|
40
|
-
if (this.sessionConnect) {
|
|
41
|
-
return Promise.resolve();
|
|
42
|
-
}
|
|
43
|
-
return this.connection.open();
|
|
44
|
-
}
|
|
45
|
-
async connectSession(shouldThrow = false) {
|
|
46
|
-
if (!this.connection) {
|
|
47
|
-
throw new Error('No connection defined. please set a connection before trying to connect.');
|
|
48
|
-
}
|
|
49
|
-
const { connection: previousConnection } = this;
|
|
50
|
-
const tokenAuth = new CookieTokenAuthentication();
|
|
51
|
-
const tokenConnection = new FrontgateWSConnection(tokenAuth, {
|
|
52
|
-
...this.connection.options,
|
|
53
|
-
sessionHandling: true,
|
|
54
|
-
});
|
|
55
|
-
this.setConnection(tokenConnection);
|
|
56
|
-
try {
|
|
57
|
-
await this.connection.open();
|
|
58
|
-
}
|
|
59
|
-
catch (error) {
|
|
60
|
-
this.setConnection(previousConnection);
|
|
61
|
-
if (shouldThrow) {
|
|
62
|
-
throw error;
|
|
63
|
-
}
|
|
64
|
-
return false;
|
|
65
|
-
}
|
|
66
|
-
return true;
|
|
67
|
-
}
|
|
68
|
-
async disconnect(logout = false) {
|
|
69
|
-
if (!this.connection) {
|
|
70
|
-
throw new Error('No connection defined. please set a connection before trying to disconnect.');
|
|
71
|
-
}
|
|
72
|
-
await this.connection.close(false, logout);
|
|
73
|
-
}
|
|
74
|
-
async request(msg, timeOutInMs = this.defaultTimeoutInMs) {
|
|
75
|
-
return this.requestModule.request(msg, timeOutInMs);
|
|
76
|
-
}
|
|
77
|
-
restartSubscriptions() {
|
|
78
|
-
this.subscriptionModule.restartSubscriptions();
|
|
79
|
-
}
|
|
80
|
-
async requestWithQuality(msg, quality = DEFAULT_QUALITY, timeOutInMs = this.defaultTimeoutInMs) {
|
|
81
|
-
return this.requestModule.requestWithQuality(msg, quality, timeOutInMs);
|
|
82
|
-
}
|
|
83
|
-
async requestEndpoint(method, path, data, options, timeOutInMs = this.defaultTimeoutInMs) {
|
|
84
|
-
return this.requestModule.requestEndpoint(method, path, data, options, timeOutInMs);
|
|
85
|
-
}
|
|
86
|
-
async requestProxyEndpoint(method, path, body, options, timeOutInMs = this.defaultTimeoutInMs) {
|
|
87
|
-
return this.requestModule.requestProxyEndpoint(method, path, body, options, timeOutInMs);
|
|
88
|
-
}
|
|
89
|
-
async requestAuthenticationToken(lifetimeSeconds, idUser, idApplication, timeOutInMs = this.defaultTimeoutTokenInMs) {
|
|
90
|
-
return this.requestModule.requestAuthenticationToken(lifetimeSeconds, idUser, idApplication, timeOutInMs);
|
|
91
|
-
}
|
|
92
|
-
async requestAuthenticationTokenExpiry(lifetimeSeconds, idUser, idApplication, timeOutInMs = this.defaultTimeoutTokenInMs, otp = false) {
|
|
93
|
-
return this.requestModule.requestAuthenticationTokenExpiry(lifetimeSeconds, idUser, idApplication, timeOutInMs, otp);
|
|
94
|
-
}
|
|
95
|
-
async requestOtpAuthenticationTokenForSessionHandling(lifetimeSeconds = AuthenticationTokenRequest.LIFETIME_SECONDS_MAXIMUM, idUser = ID_USER_AUTHENTICATED, idApplication = ID_APP_AUTHENTICATED, timeOutInMs = this.defaultTimeoutTokenInMs) {
|
|
96
|
-
const { token, expiry } = await this.requestModule.requestAuthenticationTokenExpiry(lifetimeSeconds, idUser, idApplication, timeOutInMs, true);
|
|
97
|
-
this.options.otpToken = token;
|
|
98
|
-
this.options.otpTokenExpiry = expiry;
|
|
99
|
-
}
|
|
100
|
-
async requestAuthenticationTokenForCookieTokenAuthentication(lifetimeSeconds, idUser, idApplication, timeOutInMs = this.defaultTimeoutTokenInMs) {
|
|
101
|
-
return this.requestModule.requestAuthenticationTokenFactorsForCookieAuthentication(lifetimeSeconds, idUser, idApplication, timeOutInMs);
|
|
102
|
-
}
|
|
103
|
-
observeEndpoint(method, path, data, options, requestOptions) {
|
|
104
|
-
return this.subscriptionModule.observeEndpoint(method, path, data, options, requestOptions);
|
|
105
|
-
}
|
|
106
|
-
async unobserveEndpoint(idJob) {
|
|
107
|
-
return this.subscriptionModule.unobserveEndpoint(idJob);
|
|
108
|
-
}
|
|
109
|
-
setConnection(connection) {
|
|
110
|
-
if (connection.options.logger) {
|
|
111
|
-
this.setLogger(connection.options.logger);
|
|
112
|
-
}
|
|
113
|
-
if (this.isConnected) {
|
|
114
|
-
this.logger.warn('Cannot modify an open connection. Disconnect first, before trying to set the connection.');
|
|
115
|
-
}
|
|
116
|
-
this.connection = connection;
|
|
117
|
-
this.connection.clientOptions = this.options;
|
|
118
|
-
this.connection.shouldRestartSubscriptions = this.shouldRestartSubscriptions;
|
|
119
|
-
this.connection.onAuthentication = this.requestModule.onConnection.bind(this.requestModule);
|
|
120
|
-
this.connection.onCleanupRequests = this.requestModule.clearPendingRequests.bind(this.requestModule);
|
|
121
|
-
this.connection.onCleanupSubscriptions = this.subscriptionModule.clearPendingSubscriptions.bind(this.subscriptionModule);
|
|
122
|
-
this.connection.onClearPendingSubscription = (jobId) => {
|
|
123
|
-
this.subscriptionModule.clearPendingSubscription(jobId);
|
|
124
|
-
};
|
|
125
|
-
this.connection.restartSubscriptions = this.subscriptionModule.restartSubscriptions.bind(this.subscriptionModule);
|
|
126
|
-
this.connection.onConnect = this.onConnectCallback;
|
|
127
|
-
}
|
|
128
|
-
getConnection() {
|
|
129
|
-
return this.connection;
|
|
130
|
-
}
|
|
131
|
-
async setConnectionFromFetchConfiguration(input, init, shouldReconnectOnConnectionLoss) {
|
|
132
|
-
if (this.enableSessionHandling) {
|
|
133
|
-
if (this.setConnectionFromSavedConfig() && (await this.connectSession())) {
|
|
134
|
-
this.sessionConnect = true;
|
|
135
|
-
return Promise.resolve();
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
const { config, response } = await fetchConnectionConfiguration(input, init);
|
|
139
|
-
if (this.enableSessionHandling) {
|
|
140
|
-
setConnectionConfiguration(config);
|
|
141
|
-
}
|
|
142
|
-
this.setConnection(Mdg2Client.createConnection({
|
|
143
|
-
...config,
|
|
144
|
-
logger: this.logger,
|
|
145
|
-
loglevel: this.logger.getLevel(),
|
|
146
|
-
shouldReconnectOnConnectionLoss,
|
|
147
|
-
}, input, init));
|
|
148
|
-
return response;
|
|
149
|
-
}
|
|
150
|
-
static createConnection(config, input, init) {
|
|
151
|
-
return createConnection(config, input, init);
|
|
152
|
-
}
|
|
153
|
-
setLogger(logger) {
|
|
154
|
-
this.logger = logger;
|
|
155
|
-
this.requestModule.setLogger(logger);
|
|
156
|
-
this.subscriptionModule.setLogger(logger);
|
|
157
|
-
if (this.connection) {
|
|
158
|
-
this.connection.setLogger(logger);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
getLogger() {
|
|
162
|
-
return this.logger;
|
|
163
|
-
}
|
|
164
|
-
get isConnected() {
|
|
165
|
-
return this.connection?.isAuthenticated() ?? false;
|
|
166
|
-
}
|
|
167
|
-
get isConnecting() {
|
|
168
|
-
return this.connection?.isConnecting() ?? false;
|
|
169
|
-
}
|
|
170
|
-
getServerInfo() {
|
|
171
|
-
return this.connection?.auth.getServerInfo();
|
|
172
|
-
}
|
|
173
|
-
setConnectionFromSavedConfig() {
|
|
174
|
-
const savedConfig = getConnectionConfiguration();
|
|
175
|
-
if (savedConfig) {
|
|
176
|
-
this.setConnection(Mdg2Client.createConnection({
|
|
177
|
-
...savedConfig,
|
|
178
|
-
logger: this.logger,
|
|
179
|
-
loglevel: this.logger.getLevel(),
|
|
180
|
-
}));
|
|
181
|
-
return true;
|
|
182
|
-
}
|
|
183
|
-
return false;
|
|
184
|
-
}
|
|
185
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
export const ID_APP_AUTHENTICATED = -2;
|
|
2
|
-
export const ID_USER_AUTHENTICATED = -2;
|
|
3
|
-
export const ID_USER_NONE = -1;
|
|
4
|
-
export class AbstractAuthentication {
|
|
5
|
-
constructor(idApplication, idUser = ID_USER_NONE) {
|
|
6
|
-
if (!Number.isInteger(idApplication)) {
|
|
7
|
-
throw new TypeError(`idApplication is not an integer number. Given: ${idApplication} (${typeof idApplication})`);
|
|
8
|
-
}
|
|
9
|
-
this.idApplication = idApplication;
|
|
10
|
-
if (!Number.isInteger(idUser)) {
|
|
11
|
-
throw new TypeError(`idUser is not an integer number. Given: ${idUser} (${typeof idUser})`);
|
|
12
|
-
}
|
|
13
|
-
this.idUser = idUser;
|
|
14
|
-
}
|
|
15
|
-
peerInfoFromMessage(msg) {
|
|
16
|
-
if (msg.Message === 'Foundation::DisconnectionMessage') {
|
|
17
|
-
const disconnectMessage = msg;
|
|
18
|
-
throw new Error(`Disconnection Message: ${disconnectMessage.details}`);
|
|
19
|
-
}
|
|
20
|
-
if (msg.Message === 'Foundation::AuthenticationByTokenResponse' || msg.Message === 'Foundation::ConfigurationResponse') {
|
|
21
|
-
const message = msg;
|
|
22
|
-
this.serverInfo = this.parseServerInfo(message);
|
|
23
|
-
return {
|
|
24
|
-
uuid: message.server_info.uuid,
|
|
25
|
-
description: message.server_info.description,
|
|
26
|
-
software: message.server_info.software,
|
|
27
|
-
os: message.server_info.os,
|
|
28
|
-
maximumIdleInterval: parseInt(message.maximum_idle_interval, 10),
|
|
29
|
-
maximumReceivableMessageSize: message.maximum_receivable_message_size,
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
throw new Error('Could not extract server_info from unknown message type.');
|
|
33
|
-
}
|
|
34
|
-
parseServerInfo(msg) {
|
|
35
|
-
const message = msg;
|
|
36
|
-
const timeInMs = Number(BigInt(message.time_at_server.microseconds)) / 1000;
|
|
37
|
-
const offsetInMs = Math.ceil(Date.now() - timeInMs);
|
|
38
|
-
return {
|
|
39
|
-
description: message.server_info.description,
|
|
40
|
-
software: message.server_info.software,
|
|
41
|
-
os: message.server_info.os,
|
|
42
|
-
time: new Date(timeInMs),
|
|
43
|
-
offsetInMs,
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
getServerInfo() {
|
|
47
|
-
return this.serverInfo;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { getBytesFromBuffer } from '../connection/util/functions';
|
|
2
|
-
import { SecretGenerator } from './util';
|
|
3
|
-
import { AbstractAuthentication } from './AbstractAuthentication';
|
|
4
|
-
import { AuthenticationRequest } from '../message/request/AuthenticationRequest';
|
|
5
|
-
import { ConfigurationRequest } from '../message/request/ConfigurationRequest';
|
|
6
|
-
import { randomBytes } from 'crypto';
|
|
7
|
-
export class AppAuthentication extends AbstractAuthentication {
|
|
8
|
-
constructor(idApplication, idUser, clientCredentials) {
|
|
9
|
-
super(idApplication, idUser);
|
|
10
|
-
this.reconnectable = true;
|
|
11
|
-
if (typeof clientCredentials !== 'string') {
|
|
12
|
-
throw new Error('clientCredentials not provided or not a string. Client credentials must have the form "{server_secret}-{shared_secret}-{client_secret}".');
|
|
13
|
-
}
|
|
14
|
-
const secrets = clientCredentials.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.sharedSecret = Buffer.from(secrets[1], 'base64');
|
|
22
|
-
this.clientSecret = Buffer.from(secrets[2], 'base64');
|
|
23
|
-
}
|
|
24
|
-
async authenticate(connection) {
|
|
25
|
-
this.connection = connection;
|
|
26
|
-
const authenticationResponse = await this.sendAuthenticationRequest();
|
|
27
|
-
const configurationResponse = await this.sendConfigurationRequest(authenticationResponse);
|
|
28
|
-
const peerInfo = this.peerInfoFromMessage(configurationResponse);
|
|
29
|
-
this.connection.setPeerInfo(peerInfo);
|
|
30
|
-
await this.sendTransportLayerRequestHeaderConfigurationRequest(configurationResponse);
|
|
31
|
-
}
|
|
32
|
-
async sendAuthenticationRequest() {
|
|
33
|
-
const salt = randomBytes(16);
|
|
34
|
-
const options = {
|
|
35
|
-
idApplication: this.idApplication,
|
|
36
|
-
salt: getBytesFromBuffer(salt),
|
|
37
|
-
challenge: getBytesFromBuffer(randomBytes(16)),
|
|
38
|
-
encryptedSecrets: [{ encrypted_secret: SecretGenerator.createEncryptedSecret(salt, this.sharedSecret, this.clientSecret) }],
|
|
39
|
-
};
|
|
40
|
-
const request = new 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
|
-
const { challenge } = msg.challenge;
|
|
49
|
-
const options = {
|
|
50
|
-
shared_secret: this.sharedSecret,
|
|
51
|
-
payload_content: this.connection.options.payload_content,
|
|
52
|
-
deployment_stage: this.connection.options.deployment_stage,
|
|
53
|
-
maximum_idle_interval: this.connection.options.maximum_idle_interval,
|
|
54
|
-
};
|
|
55
|
-
const configRequest = new ConfigurationRequest(challenge, options);
|
|
56
|
-
return (await this.connection.submit(configRequest.toJson()));
|
|
57
|
-
}
|
|
58
|
-
async sendTransportLayerRequestHeaderConfigurationRequest(msg) {
|
|
59
|
-
const expectedMessage = 'Foundation::ConfigurationResponse';
|
|
60
|
-
if (msg.Message !== expectedMessage) {
|
|
61
|
-
throw new Error(`Expected message "${expectedMessage}" but received "${msg.Message}"`);
|
|
62
|
-
}
|
|
63
|
-
const request = {
|
|
64
|
-
Message: 'TransportLayerClientConfigurationRequest',
|
|
65
|
-
Version: 1,
|
|
66
|
-
flags: 0,
|
|
67
|
-
};
|
|
68
|
-
return this.connection.submit(request);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { fetchConnectionConfiguration } from '../connection/util/functions';
|
|
2
|
-
import { TokenAuthentication } from './TokenAuthentication';
|
|
3
|
-
export class CookieTokenAuthentication extends TokenAuthentication {
|
|
4
|
-
constructor() {
|
|
5
|
-
super('', false);
|
|
6
|
-
}
|
|
7
|
-
getEncodedToken() {
|
|
8
|
-
return [];
|
|
9
|
-
}
|
|
10
|
-
async onReconnect() {
|
|
11
|
-
if (this.fetchConfigurationInput) {
|
|
12
|
-
const { config } = await fetchConnectionConfiguration(this.fetchConfigurationInput, this.fetchConfigurationConfig);
|
|
13
|
-
if (config.frontgateSplitAuthenticationTokenSecondFactor) {
|
|
14
|
-
this.connection.options.frontgateSplitAuthenticationTokenSecondFactor = config.frontgateSplitAuthenticationTokenSecondFactor;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { fetchConnectionConfiguration } from '../connection/util/functions';
|
|
2
|
-
import { AbstractAuthentication, ID_APP_AUTHENTICATED, ID_USER_AUTHENTICATED } from './AbstractAuthentication';
|
|
3
|
-
import { AuthenticationByTokenRequest } from '../message';
|
|
4
|
-
import { isBase64Url, base64UrlToBase64 } from '../common/functions';
|
|
5
|
-
export class TokenAuthentication extends AbstractAuthentication {
|
|
6
|
-
constructor(token, validate = true) {
|
|
7
|
-
super(ID_APP_AUTHENTICATED, ID_USER_AUTHENTICATED);
|
|
8
|
-
if (validate && (!token || token.length < 80)) {
|
|
9
|
-
throw new Error('Invalid token passed to TokenAuthentication');
|
|
10
|
-
}
|
|
11
|
-
this.setToken(token);
|
|
12
|
-
}
|
|
13
|
-
setToken(token) {
|
|
14
|
-
this.token = isBase64Url(token) ? base64UrlToBase64(token) : token;
|
|
15
|
-
}
|
|
16
|
-
setFetchConfiguration(input, config) {
|
|
17
|
-
this.fetchConfigurationInput = input;
|
|
18
|
-
this.fetchConfigurationConfig = config;
|
|
19
|
-
}
|
|
20
|
-
async authenticate(connection) {
|
|
21
|
-
this.connection = connection;
|
|
22
|
-
const authenticationByTokenResponse = await this.sendAuthenticationByTokenRequest();
|
|
23
|
-
const peerInfo = this.peerInfoFromMessage(authenticationByTokenResponse);
|
|
24
|
-
this.connection.setPeerInfo(peerInfo);
|
|
25
|
-
}
|
|
26
|
-
async sendAuthenticationByTokenRequest() {
|
|
27
|
-
const token = { b64: this.token };
|
|
28
|
-
const request = new AuthenticationByTokenRequest(token, this.connection.options.maximum_idle_interval);
|
|
29
|
-
return (await this.connection.submit(request.toJson()));
|
|
30
|
-
}
|
|
31
|
-
get reconnectable() {
|
|
32
|
-
return !!this.fetchConfigurationInput;
|
|
33
|
-
}
|
|
34
|
-
async onReconnect() {
|
|
35
|
-
if (this.fetchConfigurationInput) {
|
|
36
|
-
const { config } = await fetchConnectionConfiguration(this.fetchConfigurationInput, this.fetchConfigurationConfig);
|
|
37
|
-
if (config.frontgateAuthenticationType === 'token' && config.frontgateAuthenticationToken) {
|
|
38
|
-
this.setToken(config.frontgateAuthenticationToken);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { getBytesFromBuffer } from '../connection/util/functions';
|
|
2
|
-
import { AbstractAuthentication, ID_APP_AUTHENTICATED, ID_USER_AUTHENTICATED } from './AbstractAuthentication';
|
|
3
|
-
import { SecretGenerator } from './util';
|
|
4
|
-
import { AuthenticationRequest } from '../message/request/AuthenticationRequest';
|
|
5
|
-
import { ConfigurationRequest } from '../message/request/ConfigurationRequest';
|
|
6
|
-
import { randomBytes } from 'crypto';
|
|
7
|
-
export class UserCredentialAuthentication extends AbstractAuthentication {
|
|
8
|
-
constructor(idApplication, username, credentials) {
|
|
9
|
-
super(idApplication);
|
|
10
|
-
this.reconnectable = true;
|
|
11
|
-
const secrets = credentials.split('-');
|
|
12
|
-
if (secrets.length !== 3) {
|
|
13
|
-
throw new Error('Invalid clientCredentials. Client credentials must have the form "{server_secret}-{shared_secret}-{client_secret}".');
|
|
14
|
-
}
|
|
15
|
-
if (secrets[0] === '*') {
|
|
16
|
-
throw new Error('Invalid clientCredentials. Client credentials first part must be a hashed server secret.');
|
|
17
|
-
}
|
|
18
|
-
this.username = username;
|
|
19
|
-
this.sharedSecret = Buffer.from(secrets[1], 'base64');
|
|
20
|
-
this.clientSecret = Buffer.from(secrets[2], 'base64');
|
|
21
|
-
}
|
|
22
|
-
async authenticate(connection) {
|
|
23
|
-
this.connection = connection;
|
|
24
|
-
const authenticationResponse = await this.sendAuthenticationRequest();
|
|
25
|
-
const configurationResponse = await this.sendConfigurationRequest(authenticationResponse);
|
|
26
|
-
const peerInfo = this.peerInfoFromMessage(configurationResponse);
|
|
27
|
-
this.connection.setPeerInfo(peerInfo);
|
|
28
|
-
await this.sendTransportLayerRequestHeaderConfigurationRequest(configurationResponse);
|
|
29
|
-
}
|
|
30
|
-
async sendAuthenticationRequest() {
|
|
31
|
-
const salt = randomBytes(16);
|
|
32
|
-
const options = {
|
|
33
|
-
idApplication: this.idApplication,
|
|
34
|
-
username: this.username,
|
|
35
|
-
salt: getBytesFromBuffer(salt),
|
|
36
|
-
challenge: getBytesFromBuffer(randomBytes(16)),
|
|
37
|
-
encryptedSecrets: [{ encrypted_secret: SecretGenerator.createEncryptedSecret(salt, this.sharedSecret, this.clientSecret) }],
|
|
38
|
-
};
|
|
39
|
-
const request = new AuthenticationRequest(options);
|
|
40
|
-
return (await this.connection.submit(request.toJson()));
|
|
41
|
-
}
|
|
42
|
-
async sendConfigurationRequest(msg) {
|
|
43
|
-
const expectedMessage = 'Foundation::AuthenticationResponse';
|
|
44
|
-
if (msg.Message !== expectedMessage) {
|
|
45
|
-
throw new Error(`Expected message "${expectedMessage}" but received "${msg.Message}"`);
|
|
46
|
-
}
|
|
47
|
-
if (msg.id_user === ID_USER_AUTHENTICATED) {
|
|
48
|
-
this.connection.auth.idUser = ID_USER_AUTHENTICATED;
|
|
49
|
-
this.connection.auth.idApplication = ID_APP_AUTHENTICATED;
|
|
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(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
|
-
}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { getBytesFromBuffer } from '../connection/util/functions';
|
|
2
|
-
import { AbstractAuthentication, ID_APP_AUTHENTICATED, ID_USER_AUTHENTICATED } from './AbstractAuthentication';
|
|
3
|
-
import { SecretGenerator } from './util';
|
|
4
|
-
import { AuthenticationRequest } from '../message/request/AuthenticationRequest';
|
|
5
|
-
import { ConfigurationRequest } from '../message/request/ConfigurationRequest';
|
|
6
|
-
import { randomBytes } from 'crypto';
|
|
7
|
-
export class UserPasswordAuthentication extends AbstractAuthentication {
|
|
8
|
-
constructor(idApplication, username, password) {
|
|
9
|
-
super(idApplication);
|
|
10
|
-
this.reconnectable = true;
|
|
11
|
-
this.username = username;
|
|
12
|
-
this.password = password;
|
|
13
|
-
const plainSharedSecret = SecretGenerator.generateSharedSecret(username, password);
|
|
14
|
-
const plainClientSecret = SecretGenerator.generateClientSecret(username, password);
|
|
15
|
-
if (plainSharedSecret && plainClientSecret) {
|
|
16
|
-
this.sharedSecret = Buffer.from(plainSharedSecret);
|
|
17
|
-
this.clientSecret = Buffer.from(plainClientSecret);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
async authenticate(connection) {
|
|
21
|
-
this.connection = connection;
|
|
22
|
-
const authenticationResponse = await this.sendAuthenticationRequest();
|
|
23
|
-
const configurationResponse = await this.sendConfigurationRequest(authenticationResponse);
|
|
24
|
-
const peerInfo = this.peerInfoFromMessage(configurationResponse);
|
|
25
|
-
this.connection.setPeerInfo(peerInfo);
|
|
26
|
-
await this.sendTransportLayerRequestHeaderConfigurationRequest(configurationResponse);
|
|
27
|
-
}
|
|
28
|
-
async sendAuthenticationRequest() {
|
|
29
|
-
const salt = randomBytes(16);
|
|
30
|
-
const options = {
|
|
31
|
-
idApplication: this.idApplication,
|
|
32
|
-
username: this.username,
|
|
33
|
-
salt: getBytesFromBuffer(salt),
|
|
34
|
-
challenge: getBytesFromBuffer(randomBytes(16)),
|
|
35
|
-
encryptedSecrets: [{ encrypted_secret: SecretGenerator.createEncryptedSecret(salt, this.sharedSecret, this.clientSecret) }],
|
|
36
|
-
};
|
|
37
|
-
const request = new AuthenticationRequest(options);
|
|
38
|
-
return (await this.connection.submit(request.toJson()));
|
|
39
|
-
}
|
|
40
|
-
async sendConfigurationRequest(msg) {
|
|
41
|
-
const expectedMessage = 'Foundation::AuthenticationResponse';
|
|
42
|
-
if (msg.Message !== expectedMessage) {
|
|
43
|
-
throw new Error(`Expected message "${expectedMessage}" but received "${msg.Message}"`);
|
|
44
|
-
}
|
|
45
|
-
if (msg.id_user === ID_USER_AUTHENTICATED) {
|
|
46
|
-
this.connection.auth.idApplication = ID_APP_AUTHENTICATED;
|
|
47
|
-
this.connection.auth.idUser = ID_USER_AUTHENTICATED;
|
|
48
|
-
}
|
|
49
|
-
const { challenge } = msg.challenge;
|
|
50
|
-
const options = {
|
|
51
|
-
shared_secret: this.sharedSecret,
|
|
52
|
-
payload_content: this.connection.options.payload_content,
|
|
53
|
-
deployment_stage: this.connection.options.deployment_stage,
|
|
54
|
-
maximum_idle_interval: this.connection.options.maximum_idle_interval,
|
|
55
|
-
};
|
|
56
|
-
const configRequest = new ConfigurationRequest(challenge, options);
|
|
57
|
-
return (await this.connection.submit(configRequest.toJson()));
|
|
58
|
-
}
|
|
59
|
-
async sendTransportLayerRequestHeaderConfigurationRequest(msg) {
|
|
60
|
-
const expectedMessage = 'Foundation::ConfigurationResponse';
|
|
61
|
-
if (msg.Message !== expectedMessage) {
|
|
62
|
-
throw new Error(`Expected message "${expectedMessage}" but received "${msg.Message}"`);
|
|
63
|
-
}
|
|
64
|
-
const request = {
|
|
65
|
-
Message: 'TransportLayerClientConfigurationRequest',
|
|
66
|
-
Version: 1,
|
|
67
|
-
flags: 0,
|
|
68
|
-
};
|
|
69
|
-
return this.connection.submit(request);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export const LOGGER_NAME = 'Mdg2Client';
|
|
2
|
-
export const DEFAULT_QUALITY = 'BST';
|
|
3
|
-
export const DEFAULT_TIMEOUT_IN_MS = 6000;
|
|
4
|
-
export const DEFAULT_TIMEOUT_TOKEN_IN_MS = 3000;
|
|
5
|
-
export const DEFAULT_TIMEOUT_CONNECTION_IN_MS = 9000;
|
|
6
|
-
export const DEFAULT_MAX_TIMEOUTS_BEFORE_RECONNECT = 3;
|
|
7
|
-
export const DEFAULT_ENABLE_SESSION_HANDLING = false;
|
|
8
|
-
export const DEFAULT_RESUBSCRIBE_WAIT_TIME_IN_MS = 9000;
|
|
9
|
-
export const DEFAULT_FLAG_PERMISSION_DENIED = false;
|
|
10
|
-
export const DEFAULT_REPLAY_SUBJECT_BUFFER_SIZE = 512;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|