1
0
mirror of https://github.com/bitwarden/server.git synced 2025-04-07 05:58:13 -05:00

AddIdentityCore for passwordless identity service

This commit is contained in:
Kyle Spearrin 2018-09-12 10:35:05 -04:00
parent 88384836b5
commit 07855a3203
2 changed files with 9 additions and 6 deletions

View File

@ -1,4 +1,5 @@
using System; using System;
using Bit.Core.Identity;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.DependencyInjection.Extensions;
@ -28,7 +29,7 @@ namespace Microsoft.Extensions.DependencyInjection
services.TryAddScoped<IUserValidator<TUser>, UserValidator<TUser>>(); services.TryAddScoped<IUserValidator<TUser>, UserValidator<TUser>>();
services.TryAddScoped<IPasswordValidator<TUser>, PasswordValidator<TUser>>(); services.TryAddScoped<IPasswordValidator<TUser>, PasswordValidator<TUser>>();
services.TryAddScoped<IPasswordHasher<TUser>, PasswordHasher<TUser>>(); services.TryAddScoped<IPasswordHasher<TUser>, PasswordHasher<TUser>>();
services.TryAddScoped<ILookupNormalizer, UpperInvariantLookupNormalizer>(); services.TryAddScoped<ILookupNormalizer, LowerInvariantLookupNormalizer>();
services.TryAddScoped<IRoleValidator<TRole>, RoleValidator<TRole>>(); services.TryAddScoped<IRoleValidator<TRole>, RoleValidator<TRole>>();
// No interface for the error describer so we can add errors without rev'ing the interface // No interface for the error describer so we can add errors without rev'ing the interface
services.TryAddScoped<IdentityErrorDescriber>(); services.TryAddScoped<IdentityErrorDescriber>();

View File

@ -153,7 +153,6 @@ namespace Bit.Core.Utilities
public static IdentityBuilder AddCustomIdentityServices( public static IdentityBuilder AddCustomIdentityServices(
this IServiceCollection services, GlobalSettings globalSettings) this IServiceCollection services, GlobalSettings globalSettings)
{ {
services.TryAddTransient<ILookupNormalizer, LowerInvariantLookupNormalizer>();
services.AddSingleton<IOrganizationDuoWebTokenProvider, OrganizationDuoWebTokenProvider>(); services.AddSingleton<IOrganizationDuoWebTokenProvider, OrganizationDuoWebTokenProvider>();
services.Configure<PasswordHasherOptions>(options => options.IterationCount = 100000); services.Configure<PasswordHasherOptions>(options => options.IterationCount = 100000);
services.Configure<TwoFactorRememberTokenProviderOptions>(options => services.Configure<TwoFactorRememberTokenProviderOptions>(options =>
@ -199,7 +198,7 @@ namespace Bit.Core.Utilities
return identityBuilder; return identityBuilder;
} }
public static IdentityBuilder AddPasswordlessIdentityServices<TUserStore>( public static Tuple<IdentityBuilder, IdentityBuilder> AddPasswordlessIdentityServices<TUserStore>(
this IServiceCollection services, GlobalSettings globalSettings) where TUserStore : class this IServiceCollection services, GlobalSettings globalSettings) where TUserStore : class
{ {
services.TryAddTransient<ILookupNormalizer, LowerInvariantLookupNormalizer>(); services.TryAddTransient<ILookupNormalizer, LowerInvariantLookupNormalizer>();
@ -208,11 +207,14 @@ namespace Bit.Core.Utilities
options.TokenLifespan = TimeSpan.FromMinutes(15); options.TokenLifespan = TimeSpan.FromMinutes(15);
}); });
var identityBuilder = services.AddIdentity<IdentityUser, Role>() var passwordlessIdentityBuilder = services.AddIdentity<IdentityUser, Role>()
.AddUserStore<TUserStore>() .AddUserStore<TUserStore>()
.AddRoleStore<RoleStore>() .AddRoleStore<RoleStore>()
.AddDefaultTokenProviders(); .AddDefaultTokenProviders();
var regularIdentityBuilder = services.AddIdentityCore<User>()
.AddUserStore<UserStore>();
services.TryAddScoped<PasswordlessSignInManager<IdentityUser>, PasswordlessSignInManager<IdentityUser>>(); services.TryAddScoped<PasswordlessSignInManager<IdentityUser>, PasswordlessSignInManager<IdentityUser>>();
services.ConfigureApplicationCookie(options => services.ConfigureApplicationCookie(options =>
@ -227,7 +229,7 @@ namespace Bit.Core.Utilities
options.SlidingExpiration = true; options.SlidingExpiration = true;
}); });
return identityBuilder; return new Tuple<IdentityBuilder, IdentityBuilder>(passwordlessIdentityBuilder, regularIdentityBuilder);
} }
public static void AddIdentityAuthenticationServices( public static void AddIdentityAuthenticationServices(