added user confirmation extension method (#14409)

This commit is contained in:
Bharat Kumar Bellamkonda 2019-12-28 06:28:37 +05:30 committed by Hao Kung
parent 654140736c
commit af9f99299c
4 changed files with 30 additions and 0 deletions

View File

@ -57,6 +57,7 @@ namespace Microsoft.AspNetCore.Identity
public virtual Microsoft.AspNetCore.Identity.IdentityBuilder AddRoleValidator<TRole>() where TRole : class { throw null; }
public virtual Microsoft.AspNetCore.Identity.IdentityBuilder AddTokenProvider(string providerName, System.Type provider) { throw null; }
public virtual Microsoft.AspNetCore.Identity.IdentityBuilder AddTokenProvider<TProvider>(string providerName) where TProvider : class { throw null; }
public virtual Microsoft.AspNetCore.Identity.IdentityBuilder AddUserConfirmation<TUserConfirmation>() where TUserConfirmation : class { throw null; }
public virtual Microsoft.AspNetCore.Identity.IdentityBuilder AddUserManager<TUserManager>() where TUserManager : class { throw null; }
public virtual Microsoft.AspNetCore.Identity.IdentityBuilder AddUserStore<TStore>() where TStore : class { throw null; }
public virtual Microsoft.AspNetCore.Identity.IdentityBuilder AddUserValidator<TValidator>() where TValidator : class { throw null; }

View File

@ -57,6 +57,7 @@ namespace Microsoft.AspNetCore.Identity
public virtual Microsoft.AspNetCore.Identity.IdentityBuilder AddRoleValidator<TRole>() where TRole : class { throw null; }
public virtual Microsoft.AspNetCore.Identity.IdentityBuilder AddTokenProvider(string providerName, System.Type provider) { throw null; }
public virtual Microsoft.AspNetCore.Identity.IdentityBuilder AddTokenProvider<TProvider>(string providerName) where TProvider : class { throw null; }
public virtual Microsoft.AspNetCore.Identity.IdentityBuilder AddUserConfirmation<TUserConfirmation>() where TUserConfirmation : class { throw null; }
public virtual Microsoft.AspNetCore.Identity.IdentityBuilder AddUserManager<TUserManager>() where TUserManager : class { throw null; }
public virtual Microsoft.AspNetCore.Identity.IdentityBuilder AddUserStore<TStore>() where TStore : class { throw null; }
public virtual Microsoft.AspNetCore.Identity.IdentityBuilder AddUserValidator<TValidator>() where TValidator : class { throw null; }

View File

@ -238,5 +238,13 @@ namespace Microsoft.AspNetCore.Identity
}
return AddScoped(managerType, typeof(TRoleManager));
}
/// <summary>
/// Adds a <see cref="IUserConfirmation{TUser}"/> for the <seealso cref="UserType"/>.
/// </summary>
/// <typeparam name="TUserConfirmation">The type of the user confirmation to add.</typeparam>
/// <returns>The current <see cref="IdentityBuilder"/> instance.</returns>
public virtual IdentityBuilder AddUserConfirmation<TUserConfirmation>() where TUserConfirmation : class
=> AddScoped(typeof(IUserConfirmation<>).MakeGenericType(UserType), typeof(TUserConfirmation));
}
}

View File

@ -80,6 +80,22 @@ namespace Microsoft.AspNetCore.Identity.Test
Assert.NotNull(thingy);
}
[Fact]
public void CanOverrideUserConfirmation()
{
var services = new ServiceCollection()
.AddLogging()
.AddSingleton<IConfiguration>(new ConfigurationBuilder().Build());
services.AddIdentity<PocoUser, PocoRole>()
.AddClaimsPrincipalFactory<MyClaimsPrincipalFactory>()
.AddUserConfirmation<MyUserConfirmation>()
.AddUserManager<MyUserManager>()
.AddUserStore<NoopUserStore>()
.AddRoleStore<NoopRoleStore>();
var thingy = services.BuildServiceProvider().GetRequiredService<IUserConfirmation<PocoUser>>() as MyUserConfirmation;
Assert.NotNull(thingy);
}
[Fact]
public void CanOverrideRoleValidator()
{
@ -356,5 +372,9 @@ namespace Microsoft.AspNetCore.Identity.Test
}
}
private class MyUserConfirmation : DefaultUserConfirmation<PocoUser>
{
}
}
}