Skip to content

Commit 5142f2a

Browse files
authored
[identity] Add WorkloadIdentityCredential (Azure#24830)
1 parent 090f85c commit 5142f2a

29 files changed

+600
-342
lines changed

common/config/rush/pnpm-lock.yaml

Lines changed: 7 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/identity/identity/CHANGELOG.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
# Release History
22

3-
## 3.2.0-beta.1 (Unreleased)
3+
## 3.2.0-beta.1 (2023-02-24)
44

55
### Features Added
66

77
- Added support to disable instance discovery on AAD credentials.
88
- Added `AzureDeveloperCliCredential` [#24180](https://github.com/Azure/azure-sdk-for-js/pull/24180) and added it to the `DefaultAzureCredential` [#24826](https://github.com/Azure/azure-sdk-for-js/pull/24826) auth flow
9-
### Breaking Changes
10-
11-
### Bugs Fixed
12-
13-
### Other Changes
9+
- Added support for `WokloadIdentityCredential`[#24830](https://github.com/Azure/azure-sdk-for-js/pull/24830), added it to `DefaultAzureCredential` auth flow and replaced the in-house implementation of `Token Exchange MSI` in `ManagedIdentity` with `WorkloadIdentityCredential`.
1410

1511
## 3.1.3 (2023-01-12)
1612

sdk/identity/identity/images/mermaidjs/DefaultAzureCredentialAuthFlow.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
%% 2. Run command: mmdc -i DefaultAzureCredentialAuthFlow.md -o DefaultAzureCredentialAuthFlow.svg
77
88
flowchart LR;
9-
A(Environment):::deployed ==> B(Managed Identity):::deployed ==> C(Azure Developer CLI):::developer ==> D(Azure CLI):::developer ==> E(Azure PowerShell):::developer;
9+
A(Environment):::deployed ==> B(Workload Identity):::deployed ==> C(Managed Identity):::deployed ==> D(Azure Developer CLI):::developer ==> E(Azure CLI):::developer ==> F(Azure PowerShell):::developer;
1010
1111
subgraph CREDENTIAL TYPES;
1212
direction LR;
@@ -22,7 +22,7 @@ flowchart LR;
2222
2323
%% Add API ref links to credential type boxes
2424
click A "https://learn.microsoft.com/javascript/api/@azure/identity/environmentcredential?view=azure-node-latest" _blank;
25-
click B "https://learn.microsoft.com/javascript/api/@azure/identity/managedidentitycredential?view=azure-node-latest" _blank;
26-
click D "https://learn.microsoft.com/javascript/api/@azure/identity/azureclicredential?view=azure-node-latest" _blank;
27-
click E "https://learn.microsoft.com/javascript/api/@azure/identity/azurepowershellcredential?view=azure-node-latest" _blank;
25+
click C "https://learn.microsoft.com/javascript/api/@azure/identity/managedidentitycredential?view=azure-node-latest" _blank;
26+
click E "https://learn.microsoft.com/javascript/api/@azure/identity/azureclicredential?view=azure-node-latest" _blank;
27+
click F "https://learn.microsoft.com/javascript/api/@azure/identity/azurepowershellcredential?view=azure-node-latest" _blank;
2828
```

sdk/identity/identity/images/mermaidjs/DefaultAzureCredentialAuthFlow.svg

Lines changed: 1 addition & 1 deletion
Loading

sdk/identity/identity/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"./dist-esm/src/credentials/azurePowerShellCredential.js": "./dist-esm/src/credentials/azurePowerShellCredential.browser.js",
2525
"./dist-esm/src/credentials/azureApplicationCredential.js": "./dist-esm/src/credentials/azureApplicationCredential.browser.js",
2626
"./dist-esm/src/credentials/onBehalfOfCredential.js": "./dist-esm/src/credentials/onBehalfOfCredential.browser.js",
27+
"./dist-esm/src/credentials/workloadIdentityCredential.js": "./dist-esm/src/credentials/workloadIdentityCredential.browser.js",
2728
"./dist-esm/src/util/authHostEnv.js": "./dist-esm/src/util/authHostEnv.browser.js",
2829
"./dist-esm/src/util/processMultiTenantRequest.js": "./dist-esm/src/util/processMultiTenantRequest.browser.js",
2930
"./dist-esm/src/tokenCache/TokenCachePersistence.js": "./dist-esm/src/tokenCache/TokenCachePersistence.browser.js",
@@ -158,6 +159,7 @@
158159
"puppeteer": "^19.2.2",
159160
"rimraf": "^3.0.0",
160161
"sinon": "^9.0.2",
162+
"ts-node": "^10.9.1",
161163
"typescript": "~4.8.0",
162164
"util": "^0.12.1",
163165
"uuid": "^8.3.2"

sdk/identity/identity/recordings/node/workloadidentitycredential/recording_authenticates.json

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/identity/identity/recordings/node/workloadidentitycredential/recording_authenticates_with_workloadidentity_credential.json

Lines changed: 213 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/identity/identity/review/identity.api.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,19 @@ export interface VisualStudioCodeCredentialOptions extends MultiTenantTokenCrede
376376
tenantId?: string;
377377
}
378378

379+
// @public
380+
export class WorkloadIdentityCredential implements TokenCredential {
381+
constructor(options?: WorkloadIdentityCredentialOptions);
382+
getToken(scopes: string | string[], options?: GetTokenOptions): Promise<AccessToken | null>;
383+
}
384+
385+
// @public
386+
export interface WorkloadIdentityCredentialOptions extends MultiTenantTokenCredentialOptions, AuthorityValidationOptions {
387+
clientId?: string;
388+
federatedTokenFilePath?: string;
389+
tenantId?: string;
390+
}
391+
379392
// (No @packageDocumentation comment for this package)
380393

381394
```
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { DefaultAzureCredential, WorkloadIdentityCredential } from "@azure/identity";
2+
import dotenv from "dotenv";
3+
4+
dotenv.config();
5+
6+
async function testDefaultCredential() {
7+
const credential = new DefaultAzureCredential();
8+
9+
try {
10+
const token = await credential.getToken("https://storage.azure.com/.default");
11+
console.log(token);
12+
} catch (err) {
13+
console.log("Error with DefaultAzureCredential:", err);
14+
}
15+
}
16+
17+
async function testWorkloadCredential() {
18+
const credential = new WorkloadIdentityCredential({
19+
tenantId: process.env.AZURE_TENANT_ID!,
20+
clientId: process.env.AZURE_CLIENT_ID!,
21+
federatedTokenFilePath: process.env.AZURE_FEDERATED_TOKEN_FILE!,
22+
});
23+
24+
try {
25+
const token = await credential.getToken("https://storage.azure.com/.default");
26+
console.log(token);
27+
} catch (err) {
28+
console.log("Error with WorkloadIdentityCredential:", err);
29+
}
30+
}
31+
32+
async function main() {
33+
await testDefaultCredential();
34+
await testWorkloadCredential();
35+
}
36+
37+
main().catch((err) => {
38+
console.error("The sample encountered an error:", err);
39+
});

0 commit comments

Comments
 (0)