@azure/identity 3.2.0-alpha.20230308.2 → 3.2.0-alpha.20230323.2
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 +66 -29
- package/dist/index.js.map +1 -1
- package/dist-esm/src/client/identityClient.js +3 -2
- package/dist-esm/src/client/identityClient.js.map +1 -1
- package/dist-esm/src/credentials/managedIdentityCredential/appServiceMsi2017.js +2 -1
- package/dist-esm/src/credentials/managedIdentityCredential/appServiceMsi2017.js.map +1 -1
- package/dist-esm/src/credentials/managedIdentityCredential/appServiceMsi2019.js +2 -1
- package/dist-esm/src/credentials/managedIdentityCredential/appServiceMsi2019.js.map +1 -1
- package/dist-esm/src/credentials/managedIdentityCredential/arcMsi.js +2 -1
- package/dist-esm/src/credentials/managedIdentityCredential/arcMsi.js.map +1 -1
- package/dist-esm/src/credentials/managedIdentityCredential/cloudShellMsi.js +2 -1
- package/dist-esm/src/credentials/managedIdentityCredential/cloudShellMsi.js.map +1 -1
- package/dist-esm/src/credentials/managedIdentityCredential/fabricMsi.js +2 -1
- package/dist-esm/src/credentials/managedIdentityCredential/fabricMsi.js.map +1 -1
- package/dist-esm/src/credentials/managedIdentityCredential/imdsMsi.js +2 -1
- package/dist-esm/src/credentials/managedIdentityCredential/imdsMsi.js.map +1 -1
- package/dist-esm/src/credentials/managedIdentityCredential/index.js +32 -21
- package/dist-esm/src/credentials/managedIdentityCredential/index.js.map +1 -1
- package/dist-esm/src/credentials/managedIdentityCredential/models.js.map +1 -1
- package/dist-esm/src/credentials/managedIdentityCredential/utils.js +20 -1
- package/dist-esm/src/credentials/managedIdentityCredential/utils.js.map +1 -1
- package/package.json +2 -2
- package/types/identity.d.ts +1 -0
package/dist/index.js
CHANGED
|
@@ -667,7 +667,7 @@ function mapScopesToResource(scopes) {
|
|
|
667
667
|
* Given a token response, return the expiration timestamp as the number of milliseconds from the Unix epoch.
|
|
668
668
|
* @param body - A parsed response body from the authentication endpoint.
|
|
669
669
|
*/
|
|
670
|
-
function
|
|
670
|
+
function parseExpirationTimestamp(body) {
|
|
671
671
|
if (typeof body.expires_on === "number") {
|
|
672
672
|
return body.expires_on * 1000;
|
|
673
673
|
}
|
|
@@ -686,6 +686,25 @@ function parseExpiresOn(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
|
+
}
|
|
689
708
|
|
|
690
709
|
// Copyright (c) Microsoft Corporation.
|
|
691
710
|
const noCorrelationId = "noCorrelationId";
|
|
@@ -743,8 +762,9 @@ class IdentityClient extends coreClient.ServiceClient {
|
|
|
743
762
|
const token = {
|
|
744
763
|
accessToken: {
|
|
745
764
|
token: parsedBody.access_token,
|
|
746
|
-
expiresOnTimestamp:
|
|
765
|
+
expiresOnTimestamp: parseExpirationTimestamp(parsedBody),
|
|
747
766
|
},
|
|
767
|
+
refreshesIn: parseRefreshTimestamp(parsedBody),
|
|
748
768
|
refreshToken: parsedBody.refresh_token,
|
|
749
769
|
};
|
|
750
770
|
logger$n.info(`IdentityClient: [${request.url}] token acquired, expires on ${token.accessToken.expiresOnTimestamp}`);
|
|
@@ -1548,7 +1568,8 @@ const appServiceMsi2017 = {
|
|
|
1548
1568
|
// Generally, MSI endpoints use the HTTP protocol, without transport layer security (TLS).
|
|
1549
1569
|
allowInsecureConnection: true }));
|
|
1550
1570
|
const tokenResponse = await identityClient.sendTokenRequest(request);
|
|
1551
|
-
return (tokenResponse && tokenResponse.accessToken) ||
|
|
1571
|
+
return ((tokenResponse && Object.assign(Object.assign({}, tokenResponse.accessToken), { refreshesOn: tokenResponse.refreshesIn })) ||
|
|
1572
|
+
null);
|
|
1552
1573
|
},
|
|
1553
1574
|
};
|
|
1554
1575
|
|
|
@@ -1619,7 +1640,8 @@ const cloudShellMsi = {
|
|
|
1619
1640
|
// Generally, MSI endpoints use the HTTP protocol, without transport layer security (TLS).
|
|
1620
1641
|
allowInsecureConnection: true }));
|
|
1621
1642
|
const tokenResponse = await identityClient.sendTokenRequest(request);
|
|
1622
|
-
return (tokenResponse && tokenResponse.accessToken) ||
|
|
1643
|
+
return ((tokenResponse && Object.assign(Object.assign({}, tokenResponse.accessToken), { refreshesOn: tokenResponse.refreshesIn })) ||
|
|
1644
|
+
null);
|
|
1623
1645
|
},
|
|
1624
1646
|
};
|
|
1625
1647
|
|
|
@@ -1740,7 +1762,8 @@ const imdsMsi = {
|
|
|
1740
1762
|
try {
|
|
1741
1763
|
const request = coreRestPipeline.createPipelineRequest(Object.assign(Object.assign({ abortSignal: getTokenOptions.abortSignal }, prepareRequestOptions$3(scopes, clientId, resourceId)), { allowInsecureConnection: true }));
|
|
1742
1764
|
const tokenResponse = await identityClient.sendTokenRequest(request);
|
|
1743
|
-
return (tokenResponse && tokenResponse.accessToken) ||
|
|
1765
|
+
return ((tokenResponse && Object.assign(Object.assign({}, tokenResponse.accessToken), { refreshesOn: tokenResponse.refreshesIn })) ||
|
|
1766
|
+
null);
|
|
1744
1767
|
}
|
|
1745
1768
|
catch (error) {
|
|
1746
1769
|
if (error.statusCode === 404) {
|
|
@@ -1861,7 +1884,8 @@ const arcMsi = {
|
|
|
1861
1884
|
// Generally, MSI endpoints use the HTTP protocol, without transport layer security (TLS).
|
|
1862
1885
|
allowInsecureConnection: true }));
|
|
1863
1886
|
const tokenResponse = await identityClient.sendTokenRequest(request);
|
|
1864
|
-
return (tokenResponse && tokenResponse.accessToken) ||
|
|
1887
|
+
return ((tokenResponse && Object.assign(Object.assign({}, tokenResponse.accessToken), { refreshesOn: tokenResponse.refreshesIn })) ||
|
|
1888
|
+
null);
|
|
1865
1889
|
},
|
|
1866
1890
|
};
|
|
1867
1891
|
|
|
@@ -2160,7 +2184,8 @@ const fabricMsi = {
|
|
|
2160
2184
|
rejectUnauthorized: false,
|
|
2161
2185
|
});
|
|
2162
2186
|
const tokenResponse = await identityClient.sendTokenRequest(request);
|
|
2163
|
-
return (tokenResponse && tokenResponse.accessToken) ||
|
|
2187
|
+
return ((tokenResponse && Object.assign(Object.assign({}, tokenResponse.accessToken), { refreshesOn: tokenResponse.refreshesIn })) ||
|
|
2188
|
+
null);
|
|
2164
2189
|
},
|
|
2165
2190
|
};
|
|
2166
2191
|
|
|
@@ -2227,7 +2252,8 @@ const appServiceMsi2019 = {
|
|
|
2227
2252
|
// Generally, MSI endpoints use the HTTP protocol, without transport layer security (TLS).
|
|
2228
2253
|
allowInsecureConnection: true }));
|
|
2229
2254
|
const tokenResponse = await identityClient.sendTokenRequest(request);
|
|
2230
|
-
return (tokenResponse && tokenResponse.accessToken) ||
|
|
2255
|
+
return ((tokenResponse && Object.assign(Object.assign({}, tokenResponse.accessToken), { refreshesOn: tokenResponse.refreshesIn })) ||
|
|
2256
|
+
null);
|
|
2231
2257
|
},
|
|
2232
2258
|
};
|
|
2233
2259
|
|
|
@@ -2249,6 +2275,7 @@ class ManagedIdentityCredential {
|
|
|
2249
2275
|
constructor(clientIdOrOptions, options) {
|
|
2250
2276
|
var _a;
|
|
2251
2277
|
this.isEndpointUnavailable = null;
|
|
2278
|
+
this.isAppTokenProviderInitialized = false;
|
|
2252
2279
|
let _options;
|
|
2253
2280
|
if (typeof clientIdOrOptions === "string") {
|
|
2254
2281
|
this.clientId = clientIdOrOptions;
|
|
@@ -2357,27 +2384,37 @@ class ManagedIdentityCredential {
|
|
|
2357
2384
|
scopes: Array.isArray(scopes) ? scopes : [scopes],
|
|
2358
2385
|
claims: options === null || options === void 0 ? void 0 : options.claims,
|
|
2359
2386
|
};
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
logger$c.info(`SetAppTokenProvider
|
|
2365
|
-
const
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2387
|
+
// Added a check to see if SetAppTokenProvider was already defined.
|
|
2388
|
+
// Don't redefine it if it's already defined, since it should be static method.
|
|
2389
|
+
if (!this.isAppTokenProviderInitialized) {
|
|
2390
|
+
this.confidentialApp.SetAppTokenProvider(async (appTokenProviderParameters = appTokenParameters) => {
|
|
2391
|
+
logger$c.info(`SetAppTokenProvider invoked with parameters- ${JSON.stringify(appTokenProviderParameters)}`);
|
|
2392
|
+
const resultToken = await this.authenticateManagedIdentity(scopes, Object.assign(Object.assign({}, updatedOptions), appTokenProviderParameters));
|
|
2393
|
+
if (resultToken) {
|
|
2394
|
+
logger$c.info(`SetAppTokenProvider has saved the token in cache`);
|
|
2395
|
+
const expiresInSeconds = (resultToken === null || resultToken === void 0 ? void 0 : resultToken.expiresOnTimestamp)
|
|
2396
|
+
? Math.floor((resultToken.expiresOnTimestamp - Date.now()) / 1000)
|
|
2397
|
+
: 0;
|
|
2398
|
+
const refreshInSeconds = (resultToken === null || resultToken === void 0 ? void 0 : resultToken.refreshesOn)
|
|
2399
|
+
? Math.floor((resultToken.refreshesOn - Date.now()) / 1000)
|
|
2400
|
+
: 0;
|
|
2401
|
+
return {
|
|
2402
|
+
accessToken: resultToken === null || resultToken === void 0 ? void 0 : resultToken.token,
|
|
2403
|
+
expiresInSeconds,
|
|
2404
|
+
refreshInSeconds,
|
|
2405
|
+
};
|
|
2406
|
+
}
|
|
2407
|
+
else {
|
|
2408
|
+
logger$c.info(`SetAppTokenProvider token has "no_access_token_returned" as the saved token`);
|
|
2409
|
+
return {
|
|
2410
|
+
accessToken: "no_access_token_returned",
|
|
2411
|
+
expiresInSeconds: 0,
|
|
2412
|
+
refreshInSeconds: 0,
|
|
2413
|
+
};
|
|
2414
|
+
}
|
|
2415
|
+
});
|
|
2416
|
+
this.isAppTokenProviderInitialized = true;
|
|
2417
|
+
}
|
|
2381
2418
|
const authenticationResult = await this.confidentialApp.acquireTokenByClientCredential(Object.assign({}, appTokenParameters));
|
|
2382
2419
|
result = this.handleResult(scopes, authenticationResult || undefined);
|
|
2383
2420
|
}
|