Shady nagy/net6 (#614)
* udated to .net6 * used the .net6 version RC2 * added editconfig. * App core new Scoped Namespaces style. * BlazorAdmin new Scoped Namespaces style. * Blazor Shared new Scoped Namespaces style. * Infra new Scoped Namespaces style. * public api new Scoped Namespaces style. * web new Scoped Namespaces style. * FunctionalTests new Scoped Namespaces style. * Integrational tests new Scoped Namespaces style. * unit tests new Scoped Namespaces style. * update github action. * update github action. * change the global.
This commit is contained in:
@@ -1,41 +1,40 @@
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using System;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System;
|
||||
|
||||
namespace Microsoft.eShopWeb.Web.Configuration
|
||||
namespace Microsoft.eShopWeb.Web.Configuration;
|
||||
|
||||
public static class ConfigureCookieSettings
|
||||
{
|
||||
public static class ConfigureCookieSettings
|
||||
{
|
||||
public const int ValidityMinutesPeriod = 60;
|
||||
public const string IdentifierCookieName = "EshopIdentifier";
|
||||
public const int ValidityMinutesPeriod = 60;
|
||||
public const string IdentifierCookieName = "EshopIdentifier";
|
||||
|
||||
public static IServiceCollection AddCookieSettings(this IServiceCollection services)
|
||||
public static IServiceCollection AddCookieSettings(this IServiceCollection services)
|
||||
{
|
||||
services.Configure<CookiePolicyOptions>(options =>
|
||||
{
|
||||
services.Configure<CookiePolicyOptions>(options =>
|
||||
{
|
||||
// This lambda determines whether user consent for non-essential cookies is needed for a given request.
|
||||
//TODO need to check that.
|
||||
//options.CheckConsentNeeded = context => true;
|
||||
options.MinimumSameSitePolicy = SameSiteMode.Strict;
|
||||
});
|
||||
services.ConfigureApplicationCookie(options =>
|
||||
});
|
||||
services.ConfigureApplicationCookie(options =>
|
||||
{
|
||||
options.EventsType = typeof(RevokeAuthenticationEvents);
|
||||
options.Cookie.HttpOnly = true;
|
||||
options.ExpireTimeSpan = TimeSpan.FromMinutes(ValidityMinutesPeriod);
|
||||
options.LoginPath = "/Account/Login";
|
||||
options.LogoutPath = "/Account/Logout";
|
||||
options.Cookie = new CookieBuilder
|
||||
{
|
||||
options.EventsType = typeof(RevokeAuthenticationEvents);
|
||||
options.Cookie.HttpOnly = true;
|
||||
options.ExpireTimeSpan = TimeSpan.FromMinutes(ValidityMinutesPeriod);
|
||||
options.LoginPath = "/Account/Login";
|
||||
options.LogoutPath = "/Account/Logout";
|
||||
options.Cookie = new CookieBuilder
|
||||
{
|
||||
Name = IdentifierCookieName,
|
||||
IsEssential = true // required for auth to work without explicit user consent; adjust to suit your privacy policy
|
||||
Name = IdentifierCookieName,
|
||||
IsEssential = true // required for auth to work without explicit user consent; adjust to suit your privacy policy
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
services.AddScoped<RevokeAuthenticationEvents>();
|
||||
services.AddScoped<RevokeAuthenticationEvents>();
|
||||
|
||||
return services;
|
||||
}
|
||||
return services;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,24 +6,23 @@ using Microsoft.eShopWeb.Infrastructure.Services;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace Microsoft.eShopWeb.Web.Configuration
|
||||
namespace Microsoft.eShopWeb.Web.Configuration;
|
||||
|
||||
public static class ConfigureCoreServices
|
||||
{
|
||||
public static class ConfigureCoreServices
|
||||
public static IServiceCollection AddCoreServices(this IServiceCollection services,
|
||||
IConfiguration configuration)
|
||||
{
|
||||
public static IServiceCollection AddCoreServices(this IServiceCollection services,
|
||||
IConfiguration configuration)
|
||||
{
|
||||
services.AddScoped(typeof(IReadRepository<>), typeof(EfRepository<>));
|
||||
services.AddScoped(typeof(IRepository<>), typeof(EfRepository<>));
|
||||
services.AddScoped(typeof(IReadRepository<>), typeof(EfRepository<>));
|
||||
services.AddScoped(typeof(IRepository<>), typeof(EfRepository<>));
|
||||
|
||||
services.AddScoped<IBasketService, BasketService>();
|
||||
services.AddScoped<IOrderService, OrderService>();
|
||||
services.AddScoped<IBasketQueryService, BasketQueryService>();
|
||||
services.AddSingleton<IUriComposer>(new UriComposer(configuration.Get<CatalogSettings>()));
|
||||
services.AddScoped(typeof(IAppLogger<>), typeof(LoggerAdapter<>));
|
||||
services.AddTransient<IEmailSender, EmailSender>();
|
||||
services.AddScoped<IBasketService, BasketService>();
|
||||
services.AddScoped<IOrderService, OrderService>();
|
||||
services.AddScoped<IBasketQueryService, BasketQueryService>();
|
||||
services.AddSingleton<IUriComposer>(new UriComposer(configuration.Get<CatalogSettings>()));
|
||||
services.AddScoped(typeof(IAppLogger<>), typeof(LoggerAdapter<>));
|
||||
services.AddTransient<IEmailSender, EmailSender>();
|
||||
|
||||
return services;
|
||||
}
|
||||
return services;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,20 +4,19 @@ using Microsoft.eShopWeb.Web.Services;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace Microsoft.eShopWeb.Web.Configuration
|
||||
{
|
||||
public static class ConfigureWebServices
|
||||
{
|
||||
public static IServiceCollection AddWebServices(this IServiceCollection services, IConfiguration configuration)
|
||||
{
|
||||
services.AddMediatR(typeof(BasketViewModelService).Assembly);
|
||||
services.AddScoped<IBasketViewModelService, BasketViewModelService>();
|
||||
services.AddScoped<CatalogViewModelService>();
|
||||
services.AddScoped<ICatalogItemViewModelService, CatalogItemViewModelService>();
|
||||
services.Configure<CatalogSettings>(configuration);
|
||||
services.AddScoped<ICatalogViewModelService, CachedCatalogViewModelService>();
|
||||
namespace Microsoft.eShopWeb.Web.Configuration;
|
||||
|
||||
return services;
|
||||
}
|
||||
public static class ConfigureWebServices
|
||||
{
|
||||
public static IServiceCollection AddWebServices(this IServiceCollection services, IConfiguration configuration)
|
||||
{
|
||||
services.AddMediatR(typeof(BasketViewModelService).Assembly);
|
||||
services.AddScoped<IBasketViewModelService, BasketViewModelService>();
|
||||
services.AddScoped<CatalogViewModelService>();
|
||||
services.AddScoped<ICatalogItemViewModelService, CatalogItemViewModelService>();
|
||||
services.Configure<CatalogSettings>(configuration);
|
||||
services.AddScoped<ICatalogViewModelService, CachedCatalogViewModelService>();
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,36 +1,35 @@
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
using System.Linq;
|
||||
using System.Security.Claims;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
using Microsoft.AspNetCore.Authentication.Cookies;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Linq;
|
||||
using System.Security.Claims;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.eShopWeb.Web.Configuration
|
||||
namespace Microsoft.eShopWeb.Web.Configuration;
|
||||
|
||||
//TODO : replace IMemoryCache with a distributed cache if you are in multi-host scenario
|
||||
public class RevokeAuthenticationEvents : CookieAuthenticationEvents
|
||||
{
|
||||
//TODO : replace IMemoryCache with a distributed cache if you are in multi-host scenario
|
||||
public class RevokeAuthenticationEvents : CookieAuthenticationEvents
|
||||
private readonly IMemoryCache _cache;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public RevokeAuthenticationEvents(IMemoryCache cache, ILogger<RevokeAuthenticationEvents> logger)
|
||||
{
|
||||
private readonly IMemoryCache _cache;
|
||||
private readonly ILogger _logger;
|
||||
_cache = cache;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public RevokeAuthenticationEvents(IMemoryCache cache, ILogger<RevokeAuthenticationEvents> logger)
|
||||
public override async Task ValidatePrincipal(CookieValidatePrincipalContext context)
|
||||
{
|
||||
var userId = context.Principal.Claims.First(c => c.Type == ClaimTypes.Name);
|
||||
var identityKey = context.Request.Cookies[ConfigureCookieSettings.IdentifierCookieName];
|
||||
|
||||
if (_cache.TryGetValue($"{userId.Value}:{identityKey}", out var revokeKeys))
|
||||
{
|
||||
_cache = cache;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public override async Task ValidatePrincipal(CookieValidatePrincipalContext context)
|
||||
{
|
||||
var userId = context.Principal.Claims.First(c => c.Type == ClaimTypes.Name);
|
||||
var identityKey = context.Request.Cookies[ConfigureCookieSettings.IdentifierCookieName];
|
||||
|
||||
if (_cache.TryGetValue($"{userId.Value}:{identityKey}", out var revokeKeys))
|
||||
{
|
||||
_logger.LogDebug($"Access has been revoked for: {userId.Value}.");
|
||||
context.RejectPrincipal();
|
||||
await context.HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
|
||||
}
|
||||
_logger.LogDebug($"Access has been revoked for: {userId.Value}.");
|
||||
context.RejectPrincipal();
|
||||
await context.HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user