From bd226c84a7db8c84e0e9970bd3e1ac138e3c6f47 Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Sat, 15 Feb 2025 14:46:40 +0000 Subject: [PATCH] code reorg --- src/Yavsc/Extensions/HostingExtensions.cs | 50 +++++++++++------------ 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/src/Yavsc/Extensions/HostingExtensions.cs b/src/Yavsc/Extensions/HostingExtensions.cs index 7d4e4ac4..67fc960a 100644 --- a/src/Yavsc/Extensions/HostingExtensions.cs +++ b/src/Yavsc/Extensions/HostingExtensions.cs @@ -297,6 +297,31 @@ public static class HostingExtensions return services; } + private static void AddAuthentication(IServiceCollection services, IConfigurationRoot configurationRoot) + { + string? googleClientId = configurationRoot["Authentication:Google:ClientId"]; + string? googleClientSecret = configurationRoot["Authentication:Google:ClientSecret"]; + + var authenticationBuilder = services.AddAuthentication() + .AddJwtBearer("Bearer", options => + { + options.IncludeErrorDetails = true; + options.Authority = "https://localhost:5001"; + options.TokenValidationParameters = + new() { ValidateAudience = false }; + }); + + authenticationBuilder.AddGoogle(options => + { + options.SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme; + + // register your IdentityServer with Google at https://console.developers.google.com + // enable the Google+ API + // set the redirect URI to https://localhost:5001/signin-google + options.ClientId = googleClientId; + options.ClientSecret = googleClientSecret; + }); + } private static IIdentityServerBuilder AddIdentityServer(WebApplicationBuilder builder) { var identityServerBuilder = builder.Services.AddIdentityServer() @@ -353,31 +378,6 @@ public static class HostingExtensions }); } - private static void AddAuthentication(IServiceCollection services, IConfigurationRoot configurationRoot) - { - string? googleClientId = configurationRoot["Authentication:Google:ClientId"]; - string? googleClientSecret = configurationRoot["Authentication:Google:ClientSecret"]; - - var authenticationBuilder = services.AddAuthentication() - .AddJwtBearer("Bearer", options => - { - options.IncludeErrorDetails = true; - options.Authority = "https://localhost:5001"; - options.TokenValidationParameters = - new() { ValidateAudience = false }; - }); - - authenticationBuilder.AddGoogle(options => - { - options.SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme; - - // register your IdentityServer with Google at https://console.developers.google.com - // enable the Google+ API - // set the redirect URI to https://localhost:5001/signin-google - options.ClientId = googleClientId; - options.ClientSecret = googleClientSecret; - }); - } public static WebApplication ConfigurePipeline(this WebApplication app) {