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 Service Bus
@@ -20,24 +26,44 @@ Application requests to Azure Service Bus must be authenticated using either acc
20
26
21
27
The following code example demonstrates how to connect to Azure Service Bus using a connection string that includes an access key. When you create a Service Bus, Azure generates these keys and connection strings automatically. Many developers gravitate towards this solution because it feels familiar to options they've worked with in the past. If your application currently uses connection strings, consider migrating to passwordless connections using the steps described in this document.
Connection strings should be used with caution. Developers must be diligent to never expose the keys in an unsecure location. Anyone who gains access to the key is able to authenticate. For example, if an account key is accidentally checked into source control, sent through an unsecure email, pasted into the wrong chat, or viewed by someone who shouldn't have permission, there's risk of a malicious user accessing the application. Instead, consider updating your application to use passwordless connections.
@@ -60,42 +86,60 @@ For local development, make sure you're authenticated with the same Azure AD acc
Next you'll need to update your code to use passwordless connections.
89
+
Next, update your code to use passwordless connections.
64
90
65
-
#[C#](#tab/csharp)
91
+
## [.NET](#tab/dotnet)
66
92
67
-
1. To use `DefaultAzureCredential` in a .NET application, add the **Azure.Identity** NuGet package to your application.
93
+
1. To use `DefaultAzureCredential` in a .NET application, install the `Azure.Identity`package:
68
94
69
95
```dotnetcli
70
96
dotnet add package Azure.Identity
71
97
```
72
98
73
-
1. At the top of your `Program.cs`file, add the following `using` statement:
99
+
1. At the top of your file, add the following code:
74
100
75
101
```csharp
76
102
usingAzure.Identity;
77
103
```
78
104
79
-
1. Identify the locations in your code that currently create a `ServiceBusClient` to connect to Azure Service Bus. 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:
105
+
1. Identify the locations in your code that create a `ServiceBusClient` to connect to Azure Service Bus. Update your code to match the following example:
1. Make sure to update the Service Bus namespace in the URI of your `ServiceBusClient`. You can find the namespace on the overview page of the Azure portal.
114
+
## [Java](#tab/java)
115
+
116
+
1. To use `DefaultAzureCredential` in a Java application, install the `azure-identity` package via one of the following approaches:
117
+
1.[Include the BOM file](/java/api/overview/azure/identity-readme?view=azure-java-stable&preserve-view=true#include-the-bom-file).
118
+
1.[Include a direct dependency](/java/api/overview/azure/identity-readme?view=azure-java-stable&preserve-view=true#include-direct-dependency).
119
+
120
+
1. At the top of your file, add the following code:
1.Identify the locations in your code that create a `ServiceBusSenderClient` or `ServiceBusSenderAsyncClient` object to connect to AzureServiceBus. Update your code to match the following example:
3. Identify the locations in your code that currently create a `ServiceBusJmsConnectionFactory` to connect to Azure Service Bus. Update your code to match the following example:
159
+
1.Identify the locations in your code that currently create a `ServiceBusJmsConnectionFactory` to connect to AzureServiceBus. Update your code to match the following example:
116
160
117
-
```java
118
-
TokenCredential tokenCredential = new DefaultAzureCredentialBuilder()
4. Make sure to update the Service Bus namespace in the URI of your `ServiceBusJmsConnectionFactory`. You can find the namespace on the overview page of the Azure portal.
172
+
## [Node.js](#tab/nodejs)
173
+
174
+
1. To use `DefaultAzureCredential` in a Node.js application, install the `@azure/identity` package:
175
+
176
+
```bash
177
+
npm install --save @azure/identity
178
+
```
179
+
180
+
1. At the top of your file, add the following code:
1. Identify the locations in your code that create a `ServiceBusClient` object to connect to Azure Service Bus. Update your code to match the following example:
187
+
188
+
```nodejs
189
+
const credential = new DefaultAzureCredential();
190
+
191
+
// TODO: Update the <NAMESPACE-CONNECTION-STRING> placeholder.
192
+
const client = new ServiceBusClient(
193
+
"<NAMESPACE-CONNECTION-STRING>",
194
+
credential
195
+
);
196
+
```
197
+
198
+
## [Python](#tab/python)
199
+
200
+
1. To use `DefaultAzureCredential`in a Python application, install the `azure-identity` package:
201
+
202
+
```bash
203
+
pip install azure-identity
204
+
```
205
+
206
+
1. At the top of your file, add the following code:
207
+
208
+
```python
209
+
from azure.identity import DefaultAzureCredential
210
+
```
211
+
212
+
1. Identify the locations in your code that create a `ServiceBusClient` to connect to Azure Service Bus. Update your code to match the following example:
213
+
214
+
```python
215
+
credential = DefaultAzureCredential()
216
+
217
+
# TODO: Update the <NAMESPACE-CONNECTION-STRING> placeholder.
0 commit comments