Skip to content

Commit 5c62ec1

Browse files
committed
More code cleanup
1 parent a086bb9 commit 5c62ec1

File tree

1 file changed

+64
-69
lines changed

1 file changed

+64
-69
lines changed

articles/storage/common/multiple-identity-scenarios.md

Lines changed: 64 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ ms.custom: devx-track-csharp, passwordless-java, passwordless-js, passwordless-p
1717

1818
Applications often require secure connections between multiple Azure services simultaneously. For example, an enterprise Azure App Service instance might connect to several different storage accounts, an Azure SQL database instance, a service bus, and more.
1919

20-
[Managed identities](../../active-directory/managed-identities-azure-resources/overview.md) are the recommended authentication option for secure, passwordless connections between Azure resources. Developers don't have to manually track and manage many different secrets for managed identities, since most of these tasks are handled internally by Azure. This tutorial explores how to manage connections between multiple services using managed identities and the Azure Identity client library.
20+
[Managed identities](/entra/identity/managed-identities-azure-resources/overview) are the recommended authentication option for secure, passwordless connections between Azure resources. Developers don't have to manually track and manage many different secrets for managed identities, since most of these tasks are handled internally by Azure. This tutorial explores how to manage connections between multiple services using managed identities and the Azure Identity client library.
2121

2222
## Compare the types of managed identities
2323

@@ -26,11 +26,11 @@ Azure provides the following types of managed identities:
2626
* **System-assigned managed identities** are directly tied to a single Azure resource. When you enable a system-assigned managed identity on a service, Azure will create a linked identity and handle administrative tasks for that identity internally. When the Azure resource is deleted, the identity is also deleted.
2727
* **User-assigned managed identities** are independent identities that are created by an administrator and can be associated with one or more Azure resources. The lifecycle of the identity is independent of those resources.
2828

29-
You can read more about best practices and when to use system-assigned identities versus user-assigned identities in the [identities best practice recommendations](../../active-directory/managed-identities-azure-resources/managed-identity-best-practice-recommendations.md).
29+
You can read more about best practices and when to use system-assigned versus user-assigned managed identities in [managed identity best practice recommendations](/entra/identity/managed-identities-azure-resources/managed-identity-best-practice-recommendations).
3030

3131
## Explore DefaultAzureCredential
3232

33-
Managed identities are most easily implemented in your application code through a class called `DefaultAzureCredential` from the Azure Identity client library. `DefaultAzureCredential` supports multiple authentication mechanisms and automatically determines which should be used at runtime. Learn more about `DefaultAzureCredential` for the following ecosystems:
33+
Managed identities are most easily implemented in your application code via a class called `DefaultAzureCredential` from the Azure Identity client library. `DefaultAzureCredential` supports multiple authentication mechanisms and automatically determines which should be used at runtime. Learn more about `DefaultAzureCredential` for the following ecosystems:
3434

