Skip to content

Commit e2d95cc

Browse files
committed
Update managed identity credential
1 parent ee00c7b commit e2d95cc

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

articles/digital-twins/how-to-authenticate-client.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ titleSuffix: Azure Digital Twins
55
description: Learn how to write authentication code in a client application
66
author: baanders
77
ms.author: baanders # Microsoft employees only
8-
ms.date: 02/22/2022
8+
ms.date: 03/01/2023
99
ms.topic: how-to
1010
ms.service: digital-twins
1111

@@ -41,7 +41,7 @@ To continue, you'll need a client app project in which you write your code. If y
4141
Three common credential-obtaining methods in `Azure.Identity` are:
4242

4343
* [DefaultAzureCredential](/dotnet/api/azure.identity.defaultazurecredential?view=azure-dotnet&preserve-view=true) provides a default `TokenCredential` authentication flow for applications that will be deployed to Azure, and is **the recommended choice for local development**. It also can be enabled to try the other two methods recommended in this article; it wraps `ManagedIdentityCredential` and can access `InteractiveBrowserCredential` with a configuration variable.
44-
* [ManagedIdentityCredential](/dotnet/api/azure.identity.managedidentitycredential?view=azure-dotnet&preserve-view=true) works great in cases where you need [managed identities (MSI)](../active-directory/managed-identities-azure-resources/overview.md), and is a good candidate for working with Azure Functions and deploying to Azure services.
44+
* [ManagedIdentityCredential](/dotnet/api/azure.identity.managedidentitycredential?view=azure-dotnet&preserve-view=true) works well in cases where you need [managed identities (MSI)](../active-directory/managed-identities-azure-resources/overview.md), and is a good candidate for working with Azure Functions and deploying to Azure services.
4545
* [InteractiveBrowserCredential](/dotnet/api/azure.identity.interactivebrowsercredential?view=azure-dotnet&preserve-view=true) is intended for interactive applications, and can be used to create an authenticated SDK client.
4646

4747
The rest of this article shows how to use these methods with the [.NET (C#) SDK](/dotnet/api/overview/azure/digitaltwins.core-readme).
@@ -76,16 +76,18 @@ Here's a code sample to add a `DefaultAzureCredential` to your project:
7676

7777
### ManagedIdentityCredential method
7878

79-
The [ManagedIdentityCredential](/dotnet/api/azure.identity.managedidentitycredential?view=azure-dotnet&preserve-view=true) method works great in cases where you need [managed identities (MSI)](../active-directory/managed-identities-azure-resources/overview.md)—for example, when [authenticating with Azure Functions](#authenticate-azure-functions).
79+
The [ManagedIdentityCredential](/dotnet/api/azure.identity.managedidentitycredential?view=azure-dotnet&preserve-view=true) method works well in cases where you need [managed identities (MSI)](../active-directory/managed-identities-azure-resources/overview.md)—for example, when [authenticating with Azure Functions](#authenticate-azure-functions).
8080

81-
This means that you may use `ManagedIdentityCredential` in the same project as `DefaultAzureCredential` or `InteractiveBrowserCredential`, to authenticate a different part of the project.
81+
This means that you can use `ManagedIdentityCredential` in the same project as `DefaultAzureCredential` or `InteractiveBrowserCredential`, to authenticate a different part of the project.
8282

8383
To use the default Azure credentials, you'll need the Azure Digital Twins instance's URL ([instructions to find](how-to-set-up-instance-portal.md#verify-success-and-collect-important-values)). You may also need an [app registration](./how-to-create-app-registration.md) and the registration's [Application (client) ID](./how-to-create-app-registration.md#collect-client-id-and-tenant-id).
8484

8585
In an Azure function, you can use the managed identity credentials like this:
8686

8787
:::code language="csharp" source="~/digital-twins-docs-samples/sdks/csharp/authentication.cs" id="ManagedIdentityCredential":::
8888

89+
If you're using a user-assigned identity for the function app, enter the client ID of the user-assigned identity as a parameter when creating the credential. If you're using the function app's system-assigned identity to authenticate, you can leave the parameter empty.
90+
8991
### InteractiveBrowserCredential method
9092

9193
The [InteractiveBrowserCredential](/dotnet/api/azure.identity.interactivebrowsercredential?view=azure-dotnet&preserve-view=true) method is intended for interactive applications and will bring up a web browser for authentication. You can use this method instead of `DefaultAzureCredential` in cases where you require interactive authentication.
@@ -120,9 +122,13 @@ When writing the Azure function, consider adding these variables and code to you
120122

121123
:::code language="csharp" source="~/digital-twins-docs-samples/sdks/csharp/adtIngestFunctionSample.cs" id="HTTP_client":::
122124

123-
* **Managed identity credentials.** Create a managed identity credential that your function will use to access Azure Digital Twins.
125+
* **Managed identity credentials.** Create a managed identity credential that your function will use to access Azure Digital Twins.
126+
127+
If you're using a user-assigned identity for the function app, enter the client ID of the user-assigned identity as a parameter when creating the credential, as shown below:
124128
:::code language="csharp" source="~/digital-twins-docs-samples/sdks/csharp/adtIngestFunctionSample.cs" id="ManagedIdentityCredential":::
125129

130+
If you're using the function app's system-assigned identity to authenticate, you can leave the parameter empty.
131+
126132
Later, after publishing the function, you'll make sure the function's identity has permission to access the Azure Digital Twins APIs. For instructions on how to do so, skip ahead to [Assign an access role](#assign-an-access-role).
127133

128134
* **A local variable _DigitalTwinsClient_.** Add the variable inside your function to hold your Azure Digital Twins client instance. _Don't_ make this variable static inside your class.

0 commit comments

Comments
 (0)