@azure/identity-cache-persistence 1.1.2-alpha.20241112.1 → 1.1.2-alpha.20241114.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.
- package/dist/index.js.map +1 -1
- package/dist-esm/src/index.js.map +1 -0
- package/dist-esm/src/platforms.js.map +1 -0
- package/dist-esm/src/provider.js.map +1 -0
- package/package.json +3 -4
- package/dist-esm/identity/src/client/identityClient.js +0 -257
- package/dist-esm/identity/src/client/identityClient.js.map +0 -1
- package/dist-esm/identity/src/constants.js +0 -70
- package/dist-esm/identity/src/constants.js.map +0 -1
- package/dist-esm/identity/src/credentials/authorityValidationOptions.js +0 -4
- package/dist-esm/identity/src/credentials/authorityValidationOptions.js.map +0 -1
- package/dist-esm/identity/src/credentials/authorizationCodeCredential.js +0 -63
- package/dist-esm/identity/src/credentials/authorizationCodeCredential.js.map +0 -1
- package/dist-esm/identity/src/credentials/authorizationCodeCredentialOptions.js +0 -4
- package/dist-esm/identity/src/credentials/authorizationCodeCredentialOptions.js.map +0 -1
- package/dist-esm/identity/src/credentials/azureCliCredential.js +0 -194
- package/dist-esm/identity/src/credentials/azureCliCredential.js.map +0 -1
- package/dist-esm/identity/src/credentials/azureCliCredentialOptions.js +0 -4
- package/dist-esm/identity/src/credentials/azureCliCredentialOptions.js.map +0 -1
- package/dist-esm/identity/src/credentials/azureDeveloperCliCredential.js +0 -176
- package/dist-esm/identity/src/credentials/azureDeveloperCliCredential.js.map +0 -1
- package/dist-esm/identity/src/credentials/azureDeveloperCliCredentialOptions.js +0 -4
- package/dist-esm/identity/src/credentials/azureDeveloperCliCredentialOptions.js.map +0 -1
- package/dist-esm/identity/src/credentials/azurePipelinesCredential.js +0 -146
- package/dist-esm/identity/src/credentials/azurePipelinesCredential.js.map +0 -1
- package/dist-esm/identity/src/credentials/azurePipelinesCredentialOptions.js +0 -4
- package/dist-esm/identity/src/credentials/azurePipelinesCredentialOptions.js.map +0 -1
- package/dist-esm/identity/src/credentials/azurePowerShellCredential.js +0 -238
- package/dist-esm/identity/src/credentials/azurePowerShellCredential.js.map +0 -1
- package/dist-esm/identity/src/credentials/azurePowerShellCredentialOptions.js +0 -4
- package/dist-esm/identity/src/credentials/azurePowerShellCredentialOptions.js.map +0 -1
- package/dist-esm/identity/src/credentials/brokerAuthOptions.js +0 -2
- package/dist-esm/identity/src/credentials/brokerAuthOptions.js.map +0 -1
- package/dist-esm/identity/src/credentials/browserCustomizationOptions.js +0 -4
- package/dist-esm/identity/src/credentials/browserCustomizationOptions.js.map +0 -1
- package/dist-esm/identity/src/credentials/chainedTokenCredential.js +0 -95
- package/dist-esm/identity/src/credentials/chainedTokenCredential.js.map +0 -1
- package/dist-esm/identity/src/credentials/clientAssertionCredential.js +0 -58
- package/dist-esm/identity/src/credentials/clientAssertionCredential.js.map +0 -1
- package/dist-esm/identity/src/credentials/clientAssertionCredentialOptions.js +0 -4
- package/dist-esm/identity/src/credentials/clientAssertionCredentialOptions.js.map +0 -1
- package/dist-esm/identity/src/credentials/clientCertificateCredential.js +0 -126
- package/dist-esm/identity/src/credentials/clientCertificateCredential.js.map +0 -1
- package/dist-esm/identity/src/credentials/clientCertificateCredentialOptions.js +0 -4
- package/dist-esm/identity/src/credentials/clientCertificateCredentialOptions.js.map +0 -1
- package/dist-esm/identity/src/credentials/clientSecretCredential.js +0 -63
- package/dist-esm/identity/src/credentials/clientSecretCredential.js.map +0 -1
- package/dist-esm/identity/src/credentials/clientSecretCredentialOptions.js +0 -4
- package/dist-esm/identity/src/credentials/clientSecretCredentialOptions.js.map +0 -1
- package/dist-esm/identity/src/credentials/credentialPersistenceOptions.js +0 -4
- package/dist-esm/identity/src/credentials/credentialPersistenceOptions.js.map +0 -1
- package/dist-esm/identity/src/credentials/defaultAzureCredential.js +0 -164
- package/dist-esm/identity/src/credentials/defaultAzureCredential.js.map +0 -1
- package/dist-esm/identity/src/credentials/defaultAzureCredentialOptions.js +0 -4
- package/dist-esm/identity/src/credentials/defaultAzureCredentialOptions.js.map +0 -1
- package/dist-esm/identity/src/credentials/deviceCodeCredential.js +0 -96
- package/dist-esm/identity/src/credentials/deviceCodeCredential.js.map +0 -1
- package/dist-esm/identity/src/credentials/deviceCodeCredentialOptions.js +0 -4
- package/dist-esm/identity/src/credentials/deviceCodeCredentialOptions.js.map +0 -1
- package/dist-esm/identity/src/credentials/environmentCredential.js +0 -133
- package/dist-esm/identity/src/credentials/environmentCredential.js.map +0 -1
- package/dist-esm/identity/src/credentials/environmentCredentialOptions.js +0 -4
- package/dist-esm/identity/src/credentials/environmentCredentialOptions.js.map +0 -1
- package/dist-esm/identity/src/credentials/interactiveBrowserCredential.js +0 -96
- package/dist-esm/identity/src/credentials/interactiveBrowserCredential.js.map +0 -1
- package/dist-esm/identity/src/credentials/interactiveBrowserCredentialOptions.js +0 -4
- package/dist-esm/identity/src/credentials/interactiveBrowserCredentialOptions.js.map +0 -1
- package/dist-esm/identity/src/credentials/interactiveCredentialOptions.js +0 -4
- package/dist-esm/identity/src/credentials/interactiveCredentialOptions.js.map +0 -1
- package/dist-esm/identity/src/credentials/managedIdentityCredential/imdsMsi.js +0 -125
- package/dist-esm/identity/src/credentials/managedIdentityCredential/imdsMsi.js.map +0 -1
- package/dist-esm/identity/src/credentials/managedIdentityCredential/imdsRetryPolicy.js +0 -33
- package/dist-esm/identity/src/credentials/managedIdentityCredential/imdsRetryPolicy.js.map +0 -1
- package/dist-esm/identity/src/credentials/managedIdentityCredential/index.js +0 -220
- package/dist-esm/identity/src/credentials/managedIdentityCredential/index.js.map +0 -1
- package/dist-esm/identity/src/credentials/managedIdentityCredential/models.js +0 -4
- package/dist-esm/identity/src/credentials/managedIdentityCredential/models.js.map +0 -1
- package/dist-esm/identity/src/credentials/managedIdentityCredential/tokenExchangeMsi.js +0 -37
- package/dist-esm/identity/src/credentials/managedIdentityCredential/tokenExchangeMsi.js.map +0 -1
- package/dist-esm/identity/src/credentials/managedIdentityCredential/utils.js +0 -77
- package/dist-esm/identity/src/credentials/managedIdentityCredential/utils.js.map +0 -1
- package/dist-esm/identity/src/credentials/multiTenantTokenCredentialOptions.js +0 -4
- package/dist-esm/identity/src/credentials/multiTenantTokenCredentialOptions.js.map +0 -1
- package/dist-esm/identity/src/credentials/onBehalfOfCredential.js +0 -119
- package/dist-esm/identity/src/credentials/onBehalfOfCredential.js.map +0 -1
- package/dist-esm/identity/src/credentials/onBehalfOfCredentialOptions.js +0 -4
- package/dist-esm/identity/src/credentials/onBehalfOfCredentialOptions.js.map +0 -1
- package/dist-esm/identity/src/credentials/usernamePasswordCredential.js +0 -70
- package/dist-esm/identity/src/credentials/usernamePasswordCredential.js.map +0 -1
- package/dist-esm/identity/src/credentials/usernamePasswordCredentialOptions.js +0 -4
- package/dist-esm/identity/src/credentials/usernamePasswordCredentialOptions.js.map +0 -1
- package/dist-esm/identity/src/credentials/visualStudioCodeCredential.js +0 -195
- package/dist-esm/identity/src/credentials/visualStudioCodeCredential.js.map +0 -1
- package/dist-esm/identity/src/credentials/visualStudioCodeCredentialOptions.js +0 -4
- package/dist-esm/identity/src/credentials/visualStudioCodeCredentialOptions.js.map +0 -1
- package/dist-esm/identity/src/credentials/visualStudioCodeCredentialPlugin.js +0 -4
- package/dist-esm/identity/src/credentials/visualStudioCodeCredentialPlugin.js.map +0 -1
- package/dist-esm/identity/src/credentials/workloadIdentityCredential.js +0 -119
- package/dist-esm/identity/src/credentials/workloadIdentityCredential.js.map +0 -1
- package/dist-esm/identity/src/credentials/workloadIdentityCredentialOptions.js +0 -4
- package/dist-esm/identity/src/credentials/workloadIdentityCredentialOptions.js.map +0 -1
- package/dist-esm/identity/src/errors.js +0 -123
- package/dist-esm/identity/src/errors.js.map +0 -1
- package/dist-esm/identity/src/index.js +0 -34
- package/dist-esm/identity/src/index.js.map +0 -1
- package/dist-esm/identity/src/msal/msal.js +0 -5
- package/dist-esm/identity/src/msal/msal.js.map +0 -1
- package/dist-esm/identity/src/msal/nodeFlows/brokerOptions.js +0 -2
- package/dist-esm/identity/src/msal/nodeFlows/brokerOptions.js.map +0 -1
- package/dist-esm/identity/src/msal/nodeFlows/msalClient.js +0 -511
- package/dist-esm/identity/src/msal/nodeFlows/msalClient.js.map +0 -1
- package/dist-esm/identity/src/msal/nodeFlows/msalPlugins.js +0 -87
- package/dist-esm/identity/src/msal/nodeFlows/msalPlugins.js.map +0 -1
- package/dist-esm/identity/src/msal/nodeFlows/tokenCachePersistenceOptions.js +0 -4
- package/dist-esm/identity/src/msal/nodeFlows/tokenCachePersistenceOptions.js.map +0 -1
- package/dist-esm/identity/src/msal/types.js +0 -4
- package/dist-esm/identity/src/msal/types.js.map +0 -1
- package/dist-esm/identity/src/msal/utils.js +0 -232
- package/dist-esm/identity/src/msal/utils.js.map +0 -1
- package/dist-esm/identity/src/plugins/consumer.js +0 -43
- package/dist-esm/identity/src/plugins/consumer.js.map +0 -1
- package/dist-esm/identity/src/plugins/provider.js +0 -4
- package/dist-esm/identity/src/plugins/provider.js.map +0 -1
- package/dist-esm/identity/src/regionalAuthority.js +0 -140
- package/dist-esm/identity/src/regionalAuthority.js.map +0 -1
- package/dist-esm/identity/src/tokenCredentialOptions.js +0 -4
- package/dist-esm/identity/src/tokenCredentialOptions.js.map +0 -1
- package/dist-esm/identity/src/tokenProvider.js +0 -55
- package/dist-esm/identity/src/tokenProvider.js.map +0 -1
- package/dist-esm/identity/src/util/identityTokenEndpoint.js +0 -11
- package/dist-esm/identity/src/util/identityTokenEndpoint.js.map +0 -1
- package/dist-esm/identity/src/util/logging.js +0 -94
- package/dist-esm/identity/src/util/logging.js.map +0 -1
- package/dist-esm/identity/src/util/processMultiTenantRequest.js +0 -35
- package/dist-esm/identity/src/util/processMultiTenantRequest.js.map +0 -1
- package/dist-esm/identity/src/util/processUtils.js +0 -32
- package/dist-esm/identity/src/util/processUtils.js.map +0 -1
- package/dist-esm/identity/src/util/scopeUtils.js +0 -29
- package/dist-esm/identity/src/util/scopeUtils.js.map +0 -1
- package/dist-esm/identity/src/util/subscriptionUtils.js +0 -14
- package/dist-esm/identity/src/util/subscriptionUtils.js.map +0 -1
- package/dist-esm/identity/src/util/tenantIdUtils.js +0 -44
- package/dist-esm/identity/src/util/tenantIdUtils.js.map +0 -1
- package/dist-esm/identity/src/util/tracing.js +0 -14
- package/dist-esm/identity/src/util/tracing.js.map +0 -1
- package/dist-esm/identity-cache-persistence/src/index.js.map +0 -1
- package/dist-esm/identity-cache-persistence/src/platforms.js.map +0 -1
- package/dist-esm/identity-cache-persistence/src/provider.js.map +0 -1
- /package/dist-esm/{identity-cache-persistence/src → src}/index.js +0 -0
- /package/dist-esm/{identity-cache-persistence/src → src}/platforms.js +0 -0
- /package/dist-esm/{identity-cache-persistence/src → src}/provider.js +0 -0
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Microsoft Corporation.
|
|
2
|
-
// Licensed under the MIT License.
|
|
3
|
-
import { __awaiter } from "tslib";
|
|
4
|
-
import { AuthenticationError, CredentialUnavailableError } from "../errors";
|
|
5
|
-
import { credentialLogger, formatError, formatSuccess, processEnvVars } from "../util/logging";
|
|
6
|
-
import { ClientCertificateCredential } from "./clientCertificateCredential";
|
|
7
|
-
import { ClientSecretCredential } from "./clientSecretCredential";
|
|
8
|
-
import { UsernamePasswordCredential } from "./usernamePasswordCredential";
|
|
9
|
-
import { checkTenantId } from "../util/tenantIdUtils";
|
|
10
|
-
import { tracingClient } from "../util/tracing";
|
|
11
|
-
/**
|
|
12
|
-
* Contains the list of all supported environment variable names so that an
|
|
13
|
-
* appropriate error message can be generated when no credentials can be
|
|
14
|
-
* configured.
|
|
15
|
-
*
|
|
16
|
-
* @internal
|
|
17
|
-
*/
|
|
18
|
-
export const AllSupportedEnvironmentVariables = [
|
|
19
|
-
"AZURE_TENANT_ID",
|
|
20
|
-
"AZURE_CLIENT_ID",
|
|
21
|
-
"AZURE_CLIENT_SECRET",
|
|
22
|
-
"AZURE_CLIENT_CERTIFICATE_PATH",
|
|
23
|
-
"AZURE_CLIENT_CERTIFICATE_PASSWORD",
|
|
24
|
-
"AZURE_USERNAME",
|
|
25
|
-
"AZURE_PASSWORD",
|
|
26
|
-
"AZURE_ADDITIONALLY_ALLOWED_TENANTS",
|
|
27
|
-
"AZURE_CLIENT_SEND_CERTIFICATE_CHAIN",
|
|
28
|
-
];
|
|
29
|
-
function getAdditionallyAllowedTenants() {
|
|
30
|
-
var _a;
|
|
31
|
-
const additionallyAllowedValues = (_a = process.env.AZURE_ADDITIONALLY_ALLOWED_TENANTS) !== null && _a !== void 0 ? _a : "";
|
|
32
|
-
return additionallyAllowedValues.split(";");
|
|
33
|
-
}
|
|
34
|
-
const credentialName = "EnvironmentCredential";
|
|
35
|
-
const logger = credentialLogger(credentialName);
|
|
36
|
-
export function getSendCertificateChain() {
|
|
37
|
-
var _a;
|
|
38
|
-
const sendCertificateChain = ((_a = process.env.AZURE_CLIENT_SEND_CERTIFICATE_CHAIN) !== null && _a !== void 0 ? _a : "").toLowerCase();
|
|
39
|
-
const result = sendCertificateChain === "true" || sendCertificateChain === "1";
|
|
40
|
-
logger.verbose(`AZURE_CLIENT_SEND_CERTIFICATE_CHAIN: ${process.env.AZURE_CLIENT_SEND_CERTIFICATE_CHAIN}; sendCertificateChain: ${result}`);
|
|
41
|
-
return result;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Enables authentication to Microsoft Entra ID using a client secret or certificate, or as a user
|
|
45
|
-
* with a username and password.
|
|
46
|
-
*/
|
|
47
|
-
export class EnvironmentCredential {
|
|
48
|
-
/**
|
|
49
|
-
* Creates an instance of the EnvironmentCredential class and decides what credential to use depending on the available environment variables.
|
|
50
|
-
*
|
|
51
|
-
* Required environment variables:
|
|
52
|
-
* - `AZURE_TENANT_ID`: The Microsoft Entra tenant (directory) ID.
|
|
53
|
-
* - `AZURE_CLIENT_ID`: The client (application) ID of an App Registration in the tenant.
|
|
54
|
-
*
|
|
55
|
-
* If setting the AZURE_TENANT_ID, then you can also set the additionally allowed tenants
|
|
56
|
-
* - `AZURE_ADDITIONALLY_ALLOWED_TENANTS`: For multi-tenant applications, specifies additional tenants for which the credential may acquire tokens with a single semicolon delimited string. Use * to allow all tenants.
|
|
57
|
-
*
|
|
58
|
-
* Environment variables used for client credential authentication:
|
|
59
|
-
* - `AZURE_CLIENT_SECRET`: A client secret that was generated for the App Registration.
|
|
60
|
-
* - `AZURE_CLIENT_CERTIFICATE_PATH`: The path to a PEM certificate to use during the authentication, instead of the client secret.
|
|
61
|
-
* - `AZURE_CLIENT_CERTIFICATE_PASSWORD`: (optional) password for the certificate file.
|
|
62
|
-
* - `AZURE_CLIENT_SEND_CERTIFICATE_CHAIN`: (optional) indicates that the certificate chain should be set in x5c header to support subject name / issuer based authentication.
|
|
63
|
-
*
|
|
64
|
-
* Alternatively, users can provide environment variables for username and password authentication:
|
|
65
|
-
* - `AZURE_USERNAME`: Username to authenticate with.
|
|
66
|
-
* - `AZURE_PASSWORD`: Password to authenticate with.
|
|
67
|
-
*
|
|
68
|
-
* If the environment variables required to perform the authentication are missing, a {@link CredentialUnavailableError} will be thrown.
|
|
69
|
-
* If the authentication fails, or if there's an unknown error, an {@link AuthenticationError} will be thrown.
|
|
70
|
-
*
|
|
71
|
-
* @param options - Options for configuring the client which makes the authentication request.
|
|
72
|
-
*/
|
|
73
|
-
constructor(options) {
|
|
74
|
-
// Keep track of any missing environment variables for error details
|
|
75
|
-
this._credential = undefined;
|
|
76
|
-
const assigned = processEnvVars(AllSupportedEnvironmentVariables).assigned.join(", ");
|
|
77
|
-
logger.info(`Found the following environment variables: ${assigned}`);
|
|
78
|
-
const tenantId = process.env.AZURE_TENANT_ID, clientId = process.env.AZURE_CLIENT_ID, clientSecret = process.env.AZURE_CLIENT_SECRET;
|
|
79
|
-
const additionallyAllowedTenantIds = getAdditionallyAllowedTenants();
|
|
80
|
-
const sendCertificateChain = getSendCertificateChain();
|
|
81
|
-
const newOptions = Object.assign(Object.assign({}, options), { additionallyAllowedTenantIds, sendCertificateChain });
|
|
82
|
-
if (tenantId) {
|
|
83
|
-
checkTenantId(logger, tenantId);
|
|
84
|
-
}
|
|
85
|
-
if (tenantId && clientId && clientSecret) {
|
|
86
|
-
logger.info(`Invoking ClientSecretCredential with tenant ID: ${tenantId}, clientId: ${clientId} and clientSecret: [REDACTED]`);
|
|
87
|
-
this._credential = new ClientSecretCredential(tenantId, clientId, clientSecret, newOptions);
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
const certificatePath = process.env.AZURE_CLIENT_CERTIFICATE_PATH;
|
|
91
|
-
const certificatePassword = process.env.AZURE_CLIENT_CERTIFICATE_PASSWORD;
|
|
92
|
-
if (tenantId && clientId && certificatePath) {
|
|
93
|
-
logger.info(`Invoking ClientCertificateCredential with tenant ID: ${tenantId}, clientId: ${clientId} and certificatePath: ${certificatePath}`);
|
|
94
|
-
this._credential = new ClientCertificateCredential(tenantId, clientId, { certificatePath, certificatePassword }, newOptions);
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
const username = process.env.AZURE_USERNAME;
|
|
98
|
-
const password = process.env.AZURE_PASSWORD;
|
|
99
|
-
if (tenantId && clientId && username && password) {
|
|
100
|
-
logger.info(`Invoking UsernamePasswordCredential with tenant ID: ${tenantId}, clientId: ${clientId} and username: ${username}`);
|
|
101
|
-
this._credential = new UsernamePasswordCredential(tenantId, clientId, username, password, newOptions);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Authenticates with Microsoft Entra ID and returns an access token if successful.
|
|
106
|
-
*
|
|
107
|
-
* @param scopes - The list of scopes for which the token will have access.
|
|
108
|
-
* @param options - Optional parameters. See {@link GetTokenOptions}.
|
|
109
|
-
*/
|
|
110
|
-
getToken(scopes_1) {
|
|
111
|
-
return __awaiter(this, arguments, void 0, function* (scopes, options = {}) {
|
|
112
|
-
return tracingClient.withSpan(`${credentialName}.getToken`, options, (newOptions) => __awaiter(this, void 0, void 0, function* () {
|
|
113
|
-
if (this._credential) {
|
|
114
|
-
try {
|
|
115
|
-
const result = yield this._credential.getToken(scopes, newOptions);
|
|
116
|
-
logger.getToken.info(formatSuccess(scopes));
|
|
117
|
-
return result;
|
|
118
|
-
}
|
|
119
|
-
catch (err) {
|
|
120
|
-
const authenticationError = new AuthenticationError(400, {
|
|
121
|
-
error: `${credentialName} authentication failed. To troubleshoot, visit https://aka.ms/azsdk/js/identity/environmentcredential/troubleshoot.`,
|
|
122
|
-
error_description: err.message.toString().split("More details:").join(""),
|
|
123
|
-
});
|
|
124
|
-
logger.getToken.info(formatError(scopes, authenticationError));
|
|
125
|
-
throw authenticationError;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
throw new CredentialUnavailableError(`${credentialName} is unavailable. No underlying credential could be used. To troubleshoot, visit https://aka.ms/azsdk/js/identity/environmentcredential/troubleshoot.`);
|
|
129
|
-
}));
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
//# sourceMappingURL=environmentCredential.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"environmentCredential.js","sourceRoot":"","sources":["../../../../../identity/src/credentials/environmentCredential.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;;AAGlC,OAAO,EAAE,mBAAmB,EAAE,0BAA0B,EAAE,MAAM,WAAW,CAAC;AAC5E,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAE/F,OAAO,EAAE,2BAA2B,EAAE,MAAM,+BAA+B,CAAC;AAC5E,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAElE,OAAO,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAC1E,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,gCAAgC,GAA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from \"@azure/core-auth\";\nimport { AuthenticationError, CredentialUnavailableError } from \"../errors\";\nimport { credentialLogger, formatError, formatSuccess, processEnvVars } from \"../util/logging\";\n\nimport { ClientCertificateCredential } from \"./clientCertificateCredential\";\nimport { ClientSecretCredential } from \"./clientSecretCredential\";\nimport type { EnvironmentCredentialOptions } from \"./environmentCredentialOptions\";\nimport { UsernamePasswordCredential } from \"./usernamePasswordCredential\";\nimport { checkTenantId } from \"../util/tenantIdUtils\";\nimport { tracingClient } from \"../util/tracing\";\n\n/**\n * Contains the list of all supported environment variable names so that an\n * appropriate error message can be generated when no credentials can be\n * configured.\n *\n * @internal\n */\nexport const AllSupportedEnvironmentVariables = [\n \"AZURE_TENANT_ID\",\n \"AZURE_CLIENT_ID\",\n \"AZURE_CLIENT_SECRET\",\n \"AZURE_CLIENT_CERTIFICATE_PATH\",\n \"AZURE_CLIENT_CERTIFICATE_PASSWORD\",\n \"AZURE_USERNAME\",\n \"AZURE_PASSWORD\",\n \"AZURE_ADDITIONALLY_ALLOWED_TENANTS\",\n \"AZURE_CLIENT_SEND_CERTIFICATE_CHAIN\",\n];\n\nfunction getAdditionallyAllowedTenants(): string[] {\n const additionallyAllowedValues = process.env.AZURE_ADDITIONALLY_ALLOWED_TENANTS ?? \"\";\n return additionallyAllowedValues.split(\";\");\n}\n\nconst credentialName = \"EnvironmentCredential\";\nconst logger = credentialLogger(credentialName);\n\nexport function getSendCertificateChain(): boolean {\n const sendCertificateChain = (\n process.env.AZURE_CLIENT_SEND_CERTIFICATE_CHAIN ?? \"\"\n ).toLowerCase();\n const result = sendCertificateChain === \"true\" || sendCertificateChain === \"1\";\n logger.verbose(\n `AZURE_CLIENT_SEND_CERTIFICATE_CHAIN: ${process.env.AZURE_CLIENT_SEND_CERTIFICATE_CHAIN}; sendCertificateChain: ${result}`,\n );\n return result;\n}\n\n/**\n * Enables authentication to Microsoft Entra ID using a client secret or certificate, or as a user\n * with a username and password.\n */\nexport class EnvironmentCredential implements TokenCredential {\n private _credential?:\n | ClientSecretCredential\n | ClientCertificateCredential\n | UsernamePasswordCredential = undefined;\n /**\n * Creates an instance of the EnvironmentCredential class and decides what credential to use depending on the available environment variables.\n *\n * Required environment variables:\n * - `AZURE_TENANT_ID`: The Microsoft Entra tenant (directory) ID.\n * - `AZURE_CLIENT_ID`: The client (application) ID of an App Registration in the tenant.\n *\n * If setting the AZURE_TENANT_ID, then you can also set the additionally allowed tenants\n * - `AZURE_ADDITIONALLY_ALLOWED_TENANTS`: For multi-tenant applications, specifies additional tenants for which the credential may acquire tokens with a single semicolon delimited string. Use * to allow all tenants.\n *\n * Environment variables used for client credential authentication:\n * - `AZURE_CLIENT_SECRET`: A client secret that was generated for the App Registration.\n * - `AZURE_CLIENT_CERTIFICATE_PATH`: The path to a PEM certificate to use during the authentication, instead of the client secret.\n * - `AZURE_CLIENT_CERTIFICATE_PASSWORD`: (optional) password for the certificate file.\n * - `AZURE_CLIENT_SEND_CERTIFICATE_CHAIN`: (optional) indicates that the certificate chain should be set in x5c header to support subject name / issuer based authentication.\n *\n * Alternatively, users can provide environment variables for username and password authentication:\n * - `AZURE_USERNAME`: Username to authenticate with.\n * - `AZURE_PASSWORD`: Password to authenticate with.\n *\n * If the environment variables required to perform the authentication are missing, a {@link CredentialUnavailableError} will be thrown.\n * If the authentication fails, or if there's an unknown error, an {@link AuthenticationError} will be thrown.\n *\n * @param options - Options for configuring the client which makes the authentication request.\n */\n constructor(options?: EnvironmentCredentialOptions) {\n // Keep track of any missing environment variables for error details\n\n const assigned = processEnvVars(AllSupportedEnvironmentVariables).assigned.join(\", \");\n logger.info(`Found the following environment variables: ${assigned}`);\n\n const tenantId = process.env.AZURE_TENANT_ID,\n clientId = process.env.AZURE_CLIENT_ID,\n clientSecret = process.env.AZURE_CLIENT_SECRET;\n\n const additionallyAllowedTenantIds = getAdditionallyAllowedTenants();\n const sendCertificateChain = getSendCertificateChain();\n const newOptions = { ...options, additionallyAllowedTenantIds, sendCertificateChain };\n\n if (tenantId) {\n checkTenantId(logger, tenantId);\n }\n\n if (tenantId && clientId && clientSecret) {\n logger.info(\n `Invoking ClientSecretCredential with tenant ID: ${tenantId}, clientId: ${clientId} and clientSecret: [REDACTED]`,\n );\n this._credential = new ClientSecretCredential(tenantId, clientId, clientSecret, newOptions);\n return;\n }\n\n const certificatePath = process.env.AZURE_CLIENT_CERTIFICATE_PATH;\n const certificatePassword = process.env.AZURE_CLIENT_CERTIFICATE_PASSWORD;\n if (tenantId && clientId && certificatePath) {\n logger.info(\n `Invoking ClientCertificateCredential with tenant ID: ${tenantId}, clientId: ${clientId} and certificatePath: ${certificatePath}`,\n );\n this._credential = new ClientCertificateCredential(\n tenantId,\n clientId,\n { certificatePath, certificatePassword },\n newOptions,\n );\n return;\n }\n\n const username = process.env.AZURE_USERNAME;\n const password = process.env.AZURE_PASSWORD;\n if (tenantId && clientId && username && password) {\n logger.info(\n `Invoking UsernamePasswordCredential with tenant ID: ${tenantId}, clientId: ${clientId} and username: ${username}`,\n );\n this._credential = new UsernamePasswordCredential(\n tenantId,\n clientId,\n username,\n password,\n newOptions,\n );\n }\n }\n\n /**\n * Authenticates with Microsoft Entra ID and returns an access token if successful.\n *\n * @param scopes - The list of scopes for which the token will have access.\n * @param options - Optional parameters. See {@link GetTokenOptions}.\n */\n async getToken(scopes: string | string[], options: GetTokenOptions = {}): Promise<AccessToken> {\n return tracingClient.withSpan(`${credentialName}.getToken`, options, async (newOptions) => {\n if (this._credential) {\n try {\n const result = await this._credential.getToken(scopes, newOptions);\n logger.getToken.info(formatSuccess(scopes));\n return result;\n } catch (err: any) {\n const authenticationError = new AuthenticationError(400, {\n error: `${credentialName} authentication failed. To troubleshoot, visit https://aka.ms/azsdk/js/identity/environmentcredential/troubleshoot.`,\n error_description: err.message.toString().split(\"More details:\").join(\"\"),\n });\n logger.getToken.info(formatError(scopes, authenticationError));\n throw authenticationError;\n }\n }\n throw new CredentialUnavailableError(\n `${credentialName} is unavailable. No underlying credential could be used. To troubleshoot, visit https://aka.ms/azsdk/js/identity/environmentcredential/troubleshoot.`,\n );\n });\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"environmentCredentialOptions.js","sourceRoot":"","sources":["../../../../../identity/src/credentials/environmentCredentialOptions.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { AuthorityValidationOptions } from \"./authorityValidationOptions\";\nimport type { MultiTenantTokenCredentialOptions } from \"./multiTenantTokenCredentialOptions\";\n\n/**\n * Enables authentication to Microsoft Entra ID depending on the available environment variables.\n * Defines options for the EnvironmentCredential class.\n */\nexport interface EnvironmentCredentialOptions\n extends MultiTenantTokenCredentialOptions,\n AuthorityValidationOptions {}\n"]}
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Microsoft Corporation.
|
|
2
|
-
// Licensed under the MIT License.
|
|
3
|
-
import { __awaiter } from "tslib";
|
|
4
|
-
import { processMultiTenantRequest, resolveAdditionallyAllowedTenantIds, resolveTenantId, } from "../util/tenantIdUtils";
|
|
5
|
-
import { credentialLogger } from "../util/logging";
|
|
6
|
-
import { ensureScopes } from "../util/scopeUtils";
|
|
7
|
-
import { tracingClient } from "../util/tracing";
|
|
8
|
-
import { createMsalClient } from "../msal/nodeFlows/msalClient";
|
|
9
|
-
import { DeveloperSignOnClientId } from "../constants";
|
|
10
|
-
const logger = credentialLogger("InteractiveBrowserCredential");
|
|
11
|
-
/**
|
|
12
|
-
* Enables authentication to Microsoft Entra ID inside of the web browser
|
|
13
|
-
* using the interactive login flow.
|
|
14
|
-
*/
|
|
15
|
-
export class InteractiveBrowserCredential {
|
|
16
|
-
/**
|
|
17
|
-
* Creates an instance of InteractiveBrowserCredential with the details needed.
|
|
18
|
-
*
|
|
19
|
-
* This credential uses the [Authorization Code Flow](https://learn.microsoft.com/entra/identity-platform/v2-oauth2-auth-code-flow).
|
|
20
|
-
* On Node.js, it will open a browser window while it listens for a redirect response from the authentication service.
|
|
21
|
-
* On browsers, it authenticates via popups. The `loginStyle` optional parameter can be set to `redirect` to authenticate by redirecting the user to an Azure secure login page, which then will redirect the user back to the web application where the authentication started.
|
|
22
|
-
*
|
|
23
|
-
* For Node.js, if a `clientId` is provided, the Microsoft Entra application will need to be configured to have a "Mobile and desktop applications" redirect endpoint.
|
|
24
|
-
* Follow our guide on [setting up Redirect URIs for Desktop apps that calls to web APIs](https://learn.microsoft.com/entra/identity-platform/scenario-desktop-app-registration#redirect-uris).
|
|
25
|
-
*
|
|
26
|
-
* @param options - Options for configuring the client which makes the authentication requests.
|
|
27
|
-
*/
|
|
28
|
-
constructor(options) {
|
|
29
|
-
var _a, _b, _c, _d, _e;
|
|
30
|
-
this.tenantId = resolveTenantId(logger, options.tenantId, options.clientId);
|
|
31
|
-
this.additionallyAllowedTenantIds = resolveAdditionallyAllowedTenantIds(options === null || options === void 0 ? void 0 : options.additionallyAllowedTenants);
|
|
32
|
-
const msalClientOptions = Object.assign(Object.assign({}, options), { tokenCredentialOptions: options, logger });
|
|
33
|
-
const ibcNodeOptions = options;
|
|
34
|
-
this.browserCustomizationOptions = ibcNodeOptions.browserCustomizationOptions;
|
|
35
|
-
this.loginHint = ibcNodeOptions.loginHint;
|
|
36
|
-
if ((_a = ibcNodeOptions === null || ibcNodeOptions === void 0 ? void 0 : ibcNodeOptions.brokerOptions) === null || _a === void 0 ? void 0 : _a.enabled) {
|
|
37
|
-
if (!((_b = ibcNodeOptions === null || ibcNodeOptions === void 0 ? void 0 : ibcNodeOptions.brokerOptions) === null || _b === void 0 ? void 0 : _b.parentWindowHandle)) {
|
|
38
|
-
throw new Error("In order to do WAM authentication, `parentWindowHandle` under `brokerOptions` is a required parameter");
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
msalClientOptions.brokerOptions = {
|
|
42
|
-
enabled: true,
|
|
43
|
-
parentWindowHandle: ibcNodeOptions.brokerOptions.parentWindowHandle,
|
|
44
|
-
legacyEnableMsaPassthrough: (_c = ibcNodeOptions.brokerOptions) === null || _c === void 0 ? void 0 : _c.legacyEnableMsaPassthrough,
|
|
45
|
-
useDefaultBrokerAccount: (_d = ibcNodeOptions.brokerOptions) === null || _d === void 0 ? void 0 : _d.useDefaultBrokerAccount,
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
this.msalClient = createMsalClient((_e = options.clientId) !== null && _e !== void 0 ? _e : DeveloperSignOnClientId, this.tenantId, msalClientOptions);
|
|
50
|
-
this.disableAutomaticAuthentication = options === null || options === void 0 ? void 0 : options.disableAutomaticAuthentication;
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Authenticates with Microsoft Entra ID and returns an access token if successful.
|
|
54
|
-
* If authentication fails, a {@link CredentialUnavailableError} will be thrown with the details of the failure.
|
|
55
|
-
*
|
|
56
|
-
* If the user provided the option `disableAutomaticAuthentication`,
|
|
57
|
-
* once the token can't be retrieved silently,
|
|
58
|
-
* this method won't attempt to request user interaction to retrieve the token.
|
|
59
|
-
*
|
|
60
|
-
* @param scopes - The list of scopes for which the token will have access.
|
|
61
|
-
* @param options - The options used to configure any requests this
|
|
62
|
-
* TokenCredential implementation might make.
|
|
63
|
-
*/
|
|
64
|
-
getToken(scopes_1) {
|
|
65
|
-
return __awaiter(this, arguments, void 0, function* (scopes, options = {}) {
|
|
66
|
-
return tracingClient.withSpan(`${this.constructor.name}.getToken`, options, (newOptions) => __awaiter(this, void 0, void 0, function* () {
|
|
67
|
-
newOptions.tenantId = processMultiTenantRequest(this.tenantId, newOptions, this.additionallyAllowedTenantIds, logger);
|
|
68
|
-
const arrayScopes = ensureScopes(scopes);
|
|
69
|
-
return this.msalClient.getTokenByInteractiveRequest(arrayScopes, Object.assign(Object.assign({}, newOptions), { disableAutomaticAuthentication: this.disableAutomaticAuthentication, browserCustomizationOptions: this.browserCustomizationOptions, loginHint: this.loginHint }));
|
|
70
|
-
}));
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Authenticates with Microsoft Entra ID and returns an access token if successful.
|
|
75
|
-
* If authentication fails, a {@link CredentialUnavailableError} will be thrown with the details of the failure.
|
|
76
|
-
*
|
|
77
|
-
* If the token can't be retrieved silently, this method will always generate a challenge for the user.
|
|
78
|
-
*
|
|
79
|
-
* On Node.js, this credential has [Proof Key for Code Exchange (PKCE)](https://datatracker.ietf.org/doc/html/rfc7636) enabled by default.
|
|
80
|
-
* PKCE is a security feature that mitigates authentication code interception attacks.
|
|
81
|
-
*
|
|
82
|
-
* @param scopes - The list of scopes for which the token will have access.
|
|
83
|
-
* @param options - The options used to configure any requests this
|
|
84
|
-
* TokenCredential implementation might make.
|
|
85
|
-
*/
|
|
86
|
-
authenticate(scopes_1) {
|
|
87
|
-
return __awaiter(this, arguments, void 0, function* (scopes, options = {}) {
|
|
88
|
-
return tracingClient.withSpan(`${this.constructor.name}.authenticate`, options, (newOptions) => __awaiter(this, void 0, void 0, function* () {
|
|
89
|
-
const arrayScopes = ensureScopes(scopes);
|
|
90
|
-
yield this.msalClient.getTokenByInteractiveRequest(arrayScopes, Object.assign(Object.assign({}, newOptions), { disableAutomaticAuthentication: false, browserCustomizationOptions: this.browserCustomizationOptions, loginHint: this.loginHint }));
|
|
91
|
-
return this.msalClient.getActiveAccount();
|
|
92
|
-
}));
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
//# sourceMappingURL=interactiveBrowserCredential.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"interactiveBrowserCredential.js","sourceRoot":"","sources":["../../../../../identity/src/credentials/interactiveBrowserCredential.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;;AAOlC,OAAO,EACL,yBAAyB,EACzB,mCAAmC,EACnC,eAAe,GAChB,MAAM,uBAAuB,CAAC;AAG/B,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,C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AI,CAAC,UAAU,CAAC,4BAA4B,CAAC,WAAW,kCACzD,UAAU,KACb,8BAA8B,EAAE,KAAK,EACrC,2BAA2B,EAAE,IAAI,CAAC,2BAA2B,EAC7D,SAAS,EAAE,IAAI,CAAC,SAAS,IACzB,CAAC;gBACH,OAAO,IAAI,CAAC,UAAU,CAAC,gBAAgB,EAAE,CAAC;YAC5C,CAAC,CAAA,CACF,CAAC;QACJ,CAAC;KAAA;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { AccessToken, GetTokenOptions, TokenCredential } from \"@azure/core-auth\";\nimport type {\n InteractiveBrowserCredentialInBrowserOptions,\n InteractiveBrowserCredentialNodeOptions,\n} from \"./interactiveBrowserCredentialOptions\";\nimport {\n processMultiTenantRequest,\n resolveAdditionallyAllowedTenantIds,\n resolveTenantId,\n} from \"../util/tenantIdUtils\";\n\nimport type { AuthenticationRecord } from \"../msal/types\";\nimport { credentialLogger } from \"../util/logging\";\nimport { ensureScopes } from \"../util/scopeUtils\";\nimport { tracingClient } from \"../util/tracing\";\nimport type { MsalClient, MsalClientOptions } from \"../msal/nodeFlows/msalClient\";\nimport { createMsalClient } from \"../msal/nodeFlows/msalClient\";\nimport { DeveloperSignOnClientId } from \"../constants\";\n\nconst logger = credentialLogger(\"InteractiveBrowserCredential\");\n\n/**\n * Enables authentication to Microsoft Entra ID inside of the web browser\n * using the interactive login flow.\n */\nexport class InteractiveBrowserCredential implements TokenCredential {\n private tenantId?: string;\n private additionallyAllowedTenantIds: string[];\n private msalClient: MsalClient;\n private disableAutomaticAuthentication?: boolean;\n private browserCustomizationOptions: InteractiveBrowserCredentialNodeOptions[\"browserCustomizationOptions\"];\n private loginHint?: string;\n\n /**\n * Creates an instance of InteractiveBrowserCredential with the details needed.\n *\n * This credential uses the [Authorization Code Flow](https://learn.microsoft.com/entra/identity-platform/v2-oauth2-auth-code-flow).\n * On Node.js, it will open a browser window while it listens for a redirect response from the authentication service.\n * On browsers, it authenticates via popups. The `loginStyle` optional parameter can be set to `redirect` to authenticate by redirecting the user to an Azure secure login page, which then will redirect the user back to the web application where the authentication started.\n *\n * For Node.js, if a `clientId` is provided, the Microsoft Entra application will need to be configured to have a \"Mobile and desktop applications\" redirect endpoint.\n * Follow our guide on [setting up Redirect URIs for Desktop apps that calls to web APIs](https://learn.microsoft.com/entra/identity-platform/scenario-desktop-app-registration#redirect-uris).\n *\n * @param options - Options for configuring the client which makes the authentication requests.\n */\n constructor(\n options: InteractiveBrowserCredentialNodeOptions | InteractiveBrowserCredentialInBrowserOptions,\n ) {\n this.tenantId = resolveTenantId(logger, options.tenantId, options.clientId);\n this.additionallyAllowedTenantIds = resolveAdditionallyAllowedTenantIds(\n options?.additionallyAllowedTenants,\n );\n\n const msalClientOptions: MsalClientOptions = {\n ...options,\n tokenCredentialOptions: options,\n logger,\n };\n const ibcNodeOptions = options as InteractiveBrowserCredentialNodeOptions;\n this.browserCustomizationOptions = ibcNodeOptions.browserCustomizationOptions;\n this.loginHint = ibcNodeOptions.loginHint;\n if (ibcNodeOptions?.brokerOptions?.enabled) {\n if (!ibcNodeOptions?.brokerOptions?.parentWindowHandle) {\n throw new Error(\n \"In order to do WAM authentication, `parentWindowHandle` under `brokerOptions` is a required parameter\",\n );\n } else {\n msalClientOptions.brokerOptions = {\n enabled: true,\n parentWindowHandle: ibcNodeOptions.brokerOptions.parentWindowHandle,\n legacyEnableMsaPassthrough: ibcNodeOptions.brokerOptions?.legacyEnableMsaPassthrough,\n useDefaultBrokerAccount: ibcNodeOptions.brokerOptions?.useDefaultBrokerAccount,\n };\n }\n }\n this.msalClient = createMsalClient(\n options.clientId ?? DeveloperSignOnClientId,\n this.tenantId,\n msalClientOptions,\n );\n this.disableAutomaticAuthentication = options?.disableAutomaticAuthentication;\n }\n\n /**\n * Authenticates with Microsoft Entra ID and returns an access token if successful.\n * If authentication fails, a {@link CredentialUnavailableError} will be thrown with the details of the failure.\n *\n * If the user provided the option `disableAutomaticAuthentication`,\n * once the token can't be retrieved silently,\n * this method won't attempt to request user interaction to retrieve the token.\n *\n * @param scopes - The list of scopes for which the token will have access.\n * @param options - The options used to configure any requests this\n * TokenCredential implementation might make.\n */\n async getToken(scopes: string | string[], options: GetTokenOptions = {}): Promise<AccessToken> {\n return tracingClient.withSpan(\n `${this.constructor.name}.getToken`,\n options,\n async (newOptions) => {\n newOptions.tenantId = processMultiTenantRequest(\n this.tenantId,\n newOptions,\n this.additionallyAllowedTenantIds,\n logger,\n );\n\n const arrayScopes = ensureScopes(scopes);\n return this.msalClient.getTokenByInteractiveRequest(arrayScopes, {\n ...newOptions,\n disableAutomaticAuthentication: this.disableAutomaticAuthentication,\n browserCustomizationOptions: this.browserCustomizationOptions,\n loginHint: this.loginHint,\n });\n },\n );\n }\n\n /**\n * Authenticates with Microsoft Entra ID and returns an access token if successful.\n * If authentication fails, a {@link CredentialUnavailableError} will be thrown with the details of the failure.\n *\n * If the token can't be retrieved silently, this method will always generate a challenge for the user.\n *\n * On Node.js, this credential has [Proof Key for Code Exchange (PKCE)](https://datatracker.ietf.org/doc/html/rfc7636) enabled by default.\n * PKCE is a security feature that mitigates authentication code interception attacks.\n *\n * @param scopes - The list of scopes for which the token will have access.\n * @param options - The options used to configure any requests this\n * TokenCredential implementation might make.\n */\n async authenticate(\n scopes: string | string[],\n options: GetTokenOptions = {},\n ): Promise<AuthenticationRecord | undefined> {\n return tracingClient.withSpan(\n `${this.constructor.name}.authenticate`,\n options,\n async (newOptions) => {\n const arrayScopes = ensureScopes(scopes);\n await this.msalClient.getTokenByInteractiveRequest(arrayScopes, {\n ...newOptions,\n disableAutomaticAuthentication: false, // this method should always allow user interaction\n browserCustomizationOptions: this.browserCustomizationOptions,\n loginHint: this.loginHint,\n });\n return this.msalClient.getActiveAccount();\n },\n );\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"interactiveBrowserCredentialOptions.js","sourceRoot":"","sources":["../../../../../identity/src/credentials/interactiveBrowserCredentialOptions.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { BrowserCustomizationOptions } from \"./browserCustomizationOptions\";\nimport type { BrokerAuthOptions } from \"./brokerAuthOptions\";\nimport type { CredentialPersistenceOptions } from \"./credentialPersistenceOptions\";\nimport type { InteractiveCredentialOptions } from \"./interactiveCredentialOptions\";\n\n/**\n * (Browser-only feature)\n * The \"login style\" to use in the authentication flow:\n * - \"redirect\" redirects the user to the authentication page and then\n * redirects them back to the page once authentication is completed.\n * - \"popup\" opens a new browser window through with the redirect flow\n * is initiated. The user's existing browser window does not leave\n * the current page\n */\nexport type BrowserLoginStyle = \"redirect\" | \"popup\";\n\n/**\n * Defines the common options for the InteractiveBrowserCredential class.\n */\nexport interface InteractiveBrowserCredentialNodeOptions\n extends InteractiveCredentialOptions,\n CredentialPersistenceOptions,\n BrowserCustomizationOptions,\n BrokerAuthOptions {\n /**\n * Gets the redirect URI of the application. This should be same as the value\n * in the application registration portal. Defaults to `window.location.href`.\n * This field is no longer required for Node.js.\n */\n redirectUri?: string | (() => string);\n\n /**\n * The Microsoft Entra tenant (directory) ID.\n */\n tenantId?: string;\n\n /**\n * The Client ID of the Microsoft Entra application that users will sign into.\n * It is recommended that developers register their applications and assign appropriate roles.\n * For more information, visit https://aka.ms/identity/AppRegistrationAndRoleAssignment.\n * If not specified, users will authenticate to an Azure development application,\n * which is not recommended for production scenarios.\n */\n clientId?: string;\n\n /**\n * loginHint allows a user name to be pre-selected for interactive logins.\n * Setting this option skips the account selection prompt and immediately attempts to login with the specified account.\n */\n loginHint?: string;\n}\n\n/**\n * Defines the common options for the InteractiveBrowserCredential class.\n */\nexport interface InteractiveBrowserCredentialInBrowserOptions extends InteractiveCredentialOptions {\n /**\n * Gets the redirect URI of the application. This should be same as the value\n * in the application registration portal. Defaults to `window.location.href`.\n * This field is no longer required for Node.js.\n */\n redirectUri?: string | (() => string);\n\n /**\n * The Microsoft Entra tenant (directory) ID.\n */\n tenantId?: string;\n\n /**\n * The Client ID of the Microsoft Entra application that users will sign into.\n * This parameter is required on the browser.\n * Developers need to register their applications and assign appropriate roles.\n * For more information, visit https://aka.ms/identity/AppRegistrationAndRoleAssignment.\n */\n clientId: string;\n\n /**\n * Specifies whether a redirect or a popup window should be used to\n * initiate the user authentication flow. Possible values are \"redirect\"\n * or \"popup\" (default) for browser and \"popup\" (default) for node.\n *\n */\n loginStyle?: BrowserLoginStyle;\n\n /**\n * loginHint allows a user name to be pre-selected for interactive logins.\n * Setting this option skips the account selection prompt and immediately attempts to login with the specified account.\n */\n loginHint?: string;\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"interactiveCredentialOptions.js","sourceRoot":"","sources":["../../../../../identity/src/credentials/interactiveCredentialOptions.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { AuthenticationRecord } from \"../msal/types\";\nimport type { AuthorityValidationOptions } from \"./authorityValidationOptions\";\nimport type { MultiTenantTokenCredentialOptions } from \"./multiTenantTokenCredentialOptions\";\n\n/**\n * Common constructor options for the Identity credentials that requires user interaction.\n */\nexport interface InteractiveCredentialOptions\n extends MultiTenantTokenCredentialOptions,\n AuthorityValidationOptions {\n /**\n * Result of a previous authentication that can be used to retrieve the cached credentials of each individual account.\n * This is necessary to provide in case the application wants to work with more than one account per\n * Client ID and Tenant ID pair.\n *\n * This record can be retrieved by calling to the credential's `authenticate()` method, as follows:\n *\n * const authenticationRecord = await credential.authenticate();\n *\n */\n authenticationRecord?: AuthenticationRecord;\n\n /**\n * Makes getToken throw if a manual authentication is necessary.\n * Developers will need to call to `authenticate()` to control when to manually authenticate.\n */\n disableAutomaticAuthentication?: boolean;\n}\n"]}
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Microsoft Corporation.
|
|
2
|
-
// Licensed under the MIT License.
|
|
3
|
-
import { __awaiter } from "tslib";
|
|
4
|
-
import { createHttpHeaders, createPipelineRequest } from "@azure/core-rest-pipeline";
|
|
5
|
-
import { isError } from "@azure/core-util";
|
|
6
|
-
import { credentialLogger } from "../../util/logging";
|
|
7
|
-
import { mapScopesToResource } from "./utils";
|
|
8
|
-
import { tracingClient } from "../../util/tracing";
|
|
9
|
-
const msiName = "ManagedIdentityCredential - IMDS";
|
|
10
|
-
const logger = credentialLogger(msiName);
|
|
11
|
-
const imdsHost = "http://169.254.169.254";
|
|
12
|
-
const imdsEndpointPath = "/metadata/identity/oauth2/token";
|
|
13
|
-
const imdsApiVersion = "2018-02-01";
|
|
14
|
-
/**
|
|
15
|
-
* Generates the options used on the request for an access token.
|
|
16
|
-
*/
|
|
17
|
-
function prepareRequestOptions(scopes, clientId, resourceId, options) {
|
|
18
|
-
var _a;
|
|
19
|
-
const resource = mapScopesToResource(scopes);
|
|
20
|
-
if (!resource) {
|
|
21
|
-
throw new Error(`${msiName}: Multiple scopes are not supported.`);
|
|
22
|
-
}
|
|
23
|
-
const { skipQuery, skipMetadataHeader } = options || {};
|
|
24
|
-
let query = "";
|
|
25
|
-
// Pod Identity will try to process this request even if the Metadata header is missing.
|
|
26
|
-
// We can exclude the request query to ensure no IMDS endpoint tries to process the ping request.
|
|
27
|
-
if (!skipQuery) {
|
|
28
|
-
const queryParameters = {
|
|
29
|
-
resource,
|
|
30
|
-
"api-version": imdsApiVersion,
|
|
31
|
-
};
|
|
32
|
-
if (clientId) {
|
|
33
|
-
queryParameters.client_id = clientId;
|
|
34
|
-
}
|
|
35
|
-
if (resourceId) {
|
|
36
|
-
queryParameters.msi_res_id = resourceId;
|
|
37
|
-
}
|
|
38
|
-
const params = new URLSearchParams(queryParameters);
|
|
39
|
-
query = `?${params.toString()}`;
|
|
40
|
-
}
|
|
41
|
-
const url = new URL(imdsEndpointPath, (_a = process.env.AZURE_POD_IDENTITY_AUTHORITY_HOST) !== null && _a !== void 0 ? _a : imdsHost);
|
|
42
|
-
const rawHeaders = {
|
|
43
|
-
Accept: "application/json",
|
|
44
|
-
Metadata: "true",
|
|
45
|
-
};
|
|
46
|
-
// Remove the Metadata header to invoke a request error from some IMDS endpoints.
|
|
47
|
-
if (skipMetadataHeader) {
|
|
48
|
-
delete rawHeaders.Metadata;
|
|
49
|
-
}
|
|
50
|
-
return {
|
|
51
|
-
// In this case, the `?` should be added in the "query" variable `skipQuery` is not set.
|
|
52
|
-
url: `${url}${query}`,
|
|
53
|
-
method: "GET",
|
|
54
|
-
headers: createHttpHeaders(rawHeaders),
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Defines how to determine whether the Azure IMDS MSI is available.
|
|
59
|
-
*
|
|
60
|
-
* Actually getting the token once we determine IMDS is available is handled by MSAL.
|
|
61
|
-
*/
|
|
62
|
-
export const imdsMsi = {
|
|
63
|
-
name: "imdsMsi",
|
|
64
|
-
isAvailable(options) {
|
|
65
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
66
|
-
const { scopes, identityClient, clientId, resourceId, getTokenOptions } = options;
|
|
67
|
-
const resource = mapScopesToResource(scopes);
|
|
68
|
-
if (!resource) {
|
|
69
|
-
logger.info(`${msiName}: Unavailable. Multiple scopes are not supported.`);
|
|
70
|
-
return false;
|
|
71
|
-
}
|
|
72
|
-
// if the PodIdentityEndpoint environment variable was set no need to probe the endpoint, it can be assumed to exist
|
|
73
|
-
if (process.env.AZURE_POD_IDENTITY_AUTHORITY_HOST) {
|
|
74
|
-
return true;
|
|
75
|
-
}
|
|
76
|
-
if (!identityClient) {
|
|
77
|
-
throw new Error("Missing IdentityClient");
|
|
78
|
-
}
|
|
79
|
-
const requestOptions = prepareRequestOptions(resource, clientId, resourceId, {
|
|
80
|
-
skipMetadataHeader: true,
|
|
81
|
-
skipQuery: true,
|
|
82
|
-
});
|
|
83
|
-
return tracingClient.withSpan("ManagedIdentityCredential-pingImdsEndpoint", getTokenOptions !== null && getTokenOptions !== void 0 ? getTokenOptions : {}, (updatedOptions) => __awaiter(this, void 0, void 0, function* () {
|
|
84
|
-
var _a, _b;
|
|
85
|
-
requestOptions.tracingOptions = updatedOptions.tracingOptions;
|
|
86
|
-
// Create a request with a timeout since we expect that
|
|
87
|
-
// not having a "Metadata" header should cause an error to be
|
|
88
|
-
// returned quickly from the endpoint, proving its availability.
|
|
89
|
-
const request = createPipelineRequest(requestOptions);
|
|
90
|
-
// Default to 1000 if the default of 0 is used.
|
|
91
|
-
// Negative values can still be used to disable the timeout.
|
|
92
|
-
request.timeout = ((_a = updatedOptions.requestOptions) === null || _a === void 0 ? void 0 : _a.timeout) || 1000;
|
|
93
|
-
// This MSI uses the imdsEndpoint to get the token, which only uses http://
|
|
94
|
-
request.allowInsecureConnection = true;
|
|
95
|
-
let response;
|
|
96
|
-
try {
|
|
97
|
-
logger.info(`${msiName}: Pinging the Azure IMDS endpoint`);
|
|
98
|
-
response = yield identityClient.sendRequest(request);
|
|
99
|
-
}
|
|
100
|
-
catch (err) {
|
|
101
|
-
// If the request failed, or Node.js was unable to establish a connection,
|
|
102
|
-
// or the host was down, we'll assume the IMDS endpoint isn't available.
|
|
103
|
-
if (isError(err)) {
|
|
104
|
-
logger.verbose(`${msiName}: Caught error ${err.name}: ${err.message}`);
|
|
105
|
-
}
|
|
106
|
-
// This is a special case for Docker Desktop which responds with a 403 with a message that contains "A socket operation was attempted to an unreachable network" or "A socket operation was attempted to an unreachable host"
|
|
107
|
-
// rather than just timing out, as expected.
|
|
108
|
-
logger.info(`${msiName}: The Azure IMDS endpoint is unavailable`);
|
|
109
|
-
return false;
|
|
110
|
-
}
|
|
111
|
-
if (response.status === 403) {
|
|
112
|
-
if ((_b = response.bodyAsText) === null || _b === void 0 ? void 0 : _b.includes("unreachable")) {
|
|
113
|
-
logger.info(`${msiName}: The Azure IMDS endpoint is unavailable`);
|
|
114
|
-
logger.info(`${msiName}: ${response.bodyAsText}`);
|
|
115
|
-
return false;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
// If we received any response, the endpoint is available
|
|
119
|
-
logger.info(`${msiName}: The Azure IMDS endpoint is available`);
|
|
120
|
-
return true;
|
|
121
|
-
}));
|
|
122
|
-
});
|
|
123
|
-
},
|
|
124
|
-
};
|
|
125
|
-
//# sourceMappingURL=imdsMsi.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"imdsMsi.js","sourceRoot":"","sources":["../../../../../../identity/src/credentials/managedIdentityCredential/imdsMsi.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;;AAGlC,OAAO,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AACrF,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAG3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGnD,MAAM,OAAO,GAAG,kCAAkC,CAAC;AACnD,MAAM,MAAM,GAAG,gBAAgB,CAAC,OAAO,CAAC,CAAC;AAEzC,MAAM,QAAQ,GAAG,wBAAwB,CAAC;AAC1C,MAAM,gBAAgB,GAAG,iCAAiC,CAAC;AAC3D,MAAM,cAAc,GAAG,YAAY,CAAC;AAEpC;;GAEG;AACH,SAAS,qBAAqB,CAC5B,MAAyB,EACzB,QAAiB,EACjB,UAAmB,EACnB,OAGC;;IAED,MAAM,QAAQ,GAAG,mBAAmB,CAAC,MAAM,CAAC,CAAC;IAC7C,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,MAAM,IAAI,KAAK,CAAC,GAAG,OAAO,sCAAsC,CAAC,CAAC;IACpE,CAAC;IAED,MAAM,EAAE,SAAS,EAAE,kBAAkB,EAAE,GAAG,OAAO,IAAI,EAAE,CAAC;IACxD,IAAI,KAA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wBACjB,MAAM,CAAC,OAAO,CAAC,GAAG,OAAO,kBAAkB,GAAG,CAAC,IAAI,KAAK,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC;oBACzE,CAAC;oBACD,6NAA6N;oBAC7N,4CAA4C;oBAC5C,MAAM,CAAC,IAAI,CAAC,GAAG,OAAO,0CAA0C,CAAC,CAAC;oBAClE,OAAO,KAAK,CAAC;gBACf,CAAC;gBACD,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;oBAC5B,IAAI,MAAA,QAAQ,CAAC,UAAU,0CAAE,QAAQ,CAAC,aAAa,CAAC,EAAE,CAAC;wBACjD,MAAM,CAAC,IAAI,CAAC,GAAG,OAAO,0CAA0C,CAAC,CAAC;wBAClE,MAAM,CAAC,IAAI,CAAC,GAAG,OAAO,KAAK,QAAQ,CAAC,UAAU,EAAE,CAAC,CAAC;wBAClD,OAAO,KAAK,CAAC;oBACf,CAAC;gBACH,CAAC;gBACD,yDAAyD;gBACzD,MAAM,CAAC,IAAI,CAAC,GAAG,OAAO,wCAAwC,CAAC,CAAC;gBAChE,OAAO,IAAI,CAAC;YACd,CAAC,CAAA,CACF,CAAC;QACJ,CAAC;KAAA;CACF,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { PipelineRequestOptions, PipelineResponse } from \"@azure/core-rest-pipeline\";\nimport { createHttpHeaders, createPipelineRequest } from \"@azure/core-rest-pipeline\";\nimport { isError } from \"@azure/core-util\";\n\nimport type { GetTokenOptions } from \"@azure/core-auth\";\nimport { credentialLogger } from \"../../util/logging\";\nimport { mapScopesToResource } from \"./utils\";\nimport { tracingClient } from \"../../util/tracing\";\nimport { IdentityClient } from \"../../client/identityClient\";\n\nconst msiName = \"ManagedIdentityCredential - IMDS\";\nconst logger = credentialLogger(msiName);\n\nconst imdsHost = \"http://169.254.169.254\";\nconst imdsEndpointPath = \"/metadata/identity/oauth2/token\";\nconst imdsApiVersion = \"2018-02-01\";\n\n/**\n * Generates the options used on the request for an access token.\n */\nfunction prepareRequestOptions(\n scopes: string | string[],\n clientId?: string,\n resourceId?: string,\n options?: {\n skipQuery?: boolean;\n skipMetadataHeader?: boolean;\n },\n): PipelineRequestOptions {\n const resource = mapScopesToResource(scopes);\n if (!resource) {\n throw new Error(`${msiName}: Multiple scopes are not supported.`);\n }\n\n const { skipQuery, skipMetadataHeader } = options || {};\n let query = \"\";\n\n // Pod Identity will try to process this request even if the Metadata header is missing.\n // We can exclude the request query to ensure no IMDS endpoint tries to process the ping request.\n if (!skipQuery) {\n const queryParameters: Record<string, string> = {\n resource,\n \"api-version\": imdsApiVersion,\n };\n if (clientId) {\n queryParameters.client_id = clientId;\n }\n if (resourceId) {\n queryParameters.msi_res_id = resourceId;\n }\n const params = new URLSearchParams(queryParameters);\n query = `?${params.toString()}`;\n }\n\n const url = new URL(imdsEndpointPath, process.env.AZURE_POD_IDENTITY_AUTHORITY_HOST ?? imdsHost);\n\n const rawHeaders: Record<string, string> = {\n Accept: \"application/json\",\n Metadata: \"true\",\n };\n\n // Remove the Metadata header to invoke a request error from some IMDS endpoints.\n if (skipMetadataHeader) {\n delete rawHeaders.Metadata;\n }\n\n return {\n // In this case, the `?` should be added in the \"query\" variable `skipQuery` is not set.\n url: `${url}${query}`,\n method: \"GET\",\n headers: createHttpHeaders(rawHeaders),\n };\n}\n\n/**\n * Defines how to determine whether the Azure IMDS MSI is available.\n *\n * Actually getting the token once we determine IMDS is available is handled by MSAL.\n */\nexport const imdsMsi = {\n name: \"imdsMsi\",\n async isAvailable(options: {\n scopes: string | string[];\n identityClient?: IdentityClient;\n clientId?: string;\n resourceId?: string;\n getTokenOptions?: GetTokenOptions;\n }): Promise<boolean> {\n const { scopes, identityClient, clientId, resourceId, getTokenOptions } = options;\n const resource = mapScopesToResource(scopes);\n if (!resource) {\n logger.info(`${msiName}: Unavailable. Multiple scopes are not supported.`);\n return false;\n }\n\n // if the PodIdentityEndpoint environment variable was set no need to probe the endpoint, it can be assumed to exist\n if (process.env.AZURE_POD_IDENTITY_AUTHORITY_HOST) {\n return true;\n }\n\n if (!identityClient) {\n throw new Error(\"Missing IdentityClient\");\n }\n\n const requestOptions = prepareRequestOptions(resource, clientId, resourceId, {\n skipMetadataHeader: true,\n skipQuery: true,\n });\n\n return tracingClient.withSpan(\n \"ManagedIdentityCredential-pingImdsEndpoint\",\n getTokenOptions ?? {},\n async (updatedOptions) => {\n requestOptions.tracingOptions = updatedOptions.tracingOptions;\n\n // Create a request with a timeout since we expect that\n // not having a \"Metadata\" header should cause an error to be\n // returned quickly from the endpoint, proving its availability.\n const request = createPipelineRequest(requestOptions);\n\n // Default to 1000 if the default of 0 is used.\n // Negative values can still be used to disable the timeout.\n request.timeout = updatedOptions.requestOptions?.timeout || 1000;\n\n // This MSI uses the imdsEndpoint to get the token, which only uses http://\n request.allowInsecureConnection = true;\n let response: PipelineResponse;\n try {\n logger.info(`${msiName}: Pinging the Azure IMDS endpoint`);\n response = await identityClient.sendRequest(request);\n } catch (err: unknown) {\n // If the request failed, or Node.js was unable to establish a connection,\n // or the host was down, we'll assume the IMDS endpoint isn't available.\n if (isError(err)) {\n logger.verbose(`${msiName}: Caught error ${err.name}: ${err.message}`);\n }\n // This is a special case for Docker Desktop which responds with a 403 with a message that contains \"A socket operation was attempted to an unreachable network\" or \"A socket operation was attempted to an unreachable host\"\n // rather than just timing out, as expected.\n logger.info(`${msiName}: The Azure IMDS endpoint is unavailable`);\n return false;\n }\n if (response.status === 403) {\n if (response.bodyAsText?.includes(\"unreachable\")) {\n logger.info(`${msiName}: The Azure IMDS endpoint is unavailable`);\n logger.info(`${msiName}: ${response.bodyAsText}`);\n return false;\n }\n }\n // If we received any response, the endpoint is available\n logger.info(`${msiName}: The Azure IMDS endpoint is available`);\n return true;\n },\n );\n },\n};\n"]}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Microsoft Corporation.
|
|
2
|
-
// Licensed under the MIT License.
|
|
3
|
-
import { retryPolicy } from "@azure/core-rest-pipeline";
|
|
4
|
-
import { calculateRetryDelay } from "@azure/core-util";
|
|
5
|
-
// Matches the default retry configuration in expontentialRetryStrategy.ts
|
|
6
|
-
const DEFAULT_CLIENT_MAX_RETRY_INTERVAL = 1000 * 64;
|
|
7
|
-
/**
|
|
8
|
-
* An additional policy that retries on 404 errors. The default retry policy does not retry on
|
|
9
|
-
* 404s, but the IMDS endpoint can return 404s when the token is not yet available. This policy
|
|
10
|
-
* will retry on 404s with an exponential backoff.
|
|
11
|
-
*
|
|
12
|
-
* @param msiRetryConfig - The retry configuration for the MSI credential.
|
|
13
|
-
* @returns - The policy that will retry on 404s.
|
|
14
|
-
*/
|
|
15
|
-
export function imdsRetryPolicy(msiRetryConfig) {
|
|
16
|
-
return retryPolicy([
|
|
17
|
-
{
|
|
18
|
-
name: "imdsRetryPolicy",
|
|
19
|
-
retry: ({ retryCount, response }) => {
|
|
20
|
-
if ((response === null || response === void 0 ? void 0 : response.status) !== 404) {
|
|
21
|
-
return { skipStrategy: true };
|
|
22
|
-
}
|
|
23
|
-
return calculateRetryDelay(retryCount, {
|
|
24
|
-
retryDelayInMs: msiRetryConfig.startDelayInMs,
|
|
25
|
-
maxRetryDelayInMs: DEFAULT_CLIENT_MAX_RETRY_INTERVAL,
|
|
26
|
-
});
|
|
27
|
-
},
|
|
28
|
-
},
|
|
29
|
-
], {
|
|
30
|
-
maxRetries: msiRetryConfig.maxRetries,
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
//# sourceMappingURL=imdsRetryPolicy.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"imdsRetryPolicy.js","sourceRoot":"","sources":["../../../../../../identity/src/credentials/managedIdentityCredential/imdsRetryPolicy.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAGxD,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAEvD,0EAA0E;AAC1E,MAAM,iCAAiC,GAAG,IAAI,GAAG,EAAE,CAAC;AAEpD;;;;;;;GAOG;AACH,MAAM,UAAU,eAAe,CAAC,cAA+C;IAC7E,OAAO,WAAW,CAChB;QACE;YACE,IAAI,EAAE,iBAAiB;YACvB,KAAK,EAAE,CAAC,EAAE,UAAU,EAAE,QAAQ,EAAE,EAAE,EAAE;gBAClC,IAAI,CAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,MAAM,MAAK,GAAG,EAAE,CAAC;oBAC7B,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC;gBAChC,CAAC;gBAED,OAAO,mBAAmB,CAAC,UAAU,EAAE;oBACrC,cAAc,EAAE,cAAc,CAAC,cAAc;oBAC7C,iBAAiB,EAAE,iCAAiC;iBACrD,CAAC,CAAC;YACL,CAAC;SACF;KACF,EACD;QACE,UAAU,EAAE,cAAc,CAAC,UAAU;KACtC,CACF,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { PipelinePolicy } from \"@azure/core-rest-pipeline\";\nimport { retryPolicy } from \"@azure/core-rest-pipeline\";\n\nimport type { MSIConfiguration } from \"./models\";\nimport { calculateRetryDelay } from \"@azure/core-util\";\n\n// Matches the default retry configuration in expontentialRetryStrategy.ts\nconst DEFAULT_CLIENT_MAX_RETRY_INTERVAL = 1000 * 64;\n\n/**\n * An additional policy that retries on 404 errors. The default retry policy does not retry on\n * 404s, but the IMDS endpoint can return 404s when the token is not yet available. This policy\n * will retry on 404s with an exponential backoff.\n *\n * @param msiRetryConfig - The retry configuration for the MSI credential.\n * @returns - The policy that will retry on 404s.\n */\nexport function imdsRetryPolicy(msiRetryConfig: MSIConfiguration[\"retryConfig\"]): PipelinePolicy {\n return retryPolicy(\n [\n {\n name: \"imdsRetryPolicy\",\n retry: ({ retryCount, response }) => {\n if (response?.status !== 404) {\n return { skipStrategy: true };\n }\n\n return calculateRetryDelay(retryCount, {\n retryDelayInMs: msiRetryConfig.startDelayInMs,\n maxRetryDelayInMs: DEFAULT_CLIENT_MAX_RETRY_INTERVAL,\n });\n },\n },\n ],\n {\n maxRetries: msiRetryConfig.maxRetries,\n },\n );\n}\n"]}
|