public async static Task InitizeIdentityserverDatabase(PersistedGrantDbContext persistedGrantDbContext, ConfigurationDbContext configurationDbContext) { if (!configurationDbContext.Clients.Any()) { foreach (var clients in Config.GetClients()) { await configurationDbContext.Clients.AddAsync(clients.ToEntity()); } configurationDbContext.SaveChangesAsync().GetAwaiter().GetResult(); } if (!configurationDbContext.ApiResources.Any()) { foreach (var apiResource in Config.GetAllApiResources()) { await configurationDbContext.ApiResources.AddAsync(apiResource.ToEntity()); } configurationDbContext.SaveChangesAsync().GetAwaiter().GetResult(); } if (!configurationDbContext.IdentityResources.Any()) { foreach (var identityResource in Config.GetAllApiIdentityResources()) { await configurationDbContext.IdentityResources.AddAsync(identityResource.ToEntity()); } configurationDbContext.SaveChangesAsync().GetAwaiter().GetResult(); } }
public Migrator(ApplicationDbContext applicationDbContext, PersistedGrantDbContext persistedGrantDbContext, ConfigurationDbContext configurationDbContext) { _applicationDbContext = applicationDbContext; _persistedGrantDbContext = persistedGrantDbContext; _configurationDbContext = configurationDbContext; }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ConfigurationDbContext configurationDbContext, PersistedGrantDbContext persistedGrantDbContext, LvMiniDbContext lvMiniDbContext) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); } else { app.UseExceptionHandler("/Home/Error"); } configurationDbContext.Database.Migrate(); configurationDbContext.SeedDataForContext(); persistedGrantDbContext.Database.Migrate(); lvMiniDbContext.SeedUsersForContext(); FileExtensionContentTypeProvider typeProvider = new FileExtensionContentTypeProvider(); if (!typeProvider.Mappings.ContainsKey(".woff2")) { typeProvider.Mappings.Add(".woff2", "application/font-woff2"); } app.UseIdentityServer(); app.UseStaticFiles(); app.UseMvcWithDefaultRoute(); }
public ConfigurationDataInitializer(ConfigurationDbContext configContext, PersistedGrantDbContext prstContext, ConfigCommon config, ApplicationDbContext dbContext) { this.cfgDbContext = configContext; this.prstDbContext = prstContext; this.dbContext = dbContext; this.config = config; }
public IActionResult Get() { var options = new DbContextOptions <PersistedGrantDbContext>(); var store = new OperationalStoreOptions(); using (var ctx = new PersistedGrantDbContext(options, store)) { ctx.Add <Client>(new Client { ClientId = "c1", ClientSecrets = new List <ClientSecret> { new ClientSecret() { Type = "SharedSecret", Value = "secret" } }, AllowedGrantTypes = new List <ClientGrantType> { new ClientGrantType { GrantType = "client_id" } }, AllowedScopes = new List <ClientScope> { new ClientScope { Scope = "api1" } } }); ctx.SaveChanges(); } return(Ok()); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory logger, UserContext userContext, ConfigurationDbContext configurationDbContext, PersistedGrantDbContext persistedGrantDbContext) { //var configuration = app.ApplicationServices.GetService<TelemetryConfiguration>(); //configuration.DisableTelemetry = true; logger.AddConsole(); logger.AddDebug(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } AutoMapper.Mapper.Initialize(cfg => { cfg.CreateMap <RegisterUserViewModel, User>() .ForMember(d => d.Username, opt => opt.MapFrom(s => s.UserName)); }); persistedGrantDbContext.Database.Migrate(); configurationDbContext.Database.Migrate(); configurationDbContext.EnsureSeedDataForContext(); userContext.Database.Migrate(); userContext.EnsureSeedDataForContext(); app.UseIdentityServer(); app.UseStaticFiles(); app.UseMvcWithDefaultRoute(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, MarvinUserContext marvinUserContext, ConfigurationDbContext configurationDbContext, PersistedGrantDbContext persistedGrantDbContext) { loggerFactory.AddConsole(); if (env.IsDevelopment()) { loggerFactory.AddDebug(); app.UseDeveloperExceptionPage(); } else { persistedGrantDbContext.Database.Migrate(); configurationDbContext.Database.Migrate(); configurationDbContext.EnsureSeedDataForContext(); marvinUserContext.Database.Migrate(); marvinUserContext.EnsureSeedDataForContext(); } app.UseIdentityServer(); app.UseAuthentication(); app.UseStaticFiles(); app.UseMvcWithDefaultRoute(); }
public void Configure ( IApplicationBuilder application, ApplicationIdentityDbContext identityContext, ConfigurationDbContext configurationContext, PersistedGrantDbContext persistedGrantContext, UserManager <ApplicationIdentityUser> userManager ) { application.UseCors(cors => cors.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod()); application.UseHsts(); application.UseHttpsRedirection(); application.UseStaticFiles(); application.UseRouting(); application.UseAuthentication(); application.UseAuthorization(); application.UseEndpoints(builder => builder.MapDefaultControllerRoute()); application.UseIdentityServer(); identityContext.Database.Migrate(); configurationContext.Database.Migrate(); persistedGrantContext.Database.Migrate(); configurationContext.Seed(); userManager.Seed(); }
public void InitIdentityServer4Database(IApplicationBuilder app) { using (var scope = app.ApplicationServices.CreateScope()) { ConfigurationDbContext configurationDbContext = scope.ServiceProvider.GetRequiredService <ConfigurationDbContext>(); PersistedGrantDbContext persistedGrantDbContext = scope.ServiceProvider.GetRequiredService <PersistedGrantDbContext>(); if (!configurationDbContext.Clients.Any()) { foreach (var client in Config.GetClient()) { configurationDbContext.Clients.Add(client.ToEntity()); } configurationDbContext.SaveChanges(); } if (!configurationDbContext.ApiResources.Any()) { foreach (var client in Config.GetResource()) { configurationDbContext.ApiResources.Add(client.ToEntity()); } configurationDbContext.SaveChanges(); } if (!configurationDbContext.IdentityResources.Any()) { foreach (var client in Config.GetIdentityResource()) { configurationDbContext.IdentityResources.Add(client.ToEntity()); } configurationDbContext.SaveChanges(); } } }
/// <summary> /// Initialises the persisted grant database. /// </summary> /// <param name="persistedGrantDbContext">The persisted grant database context.</param> /// <param name="seedingType">Type of the seeding.</param> public static void InitialisePersistedGrantDatabase(PersistedGrantDbContext persistedGrantDbContext, SeedingType seedingType) { Boolean isDbInitialised = false; Int32 retryCounter = 0; while (retryCounter < 20 && !isDbInitialised) { try { if (persistedGrantDbContext.Database.IsSqlServer()) { persistedGrantDbContext.Database.Migrate(); } persistedGrantDbContext.SaveChanges(); isDbInitialised = true; break; } catch (Exception ex) { retryCounter++; Thread.Sleep(10000); } } if (!isDbInitialised) { String connString = persistedGrantDbContext.Database.GetDbConnection().ConnectionString; Exception newException = new Exception($"Error initialising Db with Connection String [{connString}]"); throw newException; } }
public void Configure ( IApplicationBuilder application, ApplicationDbContext applicationDbContext, ConfigurationDbContext configurationDbContext, PersistedGrantDbContext persistedGrantDbContext, UserManager <IdentityUser> userManager ) { applicationDbContext.Database.Migrate(); configurationDbContext.Database.Migrate(); persistedGrantDbContext.Database.Migrate(); configurationDbContext.Seed(); userManager.Seed(); application.UseException(); application.UseCookiePolicy(); application.UseCorsAllowAny(); application.UseHsts(); application.UseHttpsRedirection(); application.UseStaticFiles(); application.UseRouting(); application.UseIdentityServer(); application.UseAuthentication(); application.UseAuthorization(); application.UseEndpoints(); }
public DbInitializer(PersistedGrantDbContext persistedGrantDbContext, ConfigurationDbContext configurationDbContext, ApplicationDbContext applicationDbContext, UserManager <ApplicationUser> userManager) { this._persistedGrantDbContext = persistedGrantDbContext; this._configurationDbContext = configurationDbContext; this._applicationDbContext = applicationDbContext; this._userManager = userManager; }
public static async Task EnsureSeedDataAsync(PersistedGrantDbContext grantContext, ConfigurationDbContext configContext) { grantContext.Database.Migrate(); configContext.Database.Migrate(); if (!configContext.Clients.Any()) { foreach (var client in Config.GetClients().ToList()) { configContext.Clients.Add(client.ToEntity()); } } if (!configContext.IdentityResources.Any()) { foreach (var resource in Config.GetIdentityResources().ToList()) { configContext.IdentityResources.Add(resource.ToEntity()); } } if (!configContext.ApiResources.Any()) { foreach (var resource in Config.GetApis().ToList()) { configContext.ApiResources.Add(resource.ToEntity()); } } await configContext.SaveChangesAsync(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, MarvinUserContext marvinUserContext, ConfigurationDbContext configurationDbContext, PersistedGrantDbContext persistedGrantDbContext) { loggerFactory.AddConsole(); loggerFactory.AddDebug(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } configurationDbContext.Database.Migrate(); configurationDbContext.EnsureSeedDataForContext(); marvinUserContext.Database.Migrate(); marvinUserContext.EnsureSeedDataForContext(); persistedGrantDbContext.Database.Migrate(); app.UseStaticFiles(); app.UseIdentityServer(); app.UseMvcWithDefaultRoute(); //app.Run(async (context) => //{ // await context.Response.WriteAsync("Hello World!"); //}); }
public Config(ConfigurationDbContext configurationDbContext, PersistedGrantDbContext persistedGrantDbContext, IConfiguration configuration, ILogger <Config> logger) { this.configurationDbContext = configurationDbContext; this.persistedGrantDbContext = persistedGrantDbContext; this.configuration = configuration; this.logger = logger; }
public void Configure( IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, UserContext userContext, ConfigurationDbContext configurationDbContext, PersistedGrantDbContext persistedGrantDbContext) { loggerFactory.AddConsole(); loggerFactory.AddDebug(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } // Garantindo que o contexto dos usuarios executara o Migrations // e o Seed será executado userContext.Database.Migrate(); userContext.EnsureSeedDataForContext(); // Garantindo que o contexto de configurações executara o Migrations // e o Seed será executado configurationDbContext.Database.Migrate(); configurationDbContext.EnsureSeedDataForContext(); // Garantindo que o contexto de configurações executara o Migrations persistedGrantDbContext.Database.Migrate(); app.UseStaticFiles(); app.UseIdentityServer(); app.UseAuthentication(); app.UseMvcWithDefaultRoute(); }
public InstallController(PersistedGrantDbContext persistedGrantDbContext, ConfigurationDbContext configurationDbContext, IConfiguration configuration, IWebHostEnvironment environment) { _persistedGrantDbContext = persistedGrantDbContext; _configurationDbContext = configurationDbContext; _configuration = configuration; Environment = environment; }
public InitializeDatabaseService(IServiceScopeFactory serviceScopeFactory) { var sp = serviceScopeFactory.CreateScope().ServiceProvider; _configurationDbContext = sp.GetRequiredService <ConfigurationDbContext>(); _persistedGrantDbContext = sp.GetRequiredService <PersistedGrantDbContext>(); _identityContext = sp.GetRequiredService <IdentityContext>(); }
public PersistedGrantRepositoryTest() { var options = new DbContextOptionsBuilder <PersistedGrantDbContext>() .UseInMemoryDatabase("RivaIdentityIdentityServerIntegrationTestsDb").Options; _context = new PersistedGrantDbContext(options, new OperationalStoreOptions()); _persistedGrantRepository = new PersistedGrantRepository(_context); }
public DatabaseInitializer(ILogger <DatabaseInitializer> logger, PersistedGrantDbContext persistedGrantContext, ConfigurationDbContext configurationContext, ApplicationDbContext applicationContext, IAccountManager accountManager) { _logger = logger; _persistedGrantContext = persistedGrantContext; _configurationContext = configurationContext; _applicationContext = applicationContext; _accountManager = accountManager; }
public AccountDataConsistencyService(RivaIdentityDbContext rivaIdentityDbContext, PersistedGrantDbContext persistedGrantDbContext, IAccountRepository accountRepository, IPersistedGrantRepository persistedGrantRepository) { _rivaIdentityDbContext = rivaIdentityDbContext; _persistedGrantDbContext = persistedGrantDbContext; _accountRepository = accountRepository; _persistedGrantRepository = persistedGrantRepository; }
public SeedDbData( PersistedGrantDbContext persistedGrantDbContext, ConfigurationDbContext configurationDbContext, UserManager <IdentityUser> userManager) { _persistedGrantDbContext = persistedGrantDbContext; _configurationDbContext = configurationDbContext; _userManager = userManager; }
public DatabaseInitializer(ILogger <DatabaseInitializer> logger, PersistedGrantDbContext persistedGrantContext, ConfigurationDbContext configurationContext, EventDbContext eventsContext, IdentityDbContext accountsContext, IIdentityManager accountManager) { _logger = logger; _persistedGrantContext = persistedGrantContext; _configurationContext = configurationContext; _eventContext = eventsContext; _identityContext = accountsContext; _identityManager = accountManager; }
public MigrateDatabaseInitialization( IdentityDbContext dbContext, PersistedGrantDbContext persistedGrantDbContext, ConfigurationDbContext configurationDbContext) { _dbContext = dbContext; _persistedGrantDbContext = persistedGrantDbContext; _configurationDbContext = configurationDbContext; }
static void Main(string[] args) { var sqlServerConnectionString = "Server=tcp:ntl-kft.database.windows.net,1433;Initial Catalog=Ntl-AuthSSDb;Persist Security Info=False;User ID=ntl-admin;Password=Welcome1@;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"; var persitantGrantOptionsBuilder = new DbContextOptionsBuilder <PersistedGrantDbContext>(); persitantGrantOptionsBuilder.UseSqlServer(sqlServerConnectionString, sql => { sql.MigrationsHistoryTable("_PersistedGrantMigrations"); }); var operationalStoreOptions = new OperationalStoreOptions() { EnableTokenCleanup = true, TokenCleanupInterval = 30 }; using (var persitantGrantDbContext = new PersistedGrantDbContext(persitantGrantOptionsBuilder.Options, operationalStoreOptions)) { //persitantGrantDbContext.Database.Migrate();//No use of this currently as migrations are in different assembly } var configurationOptionsBuilder = new DbContextOptionsBuilder <ConfigurationDbContext>(); configurationOptionsBuilder.UseSqlServer(sqlServerConnectionString, sql => { sql.MigrationsHistoryTable("_ConfigurationMigrations"); }); using (var configurationDbContext = new ConfigurationDbContext(configurationOptionsBuilder.Options, new ConfigurationStoreOptions())) { //configurationDbContext.Database.Migrate(); //No use of this currently as migrations are in different assembly if (!configurationDbContext.Clients.Any()) { foreach (var client in Config.GetClients()) { configurationDbContext.Clients.Add(client.ToEntity()); } configurationDbContext.SaveChanges(); } if (!configurationDbContext.ApiResources.Any()) { foreach (var resource in Config.GetApiResources()) { configurationDbContext.ApiResources.Add(resource.ToEntity()); } configurationDbContext.SaveChanges(); } if (!configurationDbContext.IdentityResources.Any()) { foreach (var resource in Config.GetIdentityResources()) { configurationDbContext.IdentityResources.Add(resource.ToEntity()); } configurationDbContext.SaveChanges(); } } }
public SeedController(ILogger <SeedController> logger, IConfiguration configuration, UserManager <User> userManager, RoleManager <Role> roleManager, ConfigurationDbContext configurationDbContext, ApplicationDbContext applicationDbContext, PersistedGrantDbContext persistedGrantDbContext) { _logger = logger; _configuration = configuration; _userManager = userManager; _roleManager = roleManager; _configurationDbContext = configurationDbContext; _applicationDbContext = applicationDbContext; _persistedGrantDbContext = persistedGrantDbContext; }
public void Can_initialize_PersistedGrantDbContext() { using var testDatabase = SqlServerTestStore.CreateInitialized("IdentityServerPersistedGrantDbContext"); var options = CreateOptions(testDatabase); using (var context = new PersistedGrantDbContext(options, new OperationalStoreOptions())) { context.Database.EnsureCreatedResiliently(); } }
public DbInitializer(ConfigurationDbContext configurationDbContext, PersistedGrantDbContext persistedGrantDbContext, AuthDbContext userDbContext, Config config, UserManager <Account> userManager, RoleManager <IdentityRole> roleManager) { _config = config; _configurationDbContext = configurationDbContext; _persistedGrantDbContext = persistedGrantDbContext; _userDbContext = userDbContext; _userManager = userManager; _roleManager = roleManager; }
public DatabaseInitializer(ApplicationDbContext context, IAccountManager accountManager, ILogger <DatabaseInitializer> logger, PersistedGrantDbContext persistedGrantDbContext, ConfigurationDbContext configurationDbContext, ITimedTaskManager timedTaskManager) { timedTaskManager.Start(); _accountManager = accountManager; _context = context; _logger = logger; _persistedGrantDbContext = persistedGrantDbContext; _configurationDbContext = configurationDbContext; }
public IdentityController(ApplicationDbContext context, ConfigurationDbContext contextConfig,PersistedGrantDbContext contextPers, UserManager<ApplicationUser> userManager, SignInManager<ApplicationUser> signInManager) { _context = context; _contextConfig = contextConfig; _contextPers = contextPers; _userManager = userManager; _signInManager = signInManager; }