コード例 #1
0
        public static async Task Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();

            using (var serviceScope = host.Services.CreateScope())
            {
                var dbContext = serviceScope.ServiceProvider.GetRequiredService <BBITContext>();
                await dbContext.Database.MigrateAsync();

                var roleManager = serviceScope.ServiceProvider.GetRequiredService <RoleManager <IdentityRole> >();
                var userManager = serviceScope.ServiceProvider.GetRequiredService <UserManager <AppUser> >();

                var identityInitializer = new IdentityInitializer(dbContext, userManager, roleManager);
                await identityInitializer.Initialize();

                var env = serviceScope.ServiceProvider.GetRequiredService <IWebHostEnvironment>();
                if (env.IsDevelopment())
                {
                    var testDbDataInitialization = new TestDbDataInitialization(dbContext);
                    await testDbDataInitialization.Initialize();
                }
            }

            await host.RunAsync();
        }
コード例 #2
0
        public async void Configure(
            IApplicationBuilder app,
            IWebHostEnvironment env,
            MyIdentityContext context,
            UserManager <MyIdentityUser> userManager,
            RoleManager <IdentityRole> roleManager)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            // Start the database with some users and clams.
            var initializer = new IdentityInitializer(context, userManager, roleManager);
            await initializer.Initialize();

            app.UseSwaggerConfiguration();

            app.UseHttpsRedirection();

            app.UseRouting();

            // Custom NetDevPack abstraction here!
            app.UseAuthConfiguration();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
コード例 #3
0
        public AccountController(UserManager <IdentityUser> userMgr, SignInManager <IdentityUser> signInMgr)
        {
            (userManager, signInManager) = (userMgr, signInMgr);

            // БД Identity будет заполняться каждый раз, когда создается
            // объект AccountController для обработки НТТР-запроса
            IdentityInitializer.Initialize(userMgr).Wait();
        }
        public void InitializerFailedTests()
        {
            var initializer = new IdentityInitializer(_validateDatabase, _userManager, _droneRoleValidator);

            _droneRoleValidator.CreateRoleAsync(Arg.Any <string>()).Returns(false);
            _droneRoleValidator.ExistRoleAsync(Arg.Any <string>()).Returns(false);
            _validateDatabase.EnsureCreated().Returns(true);
            Assert.Throws <Exception>(() => initializer.Initialize());
        }
        public void InitializerTests()
        {
            var initializer = new IdentityInitializer(_validateDatabase, _userManager, _droneRoleValidator);

            _droneRoleValidator.CreateRoleAsync(Arg.Any <string>()).Returns(true);
            _droneRoleValidator.ExistRoleAsync(Arg.Any <string>()).Returns(true);
            _validateDatabase.EnsureCreated().Returns(true);
            initializer.Initialize();
            _userManager.Received().FindByNameAsync(Arg.Any <string>());
        }
コード例 #6
0
 // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
 public void Configure(IApplicationBuilder app,
                       IHostingEnvironment env,
                       ApplicationDbContext context,
                       UserManager <ApplicationUser> userManager,
                       RoleManager <IdentityRole> roleManager)
 {
     if (env.IsDevelopment())
     {
         app.UseDeveloperExceptionPage();
     }
     else
     {
         // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
         app.UseHsts();
     }
     IdentityInitializer.Initialize(context, userManager, roleManager);
     app.UseAuthentication();
     app.UseHttpsRedirection();
     app.UseMvc();
 }
コード例 #7
0
ファイル: Startup.cs プロジェクト: MateuszTureek/AuctionApp
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env,
                              IdentityInitializer identityInitializer, AuctionInitializer auctionInitializer)
        {
            if (env.IsDevelopment())
            {
                app.UseBrowserLink();
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseStaticFiles();

            app.UseSession();

            app.UseAuthentication();

            app.UseSignalR(routes =>
            {
                routes.MapHub <NotifyHub>("/notify");
            });

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "areas",
                    template: "{area:exists}/{controller=Home}/{action=Index}/{id?}"
                    );
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
            identityInitializer.Initialize();
            auctionInitializer.Initialize();
        }
コード例 #8
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            var isDevelopment = env.IsDevelopment();

            ConfigureExceptions(app, isDevelopment);

            if (!isDevelopment)
            {
                app.UseHsts();
            }

            app.UseHttpsRedirection();

            app.UseSwagger();
            app.UseSwaggerUI(options =>
            {
                options.SwaggerEndpoint("/swagger/v1/swagger.json", "ApsNetCoreProject v1");
                options.RoutePrefix = string.Empty;
            });

            app.UseCors(builder => builder
                        .AllowAnyOrigin()
                        .AllowAnyHeader()
                        .AllowAnyMethod()
                        );

            app.UseAuthentication();

            app.UseRoleProvider();

            app.UseMvc();

            IdentityInitializer.Initialize(
                app.ApplicationServices.GetRequiredService <IServiceScopeFactory>().CreateScope().ServiceProvider,
                _configuration.GetSection("Identity:User").Get <CreateUserModel>()
                ).GetAwaiter().GetResult();
        }
コード例 #9
0
        void InitializeUser(string userName, string providerKey)
        {
            var userCreator = new IdentityInitializer();

            userCreator.Initialize(userName, providerKey);
        }