@azure/identity 3.2.0-alpha.20230411.7 → 3.2.0-alpha.20230414.1

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.

Files changed (24) hide show
  1. package/dist/index.js +15 -39
  2. package/dist/index.js.map +1 -1
  3. package/dist-esm/src/client/identityClient.js +1 -2
  4. package/dist-esm/src/client/identityClient.js.map +1 -1
  5. package/dist-esm/src/credentials/managedIdentityCredential/appServiceMsi2017.js +1 -2
  6. package/dist-esm/src/credentials/managedIdentityCredential/appServiceMsi2017.js.map +1 -1
  7. package/dist-esm/src/credentials/managedIdentityCredential/appServiceMsi2019.js +1 -2
  8. package/dist-esm/src/credentials/managedIdentityCredential/appServiceMsi2019.js.map +1 -1
  9. package/dist-esm/src/credentials/managedIdentityCredential/arcMsi.js +1 -2
  10. package/dist-esm/src/credentials/managedIdentityCredential/arcMsi.js.map +1 -1
  11. package/dist-esm/src/credentials/managedIdentityCredential/cloudShellMsi.js +1 -2
  12. package/dist-esm/src/credentials/managedIdentityCredential/cloudShellMsi.js.map +1 -1
  13. package/dist-esm/src/credentials/managedIdentityCredential/fabricMsi.js +1 -2
  14. package/dist-esm/src/credentials/managedIdentityCredential/fabricMsi.js.map +1 -1
  15. package/dist-esm/src/credentials/managedIdentityCredential/imdsMsi.js +1 -2
  16. package/dist-esm/src/credentials/managedIdentityCredential/imdsMsi.js.map +1 -1
  17. package/dist-esm/src/credentials/managedIdentityCredential/index.js +0 -5
  18. package/dist-esm/src/credentials/managedIdentityCredential/index.js.map +1 -1
  19. package/dist-esm/src/credentials/managedIdentityCredential/models.js.map +1 -1
  20. package/dist-esm/src/credentials/managedIdentityCredential/utils.js +0 -19
  21. package/dist-esm/src/credentials/managedIdentityCredential/utils.js.map +1 -1
  22. package/dist-esm/src/msal/nodeFlows/msalNodeCommon.js +9 -2
  23. package/dist-esm/src/msal/nodeFlows/msalNodeCommon.js.map +1 -1
  24. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -686,25 +686,6 @@ function parseExpirationTimestamp(body) {
686
686
  }
687
687
  throw new Error(`Failed to parse token expiration from body. expires_in="${body.expires_in}", expires_on="${body.expires_on}"`);
688
688
  }
689
- /**
690
- * Given a token response, return the timestamp for refreshing token as the number of milliseconds from the Unix epoch.
691
- * @param body - A parsed response body from the authentication endpoint.
692
- */
693
- function parseRefreshTimestamp(body) {
694
- if (typeof body.refresh_in === "number") {
695
- return Date.now() + body.refresh_in * 1000;
696
- }
697
- else {
698
- const durationInMilliseconds = parseExpirationTimestamp(body) - Date.now();
699
- const durationInHours = Math.floor(durationInMilliseconds / 1000 / 60 / 60);
700
- if (durationInHours >= 2) {
701
- return Date.now() + durationInMilliseconds / 2;
702
- }
703
- else {
704
- return Date.now() + durationInMilliseconds;
705
- }
706
- }
707
- }
708
689
 
709
690
  // Copyright (c) Microsoft Corporation.
710
691
  const noCorrelationId = "noCorrelationId";
@@ -764,7 +745,6 @@ class IdentityClient extends coreClient.ServiceClient {
764
745
  token: parsedBody.access_token,
765
746
  expiresOnTimestamp: parseExpirationTimestamp(parsedBody),
766
747
  },
767
- refreshesIn: parseRefreshTimestamp(parsedBody),
768
748
  refreshToken: parsedBody.refresh_token,
769
749
  };
770
750
  logger$n.info(`IdentityClient: [${request.url}] token acquired, expires on ${token.accessToken.expiresOnTimestamp}`);
@@ -1217,7 +1197,7 @@ To work with multiple accounts for the same Client ID and Tenant ID, please prov
1217
1197
  * Attempts to retrieve a token from cache.
1218
1198
  */
1219
1199
  async getTokenSilent(scopes, options) {
1220
- var _a, _b;
1200
+ var _a, _b, _c;
1221
1201
  await this.getActiveAccount();
1222
1202
  if (!this.account) {
1223
1203
  throw new AuthenticationRequiredError({
@@ -1236,7 +1216,14 @@ To work with multiple accounts for the same Client ID and Tenant ID, please prov
1236
1216
  };
1237
1217
  try {
1238
1218
  this.logger.info("Attempting to acquire token silently");
1239
- const response = (_b = (await ((_a = this.confidentialApp) === null || _a === void 0 ? void 0 : _a.acquireTokenSilent(silentRequest)))) !== null && _b !== void 0 ? _b : (await this.publicApp.acquireTokenSilent(silentRequest));
1219
+ /**
1220
+ * The following code to retrieve all accounts is done as a workaround in an attempt to force the
1221
+ * refresh of the token cache with the token and the account passed in through the
1222
+ * `authenticationRecord` parameter. See issue - https://github.com/Azure/azure-sdk-for-js/issues/24349#issuecomment-1496715651
1223
+ * This workaround serves as a workoaround for silent authentication not happening when authenticationRecord is passed.
1224
+ */
1225
+ await ((_a = (this.publicApp || this.confidentialApp)) === null || _a === void 0 ? void 0 : _a.getTokenCache().getAllAccounts());
1226
+ const response = (_c = (await ((_b = this.confidentialApp) === null || _b === void 0 ? void 0 : _b.acquireTokenSilent(silentRequest)))) !== null && _c !== void 0 ? _c : (await this.publicApp.acquireTokenSilent(silentRequest));
1240
1227
  return this.handleResult(scopes, this.clientId, response || undefined);
1241
1228
  }
1242
1229
  catch (err) {
@@ -1568,8 +1555,7 @@ const appServiceMsi2017 = {
1568
1555
  // Generally, MSI endpoints use the HTTP protocol, without transport layer security (TLS).
1569
1556
  allowInsecureConnection: true }));
1570
1557
  const tokenResponse = await identityClient.sendTokenRequest(request);
1571
- return ((tokenResponse && Object.assign(Object.assign({}, tokenResponse.accessToken), { refreshesOn: tokenResponse.refreshesIn })) ||
1572
- null);
1558
+ return (tokenResponse && tokenResponse.accessToken) || null;
1573
1559
  },
1574
1560
  };
