using Bit.Admin.Auth.IdentityServer; using Bit.Core.Auth.Identity; using Bit.Core.Entities; using Bit.Core.Settings; using Microsoft.AspNetCore.Identity; using Microsoft.Extensions.DependencyInjection.Extensions; namespace Bit.Admin.IdentityServer; public static class ServiceCollectionExtensions { public static Tuple AddPasswordlessIdentityServices( this IServiceCollection services, GlobalSettings globalSettings) where TUserStore : class { services.TryAddTransient(); services.Configure(options => { options.TokenLifespan = TimeSpan.FromMinutes(15); }); var passwordlessIdentityBuilder = services.AddIdentity() .AddUserStore() .AddRoleStore() .AddDefaultTokenProviders() .AddClaimsPrincipalFactory(); var regularIdentityBuilder = services.AddIdentityCore() .AddUserStore(); services.TryAddScoped, PasswordlessSignInManager>(); services.ConfigureApplicationCookie(options => { options.LoginPath = "/login"; options.LogoutPath = "/"; options.AccessDeniedPath = "/login?accessDenied=true"; options.Cookie.Name = $"Bitwarden_{globalSettings.ProjectName}"; options.Cookie.HttpOnly = true; options.ExpireTimeSpan = TimeSpan.FromDays(2); options.ReturnUrlParameter = "returnUrl"; options.SlidingExpiration = true; }); return new Tuple(passwordlessIdentityBuilder, regularIdentityBuilder); } }