// This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); services.AddCors(options => { options.AddPolicy("CorsPolicy", b => b.AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader() .AllowCredentials()); }); var issuerUri = Configuration.GetSection("ConnectionStrings")?.GetSection("IssuerUri")?.Value; services.AddIdentityServer(options => { options.Events.RaiseErrorEvents = true; options.Events.RaiseInformationEvents = true; options.Events.RaiseFailureEvents = true; options.Events.RaiseSuccessEvents = true; options.IssuerUri = "https://identity-test.northeurope.cloudapp.azure.com/"; options.PublicOrigin = Environment.IsDevelopment() ? "" : "https://identity-test.northeurope.cloudapp.azure.com/"; }) .AddDeveloperSigningCredential() .AddInMemoryApiResources(InMemoryConfiguration.ApiResources()) .AddInMemoryClients(InMemoryConfiguration.Clients()) .AddTestUsers(InMemoryConfiguration.Users().ToList()) .AddJwtBearerClientAuthentication(); }
// This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public IServiceProvider ConfigureServices(IServiceCollection services) { string certFile = $"{_environment.ContentRootPath}{Path.DirectorySeparatorChar}Certificates{Path.DirectorySeparatorChar}nanofabrictest.pfx"; var cert = new X509Certificate2(certFile, "idsrv3test"); services.AddCors(); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); // TODO:IdentiyServer Config Add IdentityRegistrar.Register(services); services.AddIdentityServer() .AddDeveloperSigningCredential() .AddInMemoryIdentityResources(InMemoryConfiguration.IdentityResources()) .AddInMemoryApiResources(InMemoryConfiguration.ApiResources()) .AddInMemoryClients(InMemoryConfiguration.Clients()) .AddAbpPersistedGrants <IAbpPersistedGrantDbContext>() .AddAbpIdentityServer <User>() .AddResourceOwnerValidator <ResourceOwnerPasswordValidator>() .AddProfileService <ProfileService>(); // Configure Abp and Dependency Injection return(services.AddAbp <IdentityServerModule>( // Configure Log4Net logging options => options.IocManager.IocContainer.AddFacility <LoggingFacility>( f => f.UseAbpLog4Net().WithConfig("log4net.config") ) )); }
public void ConfigureServices(IServiceCollection services) { services.AddIdentityServer() .AddInMemoryClients(InMemoryConfiguration.Clients()) .AddInMemoryApiResources(InMemoryConfiguration.ApiResources()) .AddDeveloperSigningCredential(); }
private static void SeedData(IServiceScope serviceScope) { var context = serviceScope .ServiceProvider .GetRequiredService <ConfigurationDbContext>(); if (!context.Clients.Any()) { foreach (var client in InMemoryConfiguration.Clients()) { context.Clients.Add(client.ToEntity()); } context.SaveChanges(); } if (!context.IdentityResources.Any()) { foreach (var resource in InMemoryConfiguration.IdentityResources()) { context.IdentityResources.Add(resource.ToEntity()); } context.SaveChanges(); } if (!context.ApiResources.Any()) { foreach (var resource in InMemoryConfiguration.ApiResources()) { context.ApiResources.Add(resource.ToEntity()); } context.SaveChanges(); } }
// This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { services.AddIdentityServer() .AddDeveloperSigningCredential() //AddTemporarySigningCredential .AddTestUsers(InMemoryConfiguration.Users().ToList()) .AddInMemoryClients(InMemoryConfiguration.Clients()) .AddInMemoryApiResources(InMemoryConfiguration.ApiResources()); }
// This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { services .AddIdentityServer() .AddSigningCredential(new X509Certificate2("identity_server_test.pfx", "password")) .AddTestUsers(InMemoryConfiguration.Users().ToList()) .AddInMemoryClients(InMemoryConfiguration.Clients()) .AddInMemoryApiResources(InMemoryConfiguration.ApiResources()); services.AddMvc(); }
// This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { services.AddIdentityServer() //.AddDeveloperSigningCredential() .AddSigningCredential(new X509Certificate2(Path.Combine(AppContext.BaseDirectory, "socialnetwork.pfx"), "12345678")) .AddTestUsers(InMemoryConfiguration.Users().ToList()) .AddInMemoryClients(InMemoryConfiguration.Clients()) .AddInMemoryApiResources(InMemoryConfiguration.ApiResources()) ; services.AddMvc(); }
// This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { services.AddIdentityServer() .AddSigningCredential(new X509Certificate2("/users/rmcneill/socialnetwork.pfx", "ruthy123")) //.AddDeveloperSigningCredential() .AddTestUsers(InMemoryConfiguration.Users().ToList()) .AddInMemoryClients(InMemoryConfiguration.Clients()) .AddInMemoryApiResources(InMemoryConfiguration.ApiResources()); services.AddMvc(); }
// This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { services.AddIdentityServer() .AddDeveloperSigningCredential() // .AddSigningCredential(new X509Certificate2(@"C:\Users\Daniil\Desktop\APP\Oauth\socialnetwork.pfx", "password")) .AddTestUsers(InMemoryConfiguration.Users().ToList()) .AddInMemoryClients(InMemoryConfiguration.GetClients()) .AddInMemoryApiResources(InMemoryConfiguration.ApiResources()); services.AddMvc(); }
// This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { services.AddIdentityServer() .AddSigningCredential(new X509Certificate2(@"C:\Users\Douglas\Documents\MisRepos\SocialNetwork\SocialNetwork.OAuth\socialnetwork.pfx", "pass123")) .AddTestUsers(InMemoryConfiguration.Users().ToList()) .AddInMemoryClients(InMemoryConfiguration.Clients()) .AddInMemoryIdentityResources(InMemoryConfiguration.IdentityResources()) .AddInMemoryApiResources(InMemoryConfiguration.ApiResources()); services.AddMvc(); }
// This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { services.AddIdentityServer(options => { }) .AddDeveloperSigningCredential() .AddInMemoryApiResources(InMemoryConfiguration.ApiResources()) .AddInMemoryClients(InMemoryConfiguration.Clients()) .AddTestUsers(InMemoryConfiguration.Users().ToList()); services.AddMvc(options => options.EnableEndpointRouting = false); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddIdentityServer() .AddSigningCredential(new X509Certificate2(@"D:\AspMVC\MilkSupplyManagementApi\MilkManagement.OAuth", "password123")) // to use our own certificate //.AddDeveloperSigningCredential() //AddTemporarySigningCredential .AddTestUsers(InMemoryConfiguration.Users().ToList()) .AddInMemoryClients(InMemoryConfiguration.Clients()) .AddInMemoryApiResources(InMemoryConfiguration.ApiResources()); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); }
// This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { services.AddIdentityServer() // .AddDeveloperSigningCredential() .AddSigningCredential(new X509Certificate2(@"C:\Users\yhy\socialnetwork.pfx", "123456")) //配置Authorization Server来允许使用这些Identity Resources .AddInMemoryIdentityResources(InMemoryConfiguration.GetIdentityResources()) .AddTestUsers(InMemoryConfiguration.User().ToList()) .AddInMemoryClients(InMemoryConfiguration.Clients()) .AddInMemoryApiResources(InMemoryConfiguration.ApiResources()); services.AddMvc(); }
// This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { services.AddCors(); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); services.AddIdentityServer() //.AddDeveloperSigningCredential() .AddSigningCredential(new X509Certificate2(string.Format("{0}{1}", Directory.GetCurrentDirectory(), "\\Certificates\\IdentityServer.pfx"), "12345678")) .AddInMemoryApiResources(InMemoryConfiguration.ApiResources()) .AddInMemoryClients(InMemoryConfiguration.Clients()) .AddTestUsers(InMemoryConfiguration.Users().ToList()); }
public void ConfigureServices(IServiceCollection services) { //C:\Users\ali\source\repos\CoreMicroServices\OAuthServer\socialnetwork.pfx //openssl req -newkey rsa:2048 -nodes -keyout socialnetwok.key -x509 -days 365 -out socialnetwork.cer //you may need try this command befor execute next one => winpty bash //openssl pkcs12 -export -in socialnetwork.cer - inkey socialnetwok.key -out socialnetwork.pfx services.AddIdentityServer() //.AddDeveloperSigningCredential() .AddSigningCredential(new X509Certificate2(@"socialnetwork.pfx", "password")) //password given from pfx file which genrated by cli .AddTestUsers(InMemoryConfiguration.Users()) .AddInMemoryClients(InMemoryConfiguration.Clients()) .AddInMemoryApiResources(InMemoryConfiguration.ApiResources()); }
// This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { services.AddMvc(); string pfxFilePath = _configuration.GetValue <string>("SignInCredentials:PFXFile"); string pfxFilePass = _configuration.GetValue <string>("SignInCredentials:Password"); services.AddIdentityServer() .AddSigningCredential(new X509Certificate2(pfxFilePath, pfxFilePass)) .AddTestUsers(InMemoryConfiguration.TestUsers().ToList()) .AddInMemoryClients(InMemoryConfiguration.Clients()) .AddInMemoryApiResources(InMemoryConfiguration.ApiResources()) .AddInMemoryIdentityResources(InMemoryConfiguration.IdentityResources()); }
// This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { services.AddIdentityServer() .AddSigningCredential(new X509Certificate2( @"D:\AspMVC\Identity-Server4\SocialNetwork.OAuth\SocialNetwork.OAuth\socialnetwork.pfx", "password123")) // to use our own certificate //.AddDeveloperSigningCredential() //AddTemporarySigningCredential .AddTestUsers(InMemoryConfiguration.Users().ToList()) .AddInMemoryClients(InMemoryConfiguration.Clients()) .AddInMemoryIdentityResources(InMemoryConfiguration.IdentityResources()) .AddInMemoryApiResources(InMemoryConfiguration.ApiResources()); services.AddMvc(); }
// This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { //Specify How Identity Server Works services.AddIdentityServer() //Need to Specify 3 Things? //1. Which Api Can use this Authorization Server //2. Which Client Authozired to use ID4 //3. Which Users Authorized to Use ID4 .AddSigningCredential(new X509Certificate2(@"C:\Users\mick_\Downloads\IdentityServer4.Core2.ImplicitFlow.Token-003_Implicit_Flow_Token\IdentityServer4.Core2.ImplicitFlow.Token-003_Implicit_Flow_Token\identityserver.pfx", "Wind123456")) .AddTestUsers(InMemoryConfiguration.Users().ToList()) .AddInMemoryClients(InMemoryConfiguration.Clients()) .AddInMemoryIdentityResources(InMemoryConfiguration.IdentityResources()) .AddInMemoryApiResources(InMemoryConfiguration.ApiResources()); services.AddMvc(); }
// This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { services.AddCors(); //var assembly = typeof(Startup).GetTypeInfo().Assembly.GetName().Name; services.AddIdentityServer() .AddSigningCredential(new X509Certificate2(@"D:\RnD\IAP\Security\IdentityProvider\src\EcoSystem\keys\ecosystem.pfx", "password")) .AddTestUsers(InMemoryConfiguration.Users().ToList()) //.AddConfigurationStore(builder => builder.UseSqlServer(Configuration.GetConnectionString("EcoSystem.OAuth"), options => options.MigrationsAssembly(assembly))) //.AddOperationalStore(builder => builder.UseSqlServer(Configuration.GetConnectionString("EcoSystem.OAuth"), options => options.MigrationsAssembly(assembly))); //.AddTestUsers(IdentityServer4.Quickstart.UI.TestUsers.Users) .AddInMemoryClients(InMemoryConfiguration.Clients()) .AddInMemoryIdentityResources(InMemoryConfiguration.IdentityResources()) .AddInMemoryApiResources(InMemoryConfiguration.ApiResources()); services.AddMvc(); }
private static void EnsureSeedData(ConfigurationDbContext context) { if (!context.Clients.Any()) { Console.WriteLine("Clients being populated"); foreach (var client in InMemoryConfiguration.Clients().ToList()) { context.Clients.Add(client.ToEntity()); } context.SaveChanges(); } else { Console.WriteLine("Clients already populated"); } if (!context.IdentityResources.Any()) { Console.WriteLine("IdentityResources being populated"); foreach (var resource in InMemoryConfiguration.IdentityResources().ToList()) { context.IdentityResources.Add(resource.ToEntity()); } context.SaveChanges(); } else { Console.WriteLine("IdentityResources already populated"); } if (!context.ApiResources.Any()) { Console.WriteLine("ApiResources being populated"); foreach (var resource in InMemoryConfiguration.ApiResources().ToList()) { context.ApiResources.Add(resource.ToEntity()); } context.SaveChanges(); } else { Console.WriteLine("ApiResources already populated"); } }
/// <summary> /// InitializeDatabase /// </summary> /// <param name="app">IApplicationBuilder</param> /// <returns></returns> private async Task InitializeDatabase(IApplicationBuilder app) { using (var serviceScope = app.ApplicationServices.GetService <IServiceScopeFactory>().CreateScope()) { var context = serviceScope.ServiceProvider.GetService <IConfigurationDbContext>(); if (!context.Clients.Any()) { foreach (var client in InMemoryConfiguration.Clients()) { await context.AddClient(client.ToEntity()); } } if (!context.ApiResources.Any()) { foreach (var resource in InMemoryConfiguration.ApiResources()) { await context.AddApiResource(resource.ToEntity()); } } if (!context.IdentityResources.Any()) { foreach (var identity in InMemoryConfiguration.GetIdentityResources()) { await context.AddIdentityResource(identity.ToEntity()); } } // If the user collection is empty,add a test user in database var userRepository = serviceScope.ServiceProvider.GetService <UserRepository>(); var users = userRepository.FindAll(); if (!users.Any()) { var testUser = new User { UserName = "******", Password = "******", Email = "*****@*****.**" }; await userRepository.InsertAsync(testUser); } } }
// This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { services.AddIdentityServer() .AddDeveloperSigningCredential() .AddInMemoryIdentityResources(InMemoryConfiguration.IdentityResources()) .AddInMemoryApiResources(InMemoryConfiguration.ApiResources()) .AddInMemoryClients(InMemoryConfiguration.Clients()) .AddTestUsers(InMemoryConfiguration.Users().ToList()); services.AddCors(options => { options.AddPolicy("CorsPolicy", policy => { policy.AllowAnyOrigin(); policy.AllowAnyMethod(); policy.AllowAnyHeader(); }); }); services.AddMvc(services => services.EnableEndpointRouting = false); }
public void MigrateInMemoryDataToSqlServer(IApplicationBuilder app) { using (var scope = app.ApplicationServices.GetService <IServiceScopeFactory>().CreateScope()) { scope.ServiceProvider.GetRequiredService <PersistedGrantDbContext>().Database.Migrate(); var context = scope.ServiceProvider.GetRequiredService <ConfigurationDbContext>(); context.Database.Migrate(); if (!context.Clients.Any()) { foreach (var client in InMemoryConfiguration.Clients()) { context.Clients.Add(client.ToEntity()); } context.SaveChanges(); } if (!context.IdentityResources.Any()) { foreach (var resource in InMemoryConfiguration.IdentityResources()) { context.IdentityResources.Add(resource.ToEntity()); } context.SaveChanges(); } if (!context.ApiResources.Any()) { foreach (var resource in InMemoryConfiguration.ApiResources()) { context.ApiResources.Add(resource.ToEntity()); } context.SaveChanges(); } } }
public void ConfigureServices(IServiceCollection services) { //my user repository services.AddScoped <IUserRepository, UserRepository>(); services.AddIdentityServer() .AddDeveloperSigningCredential() // .AddSigningCredential(new X509Certificate2(@"/etc/nginx/ssl/socialnetwork.pfx", "2wsx3edc")) //.AddSigningCredential(new X509Certificate2(@"/Users/jiangzhimin/socialnetwork.pfx", "2wsx3edc")) // .AddSigningCredential(new X509Certificate2(LocaPath + "/Pfx/socialnetwork.pfx", "2wsx3edc")) // .AddTestUsers(InMemoryConfiguration.Users().ToList()) .AddInMemoryIdentityResources(InMemoryConfiguration.GetIdentityResources()) .AddInMemoryClients(InMemoryConfiguration.Clients()) .AddInMemoryApiResources(InMemoryConfiguration.ApiResources()) .AddProfileService <ProfileService>(); //Inject the classes we just created services.AddTransient <IResourceOwnerPasswordValidator, ResourceOwnerPasswordValidator>(); services.AddTransient <IProfileService, ProfileService>();//再做一次 像new }
private void InitializeDatabase(IApplicationBuilder app) { using (var serviceScope = app.ApplicationServices.GetService <IServiceScopeFactory>().CreateScope()) { serviceScope.ServiceProvider.GetRequiredService <PersistedGrantCustomDbContext>().Database.Migrate(); var context = serviceScope.ServiceProvider.GetRequiredService <ConfigurationCustomDbContext>(); var appDbContext = serviceScope.ServiceProvider.GetRequiredService <ApplicationDbContext>(); context.Database.Migrate(); appDbContext.Database.Migrate(); if (!context.Clients.Any()) { foreach (var client in InMemoryConfiguration.Clients()) { context.Clients.Add(client.ToEntity()); } context.SaveChanges(); } if (!context.IdentityResources.Any()) { foreach (var resource in InMemoryConfiguration.GetIdentityResources()) { context.IdentityResources.Add(resource.ToEntity()); } context.SaveChanges(); } if (!context.ApiResources.Any()) { foreach (var resource in InMemoryConfiguration.ApiResources()) { context.ApiResources.Add(resource.ToEntity()); } context.SaveChanges(); } } }
public void ConfigureServices(IServiceCollection services) { services.AddIdentityServer() .AddSigningCredential(new X509Certificate2(@"C:\dev\todoResources.pfx", "")) .AddTestUsers(InMemoryConfiguration.Users().ToList()) .AddInMemoryClients(InMemoryConfiguration.Clients()) .AddInMemoryApiResources(InMemoryConfiguration.ApiResources()); services.AddAuthentication("Bearer") .AddIdentityServerAuthentication(options => { options.Authority = "http://localhost:5000"; options.RequireHttpsMetadata = false; options.SaveToken = true; options.ApiName = "todoResources"; options.ApiSecret = "SKB Kontur"; }); services.AddScoped <ToDoService>(); services.AddMvc(); }
/// <summary> /// InitializeIdentityServerDatabase /// </summary> /// <param name="app">IApplicationBuilder</param> /// <returns></returns> private async Task InitializeDatabase(IApplicationBuilder app) { using (var serviceScope = app.ApplicationServices.GetService <IServiceScopeFactory>().CreateScope()) { var context = serviceScope.ServiceProvider.GetService <IConfigurationDbContext>(); if (!context.Clients.Any()) { foreach (var client in InMemoryConfiguration.Clients()) { await context.AddClient(client.ToEntity()); } } if (!context.ApiResources.Any()) { foreach (var resource in InMemoryConfiguration.ApiResources()) { await context.AddApiResource(resource.ToEntity()); } } if (!context.IdentityResources.Any()) { foreach (var identity in InMemoryConfiguration.IdentityResources()) { await context.AddIdentityResource(identity.ToEntity()); } } var repo = serviceScope.ServiceProvider.GetService <IUserRepository>(); if (!repo.FindAll().Any()) { var user = new User { UserName = "******", Password = "******", }; repo.Insert(user); } } }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddDbContext <ApplicationDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); services.AddIdentity <ApplicationUser, IdentityRole>() .AddEntityFrameworkStores <ApplicationDbContext>() .AddDefaultTokenProviders(); // Add application services. services.AddTransient <IEmailSender, EmailSender>(); services.AddMvc(); services.AddIdentityServer() .AddDeveloperSigningCredential() .AddInMemoryPersistedGrants() .AddInMemoryIdentityResources(InMemoryConfiguration.IdentityResources()) .AddInMemoryApiResources(InMemoryConfiguration.ApiResources()) .AddInMemoryClients(InMemoryConfiguration.Clients()) //.AddAspNetIdentity<ApplicationUser>(); .AddTestUsers(Users.All()); }
public void MigrateInMemoryDataToSqlServer(IApplicationBuilder app) { using var scope = app.ApplicationServices.GetService <IServiceScopeFactory>().CreateScope(); scope.ServiceProvider.GetRequiredService <PersistedGrantDbContext>().Database.Migrate(); var context = scope.ServiceProvider.GetRequiredService <ConfigurationDbContext>(); context.Database.Migrate(); if (!context.Clients.Any()) { foreach (var client in InMemoryConfiguration.Clients()) { context.Clients.Add(client.ToEntity()); } context.SaveChanges(); } if (!context.IdentityResources.Any()) { foreach (var resource in InMemoryConfiguration.IdentityResources()) { context.IdentityResources.Add(resource.ToEntity()); } context.SaveChanges(); } if (!context.ApiResources.Any()) { foreach (var resource in InMemoryConfiguration.ApiResources()) { context.ApiResources.Add(resource.ToEntity()); } context.SaveChanges(); } if (!context.ApiScopes.Any()) { foreach (var apiScope in InMemoryConfiguration.ApiScopes()) { context.ApiScopes.Add(apiScope.ToEntity()); } context.SaveChanges(); } var userManager = scope.ServiceProvider.GetRequiredService <UserManager <ApplicationUser> >(); foreach (var user in InMemoryConfiguration.Users()) { var appUser = userManager.FindByNameAsync(user.Username).Result; if (appUser == null) { appUser = new ApplicationUser { UserName = user.Username, Email = user.Claims.Single(c => c.Type == "email").Value, EmailConfirmed = true }; var result = userManager.CreateAsync(appUser, user.Password).Result; result = userManager.AddClaimsAsync(appUser, new Claim[] { new Claim(JwtClaimTypes.Name, "Nils Gruson"), new Claim(JwtClaimTypes.GivenName, "Nils"), new Claim(JwtClaimTypes.FamilyName, "Gruson") }).Result; } ; } }
public void MigrateInMemoryDataToSqlServer(IApplicationBuilder app) { using (var scope = app.ApplicationServices.GetService <IServiceScopeFactory>().CreateScope()) { scope.ServiceProvider.GetRequiredService <PersistedGrantDbContext>().Database.Migrate(); var context = scope.ServiceProvider.GetRequiredService <ConfigurationDbContext>(); context.Database.Migrate(); if (!context.Clients.Any()) { foreach (var client in InMemoryConfiguration.Clients()) { context.Clients.Add(client.ToEntity()); } context.SaveChanges(); } if (!context.IdentityResources.Any()) { foreach (var resource in InMemoryConfiguration.IdentityResources()) { context.IdentityResources.Add(resource.ToEntity()); } context.SaveChanges(); } if (!context.ApiResources.Any()) { foreach (var resource in InMemoryConfiguration.ApiResources()) { context.ApiResources.Add(resource.ToEntity()); } context.SaveChanges(); } if (!context.ApiScopes.Any()) { foreach (var apiScope in InMemoryConfiguration.ApiScopes()) { context.ApiScopes.Add(apiScope.ToEntity()); } context.SaveChanges(); } var applicationContext = scope.ServiceProvider.GetRequiredService <ApplicationDbContext>(); applicationContext.Database.Migrate(); if (!applicationContext.Users.Any()) { foreach (var user in InMemoryConfiguration.Users()) { var passwordHasher = new PasswordHasher <ApplicationUser>(); var appUser = new ApplicationUser { UserName = "******", NormalizedUserName = "******", CustomElement = "custom element" }; appUser.PasswordHash = passwordHasher.HashPassword(appUser, "Test123!"); applicationContext.Users.Add(appUser); } applicationContext.SaveChanges(); } } }