@azure/identity 4.11.0-alpha.20250717.4 → 4.11.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/credentials/defaultAzureCredentialFunctions.d.ts +62 -0
- package/dist/browser/credentials/defaultAzureCredentialFunctions.d.ts.map +1 -0
- package/dist/browser/credentials/defaultAzureCredentialFunctions.js +143 -0
- package/dist/browser/credentials/defaultAzureCredentialFunctions.js.map +1 -0
- package/dist/commonjs/credentials/defaultAzureCredential.d.ts +12 -32
- package/dist/commonjs/credentials/defaultAzureCredential.d.ts.map +1 -1
- package/dist/commonjs/credentials/defaultAzureCredential.js +46 -161
- package/dist/commonjs/credentials/defaultAzureCredential.js.map +1 -1
- package/dist/commonjs/credentials/defaultAzureCredentialFunctions.d.ts +62 -0
- package/dist/commonjs/credentials/defaultAzureCredentialFunctions.d.ts.map +1 -0
- package/dist/commonjs/credentials/defaultAzureCredentialFunctions.js +153 -0
- package/dist/commonjs/credentials/defaultAzureCredentialFunctions.js.map +1 -0
- package/dist/esm/credentials/defaultAzureCredential.d.ts +12 -32
- package/dist/esm/credentials/defaultAzureCredential.d.ts.map +1 -1
- package/dist/esm/credentials/defaultAzureCredential.js +39 -150
- package/dist/esm/credentials/defaultAzureCredential.js.map +1 -1
- package/dist/esm/credentials/defaultAzureCredentialFunctions.d.ts +62 -0
- package/dist/esm/credentials/defaultAzureCredentialFunctions.d.ts.map +1 -0
- package/dist/esm/credentials/defaultAzureCredentialFunctions.js +143 -0
- package/dist/esm/credentials/defaultAzureCredentialFunctions.js.map +1 -0
- package/dist/workerd/credentials/defaultAzureCredential.d.ts +12 -32
- package/dist/workerd/credentials/defaultAzureCredential.d.ts.map +1 -1
- package/dist/workerd/credentials/defaultAzureCredential.js +39 -150
- package/dist/workerd/credentials/defaultAzureCredential.js.map +1 -1
- package/dist/workerd/credentials/defaultAzureCredentialFunctions.d.ts +62 -0
- package/dist/workerd/credentials/defaultAzureCredentialFunctions.d.ts.map +1 -0
- package/dist/workerd/credentials/defaultAzureCredentialFunctions.js +143 -0
- package/dist/workerd/credentials/defaultAzureCredentialFunctions.js.map +1 -0
- package/package.json +5 -5
@@ -0,0 +1,62 @@
|
|
1
|
+
import type { TokenCredential } from "@azure/core-auth";
|
2
|
+
import type { DefaultAzureCredentialClientIdOptions, DefaultAzureCredentialOptions, DefaultAzureCredentialResourceIdOptions } from "./defaultAzureCredentialOptions.js";
|
3
|
+
/**
|
4
|
+
* Creates a {@link BrokerCredential} instance with the provided options.
|
5
|
+
* This credential uses the Windows Authentication Manager (WAM) broker for authentication.
|
6
|
+
* It will only attempt to authenticate silently using the default broker account
|
7
|
+
*
|
8
|
+
* @param options - Options for configuring the credential.
|
9
|
+
*
|
10
|
+
* @internal
|
11
|
+
*/
|
12
|
+
export declare function createDefaultBrokerCredential(options?: DefaultAzureCredentialOptions): TokenCredential;
|
13
|
+
/**
|
14
|
+
* Creates a {@link VisualStudioCodeCredential} from the provided options.
|
15
|
+
* @param options - Options to configure the credential.
|
16
|
+
*
|
17
|
+
* @internal
|
18
|
+
*/
|
19
|
+
export declare function createDefaultVisualStudioCodeCredential(options?: DefaultAzureCredentialOptions): TokenCredential;
|
20
|
+
/**
|
21
|
+
* Creates a {@link ManagedIdentityCredential} from the provided options.
|
22
|
+
* @param options - Options to configure the credential.
|
23
|
+
*
|
24
|
+
* @internal
|
25
|
+
*/
|
26
|
+
export declare function createDefaultManagedIdentityCredential(options?: DefaultAzureCredentialOptions | DefaultAzureCredentialResourceIdOptions | DefaultAzureCredentialClientIdOptions): TokenCredential;
|
27
|
+
/**
|
28
|
+
* Creates a {@link WorkloadIdentityCredential} from the provided options.
|
29
|
+
* @param options - Options to configure the credential.
|
30
|
+
*
|
31
|
+
* @internal
|
32
|
+
*/
|
33
|
+
export declare function createDefaultWorkloadIdentityCredential(options?: DefaultAzureCredentialOptions | DefaultAzureCredentialClientIdOptions): TokenCredential;
|
34
|
+
/**
|
35
|
+
* Creates a {@link AzureDeveloperCliCredential} from the provided options.
|
36
|
+
* @param options - Options to configure the credential.
|
37
|
+
*
|
38
|
+
* @internal
|
39
|
+
*/
|
40
|
+
export declare function createDefaultAzureDeveloperCliCredential(options?: DefaultAzureCredentialOptions): TokenCredential;
|
41
|
+
/**
|
42
|
+
* Creates a {@link AzureCliCredential} from the provided options.
|
43
|
+
* @param options - Options to configure the credential.
|
44
|
+
*
|
45
|
+
* @internal
|
46
|
+
*/
|
47
|
+
export declare function createDefaultAzureCliCredential(options?: DefaultAzureCredentialOptions): TokenCredential;
|
48
|
+
/**
|
49
|
+
* Creates a {@link AzurePowerShellCredential} from the provided options.
|
50
|
+
* @param options - Options to configure the credential.
|
51
|
+
*
|
52
|
+
* @internal
|
53
|
+
*/
|
54
|
+
export declare function createDefaultAzurePowershellCredential(options?: DefaultAzureCredentialOptions): TokenCredential;
|
55
|
+
/**
|
56
|
+
* Creates an {@link EnvironmentCredential} from the provided options.
|
57
|
+
* @param options - Options to configure the credential.
|
58
|
+
*
|
59
|
+
* @internal
|
60
|
+
*/
|
61
|
+
export declare function createDefaultEnvironmentCredential(options?: DefaultAzureCredentialOptions): TokenCredential;
|
62
|
+
//# sourceMappingURL=defaultAzureCredentialFunctions.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"defaultAzureCredentialFunctions.d.ts","sourceRoot":"","sources":["../../../src/credentials/defaultAzureCredentialFunctions.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,KAAK,EACV,qCAAqC,EACrC,6BAA6B,EAC7B,uCAAuC,EACxC,MAAM,oCAAoC,CAAC;AAe5C;;;;;;;;GAQG;AACH,wBAAgB,6BAA6B,CAC3C,OAAO,GAAE,6BAAkC,GAC1C,eAAe,CAEjB;AAED;;;;;GAKG;AACH,wBAAgB,uCAAuC,CACrD,OAAO,GAAE,6BAAkC,GAC1C,eAAe,CAEjB;AAED;;;;;GAKG;AACH,wBAAgB,sCAAsC,CACpD,OAAO,GACH,6BAA6B,GAC7B,uCAAuC,GACvC,qCAA0C,GAC7C,eAAe,CA8CjB;AAED;;;;;GAKG;AACH,wBAAgB,uCAAuC,CACrD,OAAO,CAAC,EAAE,6BAA6B,GAAG,qCAAqC,GAC9E,eAAe,CA4BjB;AAED;;;;;GAKG;AACH,wBAAgB,wCAAwC,CACtD,OAAO,GAAE,6BAAkC,GAC1C,eAAe,CAEjB;AAED;;;;;GAKG;AACH,wBAAgB,+BAA+B,CAC7C,OAAO,GAAE,6BAAkC,GAC1C,eAAe,CAEjB;AAED;;;;;GAKG;AACH,wBAAgB,sCAAsC,CACpD,OAAO,GAAE,6BAAkC,GAC1C,eAAe,CAEjB;AAED;;;;;GAKG;AACH,wBAAgB,kCAAkC,CAChD,OAAO,GAAE,6BAAkC,GAC1C,eAAe,CAEjB"}
|
@@ -0,0 +1,143 @@
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
2
|
+
// Licensed under the MIT License.
|
3
|
+
import { EnvironmentCredential } from "./environmentCredential.js";
|
4
|
+
import { ManagedIdentityCredential } from "./managedIdentityCredential/index.js";
|
5
|
+
import { WorkloadIdentityCredential } from "./workloadIdentityCredential.js";
|
6
|
+
import { AzureDeveloperCliCredential } from "./azureDeveloperCliCredential.js";
|
7
|
+
import { AzureCliCredential } from "./azureCliCredential.js";
|
8
|
+
import { AzurePowerShellCredential } from "./azurePowerShellCredential.js";
|
9
|
+
import { VisualStudioCodeCredential } from "./visualStudioCodeCredential.js";
|
10
|
+
import { BrokerCredential } from "./brokerCredential.js";
|
11
|
+
/**
|
12
|
+
* Creates a {@link BrokerCredential} instance with the provided options.
|
13
|
+
* This credential uses the Windows Authentication Manager (WAM) broker for authentication.
|
14
|
+
* It will only attempt to authenticate silently using the default broker account
|
15
|
+
*
|
16
|
+
* @param options - Options for configuring the credential.
|
17
|
+
*
|
18
|
+
* @internal
|
19
|
+
*/
|
20
|
+
export function createDefaultBrokerCredential(options = {}) {
|
21
|
+
return new BrokerCredential(options);
|
22
|
+
}
|
23
|
+
/**
|
24
|
+
* Creates a {@link VisualStudioCodeCredential} from the provided options.
|
25
|
+
* @param options - Options to configure the credential.
|
26
|
+
*
|
27
|
+
* @internal
|
28
|
+
*/
|
29
|
+
export function createDefaultVisualStudioCodeCredential(options = {}) {
|
30
|
+
return new VisualStudioCodeCredential(options);
|
31
|
+
}
|
32
|
+
/**
|
33
|
+
* Creates a {@link ManagedIdentityCredential} from the provided options.
|
34
|
+
* @param options - Options to configure the credential.
|
35
|
+
*
|
36
|
+
* @internal
|
37
|
+
*/
|
38
|
+
export function createDefaultManagedIdentityCredential(options = {}) {
|
39
|
+
options.retryOptions ??= {
|
40
|
+
maxRetries: 5,
|
41
|
+
retryDelayInMs: 800,
|
42
|
+
};
|
43
|
+
const managedIdentityClientId = options?.managedIdentityClientId ??
|
44
|
+
process.env.AZURE_CLIENT_ID;
|
45
|
+
const workloadIdentityClientId = options?.workloadIdentityClientId ??
|
46
|
+
managedIdentityClientId;
|
47
|
+
const managedResourceId = options
|
48
|
+
?.managedIdentityResourceId;
|
49
|
+
const workloadFile = process.env.AZURE_FEDERATED_TOKEN_FILE;
|
50
|
+
const tenantId = options?.tenantId ?? process.env.AZURE_TENANT_ID;
|
51
|
+
if (managedResourceId) {
|
52
|
+
const managedIdentityResourceIdOptions = {
|
53
|
+
...options,
|
54
|
+
resourceId: managedResourceId,
|
55
|
+
};
|
56
|
+
return new ManagedIdentityCredential(managedIdentityResourceIdOptions);
|
57
|
+
}
|
58
|
+
if (workloadFile && workloadIdentityClientId) {
|
59
|
+
const workloadIdentityCredentialOptions = {
|
60
|
+
...options,
|
61
|
+
tenantId: tenantId,
|
62
|
+
};
|
63
|
+
return new ManagedIdentityCredential(workloadIdentityClientId, workloadIdentityCredentialOptions);
|
64
|
+
}
|
65
|
+
if (managedIdentityClientId) {
|
66
|
+
const managedIdentityClientOptions = {
|
67
|
+
...options,
|
68
|
+
clientId: managedIdentityClientId,
|
69
|
+
};
|
70
|
+
return new ManagedIdentityCredential(managedIdentityClientOptions);
|
71
|
+
}
|
72
|
+
// We may be able to return a UnavailableCredential here, but that may be a breaking change
|
73
|
+
return new ManagedIdentityCredential(options);
|
74
|
+
}
|
75
|
+
/**
|
76
|
+
* Creates a {@link WorkloadIdentityCredential} from the provided options.
|
77
|
+
* @param options - Options to configure the credential.
|
78
|
+
*
|
79
|
+
* @internal
|
80
|
+
*/
|
81
|
+
export function createDefaultWorkloadIdentityCredential(options) {
|
82
|
+
const managedIdentityClientId = options?.managedIdentityClientId ??
|
83
|
+
process.env.AZURE_CLIENT_ID;
|
84
|
+
const workloadIdentityClientId = options?.workloadIdentityClientId ??
|
85
|
+
managedIdentityClientId;
|
86
|
+
const workloadFile = process.env.AZURE_FEDERATED_TOKEN_FILE;
|
87
|
+
const tenantId = options?.tenantId ?? process.env.AZURE_TENANT_ID;
|
88
|
+
if (workloadFile && workloadIdentityClientId) {
|
89
|
+
const workloadIdentityCredentialOptions = {
|
90
|
+
...options,
|
91
|
+
tenantId,
|
92
|
+
clientId: workloadIdentityClientId,
|
93
|
+
tokenFilePath: workloadFile,
|
94
|
+
};
|
95
|
+
return new WorkloadIdentityCredential(workloadIdentityCredentialOptions);
|
96
|
+
}
|
97
|
+
if (tenantId) {
|
98
|
+
const workloadIdentityClientTenantOptions = {
|
99
|
+
...options,
|
100
|
+
tenantId,
|
101
|
+
};
|
102
|
+
return new WorkloadIdentityCredential(workloadIdentityClientTenantOptions);
|
103
|
+
}
|
104
|
+
// We may be able to return a UnavailableCredential here, but that may be a breaking change
|
105
|
+
return new WorkloadIdentityCredential(options);
|
106
|
+
}
|
107
|
+
/**
|
108
|
+
* Creates a {@link AzureDeveloperCliCredential} from the provided options.
|
109
|
+
* @param options - Options to configure the credential.
|
110
|
+
*
|
111
|
+
* @internal
|
112
|
+
*/
|
113
|
+
export function createDefaultAzureDeveloperCliCredential(options = {}) {
|
114
|
+
return new AzureDeveloperCliCredential(options);
|
115
|
+
}
|
116
|
+
/**
|
117
|
+
* Creates a {@link AzureCliCredential} from the provided options.
|
118
|
+
* @param options - Options to configure the credential.
|
119
|
+
*
|
120
|
+
* @internal
|
121
|
+
*/
|
122
|
+
export function createDefaultAzureCliCredential(options = {}) {
|
123
|
+
return new AzureCliCredential(options);
|
124
|
+
}
|
125
|
+
/**
|
126
|
+
* Creates a {@link AzurePowerShellCredential} from the provided options.
|
127
|
+
* @param options - Options to configure the credential.
|
128
|
+
*
|
129
|
+
* @internal
|
130
|
+
*/
|
131
|
+
export function createDefaultAzurePowershellCredential(options = {}) {
|
132
|
+
return new AzurePowerShellCredential(options);
|
133
|
+
}
|
134
|
+
/**
|
135
|
+
* Creates an {@link EnvironmentCredential} from the provided options.
|
136
|
+
* @param options - Options to configure the credential.
|
137
|
+
*
|
138
|
+
* @internal
|
139
|
+
*/
|
140
|
+
export function createDefaultEnvironmentCredential(options = {}) {
|
141
|
+
return new EnvironmentCredential(options);
|
142
|
+
}
|
143
|
+
//# sourceMappingURL=defaultAzureCredentialFunctions.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"defaultAzureCredentialFunctions.js","sourceRoot":"","sources":["../../../src/credentials/defaultAzureCredentialFunctions.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAQlC,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAKnE,OAAO,EAAE,yBAAyB,EAAE,MAAM,sCAAsC,CAAC;AACjF,OAAO,EAAE,0BAA0B,EAAE,MAAM,iCAAiC,CAAC;AAC7E,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAC/E,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAE3E,OAAO,EAAE,0BAA0B,EAAE,MAAM,iCAAiC,CAAC;AAC7E,OAAO,EAAE,gBAAgB,E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B,CAC7C,UAAyC,EAAE;IAE3C,OAAO,IAAI,kBAAkB,CAAC,OAAO,CAAC,CAAC;AACzC,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,sCAAsC,CACpD,UAAyC,EAAE;IAE3C,OAAO,IAAI,yBAAyB,CAAC,OAAO,CAAC,CAAC;AAChD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,kCAAkC,CAChD,UAAyC,EAAE;IAE3C,OAAO,IAAI,qBAAqB,CAAC,OAAO,CAAC,CAAC;AAC5C,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { TokenCredential } from \"@azure/core-auth\";\nimport type {\n DefaultAzureCredentialClientIdOptions,\n DefaultAzureCredentialOptions,\n DefaultAzureCredentialResourceIdOptions,\n} from \"./defaultAzureCredentialOptions.js\";\nimport { EnvironmentCredential } from \"./environmentCredential.js\";\nimport type {\n ManagedIdentityCredentialClientIdOptions,\n ManagedIdentityCredentialResourceIdOptions,\n} from \"./managedIdentityCredential/options.js\";\nimport { ManagedIdentityCredential } from \"./managedIdentityCredential/index.js\";\nimport { WorkloadIdentityCredential } from \"./workloadIdentityCredential.js\";\nimport { AzureDeveloperCliCredential } from \"./azureDeveloperCliCredential.js\";\nimport { AzureCliCredential } from \"./azureCliCredential.js\";\nimport { AzurePowerShellCredential } from \"./azurePowerShellCredential.js\";\nimport type { WorkloadIdentityCredentialOptions } from \"./workloadIdentityCredentialOptions.js\";\nimport { VisualStudioCodeCredential } from \"./visualStudioCodeCredential.js\";\nimport { BrokerCredential } from \"./brokerCredential.js\";\n\n/**\n * Creates a {@link BrokerCredential} instance with the provided options.\n * This credential uses the Windows Authentication Manager (WAM) broker for authentication.\n * It will only attempt to authenticate silently using the default broker account\n *\n * @param options - Options for configuring the credential.\n *\n * @internal\n */\nexport function createDefaultBrokerCredential(\n options: DefaultAzureCredentialOptions = {},\n): TokenCredential {\n return new BrokerCredential(options);\n}\n\n/**\n * Creates a {@link VisualStudioCodeCredential} from the provided options.\n * @param options - Options to configure the credential.\n *\n * @internal\n */\nexport function createDefaultVisualStudioCodeCredential(\n options: DefaultAzureCredentialOptions = {},\n): TokenCredential {\n return new VisualStudioCodeCredential(options);\n}\n\n/**\n * Creates a {@link ManagedIdentityCredential} from the provided options.\n * @param options - Options to configure the credential.\n *\n * @internal\n */\nexport function createDefaultManagedIdentityCredential(\n options:\n | DefaultAzureCredentialOptions\n | DefaultAzureCredentialResourceIdOptions\n | DefaultAzureCredentialClientIdOptions = {},\n): TokenCredential {\n options.retryOptions ??= {\n maxRetries: 5,\n retryDelayInMs: 800,\n };\n const managedIdentityClientId =\n (options as DefaultAzureCredentialClientIdOptions)?.managedIdentityClientId ??\n process.env.AZURE_CLIENT_ID;\n const workloadIdentityClientId =\n (options as DefaultAzureCredentialClientIdOptions)?.workloadIdentityClientId ??\n managedIdentityClientId;\n const managedResourceId = (options as DefaultAzureCredentialResourceIdOptions)\n ?.managedIdentityResourceId;\n const workloadFile = process.env.AZURE_FEDERATED_TOKEN_FILE;\n const tenantId = options?.tenantId ?? process.env.AZURE_TENANT_ID;\n if (managedResourceId) {\n const managedIdentityResourceIdOptions: ManagedIdentityCredentialResourceIdOptions = {\n ...options,\n resourceId: managedResourceId,\n };\n return new ManagedIdentityCredential(managedIdentityResourceIdOptions);\n }\n\n if (workloadFile && workloadIdentityClientId) {\n const workloadIdentityCredentialOptions: DefaultAzureCredentialOptions = {\n ...options,\n tenantId: tenantId,\n };\n\n return new ManagedIdentityCredential(\n workloadIdentityClientId,\n workloadIdentityCredentialOptions,\n );\n }\n\n if (managedIdentityClientId) {\n const managedIdentityClientOptions: ManagedIdentityCredentialClientIdOptions = {\n ...options,\n clientId: managedIdentityClientId,\n };\n\n return new ManagedIdentityCredential(managedIdentityClientOptions);\n }\n\n // We may be able to return a UnavailableCredential here, but that may be a breaking change\n return new ManagedIdentityCredential(options);\n}\n\n/**\n * Creates a {@link WorkloadIdentityCredential} from the provided options.\n * @param options - Options to configure the credential.\n *\n * @internal\n */\nexport function createDefaultWorkloadIdentityCredential(\n options?: DefaultAzureCredentialOptions | DefaultAzureCredentialClientIdOptions,\n): TokenCredential {\n const managedIdentityClientId =\n (options as DefaultAzureCredentialClientIdOptions)?.managedIdentityClientId ??\n process.env.AZURE_CLIENT_ID;\n const workloadIdentityClientId =\n (options as DefaultAzureCredentialClientIdOptions)?.workloadIdentityClientId ??\n managedIdentityClientId;\n const workloadFile = process.env.AZURE_FEDERATED_TOKEN_FILE;\n const tenantId = options?.tenantId ?? process.env.AZURE_TENANT_ID;\n if (workloadFile && workloadIdentityClientId) {\n const workloadIdentityCredentialOptions: WorkloadIdentityCredentialOptions = {\n ...options,\n tenantId,\n clientId: workloadIdentityClientId,\n tokenFilePath: workloadFile,\n };\n return new WorkloadIdentityCredential(workloadIdentityCredentialOptions);\n }\n if (tenantId) {\n const workloadIdentityClientTenantOptions: WorkloadIdentityCredentialOptions = {\n ...options,\n tenantId,\n };\n return new WorkloadIdentityCredential(workloadIdentityClientTenantOptions);\n }\n\n // We may be able to return a UnavailableCredential here, but that may be a breaking change\n return new WorkloadIdentityCredential(options);\n}\n\n/**\n * Creates a {@link AzureDeveloperCliCredential} from the provided options.\n * @param options - Options to configure the credential.\n *\n * @internal\n */\nexport function createDefaultAzureDeveloperCliCredential(\n options: DefaultAzureCredentialOptions = {},\n): TokenCredential {\n return new AzureDeveloperCliCredential(options);\n}\n\n/**\n * Creates a {@link AzureCliCredential} from the provided options.\n * @param options - Options to configure the credential.\n *\n * @internal\n */\nexport function createDefaultAzureCliCredential(\n options: DefaultAzureCredentialOptions = {},\n): TokenCredential {\n return new AzureCliCredential(options);\n}\n\n/**\n * Creates a {@link AzurePowerShellCredential} from the provided options.\n * @param options - Options to configure the credential.\n *\n * @internal\n */\nexport function createDefaultAzurePowershellCredential(\n options: DefaultAzureCredentialOptions = {},\n): TokenCredential {\n return new AzurePowerShellCredential(options);\n}\n\n/**\n * Creates an {@link EnvironmentCredential} from the provided options.\n * @param options - Options to configure the credential.\n *\n * @internal\n */\nexport function createDefaultEnvironmentCredential(\n options: DefaultAzureCredentialOptions = {},\n): TokenCredential {\n return new EnvironmentCredential(options);\n}\n"]}
|
@@ -1,37 +1,6 @@
|
|
1
1
|
import type { DefaultAzureCredentialClientIdOptions, DefaultAzureCredentialOptions, DefaultAzureCredentialResourceIdOptions } from "./defaultAzureCredentialOptions.js";
|
2
2
|
import { ChainedTokenCredential } from "./chainedTokenCredential.js";
|
3
3
|
import type { TokenCredential } from "@azure/core-auth";
|
4
|
-
/**
|
5
|
-
* Creates a {@link ManagedIdentityCredential} from the provided options.
|
6
|
-
* @param options - Options to configure the credential.
|
7
|
-
*
|
8
|
-
* @internal
|
9
|
-
*/
|
10
|
-
export declare function createDefaultManagedIdentityCredential(options?: DefaultAzureCredentialOptions | DefaultAzureCredentialResourceIdOptions | DefaultAzureCredentialClientIdOptions): TokenCredential;
|
11
|
-
/**
|
12
|
-
* Creates a BrokerCredential instance with the provided options.
|
13
|
-
* This credential uses the Windows Authentication Manager (WAM) broker for authentication.
|
14
|
-
* It will only attempt to authenticate silently using the default broker account
|
15
|
-
*
|
16
|
-
* @param options - Options for configuring the credential.
|
17
|
-
*
|
18
|
-
* @internal
|
19
|
-
*/
|
20
|
-
export declare function createDefaultBrokerCredential(options?: DefaultAzureCredentialOptions): TokenCredential;
|
21
|
-
/**
|
22
|
-
* Creates an {@link EnvironmentCredential} from the provided options.
|
23
|
-
* @param options - Options to configure the credential.
|
24
|
-
*
|
25
|
-
* @internal
|
26
|
-
*/
|
27
|
-
export declare function createEnvironmentCredential(options?: DefaultAzureCredentialOptions): TokenCredential;
|
28
|
-
/**
|
29
|
-
* Creates a {@link VisualStudioCodeCredential} from the provided options.
|
30
|
-
* @param options - Options to configure the credential.
|
31
|
-
*
|
32
|
-
* @internal
|
33
|
-
*/
|
34
|
-
export declare function createDefaultVisualStudioCodeCredential(options?: DefaultAzureCredentialOptions): TokenCredential;
|
35
4
|
/**
|
36
5
|
* A no-op credential that logs the reason it was skipped if getToken is called.
|
37
6
|
* @internal
|
@@ -52,13 +21,24 @@ export declare class UnavailableDefaultCredential implements TokenCredential {
|
|
52
21
|
* - {@link EnvironmentCredential}
|
53
22
|
* - {@link WorkloadIdentityCredential}
|
54
23
|
* - {@link ManagedIdentityCredential}
|
24
|
+
* - {@link VisualStudioCodeCredential}
|
55
25
|
* - {@link AzureCliCredential}
|
56
26
|
* - {@link AzurePowerShellCredential}
|
57
27
|
* - {@link AzureDeveloperCliCredential}
|
58
|
-
* - {@link VisualStudioCodeCredential}
|
59
28
|
*
|
60
29
|
* Consult the documentation of these credential types for more information
|
61
30
|
* on how they attempt authentication.
|
31
|
+
*
|
32
|
+
* Selecting credentials
|
33
|
+
*
|
34
|
+
* Set environment variable AZURE_TOKEN_CREDENTIALS to select a subset of the credential chain.
|
35
|
+
* DefaultAzureCredential will try only the specified credential(s), but its other behavior remains the same.
|
36
|
+
* Valid values for AZURE_TOKEN_CREDENTIALS are the name of any single type in the above chain, for example
|
37
|
+
* "EnvironmentCredential" or "AzureCliCredential", and these special values:
|
38
|
+
*
|
39
|
+
* - "dev": try [VisualStudioCodeCredential], [AzureCliCredential], [AzurePowerShellCredential] and [AzureDeveloperCliCredential], in that order
|
40
|
+
* - "prod": try [EnvironmentCredential], [WorkloadIdentityCredential], and [ManagedIdentityCredential], in that order
|
41
|
+
*
|
62
42
|
*/
|
63
43
|
export declare class DefaultAzureCredential extends ChainedTokenCredential {
|
64
44
|
/**
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"defaultAzureCredential.d.ts","sourceRoot":"","sources":["../../../src/credentials/defaultAzureCredential.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,qCAAqC,EACrC,6BAA6B,EAC7B,uCAAuC,EACxC,MAAM,oCAAoC,CAAC;
|
1
|
+
{"version":3,"file":"defaultAzureCredential.d.ts","sourceRoot":"","sources":["../../../src/credentials/defaultAzureCredential.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,qCAAqC,EACrC,6BAA6B,EAC7B,uCAAuC,EACxC,MAAM,oCAAoC,CAAC;AAO5C,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAErE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAgBxD;;;GAGG;AACH,qBAAa,4BAA6B,YAAW,eAAe;IAClE,iCAAiC,EAAE,MAAM,CAAC;IAC1C,cAAc,EAAE,MAAM,CAAC;gBAEX,cAAc,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;IAKnD,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;CAM1B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,qBAAa,sBAAuB,SAAQ,sBAAsB;IAChE;;;;OAIG;gBACS,OAAO,CAAC,EAAE,qCAAqC;IAE3D;;;;OAIG;gBACS,OAAO,CAAC,EAAE,uCAAuC;IAE7D;;;;OAIG;gBACS,OAAO,CAAC,EAAE,6BAA6B;CAoFpD"}
|
@@ -1,151 +1,9 @@
|
|
1
1
|
// Copyright (c) Microsoft Corporation.
|
2
2
|
// Licensed under the MIT License.
|
3
|
-
import { ManagedIdentityCredential } from "./managedIdentityCredential/index.js";
|
4
|
-
import { AzureCliCredential } from "./azureCliCredential.js";
|
5
|
-
import { AzureDeveloperCliCredential } from "./azureDeveloperCliCredential.js";
|
6
|
-
import { AzurePowerShellCredential } from "./azurePowerShellCredential.js";
|
7
3
|
import { ChainedTokenCredential } from "./chainedTokenCredential.js";
|
8
|
-
import { EnvironmentCredential } from "./environmentCredential.js";
|
9
|
-
import { WorkloadIdentityCredential } from "./workloadIdentityCredential.js";
|
10
4
|
import { credentialLogger } from "../util/logging.js";
|
11
|
-
import {
|
12
|
-
import { BrokerCredential } from "./brokerCredential.js";
|
5
|
+
import { createDefaultAzureCliCredential, createDefaultAzureDeveloperCliCredential, createDefaultAzurePowershellCredential, createDefaultBrokerCredential, createDefaultManagedIdentityCredential, createDefaultVisualStudioCodeCredential, createDefaultWorkloadIdentityCredential, createDefaultEnvironmentCredential, } from "./defaultAzureCredentialFunctions.js";
|
13
6
|
const logger = credentialLogger("DefaultAzureCredential");
|
14
|
-
/**
|
15
|
-
* Creates a {@link ManagedIdentityCredential} from the provided options.
|
16
|
-
* @param options - Options to configure the credential.
|
17
|
-
*
|
18
|
-
* @internal
|
19
|
-
*/
|
20
|
-
export function createDefaultManagedIdentityCredential(options = {}) {
|
21
|
-
options.retryOptions ??= {
|
22
|
-
maxRetries: 5,
|
23
|
-
retryDelayInMs: 800,
|
24
|
-
};
|
25
|
-
const managedIdentityClientId = options?.managedIdentityClientId ??
|
26
|
-
process.env.AZURE_CLIENT_ID;
|
27
|
-
const workloadIdentityClientId = options?.workloadIdentityClientId ??
|
28
|
-
managedIdentityClientId;
|
29
|
-
const managedResourceId = options
|
30
|
-
?.managedIdentityResourceId;
|
31
|
-
const workloadFile = process.env.AZURE_FEDERATED_TOKEN_FILE;
|
32
|
-
const tenantId = options?.tenantId ?? process.env.AZURE_TENANT_ID;
|
33
|
-
if (managedResourceId) {
|
34
|
-
const managedIdentityResourceIdOptions = {
|
35
|
-
...options,
|
36
|
-
resourceId: managedResourceId,
|
37
|
-
};
|
38
|
-
return new ManagedIdentityCredential(managedIdentityResourceIdOptions);
|
39
|
-
}
|
40
|
-
if (workloadFile && workloadIdentityClientId) {
|
41
|
-
const workloadIdentityCredentialOptions = {
|
42
|
-
...options,
|
43
|
-
tenantId: tenantId,
|
44
|
-
};
|
45
|
-
return new ManagedIdentityCredential(workloadIdentityClientId, workloadIdentityCredentialOptions);
|
46
|
-
}
|
47
|
-
if (managedIdentityClientId) {
|
48
|
-
const managedIdentityClientOptions = {
|
49
|
-
...options,
|
50
|
-
clientId: managedIdentityClientId,
|
51
|
-
};
|
52
|
-
return new ManagedIdentityCredential(managedIdentityClientOptions);
|
53
|
-
}
|
54
|
-
// We may be able to return a UnavailableCredential here, but that may be a breaking change
|
55
|
-
return new ManagedIdentityCredential(options);
|
56
|
-
}
|
57
|
-
/**
|
58
|
-
* Creates a {@link WorkloadIdentityCredential} from the provided options.
|
59
|
-
* @param options - Options to configure the credential.
|
60
|
-
*
|
61
|
-
* @internal
|
62
|
-
*/
|
63
|
-
function createDefaultWorkloadIdentityCredential(options) {
|
64
|
-
const managedIdentityClientId = options?.managedIdentityClientId ??
|
65
|
-
process.env.AZURE_CLIENT_ID;
|
66
|
-
const workloadIdentityClientId = options?.workloadIdentityClientId ??
|
67
|
-
managedIdentityClientId;
|
68
|
-
const workloadFile = process.env.AZURE_FEDERATED_TOKEN_FILE;
|
69
|
-
const tenantId = options?.tenantId ?? process.env.AZURE_TENANT_ID;
|
70
|
-
if (workloadFile && workloadIdentityClientId) {
|
71
|
-
const workloadIdentityCredentialOptions = {
|
72
|
-
...options,
|
73
|
-
tenantId,
|
74
|
-
clientId: workloadIdentityClientId,
|
75
|
-
tokenFilePath: workloadFile,
|
76
|
-
};
|
77
|
-
return new WorkloadIdentityCredential(workloadIdentityCredentialOptions);
|
78
|
-
}
|
79
|
-
if (tenantId) {
|
80
|
-
const workloadIdentityClientTenantOptions = {
|
81
|
-
...options,
|
82
|
-
tenantId,
|
83
|
-
};
|
84
|
-
return new WorkloadIdentityCredential(workloadIdentityClientTenantOptions);
|
85
|
-
}
|
86
|
-
// We may be able to return a UnavailableCredential here, but that may be a breaking change
|
87
|
-
return new WorkloadIdentityCredential(options);
|
88
|
-
}
|
89
|
-
/**
|
90
|
-
* Creates a {@link AzureDeveloperCliCredential} from the provided options.
|
91
|
-
* @param options - Options to configure the credential.
|
92
|
-
*
|
93
|
-
* @internal
|
94
|
-
*/
|
95
|
-
function createDefaultAzureDeveloperCliCredential(options = {}) {
|
96
|
-
const processTimeoutInMs = options.processTimeoutInMs;
|
97
|
-
return new AzureDeveloperCliCredential({ processTimeoutInMs, ...options });
|
98
|
-
}
|
99
|
-
/**
|
100
|
-
* Creates a {@link AzureCliCredential} from the provided options.
|
101
|
-
* @param options - Options to configure the credential.
|
102
|
-
*
|
103
|
-
* @internal
|
104
|
-
*/
|
105
|
-
function createDefaultAzureCliCredential(options = {}) {
|
106
|
-
const processTimeoutInMs = options.processTimeoutInMs;
|
107
|
-
return new AzureCliCredential({ processTimeoutInMs, ...options });
|
108
|
-
}
|
109
|
-
/**
|
110
|
-
* Creates a {@link AzurePowerShellCredential} from the provided options.
|
111
|
-
* @param options - Options to configure the credential.
|
112
|
-
*
|
113
|
-
* @internal
|
114
|
-
*/
|
115
|
-
function createDefaultAzurePowershellCredential(options = {}) {
|
116
|
-
const processTimeoutInMs = options.processTimeoutInMs;
|
117
|
-
return new AzurePowerShellCredential({ processTimeoutInMs, ...options });
|
118
|
-
}
|
119
|
-
/**
|
120
|
-
* Creates a BrokerCredential instance with the provided options.
|
121
|
-
* This credential uses the Windows Authentication Manager (WAM) broker for authentication.
|
122
|
-
* It will only attempt to authenticate silently using the default broker account
|
123
|
-
*
|
124
|
-
* @param options - Options for configuring the credential.
|
125
|
-
*
|
126
|
-
* @internal
|
127
|
-
*/
|
128
|
-
export function createDefaultBrokerCredential(options = {}) {
|
129
|
-
return new BrokerCredential(options);
|
130
|
-
}
|
131
|
-
/**
|
132
|
-
* Creates an {@link EnvironmentCredential} from the provided options.
|
133
|
-
* @param options - Options to configure the credential.
|
134
|
-
*
|
135
|
-
* @internal
|
136
|
-
*/
|
137
|
-
export function createEnvironmentCredential(options = {}) {
|
138
|
-
return new EnvironmentCredential(options);
|
139
|
-
}
|
140
|
-
/**
|
141
|
-
* Creates a {@link VisualStudioCodeCredential} from the provided options.
|
142
|
-
* @param options - Options to configure the credential.
|
143
|
-
*
|
144
|
-
* @internal
|
145
|
-
*/
|
146
|
-
export function createDefaultVisualStudioCodeCredential(options = {}) {
|
147
|
-
return new VisualStudioCodeCredential(options);
|
148
|
-
}
|
149
7
|
/**
|
150
8
|
* A no-op credential that logs the reason it was skipped if getToken is called.
|
151
9
|
* @internal
|
@@ -172,13 +30,24 @@ export class UnavailableDefaultCredential {
|
|
172
30
|
* - {@link EnvironmentCredential}
|
173
31
|
* - {@link WorkloadIdentityCredential}
|
174
32
|
* - {@link ManagedIdentityCredential}
|
33
|
+
* - {@link VisualStudioCodeCredential}
|
175
34
|
* - {@link AzureCliCredential}
|
176
35
|
* - {@link AzurePowerShellCredential}
|
177
36
|
* - {@link AzureDeveloperCliCredential}
|
178
|
-
* - {@link VisualStudioCodeCredential}
|
179
37
|
*
|
180
38
|
* Consult the documentation of these credential types for more information
|
181
39
|
* on how they attempt authentication.
|
40
|
+
*
|
41
|
+
* Selecting credentials
|
42
|
+
*
|
43
|
+
* Set environment variable AZURE_TOKEN_CREDENTIALS to select a subset of the credential chain.
|
44
|
+
* DefaultAzureCredential will try only the specified credential(s), but its other behavior remains the same.
|
45
|
+
* Valid values for AZURE_TOKEN_CREDENTIALS are the name of any single type in the above chain, for example
|
46
|
+
* "EnvironmentCredential" or "AzureCliCredential", and these special values:
|
47
|
+
*
|
48
|
+
* - "dev": try [VisualStudioCodeCredential], [AzureCliCredential], [AzurePowerShellCredential] and [AzureDeveloperCliCredential], in that order
|
49
|
+
* - "prod": try [EnvironmentCredential], [WorkloadIdentityCredential], and [ManagedIdentityCredential], in that order
|
50
|
+
*
|
182
51
|
*/
|
183
52
|
export class DefaultAzureCredential extends ChainedTokenCredential {
|
184
53
|
constructor(options) {
|
@@ -194,27 +63,47 @@ export class DefaultAzureCredential extends ChainedTokenCredential {
|
|
194
63
|
createDefaultBrokerCredential,
|
195
64
|
];
|
196
65
|
const prodCredentialFunctions = [
|
197
|
-
|
66
|
+
createDefaultEnvironmentCredential,
|
198
67
|
createDefaultWorkloadIdentityCredential,
|
199
68
|
createDefaultManagedIdentityCredential,
|
200
69
|
];
|
201
70
|
let credentialFunctions = [];
|
71
|
+
const validCredentialNames = "EnvironmentCredential, WorkloadIdentityCredential, ManagedIdentityCredential, VisualStudioCodeCredential, AzureCliCredential, AzurePowerShellCredential, AzureDeveloperCliCredential";
|
202
72
|
// If AZURE_TOKEN_CREDENTIALS is set, use it to determine which credentials to use.
|
203
|
-
// The value of AZURE_TOKEN_CREDENTIALS should be either "dev" or "prod".
|
73
|
+
// The value of AZURE_TOKEN_CREDENTIALS should be either "dev" or "prod" or any one of these credentials - {validCredentialNames}.
|
204
74
|
if (azureTokenCredentials) {
|
205
75
|
switch (azureTokenCredentials) {
|
206
76
|
case "dev":
|
207
|
-
// If AZURE_TOKEN_CREDENTIALS is set to "dev", use the developer tool-based credential chain.
|
208
77
|
credentialFunctions = devCredentialFunctions;
|
209
78
|
break;
|
210
79
|
case "prod":
|
211
|
-
// If AZURE_TOKEN_CREDENTIALS is set to "prod", use the production credential chain.
|
212
80
|
credentialFunctions = prodCredentialFunctions;
|
213
81
|
break;
|
82
|
+
case "environmentcredential":
|
83
|
+
credentialFunctions = [createDefaultEnvironmentCredential];
|
84
|
+
break;
|
85
|
+
case "workloadidentitycredential":
|
86
|
+
credentialFunctions = [createDefaultWorkloadIdentityCredential];
|
87
|
+
break;
|
88
|
+
case "managedidentitycredential":
|
89
|
+
credentialFunctions = [createDefaultManagedIdentityCredential];
|
90
|
+
break;
|
91
|
+
case "visualstudiocodecredential":
|
92
|
+
credentialFunctions = [createDefaultVisualStudioCodeCredential];
|
93
|
+
break;
|
94
|
+
case "azureclicredential":
|
95
|
+
credentialFunctions = [createDefaultAzureCliCredential];
|
96
|
+
break;
|
97
|
+
case "azurepowershellcredential":
|
98
|
+
credentialFunctions = [createDefaultAzurePowershellCredential];
|
99
|
+
break;
|
100
|
+
case "azuredeveloperclicredential":
|
101
|
+
credentialFunctions = [createDefaultAzureDeveloperCliCredential];
|
102
|
+
break;
|
214
103
|
default: {
|
215
104
|
// If AZURE_TOKEN_CREDENTIALS is set to an unsupported value, throw an error.
|
216
|
-
//
|
217
|
-
const errorMessage = `Invalid value for AZURE_TOKEN_CREDENTIALS = ${process.env.AZURE_TOKEN_CREDENTIALS}. Valid values are 'prod' or 'dev'.`;
|
105
|
+
// This will prevent the creation of the DefaultAzureCredential.
|
106
|
+
const errorMessage = `Invalid value for AZURE_TOKEN_CREDENTIALS = ${process.env.AZURE_TOKEN_CREDENTIALS}. Valid values are 'prod' or 'dev' or any of these credentials - ${validCredentialNames}.`;
|
218
107
|
logger.warning(errorMessage);
|
219
108
|
throw new Error(errorMessage);
|
220
109
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"defaultAzureCredential.js","sourceRoot":"","sources":["../../../src/credentials/defaultAzureCredential.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAWlC,OAAO,EAAE,yBAAyB,EAAE,MAAM,sCAAsC,CAAC;AAEjF,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAC/E,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAC3E,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAEnE,OAAO,EAAE,0BAA0B,EAAE,MAAM,iCAAiC,CAAC;AAE7E,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,0BAA0B,EAAE,MAAM,iCAAiC,CAAC;AAC7E,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD,MAAM,MAAM,GAAG,gBAAgB,CAAC,wBAAwB,CAAC,CAAC;AAE1D;;;;;GAKG;AACH,MAAM,UAAU,sCAAsC,CACpD,UAG4C,EAAE;IAE9C,OAAO,CAAC,YAAY,KAAK;QACvB,UAAU,EAAE,CAAC;QACb,cAAc,EAAE,GAAG;KACpB,CAAC;IACF,MAAM,uBAAuB,GAC1B,OAAiD,EAAE,uBAAuB;QAC3E,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC;IAC9B,MAAM,wBAAwB,GAC3B,OAAiD,EA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BAAqB,EAAE,CAAC;YAC1B,QAAQ,qBAAqB,EAAE,CAAC;gBAC9B,KAAK,KAAK;oBACR,6FAA6F;oBAC7F,mBAAmB,GAAG,sBAAsB,CAAC;oBAC7C,MAAM;gBACR,KAAK,MAAM;oBACT,oFAAoF;oBACpF,mBAAmB,GAAG,uBAAuB,CAAC;oBAC9C,MAAM;gBACR,OAAO,CAAC,CAAC,CAAC;oBACR,6EAA6E;oBAC7E,qFAAqF;oBACrF,MAAM,YAAY,GAAG,+CAA+C,OAAO,CAAC,GAAG,CAAC,uBAAuB,qCAAqC,CAAC;oBAC7I,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;oBAC7B,MAAM,IAAI,KAAK,CAAC,YAAY,CAAC,CAAC;gBAChC,CAAC;YACH,CAAC;QACH,CAAC;aAAM,CAAC;YACN,2EAA2E;YAC3E,mBAAmB,GAAG,CAAC,GAAG,uBAAuB,EAAE,GAAG,sBAAsB,CAAC,CAAC;QAChF,CAAC;QAED,gLAAgL;QAChL,8DAA8D;QAC9D,6DAA6D;QAC7D,gEAAgE;QAChE,sHAAsH;QACtH,MAAM,WAAW,GAAsB,mBAAmB,CAAC,GAAG,CAAC,CAAC,kBAAkB,EAAE,EAAE;YACpF,IAAI,CAAC;gBACH,OAAO,kBAAkB,CAAC,OAAO,CAAC,CAAC;YACrC,CAAC;YAAC,OAAO,GAAQ,EAAE,CAAC;gBAClB,MAAM,CAAC,OAAO,CACZ,WAAW,kBAAkB,CAAC,IAAI,iDAAiD,GAAG,EAAE,CACzF,CAAC;gBACF,OAAO,IAAI,4BAA4B,CAAC,kBAAkB,CAAC,IAAI,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;YAChF,CAAC;QACH,CAAC,CAAC,CAAC;QAEH,KAAK,CAAC,GAAG,WAAW,CAAC,CAAC;IACxB,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type {\n DefaultAzureCredentialClientIdOptions,\n DefaultAzureCredentialOptions,\n DefaultAzureCredentialResourceIdOptions,\n} from \"./defaultAzureCredentialOptions.js\";\nimport type {\n ManagedIdentityCredentialClientIdOptions,\n ManagedIdentityCredentialResourceIdOptions,\n} from \"./managedIdentityCredential/options.js\";\nimport { ManagedIdentityCredential } from \"./managedIdentityCredential/index.js\";\n\nimport { AzureCliCredential } from \"./azureCliCredential.js\";\nimport { AzureDeveloperCliCredential } from \"./azureDeveloperCliCredential.js\";\nimport { AzurePowerShellCredential } from \"./azurePowerShellCredential.js\";\nimport { ChainedTokenCredential } from \"./chainedTokenCredential.js\";\nimport { EnvironmentCredential } from \"./environmentCredential.js\";\nimport type { TokenCredential } from \"@azure/core-auth\";\nimport { WorkloadIdentityCredential } from \"./workloadIdentityCredential.js\";\nimport type { WorkloadIdentityCredentialOptions } from \"./workloadIdentityCredentialOptions.js\";\nimport { credentialLogger } from \"../util/logging.js\";\nimport { VisualStudioCodeCredential } from \"./visualStudioCodeCredential.js\";\nimport { BrokerCredential } from \"./brokerCredential.js\";\n\nconst logger = credentialLogger(\"DefaultAzureCredential\");\n\n/**\n * Creates a {@link ManagedIdentityCredential} from the provided options.\n * @param options - Options to configure the credential.\n *\n * @internal\n */\nexport function createDefaultManagedIdentityCredential(\n options:\n | DefaultAzureCredentialOptions\n | DefaultAzureCredentialResourceIdOptions\n | DefaultAzureCredentialClientIdOptions = {},\n): TokenCredential {\n options.retryOptions ??= {\n maxRetries: 5,\n retryDelayInMs: 800,\n };\n const managedIdentityClientId =\n (options as DefaultAzureCredentialClientIdOptions)?.managedIdentityClientId ??\n process.env.AZURE_CLIENT_ID;\n const workloadIdentityClientId =\n (options as DefaultAzureCredentialClientIdOptions)?.workloadIdentityClientId ??\n managedIdentityClientId;\n const managedResourceId = (options as DefaultAzureCredentialResourceIdOptions)\n ?.managedIdentityResourceId;\n const workloadFile = process.env.AZURE_FEDERATED_TOKEN_FILE;\n const tenantId = options?.tenantId ?? process.env.AZURE_TENANT_ID;\n if (managedResourceId) {\n const managedIdentityResourceIdOptions: ManagedIdentityCredentialResourceIdOptions = {\n ...options,\n resourceId: managedResourceId,\n };\n return new ManagedIdentityCredential(managedIdentityResourceIdOptions);\n }\n\n if (workloadFile && workloadIdentityClientId) {\n const workloadIdentityCredentialOptions: DefaultAzureCredentialOptions = {\n ...options,\n tenantId: tenantId,\n };\n\n return new ManagedIdentityCredential(\n workloadIdentityClientId,\n workloadIdentityCredentialOptions,\n );\n }\n\n if (managedIdentityClientId) {\n const managedIdentityClientOptions: ManagedIdentityCredentialClientIdOptions = {\n ...options,\n clientId: managedIdentityClientId,\n };\n\n return new ManagedIdentityCredential(managedIdentityClientOptions);\n }\n\n // We may be able to return a UnavailableCredential here, but that may be a breaking change\n return new ManagedIdentityCredential(options);\n}\n\n/**\n * Creates a {@link WorkloadIdentityCredential} from the provided options.\n * @param options - Options to configure the credential.\n *\n * @internal\n */\nfunction createDefaultWorkloadIdentityCredential(\n options?: DefaultAzureCredentialOptions | DefaultAzureCredentialClientIdOptions,\n): TokenCredential {\n const managedIdentityClientId =\n (options as DefaultAzureCredentialClientIdOptions)?.managedIdentityClientId ??\n process.env.AZURE_CLIENT_ID;\n const workloadIdentityClientId =\n (options as DefaultAzureCredentialClientIdOptions)?.workloadIdentityClientId ??\n managedIdentityClientId;\n const workloadFile = process.env.AZURE_FEDERATED_TOKEN_FILE;\n const tenantId = options?.tenantId ?? process.env.AZURE_TENANT_ID;\n if (workloadFile && workloadIdentityClientId) {\n const workloadIdentityCredentialOptions: WorkloadIdentityCredentialOptions = {\n ...options,\n tenantId,\n clientId: workloadIdentityClientId,\n tokenFilePath: workloadFile,\n };\n return new WorkloadIdentityCredential(workloadIdentityCredentialOptions);\n }\n if (tenantId) {\n const workloadIdentityClientTenantOptions: WorkloadIdentityCredentialOptions = {\n ...options,\n tenantId,\n };\n return new WorkloadIdentityCredential(workloadIdentityClientTenantOptions);\n }\n\n // We may be able to return a UnavailableCredential here, but that may be a breaking change\n return new WorkloadIdentityCredential(options);\n}\n\n/**\n * Creates a {@link AzureDeveloperCliCredential} from the provided options.\n * @param options - Options to configure the credential.\n *\n * @internal\n */\nfunction createDefaultAzureDeveloperCliCredential(\n options: DefaultAzureCredentialOptions = {},\n): TokenCredential {\n const processTimeoutInMs = options.processTimeoutInMs;\n return new AzureDeveloperCliCredential({ processTimeoutInMs, ...options });\n}\n\n/**\n * Creates a {@link AzureCliCredential} from the provided options.\n * @param options - Options to configure the credential.\n *\n * @internal\n */\nfunction createDefaultAzureCliCredential(\n options: DefaultAzureCredentialOptions = {},\n): TokenCredential {\n const processTimeoutInMs = options.processTimeoutInMs;\n return new AzureCliCredential({ processTimeoutInMs, ...options });\n}\n\n/**\n * Creates a {@link AzurePowerShellCredential} from the provided options.\n * @param options - Options to configure the credential.\n *\n * @internal\n */\nfunction createDefaultAzurePowershellCredential(\n options: DefaultAzureCredentialOptions = {},\n): TokenCredential {\n const processTimeoutInMs = options.processTimeoutInMs;\n return new AzurePowerShellCredential({ processTimeoutInMs, ...options });\n}\n\n/**\n * Creates a BrokerCredential instance with the provided options.\n * This credential uses the Windows Authentication Manager (WAM) broker for authentication.\n * It will only attempt to authenticate silently using the default broker account\n *\n * @param options - Options for configuring the credential.\n *\n * @internal\n */\nexport function createDefaultBrokerCredential(\n options: DefaultAzureCredentialOptions = {},\n): TokenCredential {\n return new BrokerCredential(options);\n}\n\n/**\n * Creates an {@link EnvironmentCredential} from the provided options.\n * @param options - Options to configure the credential.\n *\n * @internal\n */\nexport function createEnvironmentCredential(\n options: DefaultAzureCredentialOptions = {},\n): TokenCredential {\n return new EnvironmentCredential(options);\n}\n\n/**\n * Creates a {@link VisualStudioCodeCredential} from the provided options.\n * @param options - Options to configure the credential.\n *\n * @internal\n */\nexport function createDefaultVisualStudioCodeCredential(\n options: DefaultAzureCredentialOptions = {},\n): TokenCredential {\n return new VisualStudioCodeCredential(options);\n}\n\n/**\n * A no-op credential that logs the reason it was skipped if getToken is called.\n * @internal\n */\nexport class UnavailableDefaultCredential implements TokenCredential {\n credentialUnavailableErrorMessage: string;\n credentialName: string;\n\n constructor(credentialName: string, message: string) {\n this.credentialName = credentialName;\n this.credentialUnavailableErrorMessage = message;\n }\n\n getToken(): Promise<null> {\n logger.getToken.info(\n `Skipping ${this.credentialName}, reason: ${this.credentialUnavailableErrorMessage}`,\n );\n return Promise.resolve(null);\n }\n}\n\n/**\n * Provides a default {@link ChainedTokenCredential} configuration that works for most\n * applications that use Azure SDK client libraries. For more information, see\n * [DefaultAzureCredential overview](https://aka.ms/azsdk/js/identity/credential-chains#use-defaultazurecredential-for-flexibility).\n *\n * The following credential types will be tried, in order:\n *\n * - {@link EnvironmentCredential}\n * - {@link WorkloadIdentityCredential}\n * - {@link ManagedIdentityCredential}\n * - {@link AzureCliCredential}\n * - {@link AzurePowerShellCredential}\n * - {@link AzureDeveloperCliCredential}\n * - {@link VisualStudioCodeCredential}\n *\n * Consult the documentation of these credential types for more information\n * on how they attempt authentication.\n */\nexport class DefaultAzureCredential extends ChainedTokenCredential {\n /**\n * Creates an instance of the DefaultAzureCredential class with {@link DefaultAzureCredentialClientIdOptions}.\n *\n * @param options - Optional parameters. See {@link DefaultAzureCredentialClientIdOptions}.\n */\n constructor(options?: DefaultAzureCredentialClientIdOptions);\n\n /**\n * Creates an instance of the DefaultAzureCredential class with {@link DefaultAzureCredentialResourceIdOptions}.\n *\n * @param options - Optional parameters. See {@link DefaultAzureCredentialResourceIdOptions}.\n */\n constructor(options?: DefaultAzureCredentialResourceIdOptions);\n\n /**\n * Creates an instance of the DefaultAzureCredential class with {@link DefaultAzureCredentialOptions}.\n *\n * @param options - Optional parameters. See {@link DefaultAzureCredentialOptions}.\n */\n constructor(options?: DefaultAzureCredentialOptions);\n\n constructor(options?: DefaultAzureCredentialOptions) {\n // If AZURE_TOKEN_CREDENTIALS is not set, use the default credential chain.\n const azureTokenCredentials = process.env.AZURE_TOKEN_CREDENTIALS\n ? process.env.AZURE_TOKEN_CREDENTIALS.trim().toLowerCase()\n : undefined;\n const devCredentialFunctions = [\n createDefaultVisualStudioCodeCredential,\n createDefaultAzureCliCredential,\n createDefaultAzurePowershellCredential,\n createDefaultAzureDeveloperCliCredential,\n createDefaultBrokerCredential,\n ];\n const prodCredentialFunctions = [\n createEnvironmentCredential,\n createDefaultWorkloadIdentityCredential,\n createDefaultManagedIdentityCredential,\n ];\n let credentialFunctions = [];\n // If AZURE_TOKEN_CREDENTIALS is set, use it to determine which credentials to use.\n // The value of AZURE_TOKEN_CREDENTIALS should be either \"dev\" or \"prod\".\n if (azureTokenCredentials) {\n switch (azureTokenCredentials) {\n case \"dev\":\n // If AZURE_TOKEN_CREDENTIALS is set to \"dev\", use the developer tool-based credential chain.\n credentialFunctions = devCredentialFunctions;\n break;\n case \"prod\":\n // If AZURE_TOKEN_CREDENTIALS is set to \"prod\", use the production credential chain.\n credentialFunctions = prodCredentialFunctions;\n break;\n default: {\n // If AZURE_TOKEN_CREDENTIALS is set to an unsupported value, throw an error.\n // We will throw an error here to prevent the creation of the DefaultAzureCredential.\n const errorMessage = `Invalid value for AZURE_TOKEN_CREDENTIALS = ${process.env.AZURE_TOKEN_CREDENTIALS}. Valid values are 'prod' or 'dev'.`;\n logger.warning(errorMessage);\n throw new Error(errorMessage);\n }\n }\n } else {\n // If AZURE_TOKEN_CREDENTIALS is not set, use the default credential chain.\n credentialFunctions = [...prodCredentialFunctions, ...devCredentialFunctions];\n }\n\n // Errors from individual credentials should not be thrown in the DefaultAzureCredential constructor, instead throwing on getToken() which is handled by ChainedTokenCredential.\n // When adding new credentials to the default chain, consider:\n // 1. Making the constructor parameters required and explicit\n // 2. Validating any required parameters in the factory function\n // 3. Returning a UnavailableDefaultCredential from the factory function if a credential is unavailable for any reason\n const credentials: TokenCredential[] = credentialFunctions.map((createCredentialFn) => {\n try {\n return createCredentialFn(options);\n } catch (err: any) {\n logger.warning(\n `Skipped ${createCredentialFn.name} because of an error creating the credential: ${err}`,\n );\n return new UnavailableDefaultCredential(createCredentialFn.name, err.message);\n }\n });\n\n super(...credentials);\n }\n}\n"]}
|
1
|
+
{"version":3,"file":"defaultAzureCredential.js","sourceRoot":"","sources":["../../../src/credentials/defaultAzureCredential.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAalC,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAIrE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EACL,+BAA+B,EAC/B,wCAAwC,EACxC,sCAAsC,EACtC,6BAA6B,EAC7B,sCAAsC,EACtC,uCAAuC,EACvC,uCAAuC,EACvC,kCAAkC,GACnC,MAAM,sCAAsC,CAAC;AAE9C,MAAM,MAAM,GAAG,gBAAgB,CAAC,wBAAwB,CAAC,CAAC;AAE1D;;;GAGG;AACH,MAAM,OAAO,4BAA4B;IACvC,iCAAiC,CAAS;IAC1C,cAAc,CAAS;IAEvB,YAAY,cAAsB,EAAE,OAAe;QACjD,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;QACrC,IAAI,CAAC,iCAAiC,GAAG,OAAO,CAAC;IACnD,CAAC;IAED,QAAQ;QACN,MAAM,CAAC,QAAQ,CAAC,IAAI,CAClB,YAAY,IAAI,CAAC,cAAc,aAAa,IAAI,CAAC,iCAAiC,EAAE,CACrF,CAAC;QACF,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/B,CAAC;CACF;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,OAAO,sBAAuB,SAAQ,sBAAsB;IAsBhE,YAAY,OAAuC;QACjD,2EAA2E;QAC3E,MAAM,qBAAqB,GAAG,OAAO,CAAC,GAAG,CAAC,uBAAuB;YAC/D,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,uBAAuB,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE;YAC1D,CAAC,CAAC,SAAS,CAAC;QACd,MAAM,sBAAsB,GAAG;YAC7B,uCAAuC;YACvC,+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AY,CAAC,CAAC;oBAC7B,MAAM,IAAI,KAAK,CAAC,YAAY,CAAC,CAAC;gBAChC,CAAC;YACH,CAAC;QACH,CAAC;aAAM,CAAC;YACN,2EAA2E;YAC3E,mBAAmB,GAAG,CAAC,GAAG,uBAAuB,EAAE,GAAG,sBAAsB,CAAC,CAAC;QAChF,CAAC;QAED,gLAAgL;QAChL,8DAA8D;QAC9D,6DAA6D;QAC7D,gEAAgE;QAChE,sHAAsH;QACtH,MAAM,WAAW,GAAsB,mBAAmB,CAAC,GAAG,CAAC,CAAC,kBAAkB,EAAE,EAAE;YACpF,IAAI,CAAC;gBACH,OAAO,kBAAkB,CAAC,OAAO,CAAC,CAAC;YACrC,CAAC;YAAC,OAAO,GAAQ,EAAE,CAAC;gBAClB,MAAM,CAAC,OAAO,CACZ,WAAW,kBAAkB,CAAC,IAAI,iDAAiD,GAAG,EAAE,CACzF,CAAC;gBACF,OAAO,IAAI,4BAA4B,CAAC,kBAAkB,CAAC,IAAI,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;YAChF,CAAC;QACH,CAAC,CAAC,CAAC;QAEH,KAAK,CAAC,GAAG,WAAW,CAAC,CAAC;IACxB,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type {\n DefaultAzureCredentialClientIdOptions,\n DefaultAzureCredentialOptions,\n DefaultAzureCredentialResourceIdOptions,\n} from \"./defaultAzureCredentialOptions.js\";\n\nimport { ManagedIdentityCredential } from \"./managedIdentityCredential/index.js\";\nimport { VisualStudioCodeCredential } from \"./visualStudioCodeCredential.js\";\nimport { AzureCliCredential } from \"./azureCliCredential.js\";\nimport { AzureDeveloperCliCredential } from \"./azureDeveloperCliCredential.js\";\nimport { AzurePowerShellCredential } from \"./azurePowerShellCredential.js\";\nimport { ChainedTokenCredential } from \"./chainedTokenCredential.js\";\nimport { EnvironmentCredential } from \"./environmentCredential.js\";\nimport type { TokenCredential } from \"@azure/core-auth\";\nimport { WorkloadIdentityCredential } from \"./workloadIdentityCredential.js\";\nimport { credentialLogger } from \"../util/logging.js\";\nimport {\n createDefaultAzureCliCredential,\n createDefaultAzureDeveloperCliCredential,\n createDefaultAzurePowershellCredential,\n createDefaultBrokerCredential,\n createDefaultManagedIdentityCredential,\n createDefaultVisualStudioCodeCredential,\n createDefaultWorkloadIdentityCredential,\n createDefaultEnvironmentCredential,\n} from \"./defaultAzureCredentialFunctions.js\";\n\nconst logger = credentialLogger(\"DefaultAzureCredential\");\n\n/**\n * A no-op credential that logs the reason it was skipped if getToken is called.\n * @internal\n */\nexport class UnavailableDefaultCredential implements TokenCredential {\n credentialUnavailableErrorMessage: string;\n credentialName: string;\n\n constructor(credentialName: string, message: string) {\n this.credentialName = credentialName;\n this.credentialUnavailableErrorMessage = message;\n }\n\n getToken(): Promise<null> {\n logger.getToken.info(\n `Skipping ${this.credentialName}, reason: ${this.credentialUnavailableErrorMessage}`,\n );\n return Promise.resolve(null);\n }\n}\n\n/**\n * Provides a default {@link ChainedTokenCredential} configuration that works for most\n * applications that use Azure SDK client libraries. For more information, see\n * [DefaultAzureCredential overview](https://aka.ms/azsdk/js/identity/credential-chains#use-defaultazurecredential-for-flexibility).\n *\n * The following credential types will be tried, in order:\n *\n * - {@link EnvironmentCredential}\n * - {@link WorkloadIdentityCredential}\n * - {@link ManagedIdentityCredential}\n * - {@link VisualStudioCodeCredential}\n * - {@link AzureCliCredential}\n * - {@link AzurePowerShellCredential}\n * - {@link AzureDeveloperCliCredential}\n *\n * Consult the documentation of these credential types for more information\n * on how they attempt authentication.\n *\n * Selecting credentials\n *\n * Set environment variable AZURE_TOKEN_CREDENTIALS to select a subset of the credential chain.\n * DefaultAzureCredential will try only the specified credential(s), but its other behavior remains the same.\n * Valid values for AZURE_TOKEN_CREDENTIALS are the name of any single type in the above chain, for example\n * \"EnvironmentCredential\" or \"AzureCliCredential\", and these special values:\n *\n * - \"dev\": try [VisualStudioCodeCredential], [AzureCliCredential], [AzurePowerShellCredential] and [AzureDeveloperCliCredential], in that order\n * - \"prod\": try [EnvironmentCredential], [WorkloadIdentityCredential], and [ManagedIdentityCredential], in that order\n *\n */\nexport class DefaultAzureCredential extends ChainedTokenCredential {\n /**\n * Creates an instance of the DefaultAzureCredential class with {@link DefaultAzureCredentialClientIdOptions}.\n *\n * @param options - Optional parameters. See {@link DefaultAzureCredentialClientIdOptions}.\n */\n constructor(options?: DefaultAzureCredentialClientIdOptions);\n\n /**\n * Creates an instance of the DefaultAzureCredential class with {@link DefaultAzureCredentialResourceIdOptions}.\n *\n * @param options - Optional parameters. See {@link DefaultAzureCredentialResourceIdOptions}.\n */\n constructor(options?: DefaultAzureCredentialResourceIdOptions);\n\n /**\n * Creates an instance of the DefaultAzureCredential class with {@link DefaultAzureCredentialOptions}.\n *\n * @param options - Optional parameters. See {@link DefaultAzureCredentialOptions}.\n */\n constructor(options?: DefaultAzureCredentialOptions);\n\n constructor(options?: DefaultAzureCredentialOptions) {\n // If AZURE_TOKEN_CREDENTIALS is not set, use the default credential chain.\n const azureTokenCredentials = process.env.AZURE_TOKEN_CREDENTIALS\n ? process.env.AZURE_TOKEN_CREDENTIALS.trim().toLowerCase()\n : undefined;\n const devCredentialFunctions = [\n createDefaultVisualStudioCodeCredential,\n createDefaultAzureCliCredential,\n createDefaultAzurePowershellCredential,\n createDefaultAzureDeveloperCliCredential,\n createDefaultBrokerCredential,\n ];\n const prodCredentialFunctions = [\n createDefaultEnvironmentCredential,\n createDefaultWorkloadIdentityCredential,\n createDefaultManagedIdentityCredential,\n ];\n let credentialFunctions = [];\n const validCredentialNames =\n \"EnvironmentCredential, WorkloadIdentityCredential, ManagedIdentityCredential, VisualStudioCodeCredential, AzureCliCredential, AzurePowerShellCredential, AzureDeveloperCliCredential\";\n // If AZURE_TOKEN_CREDENTIALS is set, use it to determine which credentials to use.\n // The value of AZURE_TOKEN_CREDENTIALS should be either \"dev\" or \"prod\" or any one of these credentials - {validCredentialNames}.\n if (azureTokenCredentials) {\n switch (azureTokenCredentials) {\n case \"dev\":\n credentialFunctions = devCredentialFunctions;\n break;\n case \"prod\":\n credentialFunctions = prodCredentialFunctions;\n break;\n case \"environmentcredential\":\n credentialFunctions = [createDefaultEnvironmentCredential];\n break;\n case \"workloadidentitycredential\":\n credentialFunctions = [createDefaultWorkloadIdentityCredential];\n break;\n case \"managedidentitycredential\":\n credentialFunctions = [createDefaultManagedIdentityCredential];\n break;\n case \"visualstudiocodecredential\":\n credentialFunctions = [createDefaultVisualStudioCodeCredential];\n break;\n case \"azureclicredential\":\n credentialFunctions = [createDefaultAzureCliCredential];\n break;\n case \"azurepowershellcredential\":\n credentialFunctions = [createDefaultAzurePowershellCredential];\n break;\n case \"azuredeveloperclicredential\":\n credentialFunctions = [createDefaultAzureDeveloperCliCredential];\n break;\n default: {\n // If AZURE_TOKEN_CREDENTIALS is set to an unsupported value, throw an error.\n // This will prevent the creation of the DefaultAzureCredential.\n const errorMessage = `Invalid value for AZURE_TOKEN_CREDENTIALS = ${process.env.AZURE_TOKEN_CREDENTIALS}. Valid values are 'prod' or 'dev' or any of these credentials - ${validCredentialNames}.`;\n logger.warning(errorMessage);\n throw new Error(errorMessage);\n }\n }\n } else {\n // If AZURE_TOKEN_CREDENTIALS is not set, use the default credential chain.\n credentialFunctions = [...prodCredentialFunctions, ...devCredentialFunctions];\n }\n\n // Errors from individual credentials should not be thrown in the DefaultAzureCredential constructor, instead throwing on getToken() which is handled by ChainedTokenCredential.\n // When adding new credentials to the default chain, consider:\n // 1. Making the constructor parameters required and explicit\n // 2. Validating any required parameters in the factory function\n // 3. Returning a UnavailableDefaultCredential from the factory function if a credential is unavailable for any reason\n const credentials: TokenCredential[] = credentialFunctions.map((createCredentialFn) => {\n try {\n return createCredentialFn(options);\n } catch (err: any) {\n logger.warning(\n `Skipped ${createCredentialFn.name} because of an error creating the credential: ${err}`,\n );\n return new UnavailableDefaultCredential(createCredentialFn.name, err.message);\n }\n });\n\n super(...credentials);\n }\n}\n"]}
|