@azure/identity-cache-persistence 1.1.2-alpha.20241111.1 → 1.1.2-alpha.20241113.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,70 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Microsoft Corporation.
|
|
2
|
-
// Licensed under the MIT License.
|
|
3
|
-
import { __awaiter } from "tslib";
|
|
4
|
-
import { createMsalClient } from "../msal/nodeFlows/msalClient";
|
|
5
|
-
import { processMultiTenantRequest, resolveAdditionallyAllowedTenantIds, } from "../util/tenantIdUtils";
|
|
6
|
-
import { CredentialUnavailableError } from "../errors";
|
|
7
|
-
import { credentialLogger } from "../util/logging";
|
|
8
|
-
import { ensureScopes } from "../util/scopeUtils";
|
|
9
|
-
import { tracingClient } from "../util/tracing";
|
|
10
|
-
const logger = credentialLogger("UsernamePasswordCredential");
|
|
11
|
-
/**
|
|
12
|
-
* Enables authentication to Microsoft Entra ID with a user's
|
|
13
|
-
* username and password. This credential requires a high degree of
|
|
14
|
-
* trust so you should only use it when other, more secure credential
|
|
15
|
-
* types can't be used.
|
|
16
|
-
*/
|
|
17
|
-
export class UsernamePasswordCredential {
|
|
18
|
-
/**
|
|
19
|
-
* Creates an instance of the UsernamePasswordCredential with the details
|
|
20
|
-
* needed to authenticate against Microsoft Entra ID with a username
|
|
21
|
-
* and password.
|
|
22
|
-
*
|
|
23
|
-
* @param tenantId - The Microsoft Entra tenant (directory).
|
|
24
|
-
* @param clientId - The client (application) ID of an App Registration in the tenant.
|
|
25
|
-
* @param username - The user account's e-mail address (user name).
|
|
26
|
-
* @param password - The user account's account password
|
|
27
|
-
* @param options - Options for configuring the client which makes the authentication request.
|
|
28
|
-
*/
|
|
29
|
-
constructor(tenantId, clientId, username, password, options = {}) {
|
|
30
|
-
if (!tenantId) {
|
|
31
|
-
throw new CredentialUnavailableError("UsernamePasswordCredential: tenantId is a required parameter. To troubleshoot, visit https://aka.ms/azsdk/js/identity/usernamepasswordcredential/troubleshoot.");
|
|
32
|
-
}
|
|
33
|
-
if (!clientId) {
|
|
34
|
-
throw new CredentialUnavailableError("UsernamePasswordCredential: clientId is a required parameter. To troubleshoot, visit https://aka.ms/azsdk/js/identity/usernamepasswordcredential/troubleshoot.");
|
|
35
|
-
}
|
|
36
|
-
if (!username) {
|
|
37
|
-
throw new CredentialUnavailableError("UsernamePasswordCredential: username is a required parameter. To troubleshoot, visit https://aka.ms/azsdk/js/identity/usernamepasswordcredential/troubleshoot.");
|
|
38
|
-
}
|
|
39
|
-
if (!password) {
|
|
40
|
-
throw new CredentialUnavailableError("UsernamePasswordCredential: password is a required parameter. To troubleshoot, visit https://aka.ms/azsdk/js/identity/usernamepasswordcredential/troubleshoot.");
|
|
41
|
-
}
|
|
42
|
-
this.tenantId = tenantId;
|
|
43
|
-
this.additionallyAllowedTenantIds = resolveAdditionallyAllowedTenantIds(options === null || options === void 0 ? void 0 : options.additionallyAllowedTenants);
|
|
44
|
-
this.username = username;
|
|
45
|
-
this.password = password;
|
|
46
|
-
this.msalClient = createMsalClient(clientId, this.tenantId, Object.assign(Object.assign({}, options), { tokenCredentialOptions: options !== null && options !== void 0 ? options : {} }));
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Authenticates with Microsoft Entra ID and returns an access token if successful.
|
|
50
|
-
* If authentication fails, a {@link CredentialUnavailableError} will be thrown with the details of the failure.
|
|
51
|
-
*
|
|
52
|
-
* If the user provided the option `disableAutomaticAuthentication`,
|
|
53
|
-
* once the token can't be retrieved silently,
|
|
54
|
-
* this method won't attempt to request user interaction to retrieve the token.
|
|
55
|
-
*
|
|
56
|
-
* @param scopes - The list of scopes for which the token will have access.
|
|
57
|
-
* @param options - The options used to configure any requests this
|
|
58
|
-
* TokenCredential implementation might make.
|
|
59
|
-
*/
|
|
60
|
-
getToken(scopes_1) {
|
|
61
|
-
return __awaiter(this, arguments, void 0, function* (scopes, options = {}) {
|
|
62
|
-
return tracingClient.withSpan(`${this.constructor.name}.getToken`, options, (newOptions) => __awaiter(this, void 0, void 0, function* () {
|
|
63
|
-
newOptions.tenantId = processMultiTenantRequest(this.tenantId, newOptions, this.additionallyAllowedTenantIds, logger);
|
|
64
|
-
const arrayScopes = ensureScopes(scopes);
|
|
65
|
-
return this.msalClient.getTokenByUsernamePassword(arrayScopes, this.username, this.password, newOptions);
|
|
66
|
-
}));
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
//# sourceMappingURL=usernamePasswordCredential.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"usernamePasswordCredential.js","sourceRoot":"","sources":["../../../../../identity/src/credentials/usernamePasswordCredential.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;;AAIlC,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EACL,yBAAyB,EACzB,mCAAmC,GACpC,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,0BAA0B,EAAE,MAAM,WAAW,CAAC;AAEvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,MAAM,MAAM,GAAG,gBAAgB,CAAC,4BAA4B,CAAC,CAAC;AAE9D;;;;;GAKG;AACH,MAAM,OAAO,0BAA0B;IA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EF,MAAM,WAAW,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC;gBACzC,OAAO,IAAI,CAAC,UAAU,CAAC,0BAA0B,CAC/C,WAAW,EACX,IAAI,CAAC,QAAQ,EACb,IAAI,CAAC,QAAQ,EACb,UAAU,CACX,CAAC;YACJ,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 { MsalClient } from \"../msal/nodeFlows/msalClient\";\nimport { createMsalClient } from \"../msal/nodeFlows/msalClient\";\nimport {\n processMultiTenantRequest,\n resolveAdditionallyAllowedTenantIds,\n} from \"../util/tenantIdUtils\";\n\nimport { CredentialUnavailableError } from \"../errors\";\nimport type { UsernamePasswordCredentialOptions } from \"./usernamePasswordCredentialOptions\";\nimport { credentialLogger } from \"../util/logging\";\nimport { ensureScopes } from \"../util/scopeUtils\";\nimport { tracingClient } from \"../util/tracing\";\n\nconst logger = credentialLogger(\"UsernamePasswordCredential\");\n\n/**\n * Enables authentication to Microsoft Entra ID with a user's\n * username and password. This credential requires a high degree of\n * trust so you should only use it when other, more secure credential\n * types can't be used.\n */\nexport class UsernamePasswordCredential implements TokenCredential {\n private tenantId: string;\n private additionallyAllowedTenantIds: string[];\n private msalClient: MsalClient;\n private username: string;\n private password: string;\n\n /**\n * Creates an instance of the UsernamePasswordCredential with the details\n * needed to authenticate against Microsoft Entra ID with a username\n * and password.\n *\n * @param tenantId - The Microsoft Entra tenant (directory).\n * @param clientId - The client (application) ID of an App Registration in the tenant.\n * @param username - The user account's e-mail address (user name).\n * @param password - The user account's account password\n * @param options - Options for configuring the client which makes the authentication request.\n */\n constructor(\n tenantId: string,\n clientId: string,\n username: string,\n password: string,\n options: UsernamePasswordCredentialOptions = {},\n ) {\n if (!tenantId) {\n throw new CredentialUnavailableError(\n \"UsernamePasswordCredential: tenantId is a required parameter. To troubleshoot, visit https://aka.ms/azsdk/js/identity/usernamepasswordcredential/troubleshoot.\",\n );\n }\n\n if (!clientId) {\n throw new CredentialUnavailableError(\n \"UsernamePasswordCredential: clientId is a required parameter. To troubleshoot, visit https://aka.ms/azsdk/js/identity/usernamepasswordcredential/troubleshoot.\",\n );\n }\n\n if (!username) {\n throw new CredentialUnavailableError(\n \"UsernamePasswordCredential: username is a required parameter. To troubleshoot, visit https://aka.ms/azsdk/js/identity/usernamepasswordcredential/troubleshoot.\",\n );\n }\n\n if (!password) {\n throw new CredentialUnavailableError(\n \"UsernamePasswordCredential: password is a required parameter. To troubleshoot, visit https://aka.ms/azsdk/js/identity/usernamepasswordcredential/troubleshoot.\",\n );\n }\n\n this.tenantId = tenantId;\n this.additionallyAllowedTenantIds = resolveAdditionallyAllowedTenantIds(\n options?.additionallyAllowedTenants,\n );\n\n this.username = username;\n this.password = password;\n\n this.msalClient = createMsalClient(clientId, this.tenantId, {\n ...options,\n tokenCredentialOptions: options ?? {},\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 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.getTokenByUsernamePassword(\n arrayScopes,\n this.username,\n this.password,\n newOptions,\n );\n },\n );\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"usernamePasswordCredentialOptions.js","sourceRoot":"","sources":["../../../../../identity/src/credentials/usernamePasswordCredentialOptions.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 { CredentialPersistenceOptions } from \"./credentialPersistenceOptions\";\nimport type { MultiTenantTokenCredentialOptions } from \"./multiTenantTokenCredentialOptions\";\n\n/**\n * Defines options for the {@link UsernamePasswordCredential} class.\n */\nexport interface UsernamePasswordCredentialOptions\n extends MultiTenantTokenCredentialOptions,\n CredentialPersistenceOptions,\n AuthorityValidationOptions {}\n"]}
|
|
@@ -1,195 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Microsoft Corporation.
|
|
2
|
-
// Licensed under the MIT License.
|
|
3
|
-
import { __awaiter } from "tslib";
|
|
4
|
-
import { credentialLogger, formatError, formatSuccess } from "../util/logging";
|
|
5
|
-
import { processMultiTenantRequest, resolveAdditionallyAllowedTenantIds, } from "../util/tenantIdUtils";
|
|
6
|
-
import { AzureAuthorityHosts } from "../constants";
|
|
7
|
-
import { CredentialUnavailableError } from "../errors";
|
|
8
|
-
import { IdentityClient } from "../client/identityClient";
|
|
9
|
-
import { checkTenantId } from "../util/tenantIdUtils";
|
|
10
|
-
import fs from "fs";
|
|
11
|
-
import os from "os";
|
|
12
|
-
import path from "path";
|
|
13
|
-
const CommonTenantId = "common";
|
|
14
|
-
const AzureAccountClientId = "aebc6443-996d-45c2-90f0-388ff96faa56"; // VSC: 'aebc6443-996d-45c2-90f0-388ff96faa56'
|
|
15
|
-
const logger = credentialLogger("VisualStudioCodeCredential");
|
|
16
|
-
let findCredentials = undefined;
|
|
17
|
-
export const vsCodeCredentialControl = {
|
|
18
|
-
setVsCodeCredentialFinder(finder) {
|
|
19
|
-
findCredentials = finder;
|
|
20
|
-
},
|
|
21
|
-
};
|
|
22
|
-
// Map of unsupported Tenant IDs and the errors we will be throwing.
|
|
23
|
-
const unsupportedTenantIds = {
|
|
24
|
-
adfs: "The VisualStudioCodeCredential does not support authentication with ADFS tenants.",
|
|
25
|
-
};
|
|
26
|
-
function checkUnsupportedTenant(tenantId) {
|
|
27
|
-
// If the Tenant ID isn't supported, we throw.
|
|
28
|
-
const unsupportedTenantError = unsupportedTenantIds[tenantId];
|
|
29
|
-
if (unsupportedTenantError) {
|
|
30
|
-
throw new CredentialUnavailableError(unsupportedTenantError);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
const mapVSCodeAuthorityHosts = {
|
|
34
|
-
AzureCloud: AzureAuthorityHosts.AzurePublicCloud,
|
|
35
|
-
AzureChina: AzureAuthorityHosts.AzureChina,
|
|
36
|
-
AzureGermanCloud: AzureAuthorityHosts.AzureGermany,
|
|
37
|
-
AzureUSGovernment: AzureAuthorityHosts.AzureGovernment,
|
|
38
|
-
};
|
|
39
|
-
/**
|
|
40
|
-
* Attempts to load a specific property from the VSCode configurations of the current OS.
|
|
41
|
-
* If it fails at any point, returns undefined.
|
|
42
|
-
*/
|
|
43
|
-
export function getPropertyFromVSCode(property) {
|
|
44
|
-
const settingsPath = ["User", "settings.json"];
|
|
45
|
-
// Eventually we can add more folders for more versions of VSCode.
|
|
46
|
-
const vsCodeFolder = "Code";
|
|
47
|
-
const homedir = os.homedir();
|
|
48
|
-
function loadProperty(...pathSegments) {
|
|
49
|
-
const fullPath = path.join(...pathSegments, vsCodeFolder, ...settingsPath);
|
|
50
|
-
const settings = JSON.parse(fs.readFileSync(fullPath, { encoding: "utf8" }));
|
|
51
|
-
return settings[property];
|
|
52
|
-
}
|
|
53
|
-
try {
|
|
54
|
-
let appData;
|
|
55
|
-
switch (process.platform) {
|
|
56
|
-
case "win32":
|
|
57
|
-
appData = process.env.APPDATA;
|
|
58
|
-
return appData ? loadProperty(appData) : undefined;
|
|
59
|
-
case "darwin":
|
|
60
|
-
return loadProperty(homedir, "Library", "Application Support");
|
|
61
|
-
case "linux":
|
|
62
|
-
return loadProperty(homedir, ".config");
|
|
63
|
-
default:
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
catch (e) {
|
|
68
|
-
logger.info(`Failed to load the Visual Studio Code configuration file. Error: ${e.message}`);
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Connects to Azure using the credential provided by the VSCode extension 'Azure Account'.
|
|
74
|
-
* Once the user has logged in via the extension, this credential can share the same refresh token
|
|
75
|
-
* that is cached by the extension.
|
|
76
|
-
*
|
|
77
|
-
* It's a [known issue](https://github.com/Azure/azure-sdk-for-js/issues/20500) that this credential doesn't
|
|
78
|
-
* work with [Azure Account extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode.azure-account)
|
|
79
|
-
* versions newer than **0.9.11**. A long-term fix to this problem is in progress. In the meantime, consider
|
|
80
|
-
* authenticating with {@link AzureCliCredential}.
|
|
81
|
-
*/
|
|
82
|
-
export class VisualStudioCodeCredential {
|
|
83
|
-
/**
|
|
84
|
-
* Creates an instance of VisualStudioCodeCredential to use for automatically authenticating via VSCode.
|
|
85
|
-
*
|
|
86
|
-
* **Note**: `VisualStudioCodeCredential` is provided by a plugin package:
|
|
87
|
-
* `@azure/identity-vscode`. If this package is not installed and registered
|
|
88
|
-
* using the plugin API (`useIdentityPlugin`), then authentication using
|
|
89
|
-
* `VisualStudioCodeCredential` will not be available.
|
|
90
|
-
*
|
|
91
|
-
* @param options - Options for configuring the client which makes the authentication request.
|
|
92
|
-
*/
|
|
93
|
-
constructor(options) {
|
|
94
|
-
// We want to make sure we use the one assigned by the user on the VSCode settings.
|
|
95
|
-
// Or just `AzureCloud` by default.
|
|
96
|
-
this.cloudName = (getPropertyFromVSCode("azure.cloud") || "AzureCloud");
|
|
97
|
-
// Picking an authority host based on the cloud name.
|
|
98
|
-
const authorityHost = mapVSCodeAuthorityHosts[this.cloudName];
|
|
99
|
-
this.identityClient = new IdentityClient(Object.assign({ authorityHost }, options));
|
|
100
|
-
if (options && options.tenantId) {
|
|
101
|
-
checkTenantId(logger, options.tenantId);
|
|
102
|
-
this.tenantId = options.tenantId;
|
|
103
|
-
}
|
|
104
|
-
else {
|
|
105
|
-
this.tenantId = CommonTenantId;
|
|
106
|
-
}
|
|
107
|
-
this.additionallyAllowedTenantIds = resolveAdditionallyAllowedTenantIds(options === null || options === void 0 ? void 0 : options.additionallyAllowedTenants);
|
|
108
|
-
checkUnsupportedTenant(this.tenantId);
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Runs preparations for any further getToken request.
|
|
112
|
-
*/
|
|
113
|
-
prepare() {
|
|
114
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
115
|
-
// Attempts to load the tenant from the VSCode configuration file.
|
|
116
|
-
const settingsTenant = getPropertyFromVSCode("azure.tenant");
|
|
117
|
-
if (settingsTenant) {
|
|
118
|
-
this.tenantId = settingsTenant;
|
|
119
|
-
}
|
|
120
|
-
checkUnsupportedTenant(this.tenantId);
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
/**
|
|
124
|
-
* Runs preparations for any further getToken, but only once.
|
|
125
|
-
*/
|
|
126
|
-
prepareOnce() {
|
|
127
|
-
if (!this.preparePromise) {
|
|
128
|
-
this.preparePromise = this.prepare();
|
|
129
|
-
}
|
|
130
|
-
return this.preparePromise;
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* Returns the token found by searching VSCode's authentication cache or
|
|
134
|
-
* returns null if no token could be found.
|
|
135
|
-
*
|
|
136
|
-
* @param scopes - The list of scopes for which the token will have access.
|
|
137
|
-
* @param options - The options used to configure any requests this
|
|
138
|
-
* `TokenCredential` implementation might make.
|
|
139
|
-
*/
|
|
140
|
-
getToken(scopes, options) {
|
|
141
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
142
|
-
var _a, _b;
|
|
143
|
-
yield this.prepareOnce();
|
|
144
|
-
const tenantId = processMultiTenantRequest(this.tenantId, options, this.additionallyAllowedTenantIds, logger) || this.tenantId;
|
|
145
|
-
if (findCredentials === undefined) {
|
|
146
|
-
throw new CredentialUnavailableError([
|
|
147
|
-
"No implementation of `VisualStudioCodeCredential` is available.",
|
|
148
|
-
"You must install the identity-vscode plugin package (`npm install --save-dev @azure/identity-vscode`)",
|
|
149
|
-
"and enable it by importing `useIdentityPlugin` from `@azure/identity` and calling",
|
|
150
|
-
"`useIdentityPlugin(vsCodePlugin)` before creating a `VisualStudioCodeCredential`.",
|
|
151
|
-
"To troubleshoot, visit https://aka.ms/azsdk/js/identity/vscodecredential/troubleshoot.",
|
|
152
|
-
].join(" "));
|
|
153
|
-
}
|
|
154
|
-
let scopeString = typeof scopes === "string" ? scopes : scopes.join(" ");
|
|
155
|
-
// Check to make sure the scope we get back is a valid scope
|
|
156
|
-
if (!scopeString.match(/^[0-9a-zA-Z-.:/]+$/)) {
|
|
157
|
-
const error = new Error("Invalid scope was specified by the user or calling client");
|
|
158
|
-
logger.getToken.info(formatError(scopes, error));
|
|
159
|
-
throw error;
|
|
160
|
-
}
|
|
161
|
-
if (scopeString.indexOf("offline_access") < 0) {
|
|
162
|
-
scopeString += " offline_access";
|
|
163
|
-
}
|
|
164
|
-
// findCredentials returns an array similar to:
|
|
165
|
-
// [
|
|
166
|
-
// {
|
|
167
|
-
// account: "",
|
|
168
|
-
// password: "",
|
|
169
|
-
// },
|
|
170
|
-
// /* ... */
|
|
171
|
-
// ]
|
|
172
|
-
const credentials = yield findCredentials();
|
|
173
|
-
// If we can't find the credential based on the name, we'll pick the first one available.
|
|
174
|
-
const { password: refreshToken } = (_b = (_a = credentials.find(({ account }) => account === this.cloudName)) !== null && _a !== void 0 ? _a : credentials[0]) !== null && _b !== void 0 ? _b : {};
|
|
175
|
-
if (refreshToken) {
|
|
176
|
-
const tokenResponse = yield this.identityClient.refreshAccessToken(tenantId, AzureAccountClientId, scopeString, refreshToken, undefined);
|
|
177
|
-
if (tokenResponse) {
|
|
178
|
-
logger.getToken.info(formatSuccess(scopes));
|
|
179
|
-
return tokenResponse.accessToken;
|
|
180
|
-
}
|
|
181
|
-
else {
|
|
182
|
-
const error = new CredentialUnavailableError("Could not retrieve the token associated with Visual Studio Code. Have you connected using the 'Azure Account' extension recently? To troubleshoot, visit https://aka.ms/azsdk/js/identity/vscodecredential/troubleshoot.");
|
|
183
|
-
logger.getToken.info(formatError(scopes, error));
|
|
184
|
-
throw error;
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
else {
|
|
188
|
-
const error = new CredentialUnavailableError("Could not retrieve the token associated with Visual Studio Code. Did you connect using the 'Azure Account' extension? To troubleshoot, visit https://aka.ms/azsdk/js/identity/vscodecredential/troubleshoot.");
|
|
189
|
-
logger.getToken.info(formatError(scopes, error));
|
|
190
|
-
throw error;
|
|
191
|
-
}
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
//# sourceMappingURL=visualStudioCodeCredential.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"visualStudioCodeCredential.js","sourceRoot":"","sources":["../../../../../identity/src/credentials/visualStudioCodeCredential.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;;AAGlC,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC/E,OAAO,EACL,yBAAyB,EACzB,mCAAmC,GACpC,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EAAE,0BAA0B,EAAE,MAAM,WAAW,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAG1D,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,MAAM,cAAc,GAAG,QAA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AA0N,CAC3N,CAAC;oBACF,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC;oBACjD,MAAM,KAAK,CAAC;gBACd,CAAC;YACH,CAAC;iBAAM,CAAC;gBACN,MAAM,KAAK,GAAG,IAAI,0BAA0B,CAC1C,8MAA8M,CAC/M,CAAC;gBACF,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC;gBACjD,MAAM,KAAK,CAAC;YACd,CAAC;QACH,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 { credentialLogger, formatError, formatSuccess } from \"../util/logging\";\nimport {\n processMultiTenantRequest,\n resolveAdditionallyAllowedTenantIds,\n} from \"../util/tenantIdUtils\";\nimport { AzureAuthorityHosts } from \"../constants\";\nimport { CredentialUnavailableError } from \"../errors\";\nimport { IdentityClient } from \"../client/identityClient\";\nimport type { VisualStudioCodeCredentialOptions } from \"./visualStudioCodeCredentialOptions\";\nimport type { VSCodeCredentialFinder } from \"./visualStudioCodeCredentialPlugin\";\nimport { checkTenantId } from \"../util/tenantIdUtils\";\nimport fs from \"fs\";\nimport os from \"os\";\nimport path from \"path\";\n\nconst CommonTenantId = \"common\";\nconst AzureAccountClientId = \"aebc6443-996d-45c2-90f0-388ff96faa56\"; // VSC: 'aebc6443-996d-45c2-90f0-388ff96faa56'\nconst logger = credentialLogger(\"VisualStudioCodeCredential\");\n\nlet findCredentials: VSCodeCredentialFinder | undefined = undefined;\n\nexport const vsCodeCredentialControl = {\n setVsCodeCredentialFinder(finder: VSCodeCredentialFinder): void {\n findCredentials = finder;\n },\n};\n\n// Map of unsupported Tenant IDs and the errors we will be throwing.\nconst unsupportedTenantIds: Record<string, string> = {\n adfs: \"The VisualStudioCodeCredential does not support authentication with ADFS tenants.\",\n};\n\nfunction checkUnsupportedTenant(tenantId: string): void {\n // If the Tenant ID isn't supported, we throw.\n const unsupportedTenantError = unsupportedTenantIds[tenantId];\n if (unsupportedTenantError) {\n throw new CredentialUnavailableError(unsupportedTenantError);\n }\n}\n\ntype VSCodeCloudNames = \"AzureCloud\" | \"AzureChina\" | \"AzureGermanCloud\" | \"AzureUSGovernment\";\n\nconst mapVSCodeAuthorityHosts: Record<VSCodeCloudNames, string> = {\n AzureCloud: AzureAuthorityHosts.AzurePublicCloud,\n AzureChina: AzureAuthorityHosts.AzureChina,\n AzureGermanCloud: AzureAuthorityHosts.AzureGermany,\n AzureUSGovernment: AzureAuthorityHosts.AzureGovernment,\n};\n\n/**\n * Attempts to load a specific property from the VSCode configurations of the current OS.\n * If it fails at any point, returns undefined.\n */\nexport function getPropertyFromVSCode(property: string): string | undefined {\n const settingsPath = [\"User\", \"settings.json\"];\n // Eventually we can add more folders for more versions of VSCode.\n const vsCodeFolder = \"Code\";\n const homedir = os.homedir();\n\n function loadProperty(...pathSegments: string[]): string | undefined {\n const fullPath = path.join(...pathSegments, vsCodeFolder, ...settingsPath);\n const settings = JSON.parse(fs.readFileSync(fullPath, { encoding: \"utf8\" }));\n return settings[property];\n }\n\n try {\n let appData: string;\n switch (process.platform) {\n case \"win32\":\n appData = process.env.APPDATA!;\n return appData ? loadProperty(appData) : undefined;\n case \"darwin\":\n return loadProperty(homedir, \"Library\", \"Application Support\");\n case \"linux\":\n return loadProperty(homedir, \".config\");\n default:\n return;\n }\n } catch (e: any) {\n logger.info(`Failed to load the Visual Studio Code configuration file. Error: ${e.message}`);\n return;\n }\n}\n\n/**\n * Connects to Azure using the credential provided by the VSCode extension 'Azure Account'.\n * Once the user has logged in via the extension, this credential can share the same refresh token\n * that is cached by the extension.\n *\n * It's a [known issue](https://github.com/Azure/azure-sdk-for-js/issues/20500) that this credential doesn't\n * work with [Azure Account extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode.azure-account)\n * versions newer than **0.9.11**. A long-term fix to this problem is in progress. In the meantime, consider\n * authenticating with {@link AzureCliCredential}.\n */\nexport class VisualStudioCodeCredential implements TokenCredential {\n private identityClient: IdentityClient;\n private tenantId: string;\n private additionallyAllowedTenantIds: string[];\n private cloudName: VSCodeCloudNames;\n\n /**\n * Creates an instance of VisualStudioCodeCredential to use for automatically authenticating via VSCode.\n *\n * **Note**: `VisualStudioCodeCredential` is provided by a plugin package:\n * `@azure/identity-vscode`. If this package is not installed and registered\n * using the plugin API (`useIdentityPlugin`), then authentication using\n * `VisualStudioCodeCredential` will not be available.\n *\n * @param options - Options for configuring the client which makes the authentication request.\n */\n constructor(options?: VisualStudioCodeCredentialOptions) {\n // We want to make sure we use the one assigned by the user on the VSCode settings.\n // Or just `AzureCloud` by default.\n this.cloudName = (getPropertyFromVSCode(\"azure.cloud\") || \"AzureCloud\") as VSCodeCloudNames;\n\n // Picking an authority host based on the cloud name.\n const authorityHost = mapVSCodeAuthorityHosts[this.cloudName];\n\n this.identityClient = new IdentityClient({\n authorityHost,\n ...options,\n });\n\n if (options && options.tenantId) {\n checkTenantId(logger, options.tenantId);\n this.tenantId = options.tenantId;\n } else {\n this.tenantId = CommonTenantId;\n }\n\n this.additionallyAllowedTenantIds = resolveAdditionallyAllowedTenantIds(\n options?.additionallyAllowedTenants,\n );\n\n checkUnsupportedTenant(this.tenantId);\n }\n\n /**\n * Runs preparations for any further getToken request.\n */\n private async prepare(): Promise<void> {\n // Attempts to load the tenant from the VSCode configuration file.\n const settingsTenant = getPropertyFromVSCode(\"azure.tenant\");\n if (settingsTenant) {\n this.tenantId = settingsTenant;\n }\n checkUnsupportedTenant(this.tenantId);\n }\n\n /**\n * The promise of the single preparation that will be executed at the first getToken request for an instance of this class.\n */\n private preparePromise: Promise<void> | undefined;\n\n /**\n * Runs preparations for any further getToken, but only once.\n */\n private prepareOnce(): Promise<void> | undefined {\n if (!this.preparePromise) {\n this.preparePromise = this.prepare();\n }\n return this.preparePromise;\n }\n\n /**\n * Returns the token found by searching VSCode's authentication cache or\n * returns null if no token could be found.\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 public async getToken(\n scopes: string | string[],\n options?: GetTokenOptions,\n ): Promise<AccessToken> {\n await this.prepareOnce();\n\n const tenantId =\n processMultiTenantRequest(\n this.tenantId,\n options,\n this.additionallyAllowedTenantIds,\n logger,\n ) || this.tenantId;\n\n if (findCredentials === undefined) {\n throw new CredentialUnavailableError(\n [\n \"No implementation of `VisualStudioCodeCredential` is available.\",\n \"You must install the identity-vscode plugin package (`npm install --save-dev @azure/identity-vscode`)\",\n \"and enable it by importing `useIdentityPlugin` from `@azure/identity` and calling\",\n \"`useIdentityPlugin(vsCodePlugin)` before creating a `VisualStudioCodeCredential`.\",\n \"To troubleshoot, visit https://aka.ms/azsdk/js/identity/vscodecredential/troubleshoot.\",\n ].join(\" \"),\n );\n }\n\n let scopeString = typeof scopes === \"string\" ? scopes : scopes.join(\" \");\n\n // Check to make sure the scope we get back is a valid scope\n if (!scopeString.match(/^[0-9a-zA-Z-.:/]+$/)) {\n const error = new Error(\"Invalid scope was specified by the user or calling client\");\n logger.getToken.info(formatError(scopes, error));\n throw error;\n }\n\n if (scopeString.indexOf(\"offline_access\") < 0) {\n scopeString += \" offline_access\";\n }\n\n // findCredentials returns an array similar to:\n // [\n // {\n // account: \"\",\n // password: \"\",\n // },\n // /* ... */\n // ]\n const credentials = await findCredentials();\n\n // If we can't find the credential based on the name, we'll pick the first one available.\n const { password: refreshToken } =\n credentials.find(({ account }) => account === this.cloudName) ?? credentials[0] ?? {};\n\n if (refreshToken) {\n const tokenResponse = await this.identityClient.refreshAccessToken(\n tenantId,\n AzureAccountClientId,\n scopeString,\n refreshToken,\n undefined,\n );\n\n if (tokenResponse) {\n logger.getToken.info(formatSuccess(scopes));\n return tokenResponse.accessToken;\n } else {\n const error = new CredentialUnavailableError(\n \"Could not retrieve the token associated with Visual Studio Code. Have you connected using the 'Azure Account' extension recently? To troubleshoot, visit https://aka.ms/azsdk/js/identity/vscodecredential/troubleshoot.\",\n );\n logger.getToken.info(formatError(scopes, error));\n throw error;\n }\n } else {\n const error = new CredentialUnavailableError(\n \"Could not retrieve the token associated with Visual Studio Code. Did you connect using the 'Azure Account' extension? To troubleshoot, visit https://aka.ms/azsdk/js/identity/vscodecredential/troubleshoot.\",\n );\n logger.getToken.info(formatError(scopes, error));\n throw error;\n }\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"visualStudioCodeCredentialOptions.js","sourceRoot":"","sources":["../../../../../identity/src/credentials/visualStudioCodeCredentialOptions.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { MultiTenantTokenCredentialOptions } from \"./multiTenantTokenCredentialOptions\";\n\n/**\n * Provides options to configure the Visual Studio Code credential.\n */\nexport interface VisualStudioCodeCredentialOptions extends MultiTenantTokenCredentialOptions {\n /**\n * Optionally pass in a Tenant ID to be used as part of the credential\n */\n tenantId?: string;\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"visualStudioCodeCredentialPlugin.js","sourceRoot":"","sources":["../../../../../identity/src/credentials/visualStudioCodeCredentialPlugin.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/**\n * A function that searches for credentials in the Visual Studio Code credential store.\n *\n * @returns an array of credentials (username and password)\n * @internal\n */\nexport type VSCodeCredentialFinder = () => Promise<Array<{ account: string; password: string }>>;\n"]}
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Microsoft Corporation.
|
|
2
|
-
// Licensed under the MIT License.
|
|
3
|
-
import { __awaiter } from "tslib";
|
|
4
|
-
import { credentialLogger, processEnvVars } from "../util/logging";
|
|
5
|
-
import { ClientAssertionCredential } from "./clientAssertionCredential";
|
|
6
|
-
import { CredentialUnavailableError } from "../errors";
|
|
7
|
-
import { checkTenantId } from "../util/tenantIdUtils";
|
|
8
|
-
import { readFile } from "fs/promises";
|
|
9
|
-
const credentialName = "WorkloadIdentityCredential";
|
|
10
|
-
/**
|
|
11
|
-
* Contains the list of all supported environment variable names so that an
|
|
12
|
-
* appropriate error message can be generated when no credentials can be
|
|
13
|
-
* configured.
|
|
14
|
-
*
|
|
15
|
-
* @internal
|
|
16
|
-
*/
|
|
17
|
-
export const SupportedWorkloadEnvironmentVariables = [
|
|
18
|
-
"AZURE_TENANT_ID",
|
|
19
|
-
"AZURE_CLIENT_ID",
|
|
20
|
-
"AZURE_FEDERATED_TOKEN_FILE",
|
|
21
|
-
];
|
|
22
|
-
const logger = credentialLogger(credentialName);
|
|
23
|
-
/**
|
|
24
|
-
* Workload Identity authentication is a feature in Azure that allows applications running on virtual machines (VMs)
|
|
25
|
-
* to access other Azure resources without the need for a service principal or managed identity. With Workload Identity
|
|
26
|
-
* authentication, applications authenticate themselves using their own identity, rather than using a shared service
|
|
27
|
-
* principal or managed identity. Under the hood, Workload Identity authentication uses the concept of Service Account
|
|
28
|
-
* Credentials (SACs), which are automatically created by Azure and stored securely in the VM. By using Workload
|
|
29
|
-
* Identity authentication, you can avoid the need to manage and rotate service principals or managed identities for
|
|
30
|
-
* each application on each VM. Additionally, because SACs are created automatically and managed by Azure, you don't
|
|
31
|
-
* need to worry about storing and securing sensitive credentials themselves.
|
|
32
|
-
* The WorkloadIdentityCredential supports Microsoft Entra Workload ID authentication on Azure Kubernetes and acquires
|
|
33
|
-
* a token using the SACs available in the Azure Kubernetes environment.
|
|
34
|
-
* Refer to <a href="https://learn.microsoft.com/azure/aks/workload-identity-overview">Microsoft Entra
|
|
35
|
-
* Workload ID</a> for more information.
|
|
36
|
-
*/
|
|
37
|
-
export class WorkloadIdentityCredential {
|
|
38
|
-
/**
|
|
39
|
-
* WorkloadIdentityCredential supports Microsoft Entra Workload ID on Kubernetes.
|
|
40
|
-
*
|
|
41
|
-
* @param options - The identity client options to use for authentication.
|
|
42
|
-
*/
|
|
43
|
-
constructor(options) {
|
|
44
|
-
this.azureFederatedTokenFileContent = undefined;
|
|
45
|
-
this.cacheDate = undefined;
|
|
46
|
-
// Logging environment variables for error details
|
|
47
|
-
const assignedEnv = processEnvVars(SupportedWorkloadEnvironmentVariables).assigned.join(", ");
|
|
48
|
-
logger.info(`Found the following environment variables: ${assignedEnv}`);
|
|
49
|
-
const workloadIdentityCredentialOptions = options !== null && options !== void 0 ? options : {};
|
|
50
|
-
const tenantId = workloadIdentityCredentialOptions.tenantId || process.env.AZURE_TENANT_ID;
|
|
51
|
-
const clientId = workloadIdentityCredentialOptions.clientId || process.env.AZURE_CLIENT_ID;
|
|
52
|
-
this.federatedTokenFilePath =
|
|
53
|
-
workloadIdentityCredentialOptions.tokenFilePath || process.env.AZURE_FEDERATED_TOKEN_FILE;
|
|
54
|
-
if (tenantId) {
|
|
55
|
-
checkTenantId(logger, tenantId);
|
|
56
|
-
}
|
|
57
|
-
if (!clientId) {
|
|
58
|
-
throw new CredentialUnavailableError(`${credentialName}: is unavailable. clientId is a required parameter. In DefaultAzureCredential and ManagedIdentityCredential, this can be provided as an environment variable - "AZURE_CLIENT_ID".
|
|
59
|
-
See the troubleshooting guide for more information: https://aka.ms/azsdk/js/identity/workloadidentitycredential/troubleshoot`);
|
|
60
|
-
}
|
|
61
|
-
if (!tenantId) {
|
|
62
|
-
throw new CredentialUnavailableError(`${credentialName}: is unavailable. tenantId is a required parameter. In DefaultAzureCredential and ManagedIdentityCredential, this can be provided as an environment variable - "AZURE_TENANT_ID".
|
|
63
|
-
See the troubleshooting guide for more information: https://aka.ms/azsdk/js/identity/workloadidentitycredential/troubleshoot`);
|
|
64
|
-
}
|
|
65
|
-
if (!this.federatedTokenFilePath) {
|
|
66
|
-
throw new CredentialUnavailableError(`${credentialName}: is unavailable. federatedTokenFilePath is a required parameter. In DefaultAzureCredential and ManagedIdentityCredential, this can be provided as an environment variable - "AZURE_FEDERATED_TOKEN_FILE".
|
|
67
|
-
See the troubleshooting guide for more information: https://aka.ms/azsdk/js/identity/workloadidentitycredential/troubleshoot`);
|
|
68
|
-
}
|
|
69
|
-
logger.info(`Invoking ClientAssertionCredential with tenant ID: ${tenantId}, clientId: ${workloadIdentityCredentialOptions.clientId} and federated token path: [REDACTED]`);
|
|
70
|
-
this.client = new ClientAssertionCredential(tenantId, clientId, this.readFileContents.bind(this), options);
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Authenticates with Microsoft Entra ID and returns an access token if successful.
|
|
74
|
-
* If authentication fails, a {@link CredentialUnavailableError} will be thrown with the details of the failure.
|
|
75
|
-
*
|
|
76
|
-
* @param scopes - The list of scopes for which the token will have access.
|
|
77
|
-
* @param options - The options used to configure any requests this
|
|
78
|
-
* TokenCredential implementation might make.
|
|
79
|
-
*/
|
|
80
|
-
getToken(scopes, options) {
|
|
81
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
82
|
-
if (!this.client) {
|
|
83
|
-
const errorMessage = `${credentialName}: is unavailable. tenantId, clientId, and federatedTokenFilePath are required parameters.
|
|
84
|
-
In DefaultAzureCredential and ManagedIdentityCredential, these can be provided as environment variables -
|
|
85
|
-
"AZURE_TENANT_ID",
|
|
86
|
-
"AZURE_CLIENT_ID",
|
|
87
|
-
"AZURE_FEDERATED_TOKEN_FILE". See the troubleshooting guide for more information: https://aka.ms/azsdk/js/identity/workloadidentitycredential/troubleshoot`;
|
|
88
|
-
logger.info(errorMessage);
|
|
89
|
-
throw new CredentialUnavailableError(errorMessage);
|
|
90
|
-
}
|
|
91
|
-
logger.info("Invoking getToken() of Client Assertion Credential");
|
|
92
|
-
return this.client.getToken(scopes, options);
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
readFileContents() {
|
|
96
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
97
|
-
// Cached assertions expire after 5 minutes
|
|
98
|
-
if (this.cacheDate !== undefined && Date.now() - this.cacheDate >= 1000 * 60 * 5) {
|
|
99
|
-
this.azureFederatedTokenFileContent = undefined;
|
|
100
|
-
}
|
|
101
|
-
if (!this.federatedTokenFilePath) {
|
|
102
|
-
throw new CredentialUnavailableError(`${credentialName}: is unavailable. Invalid file path provided ${this.federatedTokenFilePath}.`);
|
|
103
|
-
}
|
|
104
|
-
if (!this.azureFederatedTokenFileContent) {
|
|
105
|
-
const file = yield readFile(this.federatedTokenFilePath, "utf8");
|
|
106
|
-
const value = file.trim();
|
|
107
|
-
if (!value) {
|
|
108
|
-
throw new CredentialUnavailableError(`${credentialName}: is unavailable. No content on the file ${this.federatedTokenFilePath}.`);
|
|
109
|
-
}
|
|
110
|
-
else {
|
|
111
|
-
this.azureFederatedTokenFileContent = value;
|
|
112
|
-
this.cacheDate = Date.now();
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
return this.azureFederatedTokenFileContent;
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
//# sourceMappingURL=workloadIdentityCredential.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"workloadIdentityCredential.js","sourceRoot":"","sources":["../../../../../identity/src/credentials/workloadIdentityCredential.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;;AAGlC,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEnE,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AACxE,OAAO,EAAE,0BAA0B,EAAE,MAAM,WAAW,CAAC;AAEvD,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,MAAM,cAAc,GAAG,4BAA4B,CAAC;AACpD;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,qCAAqC,GAAG;IACn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GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;gBAC1B,IAAI,CAAC,KAAK,EAAE,CAAC;oBACX,MAAM,IAAI,0BAA0B,CAClC,GAAG,cAAc,4CAA4C,IAAI,CAAC,sBAAsB,GAAG,CAC5F,CAAC;gBACJ,CAAC;qBAAM,CAAC;oBACN,IAAI,CAAC,8BAA8B,GAAG,KAAK,CAAC;oBAC5C,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;gBAC9B,CAAC;YACH,CAAC;YACD,OAAO,IAAI,CAAC,8BAA8B,CAAC;QAC7C,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 { credentialLogger, processEnvVars } from \"../util/logging\";\n\nimport { ClientAssertionCredential } from \"./clientAssertionCredential\";\nimport { CredentialUnavailableError } from \"../errors\";\nimport type { WorkloadIdentityCredentialOptions } from \"./workloadIdentityCredentialOptions\";\nimport { checkTenantId } from \"../util/tenantIdUtils\";\nimport { readFile } from \"fs/promises\";\n\nconst credentialName = \"WorkloadIdentityCredential\";\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 SupportedWorkloadEnvironmentVariables = [\n \"AZURE_TENANT_ID\",\n \"AZURE_CLIENT_ID\",\n \"AZURE_FEDERATED_TOKEN_FILE\",\n];\nconst logger = credentialLogger(credentialName);\n/**\n * Workload Identity authentication is a feature in Azure that allows applications running on virtual machines (VMs)\n * to access other Azure resources without the need for a service principal or managed identity. With Workload Identity\n * authentication, applications authenticate themselves using their own identity, rather than using a shared service\n * principal or managed identity. Under the hood, Workload Identity authentication uses the concept of Service Account\n * Credentials (SACs), which are automatically created by Azure and stored securely in the VM. By using Workload\n * Identity authentication, you can avoid the need to manage and rotate service principals or managed identities for\n * each application on each VM. Additionally, because SACs are created automatically and managed by Azure, you don't\n * need to worry about storing and securing sensitive credentials themselves.\n * The WorkloadIdentityCredential supports Microsoft Entra Workload ID authentication on Azure Kubernetes and acquires\n * a token using the SACs available in the Azure Kubernetes environment.\n * Refer to <a href=\"https://learn.microsoft.com/azure/aks/workload-identity-overview\">Microsoft Entra\n * Workload ID</a> for more information.\n */\nexport class WorkloadIdentityCredential implements TokenCredential {\n private client: ClientAssertionCredential | undefined;\n private azureFederatedTokenFileContent: string | undefined = undefined;\n private cacheDate: number | undefined = undefined;\n private federatedTokenFilePath: string | undefined;\n\n /**\n * WorkloadIdentityCredential supports Microsoft Entra Workload ID on Kubernetes.\n *\n * @param options - The identity client options to use for authentication.\n */\n constructor(options?: WorkloadIdentityCredentialOptions) {\n // Logging environment variables for error details\n const assignedEnv = processEnvVars(SupportedWorkloadEnvironmentVariables).assigned.join(\", \");\n logger.info(`Found the following environment variables: ${assignedEnv}`);\n\n const workloadIdentityCredentialOptions = options ?? {};\n const tenantId = workloadIdentityCredentialOptions.tenantId || process.env.AZURE_TENANT_ID;\n const clientId = workloadIdentityCredentialOptions.clientId || process.env.AZURE_CLIENT_ID;\n this.federatedTokenFilePath =\n workloadIdentityCredentialOptions.tokenFilePath || process.env.AZURE_FEDERATED_TOKEN_FILE;\n if (tenantId) {\n checkTenantId(logger, tenantId);\n }\n if (!clientId) {\n throw new CredentialUnavailableError(\n `${credentialName}: is unavailable. clientId is a required parameter. In DefaultAzureCredential and ManagedIdentityCredential, this can be provided as an environment variable - \"AZURE_CLIENT_ID\".\n See the troubleshooting guide for more information: https://aka.ms/azsdk/js/identity/workloadidentitycredential/troubleshoot`,\n );\n }\n\n if (!tenantId) {\n throw new CredentialUnavailableError(\n `${credentialName}: is unavailable. tenantId is a required parameter. In DefaultAzureCredential and ManagedIdentityCredential, this can be provided as an environment variable - \"AZURE_TENANT_ID\".\n See the troubleshooting guide for more information: https://aka.ms/azsdk/js/identity/workloadidentitycredential/troubleshoot`,\n );\n }\n\n if (!this.federatedTokenFilePath) {\n throw new CredentialUnavailableError(\n `${credentialName}: is unavailable. federatedTokenFilePath is a required parameter. In DefaultAzureCredential and ManagedIdentityCredential, this can be provided as an environment variable - \"AZURE_FEDERATED_TOKEN_FILE\".\n See the troubleshooting guide for more information: https://aka.ms/azsdk/js/identity/workloadidentitycredential/troubleshoot`,\n );\n }\n\n logger.info(\n `Invoking ClientAssertionCredential with tenant ID: ${tenantId}, clientId: ${workloadIdentityCredentialOptions.clientId} and federated token path: [REDACTED]`,\n );\n this.client = new ClientAssertionCredential(\n tenantId,\n clientId,\n this.readFileContents.bind(this),\n options,\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 * @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 public async getToken(\n scopes: string | string[],\n options?: GetTokenOptions,\n ): Promise<AccessToken | null> {\n if (!this.client) {\n const errorMessage = `${credentialName}: is unavailable. tenantId, clientId, and federatedTokenFilePath are required parameters. \n In DefaultAzureCredential and ManagedIdentityCredential, these can be provided as environment variables - \n \"AZURE_TENANT_ID\",\n \"AZURE_CLIENT_ID\",\n \"AZURE_FEDERATED_TOKEN_FILE\". See the troubleshooting guide for more information: https://aka.ms/azsdk/js/identity/workloadidentitycredential/troubleshoot`;\n logger.info(errorMessage);\n throw new CredentialUnavailableError(errorMessage);\n }\n logger.info(\"Invoking getToken() of Client Assertion Credential\");\n return this.client.getToken(scopes, options);\n }\n\n private async readFileContents(): Promise<string> {\n // Cached assertions expire after 5 minutes\n if (this.cacheDate !== undefined && Date.now() - this.cacheDate >= 1000 * 60 * 5) {\n this.azureFederatedTokenFileContent = undefined;\n }\n if (!this.federatedTokenFilePath) {\n throw new CredentialUnavailableError(\n `${credentialName}: is unavailable. Invalid file path provided ${this.federatedTokenFilePath}.`,\n );\n }\n if (!this.azureFederatedTokenFileContent) {\n const file = await readFile(this.federatedTokenFilePath, \"utf8\");\n const value = file.trim();\n if (!value) {\n throw new CredentialUnavailableError(\n `${credentialName}: is unavailable. No content on the file ${this.federatedTokenFilePath}.`,\n );\n } else {\n this.azureFederatedTokenFileContent = value;\n this.cacheDate = Date.now();\n }\n }\n return this.azureFederatedTokenFileContent;\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"workloadIdentityCredentialOptions.js","sourceRoot":"","sources":["../../../../../identity/src/credentials/workloadIdentityCredentialOptions.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 * Options for the {@link WorkloadIdentityCredential}\n */\nexport interface WorkloadIdentityCredentialOptions\n extends MultiTenantTokenCredentialOptions,\n AuthorityValidationOptions {\n /**\n * ID of the application's Microsoft Entra tenant. Also called its directory ID.\n */\n tenantId?: string;\n /**\n * The client ID of a Microsoft Entra app registration.\n */\n clientId?: string;\n /**\n * The path to a file containing a Kubernetes service account token that authenticates the identity.\n */\n tokenFilePath?: string;\n}\n"]}
|
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Microsoft Corporation.
|
|
2
|
-
// Licensed under the MIT License.
|
|
3
|
-
function isErrorResponse(errorResponse) {
|
|
4
|
-
return (errorResponse &&
|
|
5
|
-
typeof errorResponse.error === "string" &&
|
|
6
|
-
typeof errorResponse.error_description === "string");
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* The Error.name value of an CredentialUnavailable
|
|
10
|
-
*/
|
|
11
|
-
export const CredentialUnavailableErrorName = "CredentialUnavailableError";
|
|
12
|
-
/**
|
|
13
|
-
* This signifies that the credential that was tried in a chained credential
|
|
14
|
-
* was not available to be used as the credential. Rather than treating this as
|
|
15
|
-
* an error that should halt the chain, it's caught and the chain continues
|
|
16
|
-
*/
|
|
17
|
-
export class CredentialUnavailableError extends Error {
|
|
18
|
-
constructor(message, options) {
|
|
19
|
-
// @ts-expect-error - TypeScript does not recognize this until we use ES2022 as the target; however, all our major runtimes do support the `cause` property
|
|
20
|
-
super(message, options);
|
|
21
|
-
this.name = CredentialUnavailableErrorName;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* The Error.name value of an AuthenticationError
|
|
26
|
-
*/
|
|
27
|
-
export const AuthenticationErrorName = "AuthenticationError";
|
|
28
|
-
/**
|
|
29
|
-
* Provides details about a failure to authenticate with Azure Active
|
|
30
|
-
* Directory. The `errorResponse` field contains more details about
|
|
31
|
-
* the specific failure.
|
|
32
|
-
*/
|
|
33
|
-
export class AuthenticationError extends Error {
|
|
34
|
-
constructor(statusCode, errorBody, options) {
|
|
35
|
-
let errorResponse = {
|
|
36
|
-
error: "unknown",
|
|
37
|
-
errorDescription: "An unknown error occurred and no additional details are available.",
|
|
38
|
-
};
|
|
39
|
-
if (isErrorResponse(errorBody)) {
|
|
40
|
-
errorResponse = convertOAuthErrorResponseToErrorResponse(errorBody);
|
|
41
|
-
}
|
|
42
|
-
else if (typeof errorBody === "string") {
|
|
43
|
-
try {
|
|
44
|
-
// Most error responses will contain JSON-formatted error details
|
|
45
|
-
// in the response body
|
|
46
|
-
const oauthErrorResponse = JSON.parse(errorBody);
|
|
47
|
-
errorResponse = convertOAuthErrorResponseToErrorResponse(oauthErrorResponse);
|
|
48
|
-
}
|
|
49
|
-
catch (e) {
|
|
50
|
-
if (statusCode === 400) {
|
|
51
|
-
errorResponse = {
|
|
52
|
-
error: "invalid_request",
|
|
53
|
-
errorDescription: `The service indicated that the request was invalid.\n\n${errorBody}`,
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
errorResponse = {
|
|
58
|
-
error: "unknown_error",
|
|
59
|
-
errorDescription: `An unknown error has occurred. Response body:\n\n${errorBody}`,
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
else {
|
|
65
|
-
errorResponse = {
|
|
66
|
-
error: "unknown_error",
|
|
67
|
-
errorDescription: "An unknown error occurred and no additional details are available.",
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
super(`${errorResponse.error} Status code: ${statusCode}\nMore details:\n${errorResponse.errorDescription},`,
|
|
71
|
-
// @ts-expect-error - TypeScript does not recognize this until we use ES2022 as the target; however, all our major runtimes do support the `cause` property
|
|
72
|
-
options);
|
|
73
|
-
this.statusCode = statusCode;
|
|
74
|
-
this.errorResponse = errorResponse;
|
|
75
|
-
// Ensure that this type reports the correct name
|
|
76
|
-
this.name = AuthenticationErrorName;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* The Error.name value of an AggregateAuthenticationError
|
|
81
|
-
*/
|
|
82
|
-
export const AggregateAuthenticationErrorName = "AggregateAuthenticationError";
|
|
83
|
-
/**
|
|
84
|
-
* Provides an `errors` array containing {@link AuthenticationError} instance
|
|
85
|
-
* for authentication failures from credentials in a {@link ChainedTokenCredential}.
|
|
86
|
-
*/
|
|
87
|
-
export class AggregateAuthenticationError extends Error {
|
|
88
|
-
constructor(errors, errorMessage) {
|
|
89
|
-
const errorDetail = errors.join("\n");
|
|
90
|
-
super(`${errorMessage}\n${errorDetail}`);
|
|
91
|
-
this.errors = errors;
|
|
92
|
-
// Ensure that this type reports the correct name
|
|
93
|
-
this.name = AggregateAuthenticationErrorName;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
function convertOAuthErrorResponseToErrorResponse(errorBody) {
|
|
97
|
-
return {
|
|
98
|
-
error: errorBody.error,
|
|
99
|
-
errorDescription: errorBody.error_description,
|
|
100
|
-
correlationId: errorBody.correlation_id,
|
|
101
|
-
errorCodes: errorBody.error_codes,
|
|
102
|
-
timestamp: errorBody.timestamp,
|
|
103
|
-
traceId: errorBody.trace_id,
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Error used to enforce authentication after trying to retrieve a token silently.
|
|
108
|
-
*/
|
|
109
|
-
export class AuthenticationRequiredError extends Error {
|
|
110
|
-
constructor(
|
|
111
|
-
/**
|
|
112
|
-
* Optional parameters. A message can be specified. The {@link GetTokenOptions} of the request can also be specified to more easily associate the error with the received parameters.
|
|
113
|
-
*/
|
|
114
|
-
options) {
|
|
115
|
-
super(options.message,
|
|
116
|
-
// @ts-expect-error - TypeScript does not recognize this until we use ES2022 as the target; however, all our major runtimes do support the `cause` property
|
|
117
|
-
options.cause ? { cause: options.cause } : undefined);
|
|
118
|
-
this.scopes = options.scopes;
|
|
119
|
-
this.getTokenOptions = options.getTokenOptions;
|
|
120
|
-
this.name = "AuthenticationRequiredError";
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
//# sourceMappingURL=errors.js.map
|