3535
- [.NET](/dotnet/azure/sdk/authentication/credential-chains?tabs=dac#defaultazurecredential-overview)
3636
- [Java](/azure/developer/java/sdk/authentication/credential-chains#defaultazurecredential-overview)
@@ -65,15 +65,15 @@ The following steps demonstrate how to configure an app to use a system-assigned
6565

6666
1. Choose **+ Add** and then **Add role assignment**.
6767

68-
:::image type="content" source="media/assign-role-system-identity.png" alt-text="Screenshot showing how to assign a system-assigned identity." :::
68+
:::image type="content" source="media/assign-role-system-identity.png" alt-text="Screenshot showing how to assign a system-assigned managed identity.":::
6969

7070
1. In the **Role** search box, search for *Storage Blob Data Contributor*, which grants permissions to perform read and write operations on blob data. You can assign whatever role is appropriate for your use case. Select the *Storage Blob Data Contributor* from the list and choose **Next**.
7171

7272
1. On the **Add role assignment** screen, for the **Assign access to** option, select **Managed identity**. Then choose **+Select members**.
7373

7474
1. In the flyout, search for the managed identity you created by entering the name of your app service. Select the system assigned identity, and then choose **Select** to close the flyout menu.
7575

76-
:::image type="content" source="media/migration-select-identity.png" alt-text="Screenshot showing how to select a system-assigned identity." :::
76+
:::image type="content" source="media/migration-select-identity.png" alt-text="Screenshot showing how to select a system-assigned managed identity.":::
7777

7878
1. Select **Next** a couple times until you're able to select **Review + assign** to finish the role assignment.
7979

@@ -94,15 +94,15 @@ You can also enable access to Azure resources for local development by assigning
9494

9595
#### [.NET](#tab/csharp)
9696

97-
1. In your project, add a reference to the `Azure.Identity` NuGet package. This library contains the necessary entities to implement `DefaultAzureCredential`. You can also add any other Azure libraries that are relevant to your app. For this example, the `Azure.Storage.Blobs` and `Azure.KeyVault.Keys` packages are added to connect to Blob Storage and Key Vault, respectively.
97+
1. In your project, add a reference to the `Azure.Identity` NuGet package. This library contains the necessary entities to implement `DefaultAzureCredential`. You can also add any other Azure libraries that are relevant to your app. For this example, the `Azure.Storage.Blobs` and `Azure.Messaging.ServiceBus` packages are added to connect to Blob Storage and Service Bus, respectively.
9898

9999
```dotnetcli
100100
dotnet add package Azure.Identity
101101
dotnet add package Azure.Messaging.ServiceBus
102102
dotnet add package Azure.Storage.Blobs
103103
```
104104
105-
1. In the `Program.cs` file of your project, instantiate service clients for the services your app will connect to. The following examples connect to Blob Storage and Service Bus using the corresponding service clients.
105+
1. In the `Program.cs` file of your project, instantiate service clients for the services your app will connect to. The following code sample interacts with Blob Storage and Service Bus using the corresponding service clients.
106106
107107
```csharp
108108
using Azure.Identity;
@@ -121,63 +121,61 @@ You can also enable access to Azure resources for local development by assigning
121121
122122
#### [Java](#tab/java)
123123
124-
In your project, add the `azure-identity` dependency to your *pom.xml* file. This library contains all the necessary entities to implement `DefaultAzureCredential`. You can also add any other Azure dependencies that are relevant to your app. For this example, the `azure-storage-blob` and `azure-messaging-servicebus` dependencies are added to connect to Blob Storage and Key Vault.
124+
1. In your project, add the `azure-identity` dependency to your *pom.xml* file. This library contains all the necessary entities to implement `DefaultAzureCredential`. You can also add any other Azure dependencies that are relevant to your app. For this example, the `azure-storage-blob` and `azure-messaging-servicebus` dependencies are added to connect to Blob Storage and Service Bus.
125125
126-
```xml
127-
<dependencyManagement>
128-
<dependencies>
129-
<dependency>
130-
<groupId>com.azure</groupId>
131-
<artifactId>azure-sdk-bom</artifactId>
132-
<version>1.2.5</version>
133-
<type>pom</type>
134-
<scope>import</scope>
135-
</dependency>
136-
</dependencies>
137-
</dependencyManagement>
138-
<dependencies>
139-
<dependency>
140-
<groupId>com.azure</groupId>
141-
<artifactId>azure-identity</artifactId>
142-
</dependency>
143-
<dependency>
144-
<groupId>com.azure</groupId>
145-
<artifactId>azure-storage-blob</artifactId>
146-
</dependency>
147-
<dependency>
148-
<groupId>com.azure</groupId>
149-
<artifactId>azure-messaging-servicebus</artifactId>
150-
</dependency>
151-
</dependencies>
152-
153-
```
154-
155-
Create instances of the service clients for the services your app will connect to. The following examples connect to Blob Storage and Service Bus using the corresponding service clients.
156-
157-
```java
158-
class Demo {
159-
160-
public static void main(String[] args) {
161-
162-
DefaultAzureCredential defaultAzureCredential = new DefaultAzureCredentialBuilder().build();
126+
```xml
127+
<dependencyManagement>
128+
<dependencies>
129+
<dependency>
130+
<groupId>com.azure</groupId>
131+
<artifactId>azure-sdk-bom</artifactId>
132+
<version>1.2.5</version>
133+
<type>pom</type>
134+
<scope>import</scope>
135+
</dependency>
136+
</dependencies>
137+
</dependencyManagement>
138+
<dependencies>
139+
<dependency>
140+
<groupId>com.azure</groupId>
141+
<artifactId>azure-identity</artifactId>
142+
</dependency>
143+
<dependency>
144+
<groupId>com.azure</groupId>
145+
<artifactId>azure-storage-blob</artifactId>
146+
</dependency>
147+
<dependency>
148+
<groupId>com.azure</groupId>
149+
<artifactId>azure-messaging-servicebus</artifactId>
150+
</dependency>
151+
</dependencies>
152+
```
163153
164-
BlobServiceClient blobServiceClient = new BlobServiceClientBuilder()
165-
.endpoint("https://<your-storage-account>.blob.core.windows.net")
166-
.credential(defaultAzureCredential)
167-
.buildClient();
154+
1. Create instances of the service clients for the services your app will connect to. The following examples interacts with Blob Storage and Service Bus using the corresponding service clients.
168155
169-
ServiceBusClientBuilder clientBuilder = new ServiceBusClientBuilder().credential(defaultAzureCredential);
170-
ServiceBusSenderClient serviceBusSenderClient = clientBuilder.sender()
171-
.queueName("producttracking")
172-
.buildClient();
156+
```java
157+
class Demo {
158+
public static void main(String[] args) {
159+
DefaultAzureCredential credential = new DefaultAzureCredentialBuilder()
160+
.build();
161+
162+
BlobServiceClient blobServiceClient = new BlobServiceClientBuilder()
163+
.endpoint("https://<your-storage-account>.blob.core.windows.net")
164+
.credential(credential)
165+
.buildClient();
166+
167+
ServiceBusClientBuilder clientBuilder = new ServiceBusClientBuilder()
168+
.credential(credential);
169+
ServiceBusSenderClient serviceBusSenderClient = clientBuilder.sender()
170+
.queueName("producttracking")
171+
.buildClient();
172+
}
173173
}
174-
175-
}
176-
```
174+
```
177175
178176
#### [Spring](#tab/spring)
179177
180-
1. In your project, you only need to add service dependencies you use. For this example, the `spring-cloud-azure-starter-storage-blob` and `spring-cloud-azure-starter-servicebus` dependencies are added in order to connect to Blob Storage and Key Vault.
178+
1. In your project, you only need to add service dependencies you use. For this example, the `spring-cloud-azure-starter-storage-blob` and `spring-cloud-azure-starter-servicebus` dependencies are added in order to connect to Blob Storage and Service Bus.
181179
182180
```xml
183181
<dependencyManagement>
@@ -234,36 +232,33 @@ class Demo {
234232
1. In your project, use [npm](https://docs.npmjs.com/) to add a reference to the `@azure/identity` package. This library contains all of the necessary entities to implement `DefaultAzureCredential`. Install any other [Azure SDK libraries](https://www.npmjs.com/search?q=%40azure) which are relevant to your app.
235233
236234
```bash
237-
npm install --save @azure/identity @azure/storage-blob @azure/keyvault-keys
235+
npm install --save @azure/identity @azure/storage-blob @azure/service-bus
238236
```
239237
240-
1. In the `index.js` file, create client objects for the Azure services your app will connect to. The following examples connect to Blob Storage and Key Vault using the corresponding service clients.
238+
1. In the `index.js` file, create client objects for the Azure services your app will connect to. The following examples connect to Blob Storage and Service Bus using the corresponding service clients.
241239
242240
```javascript
243241
import { DefaultAzureCredential } from "@azure/identity";
244242
import { BlobServiceClient } from "@azure/storage-blob";
245-
import { KeyClient } from "@azure/keyvault-keys";
243+
import { ServiceBusClient } from "@azure/service-bus";
246244
247245
// Azure resource names
248246
const storageAccount = process.env.AZURE_STORAGE_ACCOUNT_NAME;
249-
const keyVaultName = process.env.AZURE_KEYVAULT_NAME;
247+
const serviceBusNamespace = process.env.AZURE_SERVICE_BUS_NAMESPACE;
250248
251249
const credential = new DefaultAzureCredential();
252250
253-
// Create client for Blob Storage using managed identity
251+
// Create client for Blob Storage using a system-assigned managed identity
254252
const blobServiceClient = new BlobServiceClient(
255253
`https://${storageAccount}.blob.core.windows.net`,
256254
credential
257255
);
258256
259-
// Create client for Key Vault using managed identity
260-
const keyClient = new KeyClient(
261-
`https://${keyVaultName}.vault.azure.net`,
262-
credential
257+
// Create client for Service Bus using a system-assigned managed identity
258+
const serviceBusClient = new ServiceBusClient(
259+
`https://${serviceBusNamespace}.servicebus.windows.net`,
260+
credential
263261
);
264-
265-
// Create a new key in Key Vault
266-
const result = await keyClient.createKey(keyVaultName, "RSA");
267262
```
268263
269264
---

0 commit comments

Comments
 (0)