From 68bf4576797a886dc12cc32f31d31ce971456d8b Mon Sep 17 00:00:00 2001 From: jennyf19 Date: Wed, 26 Jul 2023 20:00:03 -0700 Subject: [PATCH] update daemon net6 dev app (#2347) --- .../DevApps/daemon-app/Daemon-app/Program-net60.cs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/tests/DevApps/daemon-app/Daemon-app/Program-net60.cs b/tests/DevApps/daemon-app/Daemon-app/Program-net60.cs index a9508bad3..f7b5459d0 100644 --- a/tests/DevApps/daemon-app/Daemon-app/Program-net60.cs +++ b/tests/DevApps/daemon-app/Daemon-app/Program-net60.cs @@ -5,6 +5,7 @@ using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Identity.Abstractions; using Microsoft.Identity.Web; using Microsoft.Identity.Web.TokenCacheProviders.Distributed; using GraphServiceClient = Microsoft.Graph.GraphServiceClient; @@ -23,8 +24,11 @@ static async Task Main(string[] args) var builder = WebApplication.CreateBuilder(args); var services = builder.Services; - services.Configure(option => builder.Configuration.Bind(option)); - services.AddMicrosoftGraph(); // or services.AddTokenAcquisition() if you don't need graph + services.Configure(option => builder.Configuration.GetSection("AzureAd").Bind(option)); + services.AddTokenAcquisition(); + services.AddHttpClient(); + + //services.AddMicrosoftGraph(); // or services.AddTokenAcquisition() if you don't need graph // Add a cache services.AddDistributedTokenCaches(); @@ -41,8 +45,9 @@ static async Task Main(string[] args) Console.WriteLine($"{users.Count} users"); #else // Get the token acquisition service - ITokenAcquirer tokenAcquirer = app.Services.GetRequiredService(); - var result = await tokenAcquirer.GetAuthenticationResultForAppAsync("https://graph.microsoft.com/.default"); + ITokenAcquirerFactory tokenAcquirerFactory = app.Services.GetRequiredService(); + var tokenAcquirer = tokenAcquirerFactory.GetTokenAcquirer(); + var result = await tokenAcquirer.GetTokenForAppAsync("api://a4c2469b-cf84-4145-8f5f-cb7bacf814bc/.default"); Console.WriteLine($"Token expires on {result.ExpiresOn}"); #endif