Skip to content

Commit a8b8400

Browse files
committed
chainedtokencredential updates
1 parent 32c379c commit a8b8400

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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)