зеркало из https://github.com/aspnet/Identity.git
Remove IConfiguration from AddIdentity
This commit is contained in:
Родитель
3e704f477b
Коммит
649cb0caed
|
@ -36,7 +36,7 @@ namespace IdentitySamples
|
|||
options.DefaultAdminPassword = Configuration.Get("DefaultAdminPassword");
|
||||
});
|
||||
|
||||
services.AddIdentity<ApplicationUser, IdentityRole>(Configuration)
|
||||
services.AddIdentity<ApplicationUser, IdentityRole>()
|
||||
.AddEntityFrameworkStores<ApplicationDbContext>()
|
||||
.AddDefaultTokenProviders();
|
||||
|
||||
|
|
|
@ -18,36 +18,30 @@ namespace Microsoft.Framework.DependencyInjection
|
|||
return services.Configure(configure);
|
||||
}
|
||||
|
||||
public static IdentityBuilder AddIdentity(this IServiceCollection services)
|
||||
public static IServiceCollection ConfigureIdentity(this IServiceCollection services, IConfiguration config)
|
||||
{
|
||||
return services.AddIdentity<IdentityUser, IdentityRole>();
|
||||
return services.Configure<IdentityOptions>(config);
|
||||
}
|
||||
|
||||
public static IdentityBuilder AddIdentity(
|
||||
this IServiceCollection services,
|
||||
IConfiguration identityConfig = null,
|
||||
Action<IdentityOptions> configureOptions = null,
|
||||
bool useDefaultSubKey = true)
|
||||
public static IdentityBuilder AddIdentity(this IServiceCollection services)
|
||||
{
|
||||
return services.AddIdentity<IdentityUser, IdentityRole>(identityConfig, configureOptions, useDefaultSubKey);
|
||||
return services.AddIdentity<IdentityUser, IdentityRole>(configureOptions: null);
|
||||
}
|
||||
|
||||
public static IdentityBuilder AddIdentity<TUser, TRole>(
|
||||
this IServiceCollection services)
|
||||
where TUser : class
|
||||
where TRole : class
|
||||
{
|
||||
return services.AddIdentity<TUser, TRole>(configureOptions: null);
|
||||
}
|
||||
|
||||
public static IdentityBuilder AddIdentity<TUser, TRole>(
|
||||
this IServiceCollection services,
|
||||
IConfiguration identityConfig = null,
|
||||
Action<IdentityOptions> configureOptions = null,
|
||||
bool useDefaultSubKey = true)
|
||||
Action<IdentityOptions> configureOptions)
|
||||
where TUser : class
|
||||
where TRole : class
|
||||
{
|
||||
if (identityConfig != null)
|
||||
{
|
||||
if (useDefaultSubKey)
|
||||
{
|
||||
identityConfig = identityConfig.GetSubKey("identity");
|
||||
}
|
||||
services.Configure<IdentityOptions>(identityConfig);
|
||||
}
|
||||
// Services used by identity
|
||||
services.AddOptions();
|
||||
services.AddDataProtection();
|
||||
|
|
|
@ -107,7 +107,7 @@ namespace Microsoft.AspNet.Identity.EntityFramework.Test
|
|||
builder.UseServices(services =>
|
||||
{
|
||||
DbUtil.ConfigureDbServices<TestDbContext>(ConnectionString, services);
|
||||
services.AddIdentity<TUser, TRole>(null, options =>
|
||||
services.AddIdentity<TUser, TRole>(options =>
|
||||
{
|
||||
options.Password.RequiredLength = 1;
|
||||
options.Password.RequireLowercase = false;
|
||||
|
|
|
@ -77,7 +77,7 @@ namespace Microsoft.AspNet.Identity.EntityFramework.Test
|
|||
services.AddEntityFramework()
|
||||
.AddSqlServer()
|
||||
.AddDbContext<ApplicationDbContext>(options => options.UseSqlServer(ConnectionString));
|
||||
services.AddIdentity<ApplicationUser, IdentityRole>(null, options =>
|
||||
services.AddIdentity<ApplicationUser, IdentityRole>(options =>
|
||||
{
|
||||
options.Password.RequiredLength = 1;
|
||||
options.Password.RequireLowercase = false;
|
||||
|
|
|
@ -38,10 +38,8 @@ namespace Microsoft.AspNet.Identity.Test
|
|||
Assert.Equal("AspNet.Identity.SecurityStamp", options.ClaimsIdentity.SecurityStampClaimType);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(true)]
|
||||
[InlineData(false)]
|
||||
public void IdentityOptionsFromConfig(bool useDefaultSubKey)
|
||||
[Fact]
|
||||
public void IdentityOptionsFromConfig()
|
||||
{
|
||||
const string roleClaimType = "rolez";
|
||||
const string usernameClaimType = "namez";
|
||||
|
@ -67,14 +65,8 @@ namespace Microsoft.AspNet.Identity.Test
|
|||
Assert.Equal(roleClaimType, config.Get("identity:claimsidentity:roleclaimtype"));
|
||||
|
||||
var services = new ServiceCollection();
|
||||
if (useDefaultSubKey)
|
||||
{
|
||||
services.AddIdentity(config);
|
||||
}
|
||||
else
|
||||
{
|
||||
services.AddIdentity(config.GetSubKey("identity"), null, useDefaultSubKey);
|
||||
}
|
||||
services.AddIdentity();
|
||||
services.ConfigureIdentity(config.GetSubKey("identity"));
|
||||
var accessor = services.BuildServiceProvider().GetRequiredService<IOptions<IdentityOptions>>();
|
||||
Assert.NotNull(accessor);
|
||||
var options = accessor.Options;
|
||||
|
@ -103,8 +95,8 @@ namespace Microsoft.AspNet.Identity.Test
|
|||
};
|
||||
var config = new Configuration(new MemoryConfigurationSource(dic));
|
||||
var services = new ServiceCollection();
|
||||
services.AddIdentity(config,
|
||||
o => { o.User.RequireUniqueEmail = false; o.Lockout.MaxFailedAccessAttempts++; });
|
||||
services.ConfigureIdentity(config.GetSubKey("identity"));
|
||||
services.AddIdentity<IdentityUser, IdentityRole>(o => { o.User.RequireUniqueEmail = false; o.Lockout.MaxFailedAccessAttempts++; });
|
||||
var accessor = services.BuildServiceProvider().GetRequiredService<IOptions<IdentityOptions>>();
|
||||
Assert.NotNull(accessor);
|
||||
var options = accessor.Options;
|
||||
|
|
Загрузка…
Ссылка в новой задаче