Skip to content

Commit 0f7faba

Browse files
authored
Document AzurePipelinesCredential creation via configuration (#45353)
1 parent a0411e6 commit 0f7faba

File tree

1 file changed

+72
-50
lines changed

1 file changed

+72
-50
lines changed
Lines changed: 72 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,39 @@
11
---
2-
title: Create token credentials from configuration
3-
description: This article describes how to create Microsoft Entra token credentials from configuration files.
2+
title: Create Azure Identity library credentials via configuration files
3+
description: Learn how to create token credentials from configuration files.
44
ms.topic: how-to
55
ms.custom: devx-track-dotnet, engagement-fy23
6-
ms.date: 02/19/2025
6+
ms.date: 03/14/2025
77
---
88

9-
# Create Microsoft Entra credential types using configuration files
9+
# Create Azure Identity library credentials via configuration files
1010

11-
The `Microsoft.Extensions.Azure` library supports creating different <xref:Azure.Core.TokenCredential?displayProperty=fullName> types from key-value pairs defined in _appsettings.json_ and other configuration files. The credential types correspond to a subset of the [credential classes](/dotnet/api/overview/azure/identity-readme) in the Azure Identity client library. This article describes the support for different `TokenCredential` types and how to configure the required key-value pairs for each type.
11+
The [Azure client library integration for ASP.NET Core](/dotnet/api/overview/azure/microsoft.extensions.azure-readme?view=azure-dotnet&preserve-view=true) (`Microsoft.Extensions.Azure`) supports creating different <xref:Azure.Core.TokenCredential?displayProperty=fullName> types from key-value pairs defined in _appsettings.json_ and other configuration files. The credentials correspond to a subset of the [credential classes](/dotnet/api/overview/azure/identity-readme?view=azure-dotnet&preserve-view=true#credential-classes) in the Azure Identity client library. This article describes the support for different `TokenCredential` types and how to configure the required key-value pairs for each type.
1212

1313
## Support for Azure credentials through configuration
1414

15-
The [`Microsoft.Extensions.Azure`](https://www.nuget.org/packages/Microsoft.Extensions.Azure) library can automatically provide Azure service clients with a `TokenCredential` class by searching _appsettings.json_ or other configuration files for credential values using the `IConfiguration` abstraction for .NET. This approach allows developers to explicitly set credential values across different environments through configuration rather than through app code directly.
15+
`Microsoft.Extensions.Azure` can automatically provide Azure service clients with a `TokenCredential` class by searching _appsettings.json_ or other configuration files for credential values using the `IConfiguration` abstraction for .NET. This approach allows developers to explicitly set credential values across different environments through configuration rather than through app code directly.
1616

17-
The following credential types are supported via configuration:
17+
The following credentials can be created via configuration:
1818

19-
* [ClientCertificateCredential](#create-a-clientcertificatecredential-type)
20-
* [ClientSecretCredential](#create-a-clientsecretcredential-type)
21-
* [DefaultAzureCredential](#create-a-defaultazurecredential-type)
22-
* [ManagedIdentityCredential](#create-a-managedidentitycredential-type)
23-
* [WorkloadIdentityCredential](#create-a-workloadidentitycredential-type)
19+
* [AzurePipelinesCredential](#create-an-instance-of-azurepipelinescredential)
20+
* [ClientCertificateCredential](#create-an-instance-of-clientcertificatecredential)
21+
* [ClientSecretCredential](#create-an-instance-of-clientsecretcredential)
22+
* [DefaultAzureCredential](#create-an-instance-of-defaultazurecredential)
23+
* [ManagedIdentityCredential](#create-an-instance-of-managedidentitycredential)
24+
* [WorkloadIdentityCredential](#create-an-instance-of-workloadidentitycredential)
2425

2526
## Configure Azure credentials
2627

27-
Azure service clients registered with the <xref:Microsoft.Extensions.Azure.AzureClientServiceCollectionExtensions.AddAzureClients%2A> method are automatically configured with an instance of `DefaultAzureCredential` if no explicit credential is supplied via the <xref:Microsoft.Extensions.Azure.AzureClientBuilderExtensions.WithCredential%2A> extension method. You can also override the global `DefaultAzureCredential` using credential values from configuration files when registering a client to create a specific credential type:
28+
Azure service clients registered with the <xref:Microsoft.Extensions.Azure.AzureClientServiceCollectionExtensions.AddAzureClients%2A> method are automatically configured with an instance of `DefaultAzureCredential` if no explicit credential is supplied via the <xref:Microsoft.Extensions.Azure.AzureClientBuilderExtensions.WithCredential%2A> extension method. You can also override the global `DefaultAzureCredential` using credential values from configuration files when registering a client to create a specific credential:
2829

2930
```csharp
3031
builder.Services.AddAzureClients(clientBuilder =>
3132
{
32-
// Register BlobServiceClient using credentials from appsettings.json
33+
// Register BlobServiceClient using credential from appsettings.json
3334
clientBuilder.AddBlobServiceClient(builder.Configuration.GetSection("Storage"));
3435

35-
// Register ServiceBusClient using the fallback DefaultAzureCredential credentials
36+
// Register ServiceBusClient using the fallback DefaultAzureCredential
3637
clientBuilder.AddServiceBusClientWithNamespace(
3738
"<your_namespace>.servicebus.windows.net");
3839
});
@@ -44,27 +45,29 @@ The associated _appsettings.json_ file:
4445
"Storage": {
4546
"serviceUri": "<service_uri>",
4647
"credential": "managedidentity",
47-
"clientId": "<clientId>"
48+
"clientId": "<client_id>"
4849
}
4950
```
5051

51-
The following credential types also support the `AdditionallyAllowedTenants` property, which specifies additional Microsoft Entra tenants beyond the default tenant for which the credential may acquire tokens:
52+
The following credentials also support the `AdditionallyAllowedTenants` property, which specifies Microsoft Entra tenants beyond the default tenant for which the credential can acquire tokens:
5253

53-
* [ClientCertificateCredential](#create-a-clientcertificatecredential-type)
54-
* [ClientSecretCredential](#create-a-clientsecretcredential-type)
55-
* [DefaultAzureCredential](#create-a-defaultazurecredential-type)
54+
* [AzurePipelinesCredential](#create-an-instance-of-azurepipelinescredential)
55+
* [ClientCertificateCredential](#create-an-instance-of-clientcertificatecredential)
56+
* [ClientSecretCredential](#create-an-instance-of-clientsecretcredential)
57+
* [DefaultAzureCredential](#create-an-instance-of-defaultazurecredential)
58+
* [WorkloadIdentityCredential](#create-an-instance-of-workloadidentitycredential)
5659

57-
Add the wildcard value "*" to allow the credential to acquire tokens for any Microsoft Entra tenant the logged in account can access. If no tenant IDs are specified, this option will have no effect on that authentication method, and the credential will acquire tokens for any requested tenant when using that method.
60+
Add the wildcard value `*` to allow the credential to acquire tokens for any Microsoft Entra tenant the logged in account can access. If no tenant IDs are specified, this option has no effect on that authentication method, and the credential will acquire tokens for any requested tenant when using that method.
5861

5962
```json
6063
{
61-
"additionallyAllowedTenants": "<tenant-ids-separated-by-semicolon>"
64+
"additionallyAllowedTenants": "<tenant_ids_separated_by_semicolon>"
6265
}
6366
```
6467

65-
### Create a `ManagedIdentityCredential` type
68+
### Create an instance of `ManagedIdentityCredential`
6669

67-
You can create both user-assigned and system-assigned managed identities using configuration values. Add the following key-value pairs to your _appsettings.json_ file to create an instance of <xref:Azure.Identity.ManagedIdentityCredential?displayProperty=fullName>.
70+
You can create both user-assigned and system-assigned managed identities using configuration values. To create an instance of <xref:Azure.Identity.ManagedIdentityCredential?displayProperty=fullName>, add the following key-value pairs to your _appsettings.json_ file.
6871

6972
#### User-assigned managed identities
7073

@@ -75,7 +78,7 @@ A user-assigned managed identity can be used by providing a client ID, resource
7578
```json
7679
{
7780
"credential": "managedidentity",
78-
"clientId": "<clientId>"
81+
"clientId": "<client_id>"
7982
}
8083
```
8184

@@ -84,7 +87,7 @@ A user-assigned managed identity can be used by providing a client ID, resource
8487
```json
8588
{
8689
"credential": "managedidentity",
87-
"managedIdentityResourceId": "<managedIdentityResourceId>"
90+
"managedIdentityResourceId": "<managed_identity_resource_id>"
8891
}
8992
```
9093

@@ -96,7 +99,7 @@ The resource ID takes the form:
9699
```json
97100
{
98101
"credential": "managedidentity",
99-
"managedIdentityObjectId": "<managedIdentityObjectId>"
102+
"managedIdentityObjectId": "<managed_identity_object_id>"
100103
}
101104
```
102105

@@ -113,56 +116,75 @@ The resource ID takes the form:
113116
}
114117
```
115118

116-
### Create a `WorkloadIdentityCredential` type
119+
### Create an instance of `AzurePipelinesCredential`
117120

118-
Add the following key-value pairs to your _appsettings.json_ file to create an <xref:Azure.Identity.WorkloadIdentityCredential?displayProperty=fullName>:
121+
To create an instance of <xref:Azure.Identity.AzurePipelinesCredential?displayProperty=fullName>, add the following key-value pairs to your _appsettings.json_ file:
122+
123+
```json
124+
{
125+
"credential": "azurepipelines",
126+
"clientId": "<client_id>",
127+
"tenantId": "<tenant_id>",
128+
"serviceConnectionId": "<service_connection_id>",
129+
"systemAccessToken": "<system_access_token>"
130+
}
131+
```
132+
133+
> [!IMPORTANT]
134+
> `AzurePipelinesCredential` is supported in `Microsoft.Extensions.Azure` versions 1.11.0 and later.
135+
136+
### Create an instance of `WorkloadIdentityCredential`
137+
138+
To create an instance of <xref:Azure.Identity.WorkloadIdentityCredential?displayProperty=fullName>, add the following key-value pairs to your _appsettings.json_ file:
119139

120140
```json
121141
{
122142
"credential": "workloadidentity",
123-
"tenantId": "<tenantId>",
124-
"clientId": "<clientId>",
125-
"tokenFilePath": "<tokenFilePath>"
143+
"tenantId": "<tenant_id>",
144+
"clientId": "<client_id>",
145+
"tokenFilePath": "<token_file_path>"
126146
}
127147
```
128148

129-
### Create a `ClientSecretCredential` type
149+
### Create an instance of `ClientSecretCredential`
130150

131-
Add the following key-value pairs to your _appsettings.json_ file to create an <xref:Azure.Identity.ClientSecretCredential?displayProperty=fullName>:
151+
To create an instance of <xref:Azure.Identity.ClientSecretCredential?displayProperty=fullName>, add the following key-value pairs to your _appsettings.json_ file:
132152

133153
```json
134154
{
135-
"tenantId": "<tenantId>",
136-
"clientId": "<clientId>",
137-
"clientSecret": "<clientSecret>"
155+
"tenantId": "<tenant_id>",
156+
"clientId": "<client_id>",
157+
"clientSecret": "<client_secret>"
138158
}
139159
```
140160

141-
### Create a `ClientCertificateCredential` type
161+
### Create an instance of `ClientCertificateCredential`
142162

143-
Add the following key-value pairs to your _appsettings.json_ file to create an <xref:Azure.Identity.ClientCertificateCredential?displayProperty=fullName>:
163+
To create an instance of <xref:Azure.Identity.ClientCertificateCredential?displayProperty=fullName>, add the following key-value pairs to your _appsettings.json_ file:
144164

145165
```json
146166
{
147-
"tenantId": "<tenantId>",
148-
"clientId": "<clientId>",
149-
"clientCertificate": "<clientCertificate>",
150-
"clientCertificateStoreLocation": "<clientCertificateStoreLocation>",
151-
"additionallyAllowedTenants": "<tenant-ids-separated-by-semicolon>"
167+
"tenantId": "<tenant_id>",
168+
"clientId": "<client_id>",
169+
"clientCertificate": "<client_certificate>",
170+
"clientCertificateStoreLocation": "<client_certificate_store_location>"
152171
}
153172
```
154173

155174
> [!NOTE]
156-
> The `clientCertificateStoreLocation` and `additionallyAllowedTenants` key-value pairs are optional. If the keys are present and have empty values, they are ignored. If no `clientCertificateStoreLocation` is specified, the default `CurrentUser` is used from the <xref:System.Fabric.X509Credentials.StoreLocation?displayProperty=nameWithType> enum.
175+
> The `clientCertificateStoreLocation` key is optional. If the key:
176+
>
177+
> * Is present and has an empty value, it's ignored.
178+
> * Isn't present, the default `CurrentUser` is used from the <xref:System.Fabric.X509Credentials.StoreLocation?displayProperty=nameWithType> enum.
157179
158-
### Create a `DefaultAzureCredential` type
180+
### Create an instance of `DefaultAzureCredential`
159181

160-
Add the following key-value pairs to your _appsettings.json_ file to create an <xref:Azure.Identity.DefaultAzureCredential?displayProperty=fullName>:
182+
To create an instance of <xref:Azure.Identity.DefaultAzureCredential?displayProperty=fullName>, add the following key-value pairs to your _appsettings.json_ file:
161183

162184
```json
163185
{
164-
"tenantId": "<tenantId>",
165-
"clientId": "<clientId>",
166-
"managedIdentityResourceId": "<managedIdentityResourceId>"
186+
"tenantId": "<tenant_id>",
187+
"clientId": "<client_id>",
188+
"managedIdentityResourceId": "<managed_identity_resource_id>"
167189
}
168190
```

0 commit comments

Comments
 (0)