diff --git a/package.json b/package.json index 468409b982..af9cbaa4bb 100644 --- a/package.json +++ b/package.json @@ -112,8 +112,8 @@ "@azure/arm-resources": "^5.0.0", "@azure/arm-sql": "^9.0.0", "@azure/arm-subscriptions": "^5.0.0", - "@azure/msal-common": "^10.0.0", - "@azure/msal-node": "^1.15.0", + "@azure/msal-common": "^11.0.0", + "@azure/msal-node": "^1.16.0", "@microsoft/ads-adal-library": "1.0.17", "http-proxy-agent": "5.0.0", "https-proxy-agent": "5.0.0", @@ -126,7 +126,6 @@ "getmac": "1.2.1", "jquery": "^3.4.1", "lockfile": "1.0.4", - "msal": "^1.4.17", "node-fetch": "^2.6.1", "opener": "1.4.2", "plist": "^3.0.5", diff --git a/src/azure/msal/httpClient.ts b/src/azure/msal/httpClient.ts index cd4af16714..2e5123c8b5 100644 --- a/src/azure/msal/httpClient.ts +++ b/src/azure/msal/httpClient.ts @@ -78,9 +78,6 @@ const networkRequestViaProxy = <T>( path: destinationUrl.hostname, headers: headers }; - if (destinationUrl.searchParams) { - tunnelRequestOptions.path += `?${destinationUrl.searchParams}`; - } if (timeout) { tunnelRequestOptions.timeout = timeout; @@ -226,19 +223,13 @@ const networkRequestViaHttps = <T>( const isPostRequest = httpMethod === HttpMethod.POST; const body: string = options?.body || ''; const url = new URL(urlString); - - const emptyHeaders: Record<string, string> = {}; - const customOptions: https.RequestOptions = { - hostname: url.hostname, - path: url.pathname, + const optionHeaders = options?.headers || {} as Record<string, string>; + let customOptions: https.RequestOptions = { method: httpMethod, - headers: options?.headers || emptyHeaders + headers: optionHeaders, + ...NetworkUtils.urlToHttpOptions(url) }; - if (url.searchParams) { - customOptions.path += `?${url.searchParams}`; - } - if (timeout) { customOptions.timeout = timeout; } diff --git a/src/azure/msal/networkUtils.ts b/src/azure/msal/networkUtils.ts index 57b3c41ef7..d05ce97ec7 100644 --- a/src/azure/msal/networkUtils.ts +++ b/src/azure/msal/networkUtils.ts @@ -4,6 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import { NetworkResponse } from '@azure/msal-common'; +import * as https from 'https'; export class NetworkUtils { static getNetworkResponse<T>(headers: Record<string, string>, body: T, statusCode: number): NetworkResponse<T> { @@ -13,4 +14,28 @@ export class NetworkUtils { status: statusCode }; } + /* + * Utility function that converts a URL object into an ordinary options object as expected by the + * http.request and https.request APIs. + */ + static urlToHttpOptions(url: URL): https.RequestOptions { + const options: https.RequestOptions & Partial<Omit<URL, 'port'>> = { + protocol: url.protocol, + hostname: url.hostname && url.hostname.startsWith('[') ? + url.hostname.slice(1, -1) : + url.hostname, + hash: url.hash, + search: url.search, + pathname: url.pathname, + path: `${url.pathname || ''}${url.search || ''}`, + href: url.href + }; + if (url.port !== '') { + options.port = Number(url.port); + } + if (url.username || url.password) { + options.auth = `${decodeURIComponent(url.username)}:${decodeURIComponent(url.password)}`; + } + return options; + } } diff --git a/yarn.lock b/yarn.lock index a9cc4cdd7e..31ac0c5d75 100644 --- a/yarn.lock +++ b/yarn.lock @@ -162,17 +162,17 @@ dependencies: tslib "^2.2.0" -"@azure/msal-common@^10.0.0": - version "10.0.0" - resolved "https://registry.yarnpkg.com/@azure/msal-common/-/msal-common-10.0.0.tgz#07fc39ae2a2e6f2c1da8e26657058317de52b65a" - integrity sha512-/LghpT93jsZLy55QzTsRZWMx6R1Mjc1Aktwps8sKSGE3WbrGwbSsh2uhDlpl6FMcKChYjJ0ochThWwwOodrQNg== +"@azure/msal-common@^11.0.0": + version "11.0.0" + resolved "https://registry.yarnpkg.com/@azure/msal-common/-/msal-common-11.0.0.tgz#d35bfa6cdd2a5b8c036ce427aa3fd36f8f985239" + integrity sha512-SZH8ObQ3Hq5v3ogVGBYJp1nNW7p+MtM4PH4wfNadBP9wf7K0beQHF9iOtRcjPOkwZf+ZD49oXqw91LndIkdk8g== -"@azure/msal-node@^1.15.0": - version "1.15.0" - resolved "https://registry.yarnpkg.com/@azure/msal-node/-/msal-node-1.15.0.tgz#0a0248c73afaa16b195c1afba4149c72ea3b42a2" - integrity sha512-fwC5M0c8pxOAzmScPbpx7j28YVTDebUaizlVF7bR0xvlU0r3VWW5OobCcr9ybqKS6wGyO7u4EhXJS9rjRWAuwA== +"@azure/msal-node@^1.16.0": + version "1.16.0" + resolved "https://registry.yarnpkg.com/@azure/msal-node/-/msal-node-1.16.0.tgz#0bd469916f5a9da22d844edc879ac7e8225c0ccb" + integrity sha512-eGXPp65i++mAIvziafbCH970TCeECB6iaQP7aRzZEjtU238cW4zKm40U8YxkiCn9rR1G2VeMHENB5h6WRk7ZCQ== dependencies: - "@azure/msal-common" "^10.0.0" + "@azure/msal-common" "^11.0.0" jsonwebtoken "^9.0.0" uuid "^8.3.0" @@ -3842,13 +3842,6 @@ ms@2.1.3, ms@^2.1.1: resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.3.tgz#574c8138ce1d2b5861f0b44579dbadd60c6615b2" integrity sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA== -msal@^1.4.17: - version "1.4.17" - resolved "https://registry.yarnpkg.com/msal/-/msal-1.4.17.tgz#b78171c0471ede506eeaabc86343f8f4e2d01634" - integrity sha512-RjHwP2cCIWQ9iUIk1SziUMb9+jj5mC4OqG2w16E5yig8jySi/TwiFvKlwcjNrPsndph0HtgCtbENnk5julf3yQ== - dependencies: - tslib "^1.9.3" - multipipe@^0.1.2: version "0.1.2" resolved "https://registry.yarnpkg.com/multipipe/-/multipipe-0.1.2.tgz#2a8f2ddf70eed564dff2d57f1e1a137d9f05078b"