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,57 @@ 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.
const client = new ServiceBusClient("<CONNECTION-STRING>");
70
+
```
71
+
72
+
## [Python](#tab/python)
73
+
74
+
```python
75
+
client = ServiceBusClient(
76
+
fully_qualified_namespace="<CONNECTION-STRING>"
77
+
)
78
+
```
79
+
41
80
---
42
81
43
82
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,72 +99,150 @@ 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.
102
+
Next, update your code to use passwordless connections.
64
103
65
-
#[C#](#tab/csharp)
104
+
## [.NET](#tab/dotnet)
66
105
67
-
1. To use `DefaultAzureCredential` in a .NET application, add the **Azure.Identity** NuGet package to your application.
106
+
1. To use `DefaultAzureCredential` in a .NET application, install the `Azure.Identity`package:
68
107
69
108
```dotnetcli
70
109
dotnet add package Azure.Identity
71
110
```
72
111
73
-
1. At the top of your `Program.cs`file, add the following `using` statement:
112
+
1. At the top of your file, add the following code:
74
113
75
114
```csharp
76
115
usingAzure.Identity;
77
116
```
78
117
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:
118
+
1. Identify the code that creates a `ServiceBusClient`object 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.
127
+
## [Java](#tab/java)
95
128
96
-
# [Java - JMS](#tab/java-jms)
129
+
1. To use `DefaultAzureCredential`:
130
+
- In a JMS application, add at least version 1.0.0 of the `azure-servicebus-jms` package to your application:
97
131
98
-
1. To use `DefaultAzureCredential` in a JMS application, add at least version **1.0.0** of the **azure-servicebus-jms** package to your application.
132
+
```xml
133
+
<dependency>
134
+
<groupId>com.microsoft.azure</groupId>
135
+
<artifactId>azure-servicebus-jms</artifactId>
136
+
<version>1.0.0</version>
137
+
</dependency>
138
+
```
99
139
100
-
```xml
101
-
<dependency>
102
-
<groupId>com.microsoft.azure</groupId>
103
-
<artifactId>azure-servicebus-jms</artifactId>
104
-
<version>1.0.0</version>
105
-
</dependency>
106
-
```
107
-
108
-
2. At the top of your file, add the following `import` statements:
140
+
- In a Java application, install the `azure-identity` package via one of the following approaches:
141
+
- [Include the BOM file](/java/api/overview/azure/identity-readme?view=azure-java-stable&preserve-view=true#include-the-bom-file).
142
+
- [Include a direct dependency](/java/api/overview/azure/identity-readme?view=azure-java-stable&preserve-view=true#include-direct-dependency).
143
+
144
+
1. At the top of your file, add the following code:
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:
150
+
1. Update the code that connects to Azure Service Bus:
151
+
- In a JMS application, identify the code that creates a `ServiceBusJmsConnectionFactory` object to connect to Azure Service Bus. Update your code to match the following example:
116
152
117
-
```java
118
-
TokenCredential tokenCredential = new DefaultAzureCredentialBuilder()
153
+
```java
154
+
DefaultAzureCredential credential = new DefaultAzureCredentialBuilder()
155
+
.build();
156
+
157
+
// TODO: Replace the <SERVICE-BUS-NAMESPACE-NAME> placeholder.
158
+
ConnectionFactory factory = new ServiceBusJmsConnectionFactory(
- In a Java application, identify the code that creates a Service Bus sender or receiver client object to connect to Azure Service Bus. Update your code to match one of the following examples:
165
+
166
+
**Receiver client:**
167
+
168
+
```java
169
+
DefaultAzureCredential credential = new DefaultAzureCredentialBuilder()
119
170
.build();
171
+
172
+
// TODO: Update the <SERVICE-BUS-NAMESPACE-NAME> placeholder.
173
+
ServiceBusReceiverClient receiver = new ServiceBusClientBuilder()
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.
221
+
## [Python](#tab/python)
222
+
223
+
1. To use `DefaultAzureCredential` in a Python application, install the `azure-identity` package:
224
+
225
+
```bash
226
+
pip install azure-identity
227
+
```
228
+
229
+
1. At the top of your file, add the following code:
230
+
231
+
```python
232
+
from azure.identity import DefaultAzureCredential
233
+
```
234
+
235
+
1. Identify the code that creates a `ServiceBusClient` object to connect to Azure Service Bus. Update your code to match the following example:
236
+
237
+
```python
238
+
credential = DefaultAzureCredential()
239
+
240
+
# TODO: Update the <SERVICE-BUS-NAMESPACE-NAME> placeholder.
@@ -230,7 +347,7 @@ You can assign a managed identity to an Azure Kubernetes Service (AKS) instance
230
347
```azurecli
231
348
az aks update \
232
349
--resource-group <resource-group-name> \
233
-
--name <virtual-machine-name>
350
+
--name <virtual-machine-name> \
234
351
--enable-managed-identity
235
352
```
236
353
@@ -268,7 +385,7 @@ If you connected your services using the Service Connector you don't need to com
268
385
269
386
### [Azure CLI](#tab/assign-role-azure-cli)
270
387
271
-
To assign a role at the resource level using the Azure CLI, you first must retrieve the resource ID using the `az servicebus show` command. You can filter the output properties using the --query parameter.
388
+
To assign a role at the resource level using the Azure CLI, you first must retrieve the resource ID using the `az servicebus show` command. You can filter the output properties using the `--query` parameter.
Copy file name to clipboardExpand all lines: includes/passwordless/migration-guide/migrate-to-passwordless-overview.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,7 +12,7 @@ The order and locations in which `DefaultAzureCredential` searches for credentia
12
12
13
13
The following code example demonstrates how to connect to Service Bus using passwordless connections. The next section describes how to migrate to this setup for a specific service in more detail.
14
14
15
-
A .NET Core application can pass an instance of `DefaultAzureCredential` into the constructor of a service client class. `DefaultAzureCredential` will automatically discover the credentials that are available in that environment.
15
+
A .NET application can pass an instance of `DefaultAzureCredential` into the constructor of a service client class. `DefaultAzureCredential` will automatically discover the credentials that are available in that environment.
0 commit comments