diff --git a/Amphasis.Azure.WebPortal/Authentication/CookieAuthenticationOptionsConfigurator.cs b/Amphasis.Azure.WebPortal/Authentication/CookieAuthenticationOptionsConfigurator.cs new file mode 100644 index 0000000..5d10916 --- /dev/null +++ b/Amphasis.Azure.WebPortal/Authentication/CookieAuthenticationOptionsConfigurator.cs @@ -0,0 +1,18 @@ +using Microsoft.AspNetCore.Authentication.Cookies; +using Microsoft.AspNetCore.Http; +using Microsoft.Extensions.Hosting; + +namespace Amphasis.Azure.WebPortal.Authentication; + +public static class CookieAuthenticationOptionsConfigurator +{ + public static void Configure(this CookieAuthenticationOptions options, IHostApplicationBuilder applicationBuilder) + { + options.Cookie.HttpOnly = true; + options.Cookie.SameSite = SameSiteMode.Lax; + options.Cookie.SecurePolicy = applicationBuilder.Environment.IsDevelopment() + ? CookieSecurePolicy.None + : CookieSecurePolicy.Always; + options.LoginPath = "/SignIn"; + } +} \ No newline at end of file diff --git a/Amphasis.Azure.WebPortal/Authentication/MailRuAuthenticationOptionsConfigurator.cs b/Amphasis.Azure.WebPortal/Authentication/MailRuAuthenticationOptionsConfigurator.cs index 1f5a232..041b4ef 100644 --- a/Amphasis.Azure.WebPortal/Authentication/MailRuAuthenticationOptionsConfigurator.cs +++ b/Amphasis.Azure.WebPortal/Authentication/MailRuAuthenticationOptionsConfigurator.cs @@ -7,11 +7,10 @@ namespace Amphasis.Azure.WebPortal.Authentication; public static class MailRuAuthenticationOptionsConfigurator { - public static void ConfigureOptions(ConfigurationManager configuration, MailRuAuthenticationOptions options) + public static void Configure(this MailRuAuthenticationOptions options, ConfigurationManager configuration) { configuration.Bind("MailRu", options); - options.ClaimActions.Remove(MailRuAuthenticationConstants.Claims.ImageUrl); options.ClaimActions.MapJsonKey(CustomClaims.UserImageUrl, "image"); } } \ No newline at end of file diff --git a/Amphasis.Azure.WebPortal/Authentication/VkontakteAuthenticationOptionsConfigurator.cs b/Amphasis.Azure.WebPortal/Authentication/VkontakteAuthenticationOptionsConfigurator.cs index 352409b..fa06d53 100644 --- a/Amphasis.Azure.WebPortal/Authentication/VkontakteAuthenticationOptionsConfigurator.cs +++ b/Amphasis.Azure.WebPortal/Authentication/VkontakteAuthenticationOptionsConfigurator.cs @@ -7,11 +7,10 @@ namespace Amphasis.Azure.WebPortal.Authentication; public static class VkontakteAuthenticationOptionsConfigurator { - public static void ConfigureOptions(ConfigurationManager configuration, VkontakteAuthenticationOptions options) + public static void Configure(this VkontakteAuthenticationOptions options, ConfigurationManager configuration) { configuration.Bind("VK", options); - options.ClaimActions.Remove(VkontakteAuthenticationConstants.Claims.PhotoUrl); options.ClaimActions.MapJsonKey(CustomClaims.UserImageUrl, "photo"); } } \ No newline at end of file diff --git a/Amphasis.Azure.WebPortal/Authentication/YandexAuthenticationOptionsConfigurator.cs b/Amphasis.Azure.WebPortal/Authentication/YandexAuthenticationOptionsConfigurator.cs index 4bf06e7..c1f865b 100644 --- a/Amphasis.Azure.WebPortal/Authentication/YandexAuthenticationOptionsConfigurator.cs +++ b/Amphasis.Azure.WebPortal/Authentication/YandexAuthenticationOptionsConfigurator.cs @@ -9,7 +9,7 @@ namespace Amphasis.Azure.WebPortal.Authentication; public static class YandexAuthenticationOptionsConfigurator { - public static void ConfigureOptions(ConfigurationManager configuration, YandexAuthenticationOptions options) + public static void Configure(this YandexAuthenticationOptions options, ConfigurationManager configuration) { configuration.Bind("Yandex", options); diff --git a/Amphasis.Azure.WebPortal/Program.cs b/Amphasis.Azure.WebPortal/Program.cs index 5bb5b98..a2ed407 100644 --- a/Amphasis.Azure.WebPortal/Program.cs +++ b/Amphasis.Azure.WebPortal/Program.cs @@ -26,18 +26,10 @@ var authenticationBuilder = services .AddAuthentication(options => options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme) - .AddCookie(options => - { - options.Cookie.HttpOnly = true; - options.Cookie.SameSite = SameSiteMode.Strict; - options.Cookie.SecurePolicy = applicationBuilder.Environment.IsDevelopment() - ? CookieSecurePolicy.None - : CookieSecurePolicy.Always; - options.LoginPath = "/SignIn"; - }) - .AddMailRu(options => MailRuAuthenticationOptionsConfigurator.ConfigureOptions(configuration, options)) - .AddVkontakte(options => VkontakteAuthenticationOptionsConfigurator.ConfigureOptions(configuration, options)) - .AddYandex(options => YandexAuthenticationOptionsConfigurator.ConfigureOptions(configuration, options)); + .AddCookie(options => options.Configure(applicationBuilder)) + .AddMailRu(options => options.Configure(configuration)) + .AddVkontakte(options => options.Configure(configuration)) + .AddYandex(options => options.Configure(configuration)); if (applicationBuilder.Environment.IsDevelopment()) {