@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.
Files changed (196) hide show
  1. package/CHANGELOG.md +97 -40
  2. package/dist/lib/esnext/FrontgateClient.js +0 -3
  3. package/dist/lib/esnext/authentication/index.js +3 -4
  4. package/dist/lib/esnext/common/errors.js +0 -35
  5. package/dist/lib/esnext/common/functions.js +0 -84
  6. package/dist/lib/esnext/common/interfaces/index.js +0 -1
  7. package/dist/lib/esnext/compat/index.js +0 -3
  8. package/dist/lib/esnext/connection/index.js +19 -6
  9. package/dist/lib/esnext/connection/util/functions.js +0 -56
  10. package/dist/lib/esnext/index.js +0 -1
  11. package/dist/lib/esnext/message/index.js +1 -1
  12. package/dist/lib/esnext/message/interfaces/index.js +0 -1
  13. package/dist/lib/esnext/message/request/TransportLayerClientRequestHeader.js +1 -1
  14. package/dist/lib/esnext/message/request/raw/example/CreateNotationSearchRequest.js +1 -1
  15. package/dist/lib/esnext/message/request/raw/index.js +0 -1
  16. package/dist/lib/esnext/message/response/index.js +0 -5
  17. package/dist/lib/esnext/message/update/index.js +0 -1
  18. package/dist/lib/esnext/mixins/EndpointRequestMixin.js +1 -1
  19. package/dist/lib/esnext/mixins/RemoteLoggerMixin.js +29 -0
  20. package/dist/lib/esnext/mixins/auth/AppAuthMixin.js +79 -11
  21. package/dist/lib/esnext/mixins/auth/SessionAuthMixin.js +76 -36
  22. package/dist/lib/esnext/mixins/auth/UserCredentialAuthMixin.js +82 -12
  23. package/dist/lib/esnext/mixins/auth/UserPasswordAuthMixin.js +80 -13
  24. package/dist/lib/esnext/mixins/auth/index.js +0 -31
  25. package/dist/lib/esnext/mixins/index.js +1 -0
  26. package/dist/lib/esnext/mixins/subscription/EndpointSubscriptionMixin.js +149 -122
  27. package/dist/lib/esnext/version.js +1 -1
  28. package/dist/lib/node/FrontgateClient.js +0 -3
  29. package/dist/lib/node/authentication/index.js +4 -4
  30. package/dist/lib/node/common/errors.js +1 -41
  31. package/dist/lib/node/common/functions.js +0 -92
  32. package/dist/lib/node/common/interfaces/index.js +0 -1
  33. package/dist/lib/node/compat/index.js +0 -3
  34. package/dist/lib/node/connection/index.js +20 -6
  35. package/dist/lib/node/connection/util/functions.js +0 -63
  36. package/dist/lib/node/index.js +1 -3
  37. package/dist/lib/node/message/index.js +2 -1
  38. package/dist/lib/node/message/interfaces/index.js +0 -1
  39. package/dist/lib/node/message/request/TransportLayerClientRequestHeader.js +3 -3
  40. package/dist/lib/node/message/request/raw/example/CreateNotationSearchRequest.js +3 -3
  41. package/dist/lib/node/message/request/raw/index.js +0 -1
  42. package/dist/lib/node/message/response/index.js +0 -5
  43. package/dist/lib/node/message/update/index.js +0 -1
  44. package/dist/lib/node/mixins/EndpointRequestMixin.js +2 -2
  45. package/dist/lib/node/mixins/RemoteLoggerMixin.js +33 -0
  46. package/dist/lib/node/mixins/auth/AppAuthMixin.js +78 -10
  47. package/dist/lib/node/mixins/auth/SessionAuthMixin.js +75 -35
  48. package/dist/lib/node/mixins/auth/UserCredentialAuthMixin.js +80 -10
  49. package/dist/lib/node/mixins/auth/UserPasswordAuthMixin.js +78 -11
  50. package/dist/lib/node/mixins/auth/index.js +0 -33
  51. package/dist/lib/node/mixins/index.js +1 -0
  52. package/dist/lib/node/mixins/subscription/EndpointSubscriptionMixin.js +149 -122
  53. package/dist/lib/node/version.js +1 -1
  54. package/dist/lib/types/FrontgateClient.d.ts +0 -1
  55. package/dist/lib/types/authentication/index.d.ts +3 -4
  56. package/dist/lib/types/authentication/util/ChallengeResolver.d.ts +2 -1
  57. package/dist/lib/types/common/errors.d.ts +0 -21
  58. package/dist/lib/types/common/functions.d.ts +0 -8
  59. package/dist/lib/types/common/interfaces/index.d.ts +0 -1
  60. package/dist/lib/types/compat/index.d.ts +0 -3
  61. package/dist/lib/types/connection/index.d.ts +16 -6
  62. package/dist/lib/types/connection/util/functions.d.ts +0 -18
  63. package/dist/lib/types/index.d.ts +0 -1
  64. package/dist/lib/types/message/index.d.ts +1 -1
  65. package/dist/lib/types/message/interfaces/index.d.ts +0 -1
  66. package/dist/lib/types/message/request/TransportLayerClientRequestHeader.d.ts +1 -0
  67. package/dist/lib/types/message/request/raw/index.d.ts +0 -1
  68. package/dist/lib/types/message/response/index.d.ts +0 -5
  69. package/dist/lib/types/message/update/index.d.ts +0 -1
  70. package/dist/lib/types/mixins/AuthTokenRequestMixin.d.ts +1 -2
  71. package/dist/lib/types/mixins/EndpointRequestMixin.d.ts +1 -2
  72. package/dist/lib/types/mixins/HTTPProxyRequestMixin.d.ts +1 -4
  73. package/dist/lib/types/mixins/LoggerMixin.d.ts +1 -2
  74. package/dist/lib/types/mixins/MessageCompressorMixin.d.ts +1 -2
  75. package/dist/lib/types/mixins/OpenTelemetryMixin.d.ts +1 -2
  76. package/dist/lib/types/mixins/PingMixin.d.ts +1 -2
  77. package/dist/lib/types/mixins/ReconnectMixin.d.ts +1 -2
  78. package/dist/lib/types/mixins/RemoteLoggerMixin.d.ts +16 -0
  79. package/dist/lib/types/mixins/RequestMixin.d.ts +1 -2
  80. package/dist/lib/types/mixins/auth/AppAuthMixin.d.ts +15 -8
  81. package/dist/lib/types/mixins/auth/CookieTokenAuthMixin.d.ts +1 -2
  82. package/dist/lib/types/mixins/auth/FetchAuthenticationMixin.d.ts +1 -2
  83. package/dist/lib/types/mixins/auth/SessionAuthMixin.d.ts +10 -5
  84. package/dist/lib/types/mixins/auth/TokenAuthMixin.d.ts +1 -2
  85. package/dist/lib/types/mixins/auth/UserCredentialAuthMixin.d.ts +15 -8
  86. package/dist/lib/types/mixins/auth/UserPasswordAuthMixin.d.ts +15 -8
  87. package/dist/lib/types/mixins/auth/index.d.ts +0 -8
  88. package/dist/lib/types/mixins/connection/FrontgateWSMixin.d.ts +1 -2
  89. package/dist/lib/types/mixins/index.d.ts +2 -1
  90. package/dist/lib/types/mixins/subscription/EndpointSubscriptionMixin.d.ts +4 -6
  91. package/dist/lib/types/mixins/subscription/RawSubscriptionMixin.d.ts +1 -2
  92. package/dist/lib/umd/mdg2.client.min.umd.js +1 -12
  93. package/dist/lib/umd/mdg2.client.umd.js +4061 -8138
  94. package/package.json +25 -28
  95. package/dist/lib/esnext/Mdg2Client.js +0 -185
  96. package/dist/lib/esnext/authentication/AbstractAuthentication.js +0 -49
  97. package/dist/lib/esnext/authentication/AppAuthentication.js +0 -70
  98. package/dist/lib/esnext/authentication/AuthenticationInterface.js +0 -1
  99. package/dist/lib/esnext/authentication/CookieTokenAuthentication.js +0 -18
  100. package/dist/lib/esnext/authentication/TokenAuthentication.js +0 -42
  101. package/dist/lib/esnext/authentication/UserCredentialAuthentication.js +0 -73
  102. package/dist/lib/esnext/authentication/UserPasswordAuthentication.js +0 -71
  103. package/dist/lib/esnext/common/Mdg2ClientOptions.js +0 -1
  104. package/dist/lib/esnext/common/constants.js +0 -10
  105. package/dist/lib/esnext/common/interfaces/observe/ObserveOptions.js +0 -1
  106. package/dist/lib/esnext/connection/AbstractFrontgateConnection.js +0 -324
  107. package/dist/lib/esnext/connection/ConnectionInterface.js +0 -1
  108. package/dist/lib/esnext/connection/FrontgateWSConnection.js +0 -281
  109. package/dist/lib/esnext/connection/JobPromise.js +0 -2
  110. package/dist/lib/esnext/connection/LatencyHandler.js +0 -1
  111. package/dist/lib/esnext/connection/LatencyTracker.js +0 -47
  112. package/dist/lib/esnext/connection/MessageProcessor.js +0 -1
  113. package/dist/lib/esnext/connection/util/Encoding.js +0 -14
  114. package/dist/lib/esnext/core/RequestModule.js +0 -349
  115. package/dist/lib/esnext/core/SubscriptionModule.js +0 -104
  116. package/dist/lib/esnext/core/subscription/EndpointHandler.js +0 -121
  117. package/dist/lib/esnext/core/subscription/SubjectManager.js +0 -39
  118. package/dist/lib/esnext/message/MessageFactory.js +0 -36
  119. package/dist/lib/esnext/message/guards.js +0 -21
  120. package/dist/lib/esnext/message/interfaces/JobObservable.js +0 -1
  121. package/dist/lib/esnext/message/request/raw/RawRequestFactory.js +0 -18
  122. package/dist/lib/esnext/message/response/AuthenticationByTokenResponse.js +0 -1
  123. package/dist/lib/esnext/message/response/CancelSubscriptionResponse.js +0 -3
  124. package/dist/lib/esnext/message/response/LoadNotificationMessage.js +0 -1
  125. package/dist/lib/esnext/message/response/PermissionDeniedResponse.js +0 -6
  126. package/dist/lib/esnext/message/response/RejectResponse.js +0 -9
  127. package/dist/lib/esnext/message/update/SubscriptionLossMessage.js +0 -10
  128. package/dist/lib/esnext/util/TimeOutWrapper.js +0 -51
  129. package/dist/lib/node/Mdg2Client.js +0 -189
  130. package/dist/lib/node/authentication/AbstractAuthentication.js +0 -53
  131. package/dist/lib/node/authentication/AppAuthentication.js +0 -74
  132. package/dist/lib/node/authentication/AuthenticationInterface.js +0 -2
  133. package/dist/lib/node/authentication/CookieTokenAuthentication.js +0 -22
  134. package/dist/lib/node/authentication/TokenAuthentication.js +0 -46
  135. package/dist/lib/node/authentication/UserCredentialAuthentication.js +0 -77
  136. package/dist/lib/node/authentication/UserPasswordAuthentication.js +0 -75
  137. package/dist/lib/node/common/Mdg2ClientOptions.js +0 -2
  138. package/dist/lib/node/common/constants.js +0 -13
  139. package/dist/lib/node/common/interfaces/observe/ObserveOptions.js +0 -2
  140. package/dist/lib/node/connection/AbstractFrontgateConnection.js +0 -328
  141. package/dist/lib/node/connection/ConnectionInterface.js +0 -2
  142. package/dist/lib/node/connection/FrontgateWSConnection.js +0 -288
  143. package/dist/lib/node/connection/JobPromise.js +0 -6
  144. package/dist/lib/node/connection/LatencyHandler.js +0 -2
  145. package/dist/lib/node/connection/LatencyTracker.js +0 -51
  146. package/dist/lib/node/connection/MessageProcessor.js +0 -2
  147. package/dist/lib/node/connection/util/Encoding.js +0 -18
  148. package/dist/lib/node/core/RequestModule.js +0 -353
  149. package/dist/lib/node/core/SubscriptionModule.js +0 -108
  150. package/dist/lib/node/core/subscription/EndpointHandler.js +0 -125
  151. package/dist/lib/node/core/subscription/SubjectManager.js +0 -43
  152. package/dist/lib/node/message/MessageFactory.js +0 -73
  153. package/dist/lib/node/message/guards.js +0 -30
  154. package/dist/lib/node/message/interfaces/JobObservable.js +0 -2
  155. package/dist/lib/node/message/request/raw/RawRequestFactory.js +0 -22
  156. package/dist/lib/node/message/response/AuthenticationByTokenResponse.js +0 -2
  157. package/dist/lib/node/message/response/CancelSubscriptionResponse.js +0 -7
  158. package/dist/lib/node/message/response/LoadNotificationMessage.js +0 -2
  159. package/dist/lib/node/message/response/PermissionDeniedResponse.js +0 -10
  160. package/dist/lib/node/message/response/RejectResponse.js +0 -13
  161. package/dist/lib/node/message/update/SubscriptionLossMessage.js +0 -14
  162. package/dist/lib/node/util/TimeOutWrapper.js +0 -55
  163. package/dist/lib/types/Mdg2Client.d.ts +0 -52
  164. package/dist/lib/types/authentication/AbstractAuthentication.d.ts +0 -17
  165. package/dist/lib/types/authentication/AppAuthentication.d.ts +0 -12
  166. package/dist/lib/types/authentication/AuthenticationInterface.d.ts +0 -9
  167. package/dist/lib/types/authentication/CookieTokenAuthentication.d.ts +0 -6
  168. package/dist/lib/types/authentication/TokenAuthentication.d.ts +0 -14
  169. package/dist/lib/types/authentication/UserCredentialAuthentication.d.ts +0 -13
  170. package/dist/lib/types/authentication/UserPasswordAuthentication.d.ts +0 -14
  171. package/dist/lib/types/common/Mdg2ClientOptions.d.ts +0 -12
  172. package/dist/lib/types/common/constants.d.ts +0 -11
  173. package/dist/lib/types/common/interfaces/observe/ObserveOptions.d.ts +0 -5
  174. package/dist/lib/types/connection/AbstractFrontgateConnection.d.ts +0 -116
  175. package/dist/lib/types/connection/ConnectionInterface.d.ts +0 -53
  176. package/dist/lib/types/connection/FrontgateWSConnection.d.ts +0 -23
  177. package/dist/lib/types/connection/JobPromise.d.ts +0 -3
  178. package/dist/lib/types/connection/LatencyHandler.d.ts +0 -1
  179. package/dist/lib/types/connection/LatencyTracker.d.ts +0 -13
  180. package/dist/lib/types/connection/MessageProcessor.d.ts +0 -2
  181. package/dist/lib/types/connection/util/Encoding.d.ts +0 -9
  182. package/dist/lib/types/core/RequestModule.d.ts +0 -78
  183. package/dist/lib/types/core/SubscriptionModule.d.ts +0 -24
  184. package/dist/lib/types/core/subscription/EndpointHandler.d.ts +0 -37
  185. package/dist/lib/types/core/subscription/SubjectManager.d.ts +0 -21
  186. package/dist/lib/types/message/MessageFactory.d.ts +0 -29
  187. package/dist/lib/types/message/guards.d.ts +0 -11
  188. package/dist/lib/types/message/interfaces/JobObservable.d.ts +0 -4
  189. package/dist/lib/types/message/request/raw/RawRequestFactory.d.ts +0 -4
  190. package/dist/lib/types/message/response/AuthenticationByTokenResponse.d.ts +0 -20
  191. package/dist/lib/types/message/response/CancelSubscriptionResponse.d.ts +0 -3
  192. package/dist/lib/types/message/response/LoadNotificationMessage.d.ts +0 -8
  193. package/dist/lib/types/message/response/PermissionDeniedResponse.d.ts +0 -4
  194. package/dist/lib/types/message/response/RejectResponse.d.ts +0 -5
  195. package/dist/lib/types/message/update/SubscriptionLossMessage.d.ts +0 -17
  196. package/dist/lib/types/util/TimeOutWrapper.d.ts +0 -12
