@azure/msal-node 1.14.6 → 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.
- package/LICENSE +21 -21
- package/README.md +181 -181
- package/dist/client/ClientApplication.d.ts.map +1 -1
- package/dist/client/IPublicClientApplication.d.ts +6 -1
- package/dist/client/IPublicClientApplication.d.ts.map +1 -1
- package/dist/client/PublicClientApplication.d.ts +22 -2
- package/dist/client/PublicClientApplication.d.ts.map +1 -1
- package/dist/config/Configuration.d.ts +20 -2
- package/dist/config/Configuration.d.ts.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/msal-node.cjs.development.js +149 -30
- package/dist/msal-node.cjs.development.js.map +1 -1
- package/dist/msal-node.cjs.production.min.js +1 -1
- package/dist/msal-node.cjs.production.min.js.map +1 -1
- package/dist/msal-node.esm.js +149 -30
- package/dist/msal-node.esm.js.map +1 -1
- package/dist/network/HttpClient.d.ts +6 -0
- package/dist/network/HttpClient.d.ts.map +1 -1
- package/dist/network/ILoopbackClient.d.ts +11 -0
- package/dist/network/ILoopbackClient.d.ts.map +1 -0
- package/dist/network/LoopbackClient.d.ts +2 -1
- package/dist/network/LoopbackClient.d.ts.map +1 -1
- package/dist/packageMetadata.d.ts +1 -1
- package/dist/request/AuthorizationCodeRequest.d.ts +1 -1
- package/dist/request/ClientCredentialRequest.d.ts +1 -0
- package/dist/request/ClientCredentialRequest.d.ts.map +1 -1
- package/dist/request/DeviceCodeRequest.d.ts +1 -0
- package/dist/request/DeviceCodeRequest.d.ts.map +1 -1
- package/dist/request/InteractiveRequest.d.ts +15 -0
- package/dist/request/InteractiveRequest.d.ts.map +1 -1
- package/dist/request/OnBehalfOfRequest.d.ts +1 -0
- package/dist/request/OnBehalfOfRequest.d.ts.map +1 -1
- package/dist/request/SignOutRequest.d.ts +6 -0
- package/dist/request/SignOutRequest.d.ts.map +1 -0
- package/dist/request/SilentFlowRequest.d.ts +1 -1
- package/dist/request/UsernamePasswordRequest.d.ts +1 -0
- package/dist/request/UsernamePasswordRequest.d.ts.map +1 -1
- package/dist/utils/NetworkUtils.d.ts +2 -1
- package/dist/utils/NetworkUtils.d.ts.map +1 -1
- package/package.json +68 -68
package/dist/msal-node.esm.js
CHANGED
|
@@ -112,6 +112,29 @@ class NetworkUtils {
|
|
|
112
112
|
status: statusCode
|
|
113
113
|
};
|
|
114
114
|
}
|
|
115
|
+
/*
|
|
116
|
+
* Utility function that converts a URL object into an ordinary options object as expected by the
|
|
117
|
+
* http.request and https.request APIs.
|
|
118
|
+
* https://github.com/nodejs/node/blob/main/lib/internal/url.js#L1090
|
|
119
|
+
*/
|
|
120
|
+
static urlToHttpOptions(url) {
|
|
121
|
+
const options = {
|
|
122
|
+
protocol: url.protocol,
|
|
123
|
+
hostname: url.hostname && url.hostname.startsWith("[") ? url.hostname.slice(1, -1) : url.hostname,
|
|
124
|
+
hash: url.hash,
|
|
125
|
+
search: url.search,
|
|
126
|
+
pathname: url.pathname,
|
|
127
|
+
path: `${url.pathname || ""}${url.search || ""}`,
|
|
128
|
+
href: url.href
|
|
129
|
+
};
|
|
130
|
+
if (url.port !== "") {
|
|
131
|
+
options.port = Number(url.port);
|
|
132
|
+
}
|
|
133
|
+
if (url.username || url.password) {
|
|
134
|
+
options.auth = `${decodeURIComponent(url.username)}:${decodeURIComponent(url.password)}`;
|
|
135
|
+
}
|
|
136
|
+
return options;
|
|
137
|
+
}
|
|
115
138
|
}
|
|
116
139
|
|
|
117
140
|
/*
|
|
@@ -122,16 +145,20 @@ class NetworkUtils {
|
|
|
122
145
|
* This class implements the API for network requests.
|
|
123
146
|
*/
|
|
124
147
|
class HttpClient {
|
|
148
|
+
constructor(proxyUrl, customAgentOptions) {
|
|
149
|
+
this.proxyUrl = proxyUrl || "";
|
|
150
|
+
this.customAgentOptions = customAgentOptions || {};
|
|
151
|
+
}
|
|
125
152
|
/**
|
|
126
153
|
* Http Get request
|
|
127
154
|
* @param url
|
|
128
155
|
* @param options
|
|
129
156
|
*/
|
|
130
157
|
async sendGetRequestAsync(url, options) {
|
|
131
|
-
if (
|
|
132
|
-
return networkRequestViaProxy(url, HttpMethod.GET, options);
|
|
158
|
+
if (this.proxyUrl) {
|
|
159
|
+
return networkRequestViaProxy(url, this.proxyUrl, HttpMethod.GET, options, this.customAgentOptions);
|
|
133
160
|
} else {
|
|
134
|
-
return networkRequestViaHttps(url, HttpMethod.GET, options);
|
|
161
|
+
return networkRequestViaHttps(url, HttpMethod.GET, options, this.customAgentOptions);
|
|
135
162
|
}
|
|
136
163
|
}
|
|
137
164
|
/**
|
|
@@ -140,18 +167,18 @@ class HttpClient {
|
|
|
140
167
|
* @param options
|
|
141
168
|
*/
|
|
142
169
|
async sendPostRequestAsync(url, options, cancellationToken) {
|
|
143
|
-
if (
|
|
144
|
-
return networkRequestViaProxy(url, HttpMethod.POST, options, cancellationToken);
|
|
170
|
+
if (this.proxyUrl) {
|
|
171
|
+
return networkRequestViaProxy(url, this.proxyUrl, HttpMethod.POST, options, this.customAgentOptions, cancellationToken);
|
|
145
172
|
} else {
|
|
146
|
-
return networkRequestViaHttps(url, HttpMethod.POST, options, cancellationToken);
|
|
173
|
+
return networkRequestViaHttps(url, HttpMethod.POST, options, this.customAgentOptions, cancellationToken);
|
|
147
174
|
}
|
|
148
175
|
}
|
|
149
176
|
}
|
|
150
|
-
const networkRequestViaProxy = (
|
|
151
|
-
const
|
|
152
|
-
const proxyUrl = new URL(
|
|
153
|
-
const destinationUrl = new URL(url);
|
|
177
|
+
const networkRequestViaProxy = (destinationUrlString, proxyUrlString, httpMethod, options, agentOptions, timeout) => {
|
|
178
|
+
const destinationUrl = new URL(destinationUrlString);
|
|
179
|
+
const proxyUrl = new URL(proxyUrlString);
|
|
154
180
|
// "method: connect" must be used to establish a connection to the proxy
|
|
181
|
+
const headers = (options == null ? void 0 : options.headers) || {};
|
|
155
182
|
const tunnelRequestOptions = {
|
|
156
183
|
host: proxyUrl.hostname,
|
|
157
184
|
port: proxyUrl.port,
|
|
@@ -162,6 +189,9 @@ const networkRequestViaProxy = (url, httpMethod, options, timeout) => {
|
|
|
162
189
|
if (timeout) {
|
|
163
190
|
tunnelRequestOptions.timeout = timeout;
|
|
164
191
|
}
|
|
192
|
+
if (agentOptions && Object.keys(agentOptions).length) {
|
|
193
|
+
tunnelRequestOptions.agent = new http.Agent(agentOptions);
|
|
194
|
+
}
|
|
165
195
|
// compose a request string for the socket
|
|
166
196
|
let postRequestStringContent = "";
|
|
167
197
|
if (httpMethod === HttpMethod.POST) {
|
|
@@ -259,17 +289,22 @@ const networkRequestViaProxy = (url, httpMethod, options, timeout) => {
|
|
|
259
289
|
});
|
|
260
290
|
});
|
|
261
291
|
};
|
|
262
|
-
const networkRequestViaHttps = (
|
|
292
|
+
const networkRequestViaHttps = (urlString, httpMethod, options, agentOptions, timeout) => {
|
|
263
293
|
const isPostRequest = httpMethod === HttpMethod.POST;
|
|
264
294
|
const body = (options == null ? void 0 : options.body) || "";
|
|
265
|
-
const
|
|
295
|
+
const url = new URL(urlString);
|
|
296
|
+
const headers = (options == null ? void 0 : options.headers) || {};
|
|
266
297
|
const customOptions = {
|
|
267
298
|
method: httpMethod,
|
|
268
|
-
headers:
|
|
299
|
+
headers: headers,
|
|
300
|
+
...NetworkUtils.urlToHttpOptions(url)
|
|
269
301
|
};
|
|
270
302
|
if (timeout) {
|
|
271
303
|
customOptions.timeout = timeout;
|
|
272
304
|
}
|
|
305
|
+
if (agentOptions && Object.keys(agentOptions).length) {
|
|
306
|
+
customOptions.agent = new https.Agent(agentOptions);
|
|
307
|
+
}
|
|
273
308
|
if (isPostRequest) {
|
|
274
309
|
// needed for post request to work
|
|
275
310
|
customOptions.headers = {
|
|
@@ -278,7 +313,7 @@ const networkRequestViaHttps = (url, httpMethod, options, timeout) => {
|
|
|
278
313
|
};
|
|
279
314
|
}
|
|
280
315
|
return new Promise((resolve, reject) => {
|
|
281
|
-
const request = https.request(
|
|
316
|
+
const request = https.request(customOptions);
|
|
282
317
|
if (timeout) {
|
|
283
318
|
request.on("timeout", () => {
|
|
284
319
|
request.destroy();
|
|
@@ -392,7 +427,8 @@ const DEFAULT_LOGGER_OPTIONS = {
|
|
|
392
427
|
const DEFAULT_SYSTEM_OPTIONS = {
|
|
393
428
|
loggerOptions: DEFAULT_LOGGER_OPTIONS,
|
|
394
429
|
networkClient: /*#__PURE__*/new HttpClient(),
|
|
395
|
-
proxyUrl: Constants$1.EMPTY_STRING
|
|
430
|
+
proxyUrl: Constants$1.EMPTY_STRING,
|
|
431
|
+
customAgentOptions: {}
|
|
396
432
|
};
|
|
397
433
|
const DEFAULT_TELEMETRY_OPTIONS = {
|
|
398
434
|
application: {
|
|
@@ -413,12 +449,14 @@ const DEFAULT_TELEMETRY_OPTIONS = {
|
|
|
413
449
|
*/
|
|
414
450
|
function buildAppConfiguration({
|
|
415
451
|
auth,
|
|
452
|
+
broker,
|
|
416
453
|
cache,
|
|
417
454
|
system,
|
|
418
455
|
telemetry
|
|
419
456
|
}) {
|
|
420
|
-
const
|
|
421
|
-
...
|
|
457
|
+
const systemOptions = {
|
|
458
|
+
...DEFAULT_SYSTEM_OPTIONS,
|
|
459
|
+
networkClient: new HttpClient(system == null ? void 0 : system.proxyUrl, system == null ? void 0 : system.customAgentOptions),
|
|
422
460
|
loggerOptions: (system == null ? void 0 : system.loggerOptions) || DEFAULT_LOGGER_OPTIONS
|
|
423
461
|
};
|
|
424
462
|
return {
|
|
@@ -426,13 +464,16 @@ function buildAppConfiguration({
|
|
|
426
464
|
...DEFAULT_AUTH_OPTIONS,
|
|
427
465
|
...auth
|
|
428
466
|
},
|
|
467
|
+
broker: {
|
|
468
|
+
...broker
|
|
469
|
+
},
|
|
429
470
|
cache: {
|
|
430
471
|
...DEFAULT_CACHE_OPTIONS,
|
|
431
472
|
...cache
|
|
432
473
|
},
|
|
433
474
|
system: {
|
|
434
|
-
...
|
|
435
|
-
...
|
|
475
|
+
...systemOptions,
|
|
476
|
+
...system
|
|
436
477
|
},
|
|
437
478
|
telemetry: {
|
|
438
479
|
...DEFAULT_TELEMETRY_OPTIONS,
|
|
@@ -1575,7 +1616,7 @@ class TokenCache {
|
|
|
1575
1616
|
|
|
1576
1617
|
/* eslint-disable header/header */
|
|
1577
1618
|
const name = "@azure/msal-node";
|
|
1578
|
-
const version = "1.
|
|
1619
|
+
const version = "1.16.0";
|
|
1579
1620
|
|
|
1580
1621
|
/*
|
|
1581
1622
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
@@ -1884,9 +1925,6 @@ class ClientApplication {
|
|
|
1884
1925
|
authority: discoveredAuthority,
|
|
1885
1926
|
clientCapabilities: this.config.auth.clientCapabilities
|
|
1886
1927
|
},
|
|
1887
|
-
systemOptions: {
|
|
1888
|
-
proxyUrl: this.config.system.proxyUrl
|
|
1889
|
-
},
|
|
1890
1928
|
loggerOptions: {
|
|
1891
1929
|
logLevel: this.config.system.loggerOptions.logLevel,
|
|
1892
1930
|
loggerCallback: this.config.system.loggerOptions.loggerCallback,
|
|
@@ -1973,7 +2011,7 @@ class ClientApplication {
|
|
|
1973
2011
|
azureRegionConfiguration,
|
|
1974
2012
|
skipAuthorityMetadataCache: this.config.auth.skipAuthorityMetadataCache
|
|
1975
2013
|
};
|
|
1976
|
-
return await AuthorityFactory.createDiscoveredInstance(authorityUrl, this.config.system.networkClient, this.storage, authorityOptions, this.logger
|
|
2014
|
+
return await AuthorityFactory.createDiscoveredInstance(authorityUrl, this.config.system.networkClient, this.storage, authorityOptions, this.logger);
|
|
1977
2015
|
}
|
|
1978
2016
|
/**
|
|
1979
2017
|
* Clear the cache
|
|
@@ -2092,6 +2130,14 @@ class PublicClientApplication extends ClientApplication {
|
|
|
2092
2130
|
*/
|
|
2093
2131
|
constructor(configuration) {
|
|
2094
2132
|
super(configuration);
|
|
2133
|
+
if (this.config.broker.nativeBrokerPlugin) {
|
|
2134
|
+
if (this.config.broker.nativeBrokerPlugin.isBrokerAvailable) {
|
|
2135
|
+
this.nativeBrokerPlugin = this.config.broker.nativeBrokerPlugin;
|
|
2136
|
+
this.nativeBrokerPlugin.setLogger(this.config.system.loggerOptions);
|
|
2137
|
+
} else {
|
|
2138
|
+
this.logger.warning("NativeBroker implementation was provided but the broker is unavailable.");
|
|
2139
|
+
}
|
|
2140
|
+
}
|
|
2095
2141
|
}
|
|
2096
2142
|
/**
|
|
2097
2143
|
* Acquires a token from the authority using OAuth2.0 device code flow.
|
|
@@ -2120,24 +2166,46 @@ class PublicClientApplication extends ClientApplication {
|
|
|
2120
2166
|
}
|
|
2121
2167
|
}
|
|
2122
2168
|
/**
|
|
2123
|
-
* Acquires a token by requesting an
|
|
2169
|
+
* Acquires a token interactively via the browser by requesting an authorization code then exchanging it for a token.
|
|
2124
2170
|
*/
|
|
2125
2171
|
async acquireTokenInteractive(request) {
|
|
2126
|
-
const
|
|
2127
|
-
|
|
2128
|
-
challenge
|
|
2129
|
-
} = await this.cryptoProvider.generatePkceCodes();
|
|
2172
|
+
const correlationId = request.correlationId || this.cryptoProvider.createNewGuid();
|
|
2173
|
+
this.logger.trace("acquireTokenInteractive called", correlationId);
|
|
2130
2174
|
const {
|
|
2131
2175
|
openBrowser,
|
|
2132
2176
|
successTemplate,
|
|
2133
2177
|
errorTemplate,
|
|
2178
|
+
windowHandle,
|
|
2179
|
+
loopbackClient: customLoopbackClient,
|
|
2134
2180
|
...remainingProperties
|
|
2135
2181
|
} = request;
|
|
2136
|
-
|
|
2182
|
+
if (this.nativeBrokerPlugin) {
|
|
2183
|
+
var _remainingProperties$;
|
|
2184
|
+
const brokerRequest = {
|
|
2185
|
+
...remainingProperties,
|
|
2186
|
+
clientId: this.config.auth.clientId,
|
|
2187
|
+
scopes: request.scopes || OIDC_DEFAULT_SCOPES,
|
|
2188
|
+
redirectUri: `${Constants.HTTP_PROTOCOL}${Constants.LOCALHOST}`,
|
|
2189
|
+
authority: request.authority || this.config.auth.authority,
|
|
2190
|
+
correlationId: correlationId,
|
|
2191
|
+
extraParameters: {
|
|
2192
|
+
...remainingProperties.extraQueryParameters,
|
|
2193
|
+
...remainingProperties.tokenQueryParameters
|
|
2194
|
+
},
|
|
2195
|
+
accountId: (_remainingProperties$ = remainingProperties.account) == null ? void 0 : _remainingProperties$.nativeAccountId
|
|
2196
|
+
};
|
|
2197
|
+
return this.nativeBrokerPlugin.acquireTokenInteractive(brokerRequest, windowHandle);
|
|
2198
|
+
}
|
|
2199
|
+
const {
|
|
2200
|
+
verifier,
|
|
2201
|
+
challenge
|
|
2202
|
+
} = await this.cryptoProvider.generatePkceCodes();
|
|
2203
|
+
const loopbackClient = customLoopbackClient || new LoopbackClient();
|
|
2137
2204
|
const authCodeListener = loopbackClient.listenForAuthCode(successTemplate, errorTemplate);
|
|
2138
2205
|
const redirectUri = loopbackClient.getRedirectUri();
|
|
2139
2206
|
const validRequest = {
|
|
2140
2207
|
...remainingProperties,
|
|
2208
|
+
correlationId: correlationId,
|
|
2141
2209
|
scopes: request.scopes || OIDC_DEFAULT_SCOPES,
|
|
2142
2210
|
redirectUri: redirectUri,
|
|
2143
2211
|
responseMode: ResponseMode.QUERY,
|
|
@@ -2163,6 +2231,57 @@ class PublicClientApplication extends ClientApplication {
|
|
|
2163
2231
|
};
|
|
2164
2232
|
return this.acquireTokenByCode(tokenRequest);
|
|
2165
2233
|
}
|
|
2234
|
+
/**
|
|
2235
|
+
* 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.
|
|
2236
|
+
* @param request
|
|
2237
|
+
* @returns
|
|
2238
|
+
*/
|
|
2239
|
+
async acquireTokenSilent(request) {
|
|
2240
|
+
const correlationId = request.correlationId || this.cryptoProvider.createNewGuid();
|
|
2241
|
+
this.logger.trace("acquireTokenSilent called", correlationId);
|
|
2242
|
+
if (this.nativeBrokerPlugin) {
|
|
2243
|
+
const brokerRequest = {
|
|
2244
|
+
...request,
|
|
2245
|
+
clientId: this.config.auth.clientId,
|
|
2246
|
+
scopes: request.scopes || OIDC_DEFAULT_SCOPES,
|
|
2247
|
+
redirectUri: `${Constants.HTTP_PROTOCOL}${Constants.LOCALHOST}`,
|
|
2248
|
+
authority: request.authority || this.config.auth.authority,
|
|
2249
|
+
correlationId: correlationId,
|
|
2250
|
+
extraParameters: request.tokenQueryParameters,
|
|
2251
|
+
accountId: request.account.nativeAccountId,
|
|
2252
|
+
forceRefresh: request.forceRefresh || false
|
|
2253
|
+
};
|
|
2254
|
+
return this.nativeBrokerPlugin.acquireTokenSilent(brokerRequest);
|
|
2255
|
+
}
|
|
2256
|
+
return super.acquireTokenSilent(request);
|
|
2257
|
+
}
|
|
2258
|
+
/**
|
|
2259
|
+
* Removes cache artifacts associated with the given account
|
|
2260
|
+
* @param request
|
|
2261
|
+
* @returns
|
|
2262
|
+
*/
|
|
2263
|
+
async signOut(request) {
|
|
2264
|
+
if (this.nativeBrokerPlugin && request.account.nativeAccountId) {
|
|
2265
|
+
const signoutRequest = {
|
|
2266
|
+
clientId: this.config.auth.clientId,
|
|
2267
|
+
accountId: request.account.nativeAccountId,
|
|
2268
|
+
correlationId: request.correlationId || this.cryptoProvider.createNewGuid()
|
|
2269
|
+
};
|
|
2270
|
+
await this.nativeBrokerPlugin.signOut(signoutRequest);
|
|
2271
|
+
}
|
|
2272
|
+
await this.getTokenCache().removeAccount(request.account);
|
|
2273
|
+
}
|
|
2274
|
+
/**
|
|
2275
|
+
* Returns all cached accounts for this application. If brokering is enabled this request will be serviced by the broker.
|
|
2276
|
+
* @returns
|
|
2277
|
+
*/
|
|
2278
|
+
async getAllAccounts() {
|
|
2279
|
+
if (this.nativeBrokerPlugin) {
|
|
2280
|
+
const correlationId = this.cryptoProvider.createNewGuid();
|
|
2281
|
+
return this.nativeBrokerPlugin.getAllAccounts(this.config.auth.clientId, correlationId);
|
|
2282
|
+
}
|
|
2283
|
+
return this.getTokenCache().getAllAccounts();
|
|
2284
|
+
}
|
|
2166
2285
|
}
|
|
2167
2286
|
|
|
2168
2287
|
/*
|