@azure/identity 4.1.1-alpha.20240419.1 → 4.1.1-alpha.20240422.3
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.
Potentially problematic release.
This version of @azure/identity might be problematic. Click here for more details.
- package/dist/index.js +71 -10
- package/dist/index.js.map +1 -1
- package/dist-esm/src/index.js +1 -0
- package/dist-esm/src/index.js.map +1 -1
- package/dist-esm/src/msal/nodeFlows/msalClient.js +13 -5
- package/dist-esm/src/msal/nodeFlows/msalClient.js.map +1 -1
- package/dist-esm/src/msal/nodeFlows/msalPlugins.js +6 -5
- package/dist-esm/src/msal/nodeFlows/msalPlugins.js.map +1 -1
- package/dist-esm/src/tokenProvider.js +52 -0
- package/dist-esm/src/tokenProvider.js.map +1 -0
- package/package.json +1 -1
- package/types/identity.d.ts +39 -0
package/dist/index.js
CHANGED
|
@@ -150,15 +150,16 @@ const msalNodeFlowNativeBrokerControl = {
|
|
|
150
150
|
* @returns plugin configuration
|
|
151
151
|
*/
|
|
152
152
|
function generatePluginConfiguration(options) {
|
|
153
|
-
var _a, _b, _c, _d, _e;
|
|
153
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
154
154
|
const config = {
|
|
155
155
|
cache: {},
|
|
156
156
|
broker: {
|
|
157
|
-
|
|
158
|
-
|
|
157
|
+
isEnabled: (_b = (_a = options.brokerOptions) === null || _a === void 0 ? void 0 : _a.enabled) !== null && _b !== void 0 ? _b : false,
|
|
158
|
+
enableMsaPassthrough: (_d = (_c = options.brokerOptions) === null || _c === void 0 ? void 0 : _c.legacyEnableMsaPassthrough) !== null && _d !== void 0 ? _d : false,
|
|
159
|
+
parentWindowHandle: (_e = options.brokerOptions) === null || _e === void 0 ? void 0 : _e.parentWindowHandle,
|
|
159
160
|
},
|
|
160
161
|
};
|
|
161
|
-
if ((
|
|
162
|
+
if ((_f = options.tokenCachePersistenceOptions) === null || _f === void 0 ? void 0 : _f.enabled) {
|
|
162
163
|
if (persistenceProvider === undefined) {
|
|
163
164
|
throw new Error([
|
|
164
165
|
"Persistent token caching was requested, but no persistence provider was configured.",
|
|
@@ -171,7 +172,7 @@ function generatePluginConfiguration(options) {
|
|
|
171
172
|
config.cache.cachePlugin = persistenceProvider(Object.assign({ name: `${cacheBaseName}.${CACHE_NON_CAE_SUFFIX}` }, options.tokenCachePersistenceOptions));
|
|
172
173
|
config.cache.cachePluginCae = persistenceProvider(Object.assign({ name: `${cacheBaseName}.${CACHE_CAE_SUFFIX}` }, options.tokenCachePersistenceOptions));
|
|
173
174
|
}
|
|
174
|
-
if ((
|
|
175
|
+
if ((_g = options.brokerOptions) === null || _g === void 0 ? void 0 : _g.enabled) {
|
|
175
176
|
if (nativeBrokerInfo === undefined) {
|
|
176
177
|
throw new Error([
|
|
177
178
|
"Broker for WAM was requested to be enabled, but no native broker was configured.",
|
|
@@ -1819,9 +1820,11 @@ function createMsalClient(clientId, tenantId, createMsalClientOptions = {}) {
|
|
|
1819
1820
|
const appKey = options.enableCae ? "CAE" : "default";
|
|
1820
1821
|
let confidentialClientApp = confidentialApps.get(appKey);
|
|
1821
1822
|
if (confidentialClientApp) {
|
|
1823
|
+
msalLogger.getToken.info("Existing ConfidentialClientApplication found in cache, returning it.");
|
|
1822
1824
|
return confidentialClientApp;
|
|
1823
1825
|
}
|
|
1824
1826
|
// Initialize a new app and cache it
|
|
1827
|
+
msalLogger.getToken.info(`Creating new ConfidentialClientApplication with CAE ${options.enableCae ? "enabled" : "disabled"}.`);
|
|
1825
1828
|
const cachePlugin = options.enableCae
|
|
1826
1829
|
? state.pluginConfiguration.cache.cachePluginCae
|
|
1827
1830
|
: state.pluginConfiguration.cache.cachePlugin;
|
|
@@ -1832,6 +1835,7 @@ function createMsalClient(clientId, tenantId, createMsalClientOptions = {}) {
|
|
|
1832
1835
|
}
|
|
1833
1836
|
async function getTokenSilent(app, scopes, options = {}) {
|
|
1834
1837
|
if (state.cachedAccount === null) {
|
|
1838
|
+
msalLogger.getToken.info("No cached account found in local state, attempting to load it from MSAL cache.");
|
|
1835
1839
|
const cache = app.getTokenCache();
|
|
1836
1840
|
const accounts = await cache.getAllAccounts();
|
|
1837
1841
|
if (accounts === undefined || accounts.length === 0) {
|
|
@@ -1851,14 +1855,19 @@ To work with multiple accounts for the same Client ID and Tenant ID, please prov
|
|
|
1851
1855
|
if (options.claims) {
|
|
1852
1856
|
state.cachedClaims = options.claims;
|
|
1853
1857
|
}
|
|
1854
|
-
|
|
1855
|
-
// https://github.com/Azure/azure-sdk-for-js/blob/727a7208251961b5036d8e1d86edaa944c42e3d6/sdk/identity/identity/src/msal/nodeFlows/msalNodeCommon.ts#L383-L395
|
|
1856
|
-
msalLogger.getToken.info("Attempting to acquire token silently");
|
|
1857
|
-
return app.acquireTokenSilent({
|
|
1858
|
+
const silentRequest = {
|
|
1858
1859
|
account: state.cachedAccount,
|
|
1859
1860
|
scopes,
|
|
1860
1861
|
claims: state.cachedClaims,
|
|
1861
|
-
}
|
|
1862
|
+
};
|
|
1863
|
+
if (state.pluginConfiguration.broker.isEnabled) {
|
|
1864
|
+
silentRequest.tokenQueryParameters || (silentRequest.tokenQueryParameters = {});
|
|
1865
|
+
if (state.pluginConfiguration.broker.enableMsaPassthrough) {
|
|
1866
|
+
silentRequest.tokenQueryParameters["msal_request_type"] = "consumer_passthrough";
|
|
1867
|
+
}
|
|
1868
|
+
}
|
|
1869
|
+
msalLogger.getToken.info("Attempting to acquire token silently");
|
|
1870
|
+
return app.acquireTokenSilent(silentRequest);
|
|
1862
1871
|
}
|
|
1863
1872
|
/**
|
|
1864
1873
|
* Performs silent authentication using MSAL to acquire an access token.
|
|
@@ -4546,6 +4555,57 @@ class OnBehalfOfCredential {
|
|
|
4546
4555
|
}
|
|
4547
4556
|
}
|
|
4548
4557
|
|
|
4558
|
+
// Copyright (c) Microsoft Corporation.
|
|
4559
|
+
// Licensed under the MIT license.
|
|
4560
|
+
/**
|
|
4561
|
+
* Returns a callback that provides a bearer token.
|
|
4562
|
+
* For example, the bearer token can be used to authenticate a request as follows:
|
|
4563
|
+
* ```js
|
|
4564
|
+
* import { DefaultAzureCredential } from "@azure/identity";
|
|
4565
|
+
*
|
|
4566
|
+
* const credential = new DefaultAzureCredential();
|
|
4567
|
+
* const scope = "https://cognitiveservices.azure.com/.default";
|
|
4568
|
+
* const getAccessToken = getBearerTokenProvider(credential, scope);
|
|
4569
|
+
* const token = await getAccessToken();
|
|
4570
|
+
*
|
|
4571
|
+
* // usage
|
|
4572
|
+
* const request = createPipelineRequest({ url: "https://example.com" });
|
|
4573
|
+
* request.headers.set("Authorization", `Bearer ${token}`);
|
|
4574
|
+
* ```
|
|
4575
|
+
*
|
|
4576
|
+
* @param credential - The credential used to authenticate the request.
|
|
4577
|
+
* @param scopes - The scopes required for the bearer token.
|
|
4578
|
+
* @param options - Options to configure the token provider.
|
|
4579
|
+
* @returns a callback that provides a bearer token.
|
|
4580
|
+
*/
|
|
4581
|
+
function getBearerTokenProvider(credential, scopes, options) {
|
|
4582
|
+
const { abortSignal, tracingOptions } = options || {};
|
|
4583
|
+
const pipeline = coreRestPipeline.createEmptyPipeline();
|
|
4584
|
+
pipeline.addPolicy(coreRestPipeline.bearerTokenAuthenticationPolicy({ credential, scopes }));
|
|
4585
|
+
async function getRefreshedToken() {
|
|
4586
|
+
var _a;
|
|
4587
|
+
// Create a pipeline with just the bearer token policy
|
|
4588
|
+
// and run a dummy request through it to get the token
|
|
4589
|
+
const res = await pipeline.sendRequest({
|
|
4590
|
+
sendRequest: (request) => Promise.resolve({
|
|
4591
|
+
request,
|
|
4592
|
+
status: 200,
|
|
4593
|
+
headers: request.headers,
|
|
4594
|
+
}),
|
|
4595
|
+
}, coreRestPipeline.createPipelineRequest({
|
|
4596
|
+
url: "https://example.com",
|
|
4597
|
+
abortSignal,
|
|
4598
|
+
tracingOptions,
|
|
4599
|
+
}));
|
|
4600
|
+
const accessToken = (_a = res.headers.get("authorization")) === null || _a === void 0 ? void 0 : _a.split(" ")[1];
|
|
4601
|
+
if (!accessToken) {
|
|
4602
|
+
throw new Error("Failed to get access token");
|
|
4603
|
+
}
|
|
4604
|
+
return accessToken;
|
|
4605
|
+
}
|
|
4606
|
+
return getRefreshedToken;
|
|
4607
|
+
}
|
|
4608
|
+
|
|
4549
4609
|
// Copyright (c) Microsoft Corporation.
|
|
4550
4610
|
// Licensed under the MIT license.
|
|
4551
4611
|
/**
|
|
@@ -4580,6 +4640,7 @@ exports.UsernamePasswordCredential = UsernamePasswordCredential;
|
|
|
4580
4640
|
exports.VisualStudioCodeCredential = VisualStudioCodeCredential;
|
|
4581
4641
|
exports.WorkloadIdentityCredential = WorkloadIdentityCredential;
|
|
4582
4642
|
exports.deserializeAuthenticationRecord = deserializeAuthenticationRecord;
|
|
4643
|
+
exports.getBearerTokenProvider = getBearerTokenProvider;
|
|
4583
4644
|
exports.getDefaultAzureCredential = getDefaultAzureCredential;
|
|
4584
4645
|
exports.logger = logger$p;
|
|
4585
4646
|
exports.serializeAuthenticationRecord = serializeAuthenticationRecord;
|