1575
1561
 
@@ -1640,8 +1626,7 @@ const cloudShellMsi = {
1640
1626
  // Generally, MSI endpoints use the HTTP protocol, without transport layer security (TLS).
1641
1627
  allowInsecureConnection: true }));
1642
1628
  const tokenResponse = await identityClient.sendTokenRequest(request);
1643
- return ((tokenResponse && Object.assign(Object.assign({}, tokenResponse.accessToken), { refreshesOn: tokenResponse.refreshesIn })) ||
1644
- null);
1629
+ return (tokenResponse && tokenResponse.accessToken) || null;
1645
1630
  },
1646
1631
  };
1647
1632
 
@@ -1762,8 +1747,7 @@ const imdsMsi = {
1762
1747
  try {
1763
1748
  const request = coreRestPipeline.createPipelineRequest(Object.assign(Object.assign({ abortSignal: getTokenOptions.abortSignal }, prepareRequestOptions$3(scopes, clientId, resourceId)), { allowInsecureConnection: true }));
1764
1749
  const tokenResponse = await identityClient.sendTokenRequest(request);
1765
- return ((tokenResponse && Object.assign(Object.assign({}, tokenResponse.accessToken), { refreshesOn: tokenResponse.refreshesIn })) ||
1766
- null);
1750
+ return (tokenResponse && tokenResponse.accessToken) || null;
1767
1751
  }
1768
1752
  catch (error) {
1769
1753
  if (error.statusCode === 404) {
@@ -1884,8 +1868,7 @@ const arcMsi = {
1884
1868
  // Generally, MSI endpoints use the HTTP protocol, without transport layer security (TLS).
1885
1869
  allowInsecureConnection: true }));
1886
1870
  const tokenResponse = await identityClient.sendTokenRequest(request);
1887
- return ((tokenResponse && Object.assign(Object.assign({}, tokenResponse.accessToken), { refreshesOn: tokenResponse.refreshesIn })) ||
1888
- null);
1871
+ return (tokenResponse && tokenResponse.accessToken) || null;
1889
1872
  },
1890
1873
  };
1891
1874
 
@@ -2175,8 +2158,7 @@ const fabricMsi = {
2175
2158
  rejectUnauthorized: false,
2176
2159
  });
2177
2160
  const tokenResponse = await identityClient.sendTokenRequest(request);
2178
- return ((tokenResponse && Object.assign(Object.assign({}, tokenResponse.accessToken), { refreshesOn: tokenResponse.refreshesIn })) ||
2179
- null);
2161
+ return (tokenResponse && tokenResponse.accessToken) || null;
2180
2162
  },
2181
2163
  };
2182
2164
 
@@ -2243,8 +2225,7 @@ const appServiceMsi2019 = {
2243
2225
  // Generally, MSI endpoints use the HTTP protocol, without transport layer security (TLS).
2244
2226
  allowInsecureConnection: true }));
2245
2227
  const tokenResponse = await identityClient.sendTokenRequest(request);
2246
- return ((tokenResponse && Object.assign(Object.assign({}, tokenResponse.accessToken), { refreshesOn: tokenResponse.refreshesIn })) ||
2247
- null);
2228
+ return (tokenResponse && tokenResponse.accessToken) || null;
2248
2229
  },
2249
2230
  };
2250
2231
 
@@ -2386,13 +2367,9 @@ class ManagedIdentityCredential {
2386
2367
  const expiresInSeconds = (resultToken === null || resultToken === void 0 ? void 0 : resultToken.expiresOnTimestamp)
2387
2368
  ? Math.floor((resultToken.expiresOnTimestamp - Date.now()) / 1000)
2388
2369
  : 0;
2389
- const refreshInSeconds = (resultToken === null || resultToken === void 0 ? void 0 : resultToken.refreshesOn)
2390
- ? Math.floor((resultToken.refreshesOn - Date.now()) / 1000)
2391
- : 0;
2392
2370
  return {
2393
2371
  accessToken: resultToken === null || resultToken === void 0 ? void 0 : resultToken.token,
2394
2372
  expiresInSeconds,
2395
- refreshInSeconds,
2396
2373
  };
2397
2374
  }
2398
2375
  else {
@@ -2400,7 +2377,6 @@ class ManagedIdentityCredential {
2400
2377
  return {
2401
2378
  accessToken: "no_access_token_returned",
2402
2379
  expiresInSeconds: 0,
2403
- refreshInSeconds: 0,
2404
2380
  };
2405
2381
  }
2406
2382
  });