@azure/msal-node 1.15.0 → 1.17.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/dist/cache/NodeStorage.d.ts +3 -1
- package/dist/cache/NodeStorage.d.ts.map +1 -1
- package/dist/cache/distributed/IPartitionManager.d.ts +0 -4
- package/dist/cache/distributed/IPartitionManager.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 +16 -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 +139 -15
- 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 +139 -15
- package/dist/msal-node.esm.js.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/InteractiveRequest.d.ts +15 -0
- package/dist/request/InteractiveRequest.d.ts.map +1 -1
- package/dist/request/SignOutRequest.d.ts +6 -0
- package/dist/request/SignOutRequest.d.ts.map +1 -0
- package/dist/utils/NetworkUtils.d.ts +2 -1
- package/dist/utils/NetworkUtils.d.ts.map +1 -1
- package/package.json +2 -2
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
|
/*
|
|
@@ -151,11 +174,11 @@ class HttpClient {
|
|
|
151
174
|
}
|
|
152
175
|
}
|
|
153
176
|
}
|
|
154
|
-
const networkRequestViaProxy = (
|
|
155
|
-
const
|
|
177
|
+
const networkRequestViaProxy = (destinationUrlString, proxyUrlString, httpMethod, options, agentOptions, timeout) => {
|
|
178
|
+
const destinationUrl = new URL(destinationUrlString);
|
|
156
179
|
const proxyUrl = new URL(proxyUrlString);
|
|
157
|
-
const destinationUrl = new URL(url);
|
|
158
180
|
// "method: connect" must be used to establish a connection to the proxy
|
|
181
|
+
const headers = (options == null ? void 0 : options.headers) || {};
|
|
159
182
|
const tunnelRequestOptions = {
|
|
160
183
|
host: proxyUrl.hostname,
|
|
161
184
|
port: proxyUrl.port,
|
|
@@ -266,13 +289,15 @@ const networkRequestViaProxy = (url, proxyUrlString, httpMethod, options, agentO
|
|
|
266
289
|
});
|
|
267
290
|
});
|
|
268
291
|
};
|
|
269
|
-
const networkRequestViaHttps = (
|
|
292
|
+
const networkRequestViaHttps = (urlString, httpMethod, options, agentOptions, timeout) => {
|
|
270
293
|
const isPostRequest = httpMethod === HttpMethod.POST;
|
|
271
294
|
const body = (options == null ? void 0 : options.body) || "";
|
|
272
|
-
const
|
|
295
|
+
const url = new URL(urlString);
|
|
296
|
+
const headers = (options == null ? void 0 : options.headers) || {};
|
|
273
297
|
const customOptions = {
|
|
274
298
|
method: httpMethod,
|
|
275
|
-
headers:
|
|
299
|
+
headers: headers,
|
|
300
|
+
...NetworkUtils.urlToHttpOptions(url)
|
|
276
301
|
};
|
|
277
302
|
if (timeout) {
|
|
278
303
|
customOptions.timeout = timeout;
|
|
@@ -288,7 +313,7 @@ const networkRequestViaHttps = (url, httpMethod, options, agentOptions, timeout)
|
|
|
288
313
|
};
|
|
289
314
|
}
|
|
290
315
|
return new Promise((resolve, reject) => {
|
|
291
|
-
const request = https.request(
|
|
316
|
+
const request = https.request(customOptions);
|
|
292
317
|
if (timeout) {
|
|
293
318
|
request.on("timeout", () => {
|
|
294
319
|
request.destroy();
|
|
@@ -424,6 +449,7 @@ const DEFAULT_TELEMETRY_OPTIONS = {
|
|
|
424
449
|
*/
|
|
425
450
|
function buildAppConfiguration({
|
|
426
451
|
auth,
|
|
452
|
+
broker,
|
|
427
453
|
cache,
|
|
428
454
|
system,
|
|
429
455
|
telemetry
|
|
@@ -438,6 +464,9 @@ function buildAppConfiguration({
|
|
|
438
464
|
...DEFAULT_AUTH_OPTIONS,
|
|
439
465
|
...auth
|
|
440
466
|
},
|
|
467
|
+
broker: {
|
|
468
|
+
...broker
|
|
469
|
+
},
|
|
441
470
|
cache: {
|
|
442
471
|
...DEFAULT_CACHE_OPTIONS,
|
|
443
472
|
...cache
|
|
@@ -970,7 +999,7 @@ class Serializer {
|
|
|
970
999
|
*/
|
|
971
1000
|
class NodeStorage extends CacheManager {
|
|
972
1001
|
constructor(logger, clientId, cryptoImpl) {
|
|
973
|
-
super(clientId, cryptoImpl);
|
|
1002
|
+
super(clientId, cryptoImpl, logger);
|
|
974
1003
|
this.cache = {};
|
|
975
1004
|
this.changeEmitters = [];
|
|
976
1005
|
this.logger = logger;
|
|
@@ -1095,6 +1124,20 @@ class NodeStorage extends CacheManager {
|
|
|
1095
1124
|
// write to cache
|
|
1096
1125
|
this.setCache(cache);
|
|
1097
1126
|
}
|
|
1127
|
+
getAccountKeys() {
|
|
1128
|
+
const inMemoryCache = this.getInMemoryCache();
|
|
1129
|
+
const accountKeys = Object.keys(inMemoryCache.accounts);
|
|
1130
|
+
return accountKeys;
|
|
1131
|
+
}
|
|
1132
|
+
getTokenKeys() {
|
|
1133
|
+
const inMemoryCache = this.getInMemoryCache();
|
|
1134
|
+
const tokenKeys = {
|
|
1135
|
+
idToken: Object.keys(inMemoryCache.idTokens),
|
|
1136
|
+
accessToken: Object.keys(inMemoryCache.accessTokens),
|
|
1137
|
+
refreshToken: Object.keys(inMemoryCache.refreshTokens)
|
|
1138
|
+
};
|
|
1139
|
+
return tokenKeys;
|
|
1140
|
+
}
|
|
1098
1141
|
/**
|
|
1099
1142
|
* fetch the account entity
|
|
1100
1143
|
* @param accountKey - lookup key to fetch cache type AccountEntity
|
|
@@ -1587,7 +1630,7 @@ class TokenCache {
|
|
|
1587
1630
|
|
|
1588
1631
|
/* eslint-disable header/header */
|
|
1589
1632
|
const name = "@azure/msal-node";
|
|
1590
|
-
const version = "1.
|
|
1633
|
+
const version = "1.17.0";
|
|
1591
1634
|
|
|
1592
1635
|
/*
|
|
1593
1636
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
@@ -2101,6 +2144,14 @@ class PublicClientApplication extends ClientApplication {
|
|
|
2101
2144
|
*/
|
|
2102
2145
|
constructor(configuration) {
|
|
2103
2146
|
super(configuration);
|
|
2147
|
+
if (this.config.broker.nativeBrokerPlugin) {
|
|
2148
|
+
if (this.config.broker.nativeBrokerPlugin.isBrokerAvailable) {
|
|
2149
|
+
this.nativeBrokerPlugin = this.config.broker.nativeBrokerPlugin;
|
|
2150
|
+
this.nativeBrokerPlugin.setLogger(this.config.system.loggerOptions);
|
|
2151
|
+
} else {
|
|
2152
|
+
this.logger.warning("NativeBroker implementation was provided but the broker is unavailable.");
|
|
2153
|
+
}
|
|
2154
|
+
}
|
|
2104
2155
|
}
|
|
2105
2156
|
/**
|
|
2106
2157
|
* Acquires a token from the authority using OAuth2.0 device code flow.
|
|
@@ -2129,24 +2180,46 @@ class PublicClientApplication extends ClientApplication {
|
|
|
2129
2180
|
}
|
|
2130
2181
|
}
|
|
2131
2182
|
/**
|
|
2132
|
-
* Acquires a token by requesting an
|
|
2183
|
+
* Acquires a token interactively via the browser by requesting an authorization code then exchanging it for a token.
|
|
2133
2184
|
*/
|
|
2134
2185
|
async acquireTokenInteractive(request) {
|
|
2135
|
-
const
|
|
2136
|
-
|
|
2137
|
-
challenge
|
|
2138
|
-
} = await this.cryptoProvider.generatePkceCodes();
|
|
2186
|
+
const correlationId = request.correlationId || this.cryptoProvider.createNewGuid();
|
|
2187
|
+
this.logger.trace("acquireTokenInteractive called", correlationId);
|
|
2139
2188
|
const {
|
|
2140
2189
|
openBrowser,
|
|
2141
2190
|
successTemplate,
|
|
2142
2191
|
errorTemplate,
|
|
2192
|
+
windowHandle,
|
|
2193
|
+
loopbackClient: customLoopbackClient,
|
|
2143
2194
|
...remainingProperties
|
|
2144
2195
|
} = request;
|
|
2145
|
-
|
|
2196
|
+
if (this.nativeBrokerPlugin) {
|
|
2197
|
+
var _remainingProperties$;
|
|
2198
|
+
const brokerRequest = {
|
|
2199
|
+
...remainingProperties,
|
|
2200
|
+
clientId: this.config.auth.clientId,
|
|
2201
|
+
scopes: request.scopes || OIDC_DEFAULT_SCOPES,
|
|
2202
|
+
redirectUri: `${Constants.HTTP_PROTOCOL}${Constants.LOCALHOST}`,
|
|
2203
|
+
authority: request.authority || this.config.auth.authority,
|
|
2204
|
+
correlationId: correlationId,
|
|
2205
|
+
extraParameters: {
|
|
2206
|
+
...remainingProperties.extraQueryParameters,
|
|
2207
|
+
...remainingProperties.tokenQueryParameters
|
|
2208
|
+
},
|
|
2209
|
+
accountId: (_remainingProperties$ = remainingProperties.account) == null ? void 0 : _remainingProperties$.nativeAccountId
|
|
2210
|
+
};
|
|
2211
|
+
return this.nativeBrokerPlugin.acquireTokenInteractive(brokerRequest, windowHandle);
|
|
2212
|
+
}
|
|
2213
|
+
const {
|
|
2214
|
+
verifier,
|
|
2215
|
+
challenge
|
|
2216
|
+
} = await this.cryptoProvider.generatePkceCodes();
|
|
2217
|
+
const loopbackClient = customLoopbackClient || new LoopbackClient();
|
|
2146
2218
|
const authCodeListener = loopbackClient.listenForAuthCode(successTemplate, errorTemplate);
|
|
2147
2219
|
const redirectUri = loopbackClient.getRedirectUri();
|
|
2148
2220
|
const validRequest = {
|
|
2149
2221
|
...remainingProperties,
|
|
2222
|
+
correlationId: correlationId,
|
|
2150
2223
|
scopes: request.scopes || OIDC_DEFAULT_SCOPES,
|
|
2151
2224
|
redirectUri: redirectUri,
|
|
2152
2225
|
responseMode: ResponseMode.QUERY,
|
|
@@ -2172,6 +2245,57 @@ class PublicClientApplication extends ClientApplication {
|
|
|
2172
2245
|
};
|
|
2173
2246
|
return this.acquireTokenByCode(tokenRequest);
|
|
2174
2247
|
}
|
|
2248
|
+
/**
|
|
2249
|
+
* 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.
|
|
2250
|
+
* @param request
|
|
2251
|
+
* @returns
|
|
2252
|
+
*/
|
|
2253
|
+
async acquireTokenSilent(request) {
|
|
2254
|
+
const correlationId = request.correlationId || this.cryptoProvider.createNewGuid();
|
|
2255
|
+
this.logger.trace("acquireTokenSilent called", correlationId);
|
|
2256
|
+
if (this.nativeBrokerPlugin) {
|
|
2257
|
+
const brokerRequest = {
|
|
2258
|
+
...request,
|
|
2259
|
+
clientId: this.config.auth.clientId,
|
|
2260
|
+
scopes: request.scopes || OIDC_DEFAULT_SCOPES,
|
|
2261
|
+
redirectUri: `${Constants.HTTP_PROTOCOL}${Constants.LOCALHOST}`,
|
|
2262
|
+
authority: request.authority || this.config.auth.authority,
|
|
2263
|
+
correlationId: correlationId,
|
|
2264
|
+
extraParameters: request.tokenQueryParameters,
|
|
2265
|
+
accountId: request.account.nativeAccountId,
|
|
2266
|
+
forceRefresh: request.forceRefresh || false
|
|
2267
|
+
};
|
|
2268
|
+
return this.nativeBrokerPlugin.acquireTokenSilent(brokerRequest);
|
|
2269
|
+
}
|
|
2270
|
+
return super.acquireTokenSilent(request);
|
|
2271
|
+
}
|
|
2272
|
+
/**
|
|
2273
|
+
* Removes cache artifacts associated with the given account
|
|
2274
|
+
* @param request
|
|
2275
|
+
* @returns
|
|
2276
|
+
*/
|
|
2277
|
+
async signOut(request) {
|
|
2278
|
+
if (this.nativeBrokerPlugin && request.account.nativeAccountId) {
|
|
2279
|
+
const signoutRequest = {
|
|
2280
|
+
clientId: this.config.auth.clientId,
|
|
2281
|
+
accountId: request.account.nativeAccountId,
|
|
2282
|
+
correlationId: request.correlationId || this.cryptoProvider.createNewGuid()
|
|
2283
|
+
};
|
|
2284
|
+
await this.nativeBrokerPlugin.signOut(signoutRequest);
|
|
2285
|
+
}
|
|
2286
|
+
await this.getTokenCache().removeAccount(request.account);
|
|
2287
|
+
}
|
|
2288
|
+
/**
|
|
2289
|
+
* Returns all cached accounts for this application. If brokering is enabled this request will be serviced by the broker.
|
|
2290
|
+
* @returns
|
|
2291
|
+
*/
|
|
2292
|
+
async getAllAccounts() {
|
|
2293
|
+
if (this.nativeBrokerPlugin) {
|
|
2294
|
+
const correlationId = this.cryptoProvider.createNewGuid();
|
|
2295
|
+
return this.nativeBrokerPlugin.getAllAccounts(this.config.auth.clientId, correlationId);
|
|
2296
|
+
}
|
|
2297
|
+
return this.getTokenCache().getAllAccounts();
|
|
2298
|
+
}
|
|
2175
2299
|
}
|
|
2176
2300
|
|
|
2177
2301
|
/*
|