Files
mixtape/zero.Core/Identity/ZeroIdentityModule.cs
T

31 lines
1.4 KiB
C#
Raw Normal View History

2021-11-23 22:56:22 +01:00
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Identity;
2021-11-30 14:32:10 +01:00
using Microsoft.Extensions.Configuration;
2021-11-23 22:56:22 +01:00
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Options;
2022-01-06 18:10:58 +01:00
namespace zero.Identity;
2021-11-23 22:56:22 +01:00
2022-01-06 18:10:58 +01:00
internal class ZeroIdentityModule : ZeroModule
2021-11-23 22:56:22 +01:00
{
2021-11-30 14:32:10 +01:00
public override void ConfigureServices(IServiceCollection services, IConfiguration configuration)
2021-11-23 22:56:22 +01:00
{
services.TryAddEnumerable(ServiceDescriptor.Singleton<IPostConfigureOptions<CookieAuthenticationOptions>, PostConfigureCookieAuthenticationOptions>());
services.AddZeroIdentity<ZeroUser, ZeroUserRole>();
services.Replace<IUserClaimsPrincipalFactory<ZeroUser>, ZeroBackofficeClaimsPrincipalFactory<ZeroUser, ZeroUserRole>>();
services.Replace<IUserStore<ZeroUser>, RavenCoreUserStore<ZeroUser, ZeroUserRole>>(ServiceLifetime.Scoped);
services.Replace<IRoleStore<ZeroUserRole>, RavenCoreRoleStore<ZeroUserRole>>(ServiceLifetime.Scoped);
services.AddScoped<IAuthenticationService, AuthenticationService>();
services.AddScoped<IAuthorizationService, AuthorizationService>();
services.AddScoped<IUserService, UserService>();
services.AddScoped<IUserRolesService, UserRolesService>();
2021-11-29 00:38:55 +01:00
services.AddAuthentication(Constants.Auth.BackofficeScheme)
.AddZeroBackofficeCookie<ZeroUser, ZeroUserRole>();
2021-11-23 22:56:22 +01:00
services.AddAuthorization();
}
}