@azure/msal-node 1.15.0 → 1.16.0

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.
@@ -118,6 +118,29 @@ class NetworkUtils {
118
118
  status: statusCode
119
119
  };
120
120
  }
121
+ /*
122
+ * Utility function that converts a URL object into an ordinary options object as expected by the
123
+ * http.request and https.request APIs.
124
+ * https://github.com/nodejs/node/blob/main/lib/internal/url.js#L1090
125
+ */
126
+ static urlToHttpOptions(url) {
127
+ const options = {
128
+ protocol: url.protocol,
129
+ hostname: url.hostname && url.hostname.startsWith("[") ? url.hostname.slice(1, -1) : url.hostname,
130
+ hash: url.hash,
131
+ search: url.search,
132
+ pathname: url.pathname,
133
+ path: `${url.pathname || ""}${url.search || ""}`,
134
+ href: url.href
135
+ };
136
+ if (url.port !== "") {
137
+ options.port = Number(url.port);
138
+ }
139
+ if (url.username || url.password) {
140
+ options.auth = `${decodeURIComponent(url.username)}:${decodeURIComponent(url.password)}`;
141
+ }
142
+ return options;
143
+ }
121
144
  }
122
145
 
123
146
  /*
@@ -157,11 +180,11 @@ class HttpClient {
157
180
  }
158
181
  }
159
182
  }
160
- const networkRequestViaProxy = (url, proxyUrlString, httpMethod, options, agentOptions, timeout) => {
161
- const headers = (options == null ? void 0 : options.headers) || {};
183
+ const networkRequestViaProxy = (destinationUrlString, proxyUrlString, httpMethod, options, agentOptions, timeout) => {
184
+ const destinationUrl = new URL(destinationUrlString);
162
185
  const proxyUrl = new URL(proxyUrlString);
163
- const destinationUrl = new URL(url);
164
186
  // "method: connect" must be used to establish a connection to the proxy
187
+ const headers = (options == null ? void 0 : options.headers) || {};
165
188
  const tunnelRequestOptions = {
166
189
  host: proxyUrl.hostname,
167
190
  port: proxyUrl.port,
@@ -272,13 +295,15 @@ const networkRequestViaProxy = (url, proxyUrlString, httpMethod, options, agentO
272
295
  });
273
296
  });
274
297
  };
275
- const networkRequestViaHttps = (url, httpMethod, options, agentOptions, timeout) => {
298
+ const networkRequestViaHttps = (urlString, httpMethod, options, agentOptions, timeout) => {
276
299
  const isPostRequest = httpMethod === HttpMethod.POST;
277
300
  const body = (options == null ? void 0 : options.body) || "";
278
- const emptyHeaders = {};
301
+ const url = new URL(urlString);
302
+ const headers = (options == null ? void 0 : options.headers) || {};
279
303
  const customOptions = {
280
304
  method: httpMethod,
281
- headers: (options == null ? void 0 : options.headers) || emptyHeaders
305
+ headers: headers,
306
+ ...NetworkUtils.urlToHttpOptions(url)
282
307
  };
283
308
  if (timeout) {
284
309
  customOptions.timeout = timeout;
@@ -294,7 +319,7 @@ const networkRequestViaHttps = (url, httpMethod, options, agentOptions, timeout)
294
319
  };
295
320
  }
296
321
  return new Promise((resolve, reject) => {
297
- const request = https.request(url, customOptions);
322
+ const request = https.request(customOptions);
298
323
  if (timeout) {
299
324
  request.on("timeout", () => {
300
325
  request.destroy();
@@ -430,6 +455,7 @@ const DEFAULT_TELEMETRY_OPTIONS = {
430
455
  */
