You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Migrate an application to use passwordless connections with Azure Storage
17
16
18
-
Application requests to Azure Storage must be authenticated using either account access keys or passwordless connections. However, you should prioritize passwordless connections in your applications when possible. Traditional authentication methods that use passwords or secret keys create additional security risks and complications. Visit the [passwordless connections for Azure services](/azure/developer/intro/passwordless-overview) hub to learn more about the advantages of moving to passwordless connections.
17
+
Application requests to Azure Storage must be authenticated using either account access keys or passwordless connections. However, you should prioritize passwordless connections in your applications when possible. Traditional authentication methods that use passwords or secret keys create security risks and complications. Visit the [passwordless connections for Azure services](/azure/developer/intro/passwordless-overview) hub to learn more about the advantages of moving to passwordless connections.
19
18
20
19
The following tutorial explains how to migrate an existing application to connect to Azure Storage to use passwordless connections instead of a key-based solution. These same migration steps should apply whether you're using access keys directly, or through connection strings.
21
20
@@ -29,37 +28,115 @@ For local development, make sure you're authenticated with the same Azure AD acc
Next you need to update your code to use passwordless connections.
31
+
Next, update your code to use passwordless connections.
33
32
34
33
## [.NET](#tab/dotnet)
35
34
36
-
1. To use `DefaultAzureCredential` in a .NET application, add the **Azure.Identity** NuGet package to your application.
35
+
1. To use `DefaultAzureCredential` in a .NET application, install the `Azure.Identity`package:
37
36
38
37
```dotnetcli
39
38
dotnet add package Azure.Identity
40
39
```
41
40
42
-
1. At the top of your `Program.cs`file, add the following `using` statement:
41
+
1. At the top of your file, add the following code:
43
42
44
43
```csharp
45
44
usingAzure.Identity;
46
45
```
47
46
48
-
1. Identify the locations in your code that currently create a `BlobServiceClient` to connect to Azure Storage. This task is often handled in `Program.cs`, potentially as part of your service registration with the .NET dependency injection container. Update your code to match the following example:
47
+
1. Identify the locations in your code that create a `BlobServiceClient` to connect to Azure Storage. Update your code to match the following example:
49
48
50
49
```csharp
51
-
// TODO: Update <storage-account-name> placeholder to your account name
50
+
varcredential=newDefaultAzureCredential();
51
+
52
+
// TODO: Update the <storage-account-name> placeholder.
1. Make sure to update the storage account name in the URI of your `BlobServiceClient`. You can find the storage account name on the overview page of the Azure portal.
58
+
## [Java](#tab/java)
58
59
59
-
:::image type="content" source="../blobs/media/storage-quickstart-blobs-dotnet/storage-account-name.png" alt-text="Screenshot showing how to find the storage account name.":::
60
+
1. To use `DefaultAzureCredential` in a Java application, install the `azure-identity` package via one of the following approaches:
61
+
1.[Include the BOM file](/java/api/overview/azure/identity-readme?view=azure-java-stable&preserve-view=true#include-the-bom-file).
62
+
1.[Include a direct dependency](/java/api/overview/azure/identity-readme?view=azure-java-stable&preserve-view=true#include-direct-dependency).
63
+
64
+
1. At the top of your file, add the following code:
1.Identify the locations in your code that create a `BlobServiceClient` object to connect to AzureStorage. Update your code to match the following example:
1.Identify the locations in your code that create a `BlobServiceClient` object to connect to AzureStorage. Update your code to match the following example:
98
+
99
+
```nodejs
100
+
const credential =newDefaultAzureCredential();
101
+
102
+
// TODO: Update the <storage-account-name> placeholder.
4.Make sure to update the storage account name in the URI of your `BlobServiceClient`.You can find the storage account name on the overview page of the Azure portal.
137
+
138
+
:::image type="content" source="../blobs/media/storage-quickstart-blobs-dotnet/storage-account-name.png" alt-text="Screenshot showing how to find the storage account name.":::
139
+
63
140
### Run the app locally
64
141
65
142
After making these code changes, run your application locally. Thenew configuration should pick up your local credentials, such as the Azure CLI, Visual Studio, or IntelliJ. The roles you assigned to your local dev user in Azure allows your app to connect to the Azure service locally.
@@ -83,7 +160,7 @@ Complete the following steps in the Azure portal to associate an identity with y
83
160
*AzureSpringApps
84
161
*AzureContainerApps
85
162
*Azure virtual machines
86
-
* Azure Kubernetes Service.
163
+
*AzureKubernetesService
87
164
88
165
1.Navigate to the overview page of your web app.
89
166
1.Select**Identity** from the left navigation.
@@ -155,27 +232,52 @@ If you connected your services using Service Connector you don't need to complet
155
232
156
233
### Update the application code
157
234
158
-
You need to configure your application code to look for the specific managed identity you created when it is deployed to Azure. In some scenarios, explicitly setting the managed identity for the app also prevents other environment identities from accidentally being detected and used automatically.
159
-
160
-
## [.NET](#tab/dotnet)
235
+
You need to configure your application code to look for the specific managed identity you created when it's deployed to Azure. In some scenarios, explicitly setting the managed identity for the app also prevents other environment identities from accidentally being detected and used automatically.
161
236
162
237
1. On the managed identity overview page, copy the client ID value to your clipboard.
163
-
1. Update the `DefaultAzureCredential` object in the `Program.cs` file of your app to specify this managed identity client ID.
238
+
1. Update the `DefaultAzureCredential` object to specify this managed identity client ID:
164
239
240
+
## [.NET](#tab/dotnet)
241
+
165
242
```csharp
166
-
// TODO: Update the <your-storage-account-name> and <your-managed-identity-client-id> placeholders
0 commit comments