@aligent/microservice-util-lib 1.2.1 → 1.2.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aligent/microservice-util-lib",
3
- "version": "1.2.1",
3
+ "version": "1.2.2",
4
4
  "description": "A set of utility functions for Aligent Microservices",
5
5
  "type": "commonjs",
6
6
  "main": "./src/index.js",
@@ -64,27 +64,18 @@ function combineUrlAndPathParams(url, pathParams) {
64
64
  *
65
65
  * @param {string} baseURL - The base URL.
66
66
  * @param {string} url - The URL to process.
67
- * @returns {{ baseUri: string, searchParams: URLSearchParams | null }} The processed URL and its search parameters.
67
+ * @returns The processed URL.
68
68
  */
69
- function handleOAuthUrl(baseURL, url) {
69
+ function getOAuthUrl(baseURL, url) {
70
70
  const oauthUrl = new URL(!baseURL || isAbsoluteURL(url) ? url : combineURLs(baseURL, url));
71
- let searchParams = null;
72
- // Query parameters are hashed as part of params rather than as part of the URL
73
- if (oauthUrl.search) {
74
- searchParams = new URLSearchParams(oauthUrl.search);
75
- oauthUrl.search = '';
76
- }
77
- // Do not include hash in signature
78
- oauthUrl.hash = '';
71
+ oauthUrl.search = ''; // Query parameters are hashed as part of params rather than as part of the URL
72
+ oauthUrl.hash = ''; // Do not include hash in signature
79
73
  // Remove port if it is the default for that protocol
80
74
  if ((oauthUrl.protocol === 'https:' && oauthUrl.port === '443') ||
81
75
  (oauthUrl.protocol === 'http:' && oauthUrl.port === '80')) {
82
76
  oauthUrl.port = '';
83
77
  }
84
- return {
85
- baseUri: oauthUrl.toString(),
86
- searchParams,
87
- };
78
+ return oauthUrl.toString();
88
79
  }
89
80
  /**
90
81
  * Adds a parameter to the list of parameters to sign.
@@ -174,10 +165,6 @@ async function generateOauthParams(request, options, params, config) {
174
165
  if (params.query) {
175
166
  addParamsToSign(paramsToSign, params.query);
176
167
  }
177
- const { baseUri, searchParams } = handleOAuthUrl(options.baseUrl, url);
178
- if (searchParams) {
179
- addParamsToSign(paramsToSign, searchParams);
180
- }
181
168
  const body = await request.text();
182
169
  // If user submit a form, then include form parameters in the
183
170
  // signature as parameters rather than the body hash
@@ -195,7 +182,8 @@ async function generateOauthParams(request, options, params, config) {
195
182
  addParamToSign(paramsToSign, 'oauth_body_hash', bodyHash);
196
183
  }
197
184
  }
198
- oauthParams.oauth_signature = (0, oauth_sign_1.sign)(algorithm, method, baseUri, paramsToSign, consumerSecret, tokenSecret);
185
+ const oauthUrl = getOAuthUrl(options.baseUrl, url);
186
+ oauthParams.oauth_signature = (0, oauth_sign_1.sign)(algorithm, method, oauthUrl, paramsToSign, consumerSecret, tokenSecret);
199
187
  // realm should not be included in the signature calculation
200
188
  // but is optional in the OAuth 1.0 Authorization header
201
189
  // so we need to add it after signing the request