Skip to content

Commit

Permalink
Fix auth
Browse files Browse the repository at this point in the history
  • Loading branch information
amphasis committed Sep 22, 2024
1 parent 85eb600 commit 94f0ba2
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -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";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
16 changes: 4 additions & 12 deletions Amphasis.Azure.WebPortal/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
{
Expand Down

0 comments on commit 94f0ba2

Please sign in to comment.