Files
mixtape/zero.Core/Identity/ServiceCollectionExtensions.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;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Options;
namespace zero.Identity;
internal static class ServiceCollectionExtensions
{
public static IServiceCollection AddZeroIdentity(this IServiceCollection services)
{
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();
return services;
}
}