@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
|
@@ -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
|
/*
|
|
@@ -128,16 +151,20 @@ class NetworkUtils {
|
|
|
128
151
|
* This class implements the API for network requests.
|
|
129
152
|
*/
|
|
130
153
|
class HttpClient {
|
|
154
|
+
constructor(proxyUrl, customAgentOptions) {
|
|
155
|
+
this.proxyUrl = proxyUrl || "";
|
|
156
|
+
this.customAgentOptions = customAgentOptions || {};
|
|
157
|
+
}
|
|
131
158
|
/**
|
|
132
159
|
* Http Get request
|
|
133
160
|
* @param url
|
|
134
161
|
* @param options
|
|
135
162
|
*/
|
|
136
163
|
async sendGetRequestAsync(url, options) {
|
|
137
|
-
if (
|
|
138
|
-
return networkRequestViaProxy(url, HttpMethod.GET, options);
|
|
164
|
+
if (this.proxyUrl) {
|
|
165
|
+
return networkRequestViaProxy(url, this.proxyUrl, HttpMethod.GET, options, this.customAgentOptions);
|
|
139
166
|
} else {
|
|
140
|
-
return networkRequestViaHttps(url, HttpMethod.GET, options);
|
|
167
|
+
return networkRequestViaHttps(url, HttpMethod.GET, options, this.customAgentOptions);
|
|
141
168
|
}
|
|
142
169
|
}
|
|
143
170
|
/**
|
|
@@ -146,18 +173,18 @@ class HttpClient {
|
|
|
146
173
|
* @param options
|
|
147
174
|
*/
|
|
148
175
|
async sendPostRequestAsync(url, options, cancellationToken) {
|
|
149
|
-
if (
|
|
150
|
-
return networkRequestViaProxy(url, HttpMethod.POST, options, cancellationToken);
|
|
176
|
+
if (this.proxyUrl) {
|
|
177
|
+
return networkRequestViaProxy(url, this.proxyUrl, HttpMethod.POST, options, this.customAgentOptions, cancellationToken);
|
|
151
178
|
} else {
|
|
152
|
-
return networkRequestViaHttps(url, HttpMethod.POST, options, cancellationToken);
|
|
179
|
+
return networkRequestViaHttps(url, HttpMethod.POST, options, this.customAgentOptions, cancellationToken);
|
|
153
180
|
}
|
|
154
181
|
}
|
|
155
182
|
}
|
|
156
|
-
const networkRequestViaProxy = (
|
|
157
|
-
const
|
|
158
|
-
const proxyUrl = new URL(
|
|
159
|
-
const destinationUrl = new URL(url);
|
|
183
|
+
const networkRequestViaProxy = (destinationUrlString, proxyUrlString, httpMethod, options, agentOptions, timeout) => {
|
|
184
|
+
const destinationUrl = new URL(destinationUrlString);
|
|
185
|
+
const proxyUrl = new URL(proxyUrlString);
|
|
160
186
|
// "method: connect" must be used to establish a connection to the proxy
|
|
187
|
+
const headers = (options == null ? void 0 : options.headers) || {};
|
|
161
188
|
const tunnelRequestOptions = {
|
|
162
189
|
host: proxyUrl.hostname,
|
|
163
190
|
port: proxyUrl.port,
|
|
@@ -168,6 +195,9 @@ const networkRequestViaProxy = (url, httpMethod, options, timeout) => {
|
|
|
168
195
|
if (timeout) {
|
|
169
196
|
tunnelRequestOptions.timeout = timeout;
|
|
170
197
|
}
|
|
198
|
+
if (agentOptions && Object.keys(agentOptions).length) {
|
|
199
|
+
tunnelRequestOptions.agent = new http__default.Agent(agentOptions);
|
|
200
|
+
}
|
|
171
201
|
// compose a request string for the socket
|
|
172
202
|
let postRequestStringContent = "";
|
|
173
203
|
if (httpMethod === HttpMethod.POST) {
|
|
@@ -265,17 +295,22 @@ const networkRequestViaProxy = (url, httpMethod, options, timeout) => {
|
|
|
265
295
|
});
|
|
266
296
|
});
|
|
267
297
|
};
|
|
268
|
-
const networkRequestViaHttps = (
|
|
298
|
+
const networkRequestViaHttps = (urlString, httpMethod, options, agentOptions, timeout) => {
|
|
269
299
|
const isPostRequest = httpMethod === HttpMethod.POST;
|
|
270
300
|
const body = (options == null ? void 0 : options.body) || "";
|
|
271
|
-
const
|
|
301
|
+
const url = new URL(urlString);
|
|
302
|
+
const headers = (options == null ? void 0 : options.headers) || {};
|
|
272
303
|
const customOptions = {
|
|
273
304
|
method: httpMethod,
|
|
274
|
-
headers:
|
|
305
|
+
headers: headers,
|
|
306
|
+
...NetworkUtils.urlToHttpOptions(url)
|
|
275
307
|
};
|
|
276
308
|
if (timeout) {
|
|
277
309
|
customOptions.timeout = timeout;
|
|
278
310
|
}
|
|
311
|
+
if (agentOptions && Object.keys(agentOptions).length) {
|
|
312
|
+
customOptions.agent = new https.Agent(agentOptions);
|
|
313
|
+
}
|
|
279
314
|
if (isPostRequest) {
|
|
280
315
|
// needed for post request to work
|
|
281
316
|
customOptions.headers = {
|
|
@@ -284,7 +319,7 @@ const networkRequestViaHttps = (url, httpMethod, options, timeout) => {
|
|
|
284
319
|
};
|
|
285
320
|
}
|
|
286
321
|
return new Promise((resolve, reject) => {
|
|
287
|
-
const request = https.request(
|
|
322
|
+
const request = https.request(customOptions);
|
|
288
323
|
if (timeout) {
|
|
289
324
|
request.on("timeout", () => {
|
|
290
325
|
request.destroy();
|
|
@@ -398,7 +433,8 @@ const DEFAULT_LOGGER_OPTIONS = {
|
|
|
398
433
|
const DEFAULT_SYSTEM_OPTIONS = {
|
|
399
434
|
loggerOptions: DEFAULT_LOGGER_OPTIONS,
|
|
400
435
|
networkClient: /*#__PURE__*/new HttpClient(),
|
|
401
|
-
proxyUrl: msalCommon.Constants.EMPTY_STRING
|
|
436
|
+
proxyUrl: msalCommon.Constants.EMPTY_STRING,
|
|
437
|
+
customAgentOptions: {}
|
|
402
438
|
};
|
|
403
439
|
const DEFAULT_TELEMETRY_OPTIONS = {
|
|
404
440
|
application: {
|
|
@@ -419,12 +455,14 @@ const DEFAULT_TELEMETRY_OPTIONS = {
|
|
|
419
455
|
*/
|
|
420
456
|
function buildAppConfiguration({
|
|
421
457
|
auth,
|
|
458
|
+
broker,
|
|
422
459
|
cache,
|
|
423
460
|
system,
|
|
424
461
|
telemetry
|
|
425
462
|
}) {
|
|
426
|
-
const
|
|
427
|
-
...
|
|
463
|
+
const systemOptions = {
|
|
464
|
+
...DEFAULT_SYSTEM_OPTIONS,
|
|
465
|
+
networkClient: new HttpClient(system == null ? void 0 : system.proxyUrl, system == null ? void 0 : system.customAgentOptions),
|
|
428
466
|
loggerOptions: (system == null ? void 0 : system.loggerOptions) || DEFAULT_LOGGER_OPTIONS
|
|
429
467
|
};
|
|
430
468
|
return {
|
|
@@ -432,13 +470,16 @@ function buildAppConfiguration({
|
|
|
432
470
|
...DEFAULT_AUTH_OPTIONS,
|
|
433
471
|
...auth
|
|
434
472
|
},
|
|
473
|
+
broker: {
|
|
474
|
+
...broker
|
|
475
|
+
},
|
|
435
476
|
cache: {
|
|
436
477
|
...DEFAULT_CACHE_OPTIONS,
|
|
437
478
|
...cache
|
|
438
479
|
},
|
|
439
480
|
system: {
|
|
440
|
-
...
|
|
441
|
-
...
|
|
481
|
+
...systemOptions,
|
|
482
|
+
...system
|
|
442
483
|
},
|
|
443
484
|
telemetry: {
|
|
444
485
|
...DEFAULT_TELEMETRY_OPTIONS,
|
|
@@ -1581,7 +1622,7 @@ class TokenCache {
|
|
|
1581
1622
|
|
|
1582
1623
|
/* eslint-disable header/header */
|
|
1583
1624
|
const name = "@azure/msal-node";
|
|
1584
|
-
const version = "1.
|
|
1625
|
+
const version = "1.16.0";
|
|
1585
1626
|
|
|
1586
1627
|
/*
|
|
1587
1628
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
@@ -1890,9 +1931,6 @@ class ClientApplication {
|
|
|
1890
1931
|
authority: discoveredAuthority,
|
|
1891
1932
|
clientCapabilities: this.config.auth.clientCapabilities
|
|
1892
1933
|
},
|
|
1893
|
-
systemOptions: {
|
|
1894
|
-
proxyUrl: this.config.system.proxyUrl
|
|
1895
|
-
},
|
|
1896
1934
|
loggerOptions: {
|
|
1897
1935
|
logLevel: this.config.system.loggerOptions.logLevel,
|
|
1898
1936
|
loggerCallback: this.config.system.loggerOptions.loggerCallback,
|
|
@@ -1979,7 +2017,7 @@ class ClientApplication {
|
|
|
1979
2017
|
azureRegionConfiguration,
|
|
1980
2018
|
skipAuthorityMetadataCache: this.config.auth.skipAuthorityMetadataCache
|
|
1981
2019
|
};
|
|
1982
|
-
return await msalCommon.AuthorityFactory.createDiscoveredInstance(authorityUrl, this.config.system.networkClient, this.storage, authorityOptions, this.logger
|
|
2020
|
+
return await msalCommon.AuthorityFactory.createDiscoveredInstance(authorityUrl, this.config.system.networkClient, this.storage, authorityOptions, this.logger);
|
|
1983
2021
|
}
|
|
1984
2022
|
/**
|
|
1985
2023
|
* Clear the cache
|
|
@@ -2098,6 +2136,14 @@ class PublicClientApplication extends ClientApplication {
|
|
|
2098
2136
|
*/
|
|
2099
2137
|
constructor(configuration) {
|
|
2100
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
|
+
}
|
|
2101
2147
|
}
|
|
2102
2148
|
/**
|
|
2103
2149
|
* Acquires a token from the authority using OAuth2.0 device code flow.
|
|
@@ -2126,24 +2172,46 @@ class PublicClientApplication extends ClientApplication {
|
|
|
2126
2172
|
}
|
|
2127
2173
|
}
|
|
2128
2174
|
/**
|
|
2129
|
-
* Acquires a token by requesting an
|
|
2175
|
+
* Acquires a token interactively via the browser by requesting an authorization code then exchanging it for a token.
|
|
2130
2176
|
*/
|
|
2131
2177
|
async acquireTokenInteractive(request) {
|
|
2132
|
-
const
|
|
2133
|
-
|
|
2134
|
-
challenge
|
|
2135
|
-
} = await this.cryptoProvider.generatePkceCodes();
|
|
2178
|
+
const correlationId = request.correlationId || this.cryptoProvider.createNewGuid();
|
|
2179
|
+
this.logger.trace("acquireTokenInteractive called", correlationId);
|
|
2136
2180
|
const {
|
|
2137
2181
|
openBrowser,
|
|
2138
2182
|
successTemplate,
|
|
2139
2183
|
errorTemplate,
|
|
2184
|
+
windowHandle,
|
|
2185
|
+
loopbackClient: customLoopbackClient,
|
|
2140
2186
|
...remainingProperties
|
|
2141
2187
|
} = request;
|
|
2142
|
-
|
|
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();
|
|
2143
2210
|
const authCodeListener = loopbackClient.listenForAuthCode(successTemplate, errorTemplate);
|
|
2144
2211
|
const redirectUri = loopbackClient.getRedirectUri();
|
|
2145
2212
|
const validRequest = {
|
|
2146
2213
|
...remainingProperties,
|
|
2214
|
+
correlationId: correlationId,
|
|
2147
2215
|
scopes: request.scopes || msalCommon.OIDC_DEFAULT_SCOPES,
|
|
2148
2216
|
redirectUri: redirectUri,
|
|
2149
2217
|
responseMode: msalCommon.ResponseMode.QUERY,
|
|
@@ -2169,6 +2237,57 @@ class PublicClientApplication extends ClientApplication {
|
|
|
2169
2237
|
};
|
|
2170
2238
|
return this.acquireTokenByCode(tokenRequest);
|
|
2171
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
|
+
}
|
|
2172
2291
|
}
|
|
2173
2292
|
|
|
2174
2293
|
/*
|