431
456
  function buildAppConfiguration({
432
457
  auth,
458
+ broker,
433
459
  cache,
434
460
  system,
435
461
  telemetry
@@ -444,6 +470,9 @@ function buildAppConfiguration({
444
470
  ...DEFAULT_AUTH_OPTIONS,
445
471
  ...auth
446
472
  },
473
+ broker: {
474
+ ...broker
475
+ },
447
476
  cache: {
448
477
  ...DEFAULT_CACHE_OPTIONS,
449
478
  ...cache
@@ -1593,7 +1622,7 @@ class TokenCache {
1593
1622
 
1594
1623
  /* eslint-disable header/header */
1595
1624
  const name = "@azure/msal-node";
1596
- const version = "1.15.0";
1625
+ const version = "1.16.0";
1597
1626
 
1598
1627
  /*
1599
1628
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -2107,6 +2136,14 @@ class PublicClientApplication extends ClientApplication {
2107
2136
  */
2108
2137
  constructor(configuration) {
2109
2138
  super(configuration);
2139
+ if (this.config.broker.nativeBrokerPlugin) {
2140
+ if (this.config.broker.nativeBrokerPlugin.isBrokerAvailable) {
2141
+ this.nativeBrokerPlugin = this.config.broker.nativeBrokerPlugin;
2142
+ this.nativeBrokerPlugin.setLogger(this.config.system.loggerOptions);
2143
+ } else {
2144
+ this.logger.warning("NativeBroker implementation was provided but the broker is unavailable.");
2145
+ }
2146
+ }
2110
2147
  }
2111
2148
  /**
2112
2149
  * Acquires a token from the authority using OAuth2.0 device code flow.
@@ -2135,24 +2172,46 @@ class PublicClientApplication extends ClientApplication {
2135
2172
  }
2136
2173
  }
2137
2174
  /**
2138
- * Acquires a token by requesting an Authorization code then exchanging it for a token.
2175
+ * Acquires a token interactively via the browser by requesting an authorization code then exchanging it for a token.
2139
2176
  */
2140
2177
  async acquireTokenInteractive(request) {
2141
- const {
2142
- verifier,
2143
- challenge
2144
- } = await this.cryptoProvider.generatePkceCodes();
2178
+ const correlationId = request.correlationId || this.cryptoProvider.createNewGuid();
2179
+ this.logger.trace("acquireTokenInteractive called", correlationId);
2145
2180
  const {
2146
2181
  openBrowser,
2147
2182
  successTemplate,
2148
2183
  errorTemplate,
2184
+ windowHandle,
2185
+ loopbackClient: customLoopbackClient,
2149
2186
  ...remainingProperties
2150
2187
  } = request;
2151
- const loopbackClient = new LoopbackClient();
2188
+ if (this.nativeBrokerPlugin) {
2189
+ var _remainingProperties$;
2190
+ const brokerRequest = {
2191
+ ...remainingProperties,
2192
+ clientId: this.config.auth.clientId,
2193
+ scopes: request.scopes || msalCommon.OIDC_DEFAULT_SCOPES,
2194
+ redirectUri: `${Constants.HTTP_PROTOCOL}${Constants.LOCALHOST}`,
2195
+ authority: request.authority || this.config.auth.authority,
2196
+ correlationId: correlationId,
2197
+ extraParameters: {
2198
+ ...remainingProperties.extraQueryParameters,
2199
+ ...remainingProperties.tokenQueryParameters
2200
+ },
2201
+ accountId: (_remainingProperties$ = remainingProperties.account) == null ? void 0 : _remainingProperties$.nativeAccountId
2202
+ };
2203
+ return this.nativeBrokerPlugin.acquireTokenInteractive(brokerRequest, windowHandle);
2204
+ }
2205
+ const {
2206
+ verifier,
2207
+ challenge
2208
+ } = await this.cryptoProvider.generatePkceCodes();
2209
+ const loopbackClient = customLoopbackClient || new LoopbackClient();
2152
2210
  const authCodeListener = loopbackClient.listenForAuthCode(successTemplate, errorTemplate);
2153
2211
  const redirectUri = loopbackClient.getRedirectUri();
2154
2212
  const validRequest = {
2155
2213
  ...remainingProperties,
2214
+ correlationId: correlationId,
2156
2215
  scopes: request.scopes || msalCommon.OIDC_DEFAULT_SCOPES,
2157
2216
  redirectUri: redirectUri,
2158
2217
  responseMode: msalCommon.ResponseMode.QUERY,
@@ -2178,6 +2237,57 @@ class PublicClientApplication extends ClientApplication {
2178
2237
  };
2179
2238
  return this.acquireTokenByCode(tokenRequest);
2180
2239
  }
2240
+ /**
2241
+ * Returns a token retrieved either from the cache or by exchanging the refresh token for a fresh access token. If brokering is enabled the token request will be serviced by the broker.
2242
+ * @param request
2243
+ * @returns
2244
+ */
2245
+ async acquireTokenSilent(request) {
2246
+ const correlationId = request.correlationId || this.cryptoProvider.createNewGuid();
2247
+ this.logger.trace("acquireTokenSilent called", correlationId);
2248
+ if (this.nativeBrokerPlugin) {
2249
+ const brokerRequest = {
2250
+ ...request,
2251
+ clientId: this.config.auth.clientId,
2252
+ scopes: request.scopes || msalCommon.OIDC_DEFAULT_SCOPES,
2253
+ redirectUri: `${Constants.HTTP_PROTOCOL}${Constants.LOCALHOST}`,
2254
+ authority: request.authority || this.config.auth.authority,
2255
+ correlationId: correlationId,
2256
+ extraParameters: request.tokenQueryParameters,
2257
+ accountId: request.account.nativeAccountId,
2258
+ forceRefresh: request.forceRefresh || false
2259
+ };
2260
+ return this.nativeBrokerPlugin.acquireTokenSilent(brokerRequest);
2261
+ }
2262
+ return super.acquireTokenSilent(request);
2263
+ }
2264
+ /**
2265
+ * Removes cache artifacts associated with the given account
2266
+ * @param request
2267
+ * @returns
2268
+ */
2269
+ async signOut(request) {
2270
+ if (this.nativeBrokerPlugin && request.account.nativeAccountId) {
2271
+ const signoutRequest = {
2272
+ clientId: this.config.auth.clientId,
2273
+ accountId: request.account.nativeAccountId,
2274
+ correlationId: request.correlationId || this.cryptoProvider.createNewGuid()
2275
+ };
2276
+ await this.nativeBrokerPlugin.signOut(signoutRequest);
2277
+ }
2278
+ await this.getTokenCache().removeAccount(request.account);
2279
+ }
2280
+ /**
2281
+ * Returns all cached accounts for this application. If brokering is enabled this request will be serviced by the broker.
2282
+ * @returns
2283
+ */
2284
+ async getAllAccounts() {
2285
+ if (this.nativeBrokerPlugin) {
2286
+ const correlationId = this.cryptoProvider.createNewGuid();
2287
+ return this.nativeBrokerPlugin.getAllAccounts(this.config.auth.clientId, correlationId);
2288
+ }
2289
+ return this.getTokenCache().getAllAccounts();
2290
+ }
2181
2291
  }
2182
2292
 
2183
2293
  /*