Skip to content

Commit fbf7813

Browse files
committed
Merge branch 'master' of https://github.com/MicrosoftDocs/azure-docs-pr into small-fix
2 parents 22430d8 + a1fa5cc commit fbf7813

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed
6.41 KB
Loading

articles/app-service/scenario-secure-app-access-microsoft-graph-as-app.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ manager: CelesteDG
88
ms.service: app-service-web
99
ms.topic: tutorial
1010
ms.workload: identity
11-
ms.date: 11/02/2021
11+
ms.date: 01/21/2022
1212
ms.author: ryanwi
1313
ms.reviewer: stsoneff
1414
ms.devlang: csharp, javascript
@@ -105,9 +105,9 @@ az rest --method post --uri $uri --body $body --headers "Content-Type=applicatio
105105

106106
After executing the script, you can verify in the [Azure portal](https://portal.azure.com) that the requested API permissions are assigned to the managed identity.
107107

108-
Go to **Azure Active Directory**, and then select **Enterprise applications**. This pane displays all the service principals in your tenant. In **All Applications**, select the service principal for the managed identity.
108+
Go to **Azure Active Directory**, and then select **Enterprise applications**. This pane displays all the service principals in your tenant. In **Managed Identities**, select the service principal for the managed identity.
109109

110-
If you're following this tutorial, there are two service principals with the same display name (SecureWebApp2020094113531, for example). The service principal that has a **Homepage URL** represents the web app in your tenant. The service principal without the **Homepage URL** represents the system-assigned managed identity for your web app. The **Object ID** value for the managed identity matches the object ID of the managed identity that you previously created.
110+
If you're following this tutorial, there are two service principals with the same display name (SecureWebApp2020094113531, for example). The service principal that has a **Homepage URL** represents the web app in your tenant. The service principal that appears in **Managed Identities** should *not* have a **Homepage URL** listed and the **Object ID** should match the object ID value of the managed identity in the [previous step](#enable-managed-identity-on-app).
111111

112112
Select the service principal for the managed identity.
113113

@@ -121,7 +121,7 @@ In **Overview**, select **Permissions**, and you'll see the added permissions fo
121121

122122
# [C#](#tab/programming-language-csharp)
123123

124-
The [DefaultAzureCredential](/dotnet/api/azure.identity.defaultazurecredential) class is used to get a token credential for your code to authorize requests to Microsoft Graph. Create an instance of the [DefaultAzureCredential](/dotnet/api/azure.identity.defaultazurecredential) class, which uses the managed identity to fetch tokens and attach them to the service client. The following code example gets the authenticated token credential and uses it to create a service client object, which gets the users in the group.
124+
The [ChainedTokenCredential](/dotnet/api/azure.identity.chainedtokencredential), [ManagedIdentityCredential](/dotnet/api/azure.identity.managedidentitycredential), and [EnvironmentCredential](/dotnet/api/azure.identity.environmentcredential) classes are used to get a token credential for your code to authorize requests to Microsoft Graph. Create an instance of the [ChainedTokenCredential](/dotnet/api/azure.identity.chainedtokencredential) class, which uses the managed identity in the App Service environment or the development environment variables to fetch tokens and attach them to the service client. The following code example gets the authenticated token credential and uses it to create a service client object, which gets the users in the group.
125125

126126
To see this code as part of a sample application, see the [sample on GitHub](https://github.com/Azure-Samples/ms-identity-easyauth-dotnet-storage-graphapi/tree/main/3-WebApp-graphapi-managed-identity).
127127

@@ -165,8 +165,12 @@ public IList<MSGraphUser> Users { get; set; }
165165

166166
public async Task OnGetAsync()
167167
{
168-
// Create the Microsoft Graph service client with a DefaultAzureCredential class, which gets an access token by using the available Managed Identity.
169-
var credential = new DefaultAzureCredential();
168+
// Create the Graph service client with a ChainedTokenCredential which gets an access
169+
// token using the available Managed Identity or environment variables if running
170+
// in development.
171+
var credential = new ChainedTokenCredential(
172+
new ManagedIdentityCredential(),
173+
new EnvironmentCredential());
170174
var token = credential.GetToken(
171175
new Azure.Core.TokenRequestContext(
172176
new[] { "https://graph.microsoft.com/.default" }));

0 commit comments

Comments
 (0)