@@ -12,22 +12,30 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
12
12
  import { wsConnection } from '../connection/FrontgateWSMixin';
13
13
  import { createExtendedMixinFactory } from '../.';
14
14
  import { ID_APP_AUTHENTICATED, ID_USER_AUTHENTICATED } from '../../authentication';
15
- import { UserPasswordAuthentication } from '../../compat';
15
+ import { AuthenticationRequest, ConfigurationRequest, SecretGenerator } from '../../compat';
16
+ import { getBytesFromBuffer } from '../../connection';
16
17
  import { LogLevel } from '../../logger';
17
18
  import { AuthenticationByTokenRequest, AuthenticationTokenRequest, AuthenticationTokenResponse } from '../../message';
18
- import { TimeoutWrapper } from '../../util/TimeOutWrapper';
19
+ import { randomBytes } from 'crypto';
20
+ import { useTimeout } from '../../util/functions';
19
21
  export const sessionAuth = (config, idApplication, username, password, deploymentStage) => {
20
22
  const mixinSessionAuth = (Base) => {
21
- var _instances, _auth, _tokenConnectionAttempt, _logOut, _mdg2wstoken, _requestOtpAuthenticationTokenForSessionHandling, _toUrlBase64, _a;
23
+ var _instances, _tokenConnectionAttempt, _logOut, _mdg2wstoken, _sharedSecret, _clientSecret, _requestOtpAuthenticationTokenForSessionHandling, _toUrlBase64, _createAuthenticationRequest, _createConfigurationRequest, _createTransportLayerRequestHeaderConfigurationRequest, _submit, _a;
22
24
  return _a = class extends wsConnection(config)(Base) {
23
25
  constructor(...args) {
24
26
  super(...args);
25
27
  _instances.add(this);
26
- _auth.set(this, void 0);
27
28
  _tokenConnectionAttempt.set(this, true);
28
29
  _logOut.set(this, false);
29
30
  _mdg2wstoken.set(this, void 0);
30
- __classPrivateFieldSet(this, _auth, new UserPasswordAuthentication(idApplication, username, password), "f");
31
+ _sharedSecret.set(this, void 0);
32
+ _clientSecret.set(this, void 0);
33
+ const plainSharedSecret = SecretGenerator.generateSharedSecret(username, password);
34
+ const plainClientSecret = SecretGenerator.generateClientSecret(username, password);
35
+ if (plainSharedSecret && plainClientSecret) {
36
+ __classPrivateFieldSet(this, _sharedSecret, Buffer.from(plainSharedSecret), "f");
37
+ __classPrivateFieldSet(this, _clientSecret, Buffer.from(plainClientSecret), "f");
38
+ }
31
39
  this.hooks.hook('frontgateConnection:beforeConnect', (settings) => {
32
40
  void this.hooks.callHook('frontgateConnection:setIdApp', ID_APP_AUTHENTICATED);
33
41
  void this.hooks.callHook('frontgateConnection:setIdUser', ID_USER_AUTHENTICATED);
@@ -69,35 +77,9 @@ export const sessionAuth = (config, idApplication, username, password, deploymen
69
77
  });
70
78
  return;
71
79
  }
72
- await __classPrivateFieldGet(this, _auth, "f").authenticate({
73
- options: {
74
- payload_content: conf.payloadContent,
75
- deployment_stage: deploymentStage,
76
- maximum_idle_interval: conf.maximumIdleInterval,
77
- },
78
- submit: async (message) => {
79
- this.log(LogLevel.INFO, 'Sending message', message);
80
- const msg = {
81
- message,
82
- callbackType: 'response',
83
- callbackId: message.Message.replace('Request', 'Response'),
84
- };
85
- await this.hooks.callHook('frontgateConnection:sendMessage', msg);
86
- return new Promise((resolve) => {
87
- this.hooks.hookOnce(`frontgateConnection:response:${msg.callbackId}`, (response) => {
88
- this.log(LogLevel.INFO, 'Received response', response);
89
- resolve(response);
90
- });
91
- });
92
- },
93
- setPeerInfo: (peerInfo) => {
94
- this.log(LogLevel.INFO, 'Peer info:', peerInfo);
95
- },
96
- auth: {
97
- idApplication: undefined,
98
- idUser: undefined,
99
- },
100
- });
80
+ const authResponse = await __classPrivateFieldGet(this, _instances, "m", _submit).call(this, __classPrivateFieldGet(this, _instances, "m", _createAuthenticationRequest).call(this).toJson());
81
+ await __classPrivateFieldGet(this, _instances, "m", _submit).call(this, __classPrivateFieldGet(this, _instances, "m", _createConfigurationRequest).call(this, authResponse, conf).toJson());
82
+ await __classPrivateFieldGet(this, _instances, "m", _submit).call(this, __classPrivateFieldGet(this, _instances, "m", _createTransportLayerRequestHeaderConfigurationRequest).call(this));
101
83
  await this.hooks.callHook('frontgateConnection:authenticated');
102
84
  });
103
85
  }
@@ -138,10 +120,11 @@ export const sessionAuth = (config, idApplication, username, password, deploymen
138
120
  }
139
121
  }
