From da14ff926e0f9d1ebfd72328591f76e39be72881 Mon Sep 17 00:00:00 2001 From: Jean-Marc Prieur Date: Tue, 11 Mar 2025 10:11:18 -0700 Subject: [PATCH 1/6] Update appsettings.json --- web-app-aspnet/appsettings.json | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/web-app-aspnet/appsettings.json b/web-app-aspnet/appsettings.json index a9a6fd5..c0794e6 100644 --- a/web-app-aspnet/appsettings.json +++ b/web-app-aspnet/appsettings.json @@ -3,7 +3,7 @@ "Instance": "https://login.microsoftonline.com/", "TenantId": "Enter the tenant ID obtained from the Microsoft Entra admin center", "ClientId": "Enter the client ID obtained from the Microsoft Entra admin center", - "ClientCertificates": [ + "ClientCredentials": [ { "SourceType": "StoreWithThumbprint", "CertificateStorePath": "CurrentUser/My", @@ -13,11 +13,13 @@ "CallbackPath": "/signin-oidc" }, "DownstreamApi": { - "BaseUrl": "https://graph.microsoft.com/v1.0/", - "RelativePath": "me", - "Scopes": [ - "user.read" - ] + "MicrosoftGraph" :{ + "BaseUrl": "https://graph.microsoft.com/v1.0/", + "RelativePath": "me", + "Scopes": [ + "user.read" + ] + } }, "Logging": { "LogLevel": { From f70b157f76f742a0d2284fcb443345367da4a70c Mon Sep 17 00:00:00 2001 From: Jean-Marc Prieur Date: Tue, 11 Mar 2025 10:13:59 -0700 Subject: [PATCH 2/6] Update Program.cs --- web-app-aspnet/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web-app-aspnet/Program.cs b/web-app-aspnet/Program.cs index 45b352d..09a2616 100644 --- a/web-app-aspnet/Program.cs +++ b/web-app-aspnet/Program.cs @@ -11,7 +11,7 @@ builder.Services.AddMicrosoftIdentityWebAppAuthentication(builder.Configuration, "AzureAd") .EnableTokenAcquisitionToCallDownstreamApi(initialScopes) - .AddDownstreamApi("DownstreamApi", builder.Configuration.GetSection("DownstreamApi")) + .AddDownstreamApis(builder.Configuration.GetSection("DownstreamApis")) .AddInMemoryTokenCaches(); // From dc02f4e25763df3149afa91c607c578c2b9c8ade Mon Sep 17 00:00:00 2001 From: Jean-Marc Prieur Date: Tue, 11 Mar 2025 10:14:31 -0700 Subject: [PATCH 3/6] Update Index.cshtml.cs --- web-app-aspnet/Pages/Index.cshtml.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web-app-aspnet/Pages/Index.cshtml.cs b/web-app-aspnet/Pages/Index.cshtml.cs index 14033da..dfcce84 100644 --- a/web-app-aspnet/Pages/Index.cshtml.cs +++ b/web-app-aspnet/Pages/Index.cshtml.cs @@ -21,7 +21,7 @@ public IndexModel(ILogger logger, public async Task OnGet() { - using var response = await _downstreamWebApi.CallApiForUserAsync("DownstreamApi").ConfigureAwait(false); + using var response = await _downstreamWebApi.CallApiForUserAsync("MicrosoftGraph").ConfigureAwait(false); if (response.StatusCode == System.Net.HttpStatusCode.OK) { var apiResult = await response.Content.ReadFromJsonAsync().ConfigureAwait(false); From 73d3efc529095fef219bbf6bd16c29e7ebb95fcf Mon Sep 17 00:00:00 2001 From: Jean-Marc Prieur Date: Tue, 11 Mar 2025 11:57:22 -0700 Subject: [PATCH 4/6] Update web-app-aspnet/appsettings.json Co-authored-by: Stephen Halter --- web-app-aspnet/appsettings.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web-app-aspnet/appsettings.json b/web-app-aspnet/appsettings.json index c0794e6..12f26ac 100644 --- a/web-app-aspnet/appsettings.json +++ b/web-app-aspnet/appsettings.json @@ -12,7 +12,7 @@ ], "CallbackPath": "/signin-oidc" }, - "DownstreamApi": { + "DownstreamApis": { "MicrosoftGraph" :{ "BaseUrl": "https://graph.microsoft.com/v1.0/", "RelativePath": "me", From 83ddcabedb5c385d6f0b530eb1b1c706955c3d3f Mon Sep 17 00:00:00 2001 From: Jean-Marc Prieur Date: Fri, 14 Mar 2025 15:04:15 -0700 Subject: [PATCH 5/6] Address Stephen's feedback --- web-app-aspnet/Pages/Index.cshtml.cs | 2 +- web-app-aspnet/Program.cs | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/web-app-aspnet/Pages/Index.cshtml.cs b/web-app-aspnet/Pages/Index.cshtml.cs index dfcce84..9d5200b 100644 --- a/web-app-aspnet/Pages/Index.cshtml.cs +++ b/web-app-aspnet/Pages/Index.cshtml.cs @@ -5,7 +5,7 @@ namespace sign_in_webapp.Pages; -[AuthorizeForScopes(ScopeKeySection = "DownstreamApi:Scopes")] +[AuthorizeForScopes(ScopeKeySection = "DownstreamApis:MicrosoftGraph:Scopes")] public class IndexModel : PageModel { private readonly ILogger _logger; diff --git a/web-app-aspnet/Program.cs b/web-app-aspnet/Program.cs index 09a2616..714c892 100644 --- a/web-app-aspnet/Program.cs +++ b/web-app-aspnet/Program.cs @@ -7,12 +7,13 @@ // WebApplicationBuilder builder = WebApplication.CreateBuilder(args); -IEnumerable? initialScopes = builder.Configuration.GetSection("DownstreamApi:Scopes").Get>(); +IEnumerable? initialScopes = builder.Configuration.GetSection("DownstreamApis:MicrosoftGraph:Scopes").Get>(); builder.Services.AddMicrosoftIdentityWebAppAuthentication(builder.Configuration, "AzureAd") .EnableTokenAcquisitionToCallDownstreamApi(initialScopes) - .AddDownstreamApis(builder.Configuration.GetSection("DownstreamApis")) .AddInMemoryTokenCaches(); +builder.Services.AddDownstreamApis(builder.Configuration.GetSection("DownstreamApis")); + // // From ce24cca05cfd8634161cf08bd2bfc9a36d94e917 Mon Sep 17 00:00:00 2001 From: Jean-Marc Prieur Date: Fri, 14 Mar 2025 15:06:37 -0700 Subject: [PATCH 6/6] Update IdWeb --- web-app-aspnet/WebApp.csproj | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/web-app-aspnet/WebApp.csproj b/web-app-aspnet/WebApp.csproj index 9342564..f02f53e 100644 --- a/web-app-aspnet/WebApp.csproj +++ b/web-app-aspnet/WebApp.csproj @@ -6,8 +6,8 @@ sign_in_webapp - - - + + + \ No newline at end of file