Skip to content

Commit f23cbdd

Browse files
committed
Update C++ code sample
1 parent 04070a9 commit f23cbdd

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

articles/aks/workload-identity-overview.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ The following table provides the **minimum** package version required for each l
4242

4343
† In the C++ library, `WorkloadIdentityCredential` isn't part of the `DefaultAzureCredential` authentication flow.
4444

45-
In the following code samples, `DefaultAzureCredential` is used. This credential type will use the environment variables injected by the Azure Workload Identity mutating webhook to authenticate with Azure Key Vault.
45+
In the following code samples, the credential type will use the environment variables injected by the Azure Workload Identity mutating webhook to authenticate with Azure Key Vault.
4646

4747
## [.NET](#tab/dotnet)
4848

@@ -70,11 +70,18 @@ KeyVaultSecret secret = await client.GetSecretAsync(secretName);
7070
using namespace Azure::Identity;
7171
using namespace Azure::Security::KeyVault::Secrets;
7272

73+
// * AZURE_TENANT_ID: Tenant ID for the Azure account.
74+
// * AZURE_CLIENT_ID: The client ID to authenticate the request.
75+
std::string GetTenantId() { return std::getenv("AZURE_TENANT_ID"); }
76+
std::string GetClientId() { return std::getenv("AZURE_CLIENT_ID"); }
77+
std::string GetTokenFilePath() { return std::getenv("AZURE_FEDERATED_TOKEN_FILE"); }
78+
7379
int main()
7480
{
7581
const char* keyVaultUrl = std::getenv("KEYVAULT_URL");
7682
const char* secretName = std::getenv("SECRET_NAME");
77-
auto credential = std::make_shared<DefaultAzureCredential>();
83+
auto credential = std::make_shared<WorkloadIdentityCredential>(
84+
GetTenantId(), GetClientId(), GetTokenFilePath());
7885

7986
SecretClient client(keyVaultUrl, credential);
8087
Secret secret = client.GetSecret(secretName).Value;

0 commit comments

Comments
 (0)