Skip to content

Commit 8c6bbf2

Browse files
committed
progress
1 parent 45b9c21 commit 8c6bbf2

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

docs/azure/sdk/aspnetcore-guidance.md

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,33 +35,36 @@ Complete the following steps to register the services you need:
3535
dotnet add package Azure.Messaging.ServiceBus
3636
```
3737
38-
3. In the `Program.cs` file, invoke the `AddAzureClients` extension method from the `Microsoft.Extensions.Azure` library to register a client for each service. Some services use additional subclients, which you can also register for dependency injection.
38+
3. In the `Program.cs` file of your app, invoke the `AddAzureClients` extension method from the `Microsoft.Extensions.Azure` library to register a client for each service. Some services use additional subclients, which you can also register for dependency injection.
3939
4040
:::code source="snippets/aspnetcore-guidance/BlazorSample/Program.cs" range="11-30":::
4141
4242
4. Inject the registered services into your ASP.NET Core app components, services, or API endpoint methods:
4343
4444
## [Minimal API](#tab/api)
4545
46-
:::code source="snippets/aspnetcore-guidance/MinApiSample/Program.cs" range="44-59":::
46+
:::code source="snippets/aspnetcore-guidance/MinApiSample/Program.cs" range="44-59" highlight="44,47,48":::
4747
4848
## [Blazor](#tab/blazor)
4949
50-
:::code source="snippets/aspnetcore-guidance/BlazorSample/Program.cs" range="1-28" highlight="5,21":::
50+
:::code source="snippets/aspnetcore-guidance/BlazorSample/Components/Pages/Home.razor" range="1-28" highlight="5,21":::
5151
5252
---
5353
5454
## Authenticate using Microsoft Entra ID
5555
56-
Microsoft Entra ID is the recommended approach to authorize requests to Azure services. Use the [Azure Identity client library]() to implement secretless connections to Azure services in your code. The Azure Identity client library provides tools such as `DefaultAzureCredential` to simplify configuring secure connections. `DefaultAzureCredential` supports multiple authentication methods and determines which method should be used at runtime. This approach enables your app to use different authentication methods in different environments (local vs. production) without implementing environment-specific code.
56+
[Microsoft Entra ID](/entra/fundamentals/whatis) is the recommended approach to authenticate requests to Azure services. This identity service supports [role-based access control (RBAC)](/azure/role-based-access-control/overview) to manage access to Azure resources based on a user's Entra ID account and assigned roles.
5757
58-
Some Azure services also allow you to authorize requests using secrets keys. However, this approach should be used with caution. Developers must be diligent to never expose the access key in an unsecure location. Anyone who has the access key is able to authorize requests against the service and data.
58+
Use the [Azure Identity client library](/dotnet/api/overview/azure/identity-readme) to implement secretless connections to Azure services in your code with Microsoft Entra ID. The Azure Identity client library provides tools such as `DefaultAzureCredential` to simplify configuring secure connections. `DefaultAzureCredential` supports multiple authentication methods and determines which method should be used at runtime. This approach enables your app to use different authentication methods in different environments (local vs. production) without implementing environment-specific code.
5959
60-
Consider the following service client registrations:
60+
> [!NOTE]
61+
> Many Azure services also allow you to authorize requests using secrets keys. However, this approach should be used with caution. Developers must be diligent to never expose the access key in an unsecure location. Anyone who has the access key is able to authorize requests against the service and data.
6162
62-
:::code source="snippets/aspnetcore-guidance/BlazorSample/Program.cs" range="29":::
63+
Consider the following use of `DefaultAzureCredential`:
6364
64-
In the preceding code, the `clientBuilder.UseCredential()` method accepts an instance of `DefaultAzureCredential` that will be reused across your registered services. `DefaultAzureCredential` discovers available credentials in the current environment and use them to connect to Azure services. The full order and locations in which `DefaultAzureCredential` looks for credentials can be found in the [`Azure Identity library overview`](/dotnet/api/overview/azure/Identity-readme#defaultazurecredential).
65+
:::code source="snippets/aspnetcore-guidance/BlazorSample/Program.cs" range="11-30" highlight="29":::
66+
67+
In the preceding code, the `clientBuilder.UseCredential()` method accepts an instance of `DefaultAzureCredential` to reuse across your registered services. `DefaultAzureCredential` discovers available credentials in the current environment and use them to connect to Azure services. The complete order and locations that `DefaultAzureCredential` looks for credentials lives in the [`Azure Identity library overview`](/dotnet/api/overview/azure/Identity-readme#defaultazurecredential).
6568
6669
For example, when you run the app locally, `DefaultAzureCredential` discovers and uses credentials from the following developer tools:
6770
@@ -81,16 +84,16 @@ For example, when you run the app locally, `DefaultAzureCredential` discovers an
8184
8285
Azure service clients support configurations to change their default behaviors. There are two ways to configure service clients:
8386
84-
- You can [store configurations in environment-dependent JSON files](/dotnet/core/extensions/configuration-providers#json-configuration-provider). Configuration files are generally the recommended approach because they simplify app deployments between environments and help eliminate hard coded values.
85-
- You can also configurations directly in your code when you register the service client. For example, in the [Register clients and subclients](#register-service-clients-and-subclients) section, you explicitly passed the Uri-typed variables to the client constructors.
87+
- [Store configurations in environment-dependent JSON files](/dotnet/core/extensions/configuration-providers#json-configuration-provider). Configuration files are generally the recommended approach because they simplify app deployments between environments and reduce hard coded values.
88+
- Apply configurations directly in your code when you register the service client. For example, in the [Register clients and subclients](#register-service-clients-and-subclients) section, you explicitly passed the Uri-typed variables to the client constructors.
8689
87-
The following steps use an `appsettings.Development.json` file to store development environment settings and an `appsettings.Production.json` file to contain production environment settings. You can add any properties from the [`ClientOptions`](/dotnet/api/azure.core.clientoptions) class into the JSON file.
90+
In the following sections, complete the steps using the `appsettings.Development.json` file for development settings and the `appsettings.json` file for production environment settings. You can add any properties from the [`ClientOptions`](/dotnet/api/azure.core.clientoptions) class to the JSON file.
8891
8992
### Configure registered services
9093
9194
1. Update the `appsettings.<environment>.json` file in your app with the highlighted service configurations:
9295
93-
:::code source="snippets/aspnetcore-guidance/BlazorSample/appsettings.Development.json" range="19-27":::
96+
:::code source="snippets/aspnetcore-guidance/MinApiSample/appsettings.Development.json" highlight="19-27":::
9497
9598
In the preceding JSON sample:
9699
@@ -99,19 +102,19 @@ The following steps use an `appsettings.Development.json` file to store developm
99102
100103
1. Update the the `Program.cs` file to retrieve the JSON file configurations using `IConfiguration` and pass them into your service registrations:
101104
102-
:::code source="snippets/aspnetcore-guidance/BlazorSample/Program.cs" range="13-31":::
105+
:::code source="snippets/aspnetcore-guidance/MinApiSample/Program.cs" range="13-31" highlight="29-30":::
103106
104107
### Configure Azure defaults and retries
105108
106109
At some point, you may want to change default Azure client configurations globally or for a specific service client. For example, you may want different retry settings or to use a different service API version. You can set the retry settings globally or on a per-service basis.
107110
108-
1. Update your configuration file to set default Azure settings, such as a new default retry policy and a specific retry policy for Azure Key Vault:
111+
1. Update your configuration file to set default Azure settings, such as a new default retry policy:
109112
110-
:::code source="snippets/aspnetcore-guidance/BlazorSample/appsettings.Development.json" range="9-23":::
113+
:::code source="snippets/aspnetcore-guidance/MinApiSample/appsettings.Development.json" highlight="9-18":::
111114
112115
2. In the `Program.cs` file, the `ConfigureDefaults` extension method `AddAzureClients` retrieves the default settings and applies them to your services:
113116
114-
:::code source="snippets/aspnetcore-guidance/BlazorSample/Program.cs" range="13-31":::
117+
:::code source="snippets/aspnetcore-guidance/MinApiSample/Program.cs" range="13-31" highlight="29,30":::
115118
116119
## Configure logging
117120

docs/azure/sdk/snippets/aspnetcore-guidance/MinApiSample/appsettings.Development.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@
1717
}
1818
},
1919
"KeyVault": {
20-
"VaultUri": "https://<your-key-vault-name>.vault.azure.net",
21-
"Retry": {
22-
"maxRetries": 10
23-
}
20+
"VaultUri": "https://<your-key-vault-name>.vault.azure.net"
2421
},
2522
"ServiceBus": {
2623
"Namespace": "<your_service-bus_namespace>.servicebus.windows.net"

0 commit comments

Comments
 (0)