Skip to content

Commit

Permalink
update daemon net6 dev app (#2347)
Browse files Browse the repository at this point in the history
  • Loading branch information
jennyf19 authored Jul 27, 2023
1 parent 48e4a5e commit 68bf457
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions tests/DevApps/daemon-app/Daemon-app/Program-net60.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -23,8 +24,11 @@ static async Task Main(string[] args)
var builder = WebApplication.CreateBuilder(args);
var services = builder.Services;

services.Configure<MicrosoftIdentityOptions>(option => builder.Configuration.Bind(option));
services.AddMicrosoftGraph(); // or services.AddTokenAcquisition() if you don't need graph
services.Configure<MicrosoftIdentityOptions>(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();
Expand All @@ -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<ITokenAcquirer>();
var result = await tokenAcquirer.GetAuthenticationResultForAppAsync("https://graph.microsoft.com/.default");
ITokenAcquirerFactory tokenAcquirerFactory = app.Services.GetRequiredService<ITokenAcquirerFactory>();
var tokenAcquirer = tokenAcquirerFactory.GetTokenAcquirer();
var result = await tokenAcquirer.GetTokenForAppAsync("api://a4c2469b-cf84-4145-8f5f-cb7bacf814bc/.default");
Console.WriteLine($"Token expires on {result.ExpiresOn}");

#endif
Expand Down

0 comments on commit 68bf457

Please sign in to comment.