140
122
  },
141
- _auth = new WeakMap(),
142
123
  _tokenConnectionAttempt = new WeakMap(),
143
124
  _logOut = new WeakMap(),
144
125
  _mdg2wstoken = new WeakMap(),
126
+ _sharedSecret = new WeakMap(),
127
+ _clientSecret = new WeakMap(),
145
128
  _instances = new WeakSet(),
146
129
  _requestOtpAuthenticationTokenForSessionHandling = async function _requestOtpAuthenticationTokenForSessionHandling(lifetimeSeconds = AuthenticationTokenRequest.LIFETIME_SECONDS_MAXIMUM, idUser = ID_USER_AUTHENTICATED, idApplication = ID_APP_AUTHENTICATED, timeOutInMs = this.defaultTimeoutInMs) {
147
130
  const request = new AuthenticationTokenRequest(lifetimeSeconds, idUser, idApplication, timeOutInMs, true);
@@ -165,11 +148,68 @@ export const sessionAuth = (config, idApplication, username, password, deploymen
165
148
  });
166
149
  });
167
150
  const rejectReason = `Request timeout reached (${timeOutInMs} ms) for ${msg.message.Message}`;
168
- return TimeoutWrapper.wrap(promise, timeOutInMs, rejectReason);
151
+ return useTimeout(timeOutInMs, rejectReason, promise);
169
152
  },
170
153
  _toUrlBase64 = function _toUrlBase64(strInBase64) {
171
154
  return strInBase64.replace(/[=]/g, '').replace(/\//g, '_').replace(/\+/g, '-');
172
155
  },
156
+ _createAuthenticationRequest = function _createAuthenticationRequest() {
157
+ const salt = randomBytes(16);
158
+ const options = {
159
+ idApplication,
160
+ username,
161
+ salt: getBytesFromBuffer(salt),
162
+ challenge: getBytesFromBuffer(randomBytes(16)),
163
+ encryptedSecrets: [{ encrypted_secret: SecretGenerator.createEncryptedSecret(salt, __classPrivateFieldGet(this, _sharedSecret, "f"), __classPrivateFieldGet(this, _clientSecret, "f")) }],
164
+ };
165
+ return new AuthenticationRequest(options);
166
+ },
167
+ _createConfigurationRequest = function _createConfigurationRequest(msg, conf) {
168
+ const expectedMessage = 'Foundation::AuthenticationResponse';
169
+ if (msg.Message !== expectedMessage) {
170
+ throw new Error(`Expected message "${expectedMessage}" but received "${msg.Message}"`);
171
+ }
172
+ if (msg.id_user === ID_USER_AUTHENTICATED) {
173
+ void this.hooks.callHook('frontgateConnection:setIdApp', ID_APP_AUTHENTICATED);
174
+ void this.hooks.callHook('frontgateConnection:setIdUser', ID_USER_AUTHENTICATED);
175
+ }
176
+ const { challenge } = msg.challenge;
177
+ const options = {
178
+ shared_secret: __classPrivateFieldGet(this, _sharedSecret, "f"),
179
+ payload_content: conf.payloadContent,
180
+ deployment_stage: deploymentStage,
181
+ maximum_idle_interval: conf.maximumIdleInterval,
182
+ };
183
+ return new ConfigurationRequest(challenge, options);
184
+ },
185
+ _createTransportLayerRequestHeaderConfigurationRequest = function _createTransportLayerRequestHeaderConfigurationRequest() {
186
+ return {
187
+ Message: 'TransportLayerClientConfigurationRequest',
188
+ Version: 1,
189
+ flags: 0,
190
+ };
191
+ },
192
+ _submit = async function _submit(message) {
193
+ this.log(LogLevel.INFO, 'Sending message', message);
194
+ const msg = {
195
+ message,
196
+ callbackType: 'response',
197
+ callbackId: message.Message.replace('Request', 'Response'),
198
+ };
199
+ await this.hooks.callHook('frontgateConnection:sendMessage', msg);
200
+ let timeout;
201
+ return new Promise((resolve, reject) => {
202
+ const unsubMessage = this.hooks.hookOnce(`frontgateConnection:response:${msg.callbackId}`, (response) => {
203
+ clearTimeout(timeout);
204
+ this.log(LogLevel.INFO, 'Received response', response);
205
+ resolve(response);
206
+ });
207
+ timeout = setTimeout(() => {
208
+ unsubMessage();
209
+ reject(new Error('Authentication message timeout'));
210
+ }, 3000);
211
+ });
212
+ },
173
213
  _a;
174
214
  };
175
215
  return createExtendedMixinFactory(mixinSessionAuth, {
@@ -9,30 +9,100 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
9
9
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
10
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
11
  };
12
- import { createExtendedMixinFactory, createConnectionInterface, } from '../.';
13
- import { UserCredentialAuthentication } from '../../compat';
12
+ import { createExtendedMixinFactory } from '../.';
13
+ import { getBytesFromBuffer } from '../../connection';
14
+ import { AuthenticationRequest, ConfigurationRequest, SecretGenerator } from '../../compat';
14
15
  import { ID_APP_AUTHENTICATED, ID_USER_AUTHENTICATED } from '../../authentication';
16
+ import { randomBytes } from 'crypto';
17
+ import { LogLevel } from '../../logger';
15
18
  export const userCredentialAuth = (idApplication, username, credentials, deploymentStage) => {
16
19
  const mixinUserCredentialAuth = (Base) => {
17
- var _auth, _a;
20
+ var _instances, _sharedSecret, _clientSecret, _createAuthenticationRequest, _createConfigurationRequest, _createTransportLayerRequestHeaderConfigurationRequest, _submit, _a;
18
21
  return _a = class extends Base {
19
22
  constructor(...args) {
20
23
  super(...args);
21
- _auth.set(this, void 0);
22
- __classPrivateFieldSet(this, _auth, new UserCredentialAuthentication(idApplication, username, credentials), "f");
24
+ _instances.add(this);
25
+ _sharedSecret.set(this, void 0);
26
+ _clientSecret.set(this, void 0);
27
+ const secrets = credentials.split('-');
28
+ if (secrets.length !== 3) {
29
+ throw new Error('Invalid clientCredentials. Client credentials must have the form "{server_secret}-{shared_secret}-{client_secret}".');
30
+ }
31
+ if (secrets[0] === '*') {
32
+ throw new Error('Invalid clientCredentials. Client credentials first part must be a hashed server secret.');
33
+ }
34
+ __classPrivateFieldSet(this, _sharedSecret, Buffer.from(secrets[1], 'base64'), "f");
35
+ __classPrivateFieldSet(this, _clientSecret, Buffer.from(secrets[2], 'base64'), "f");
23
36
  this.hooks.hook('frontgateConnection:connected', async (conf) => {
24
- void this.hooks.callHook('frontgateConnection:setIdApp', ID_APP_AUTHENTICATED);
37
+ void this.hooks.callHook('frontgateConnection:setIdApp', idApplication);
25
38
  void this.hooks.callHook('frontgateConnection:setIdUser', ID_USER_AUTHENTICATED);
26
- await __classPrivateFieldGet(this, _auth, "f").authenticate(createConnectionInterface({
27
- payload_content: conf.payloadContent,
28
- deployment_stage: deploymentStage,
29
- maximum_idle_interval: conf.maximumIdleInterval,
30
- }, this));
39
+ const authResponse = await __classPrivateFieldGet(this, _instances, "m", _submit).call(this, __classPrivateFieldGet(this, _instances, "m", _createAuthenticationRequest).call(this).toJson());
40
+ await __classPrivateFieldGet(this, _instances, "m", _submit).call(this, __classPrivateFieldGet(this, _instances, "m", _createConfigurationRequest).call(this, authResponse, conf).toJson());
41
+ await __classPrivateFieldGet(this, _instances, "m", _submit).call(this, __classPrivateFieldGet(this, _instances, "m", _createTransportLayerRequestHeaderConfigurationRequest).call(this));
31
42
  await this.hooks.callHook('frontgateConnection:authenticated');
32
43
  });
33
44
  }
34
45
  },
35
- _auth = new WeakMap(),
46
+ _sharedSecret = new WeakMap(),
47
+ _clientSecret = new WeakMap(),
48
+ _instances = new WeakSet(),
49
+ _createAuthenticationRequest = function _createAuthenticationRequest() {
50
+ const salt = randomBytes(16);
51
+ const options = {
52
+ idApplication,
53
+ username,
54
+ salt: getBytesFromBuffer(salt),
55
+ challenge: getBytesFromBuffer(randomBytes(16)),
56
+ encryptedSecrets: [{ encrypted_secret: SecretGenerator.createEncryptedSecret(salt, __classPrivateFieldGet(this, _sharedSecret, "f"), __classPrivateFieldGet(this, _clientSecret, "f")) }],
57
+ };
58
+ return new AuthenticationRequest(options);
59
+ },
60
+ _createConfigurationRequest = function _createConfigurationRequest(msg, conf) {
61
+ const expectedMessage = 'Foundation::AuthenticationResponse';
62
+ if (msg.Message !== expectedMessage) {
63
+ throw new Error(`Expected message "${expectedMessage}" but received "${msg.Message}"`);
64
+ }
65
+ if (msg.id_user === ID_USER_AUTHENTICATED) {
66
+ void this.hooks.callHook('frontgateConnection:setIdApp', ID_APP_AUTHENTICATED);
67
+ void this.hooks.callHook('frontgateConnection:setIdUser', ID_USER_AUTHENTICATED);
68
+ }
69
+ const { challenge } = msg.challenge;
70
+ const options = {
71
+ shared_secret: __classPrivateFieldGet(this, _sharedSecret, "f"),
72
+ payload_content: conf.payloadContent,
73
+ deployment_stage: deploymentStage,
74
+ maximum_idle_interval: conf.maximumIdleInterval,
75
+ };
76
+ return new ConfigurationRequest(challenge, options);
77
+ },
78
+ _createTransportLayerRequestHeaderConfigurationRequest = function _createTransportLayerRequestHeaderConfigurationRequest() {
79
+ return {
80
+ Message: 'TransportLayerClientConfigurationRequest',
81
+ Version: 1,
82
+ flags: 0,
83
+ };
84
+ },
85
+ _submit = async function _submit(message) {
86
+ this.log(LogLevel.INFO, 'Sending message', message);
87
+ const msg = {
88
+ message,
89
+ callbackType: 'response',
90
+ callbackId: message.Message.replace('Request', 'Response'),
91
+ };
92
+ await this.hooks.callHook('frontgateConnection:sendMessage', msg);
93
+ let timeout;
94
+ return new Promise((resolve, reject) => {
95
+ const unsubMessage = this.hooks.hookOnce(`frontgateConnection:response:${msg.callbackId}`, (response) => {
96
+ clearTimeout(timeout);
97
+ this.log(LogLevel.INFO, 'Received response', response);
98
+ resolve(response);
99
+ });
100
+ timeout = setTimeout(() => {
101
+ unsubMessage();
102
+ reject(new Error('Authentication message timeout'));
103
+ }, 3000);
104
+ });
105
+ },
36
106
  _a;
37
107
  };
38
108
  return createExtendedMixinFactory(mixinUserCredentialAuth, {
@@ -9,30 +9,97 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
9
9
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
10
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
11
  };
12
- import { createExtendedMixinFactory, createConnectionInterface, } from '../.';
13
- import { UserPasswordAuthentication } from '../../compat';
14
- import { ID_USER_NONE } from '../../authentication';
12
+ import { createExtendedMixinFactory } from '../.';
13
+ import { getBytesFromBuffer } from '../../connection';
14
+ import { ID_APP_AUTHENTICATED, ID_USER_AUTHENTICATED } from '../../authentication';
15
+ import { AuthenticationRequest, ConfigurationRequest, SecretGenerator } from '../../compat';
16
+ import { LogLevel } from '../../logger';
17
+ import { randomBytes } from 'crypto';
15
18
  export const userPasswordAuth = (idApplication, username, password, deploymentStage) => {
16
19
  const mixinUserPasswordAuth = (Base) => {
17
- var _auth, _a;
20
+ var _instances, _sharedSecret, _clientSecret, _createAuthenticationRequest, _createConfigurationRequest, _createTransportLayerRequestHeaderConfigurationRequest, _submit, _a;
18
21
  return _a = class extends Base {
19
22
  constructor(...args) {
20
23
  super(...args);
21
- _auth.set(this, void 0);
22
- __classPrivateFieldSet(this, _auth, new UserPasswordAuthentication(idApplication, username, password), "f");
24
+ _instances.add(this);
25
+ _sharedSecret.set(this, void 0);
26
+ _clientSecret.set(this, void 0);
27
+ const plainSharedSecret = SecretGenerator.generateSharedSecret(username, password);
28
+ const plainClientSecret = SecretGenerator.generateClientSecret(username, password);
29
+ if (plainSharedSecret && plainClientSecret) {
30
+ __classPrivateFieldSet(this, _sharedSecret, Buffer.from(plainSharedSecret), "f");
31
+ __classPrivateFieldSet(this, _clientSecret, Buffer.from(plainClientSecret), "f");
32
+ }
23
33
  this.hooks.hook('frontgateConnection:connected', async (conf) => {
24
34
  void this.hooks.callHook('frontgateConnection:setIdApp', idApplication);
25
- void this.hooks.callHook('frontgateConnection:setIdUser', ID_USER_NONE);
26
- await __classPrivateFieldGet(this, _auth, "f").authenticate(createConnectionInterface({
27
- payload_content: conf.payloadContent,
28
- deployment_stage: deploymentStage,
29
- maximum_idle_interval: conf.maximumIdleInterval,
30
- }, this));
35
+ void this.hooks.callHook('frontgateConnection:setIdUser', ID_USER_AUTHENTICATED);
36
+ const authResponse = await __classPrivateFieldGet(this, _instances, "m", _submit).call(this, __classPrivateFieldGet(this, _instances, "m", _createAuthenticationRequest).call(this).toJson());
37
+ await __classPrivateFieldGet(this, _instances, "m", _submit).call(this, __classPrivateFieldGet(this, _instances, "m", _createConfigurationRequest).call(this, authResponse, conf).toJson());
38
+ await __classPrivateFieldGet(this, _instances, "m", _submit).call(this, __classPrivateFieldGet(this, _instances, "m", _createTransportLayerRequestHeaderConfigurationRequest).call(this));
31
39
  await this.hooks.callHook('frontgateConnection:authenticated');
32
40
  });
33
41
  }
34
42
  },
35
- _auth = new WeakMap(),
43
+ _sharedSecret = new WeakMap(),
44
+ _clientSecret = new WeakMap(),
45
+ _instances = new WeakSet(),
46
+ _createAuthenticationRequest = function _createAuthenticationRequest() {
47
+ const salt = randomBytes(16);
48
+ const options = {
49
+ idApplication,
50
+ username,
51
+ salt: getBytesFromBuffer(salt),
52
+ challenge: getBytesFromBuffer(randomBytes(16)),
53
+ encryptedSecrets: [{ encrypted_secret: SecretGenerator.createEncryptedSecret(salt, __classPrivateFieldGet(this, _sharedSecret, "f"), __classPrivateFieldGet(this, _clientSecret, "f")) }],
54
+ };
55
+ return new AuthenticationRequest(options);
56
+ },
57
+ _createConfigurationRequest = function _createConfigurationRequest(msg, conf) {
58
+ const expectedMessage = 'Foundation::AuthenticationResponse';
59
+ if (msg.Message !== expectedMessage) {
60
+ throw new Error(`Expected message "${expectedMessage}" but received "${msg.Message}"`);
61
+ }
62
+ if (msg.id_user === ID_USER_AUTHENTICATED) {
63
+ void this.hooks.callHook('frontgateConnection:setIdApp', ID_APP_AUTHENTICATED);
64
+ void this.hooks.callHook('frontgateConnection:setIdUser', ID_USER_AUTHENTICATED);
65
+ }
66
+ const { challenge } = msg.challenge;
67
+ const options = {
68
+ shared_secret: __classPrivateFieldGet(this, _sharedSecret, "f"),
69
+ payload_content: conf.payloadContent,
70
+ deployment_stage: deploymentStage,
71
+ maximum_idle_interval: conf.maximumIdleInterval,
72
+ };
73
+ return new ConfigurationRequest(challenge, options);
74
+ },
75
+ _createTransportLayerRequestHeaderConfigurationRequest = function _createTransportLayerRequestHeaderConfigurationRequest() {
76
+ return {
77
+ Message: 'TransportLayerClientConfigurationRequest',
78
+ Version: 1,
79
+ flags: 0,
80
+ };
81
+ },
82
+ _submit = async function _submit(message) {
83
+ this.log(LogLevel.INFO, 'Sending message', message);
84
+ const msg = {
85
+ message,
86
+ callbackType: 'response',
87
+ callbackId: message.Message.replace('Request', 'Response'),
88
+ };
89
+ await this.hooks.callHook('frontgateConnection:sendMessage', msg);
90
+ let timeout;
91
+ return new Promise((resolve, reject) => {
92
+ const unsubMessage = this.hooks.hookOnce(`frontgateConnection:response:${msg.callbackId}`, (response) => {
93
+ clearTimeout(timeout);
94
+ this.log(LogLevel.INFO, 'Received response', response);
95
+ resolve(response);
96
+ });
97
+ timeout = setTimeout(() => {
98
+ unsubMessage();
99
+ reject(new Error('Authentication message timeout'));
100
+ }, 3000);
101
+ });
102
+ },
36
103
  _a;
37
104
  };
38
105
  return createExtendedMixinFactory(mixinUserPasswordAuth, {
@@ -1,34 +1,3 @@
1
- import { LogLevel } from '../../logger';
2
1
  export * from './CookieTokenAuthMixin';
3
2
  export * from './TokenAuthMixin';
4
3
  export * from './FetchAuthenticationMixin';
5
- export const createConnectionInterface = (options, base) => {
6
- return {
7
- options,
8
- submit: async (message) => {
9
- base.log(LogLevel.INFO, 'Sending message', message);
10
- const msg = {
11
- message,
12
- callbackType: 'response',
13
- callbackId: message.Message.replace('Request', 'Response'),
14
- };
15
- await base.hooks.callHook('frontgateConnection:sendMessage', msg);
16
- let timeout;
17
- return new Promise((resolve, reject) => {
18
- const unsubMessage = base.hooks.hookOnce(`frontgateConnection:response:${msg.callbackId}`, (response) => {
19
- clearTimeout(timeout);
20
- base.log(LogLevel.INFO, 'Received response', response);
21
- resolve(response);
22
- });
23
- timeout = setTimeout(() => {
24
- unsubMessage();
25
- reject(new Error('Authentication message timeout'));
26
- }, 3000);
27
- });
28
- },
29
- setPeerInfo: (peerInfo) => {
30
- base.log(LogLevel.INFO, 'Peer info:', peerInfo);
31
- },
32
- auth: {},
33
- };
34
- };
@@ -10,6 +10,7 @@ export * from './ReconnectMixin';
10
10
  export * from './OpenTelemetryMixin';
11
11
  export * from './HTTPProxyRequestMixin';
12
12
  export * from './PingMixin';
13
+ export * from './RemoteLoggerMixin';
13
14
  export const createExtendedMixinFactory = (mixinFactory, options) => {
14
15
  const extendedMixinFactory = mixinFactory;
15
16
  extendedMixinFactory.featureName = options.featureName;