internal static void InitializeServices(ServiceRegistry services, IConfiguration config) { services .AddMvc() .SetCompatibilityVersion(CompatibilityVersion.Version_2_2) .AddJsonOptions( options => options.SerializerSettings.Converters.Add(new IsoDateTimeConverter { DateTimeStyles = DateTimeStyles.AdjustToUniversal })); services .AddIdentityCore <AppUser>() .AddUserStore <AppUserStore>(); services.AddAutoMapper(typeof(ServiceInitializationService).Assembly); services.Configure <AppSettings>(config.GetSection(AppSettings.SectionKey)); InitializeCors(services); InitializeSecurity(services, config); InitializeLocalisation(services); services.Scan( scanner => { scanner.AssembliesFromApplicationBaseDirectory(); scanner.LookForRegistries(); }); }
private static void ConfigureIdentity(ServiceRegistry registry) { //registry.For<ILogger<SignInManager<ApplicationUser>>>().Use<NullLogger<SignInManager<ApplicationUser>>>(); registry.For <ILogger <UserManager <ApplicationUser> > >().Use <NullLogger <UserManager <ApplicationUser> > >(); registry.For <ILogger <RoleManager <ApplicationRole> > >().Use <NullLogger <RoleManager <ApplicationRole> > >(); registry.AddIdentityCore <ApplicationUser>( options => { // Password settings options.Password.RequireDigit = true; options.Password.RequiredLength = 8; options.Password.RequireNonAlphanumeric = false; options.Password.RequireUppercase = true; options.Password.RequireLowercase = false; // Lockout settings options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(30); options.Lockout.MaxFailedAccessAttempts = 10; // User settings options.User.RequireUniqueEmail = true; }) .AddRoles <ApplicationRole>() .AddRoleManager <RoleManager <ApplicationRole> >() .AddEntityFrameworkStores <ApplicationDbContext>(); registry.Configure <IdentityOptions>(options => { // Password settings options.Password.RequireDigit = false; options.Password.RequiredLength = 1; options.Password.RequireNonAlphanumeric = false; options.Password.RequireUppercase = false; options.Password.RequireLowercase = false; // Lockout settings options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(30); options.Lockout.MaxFailedAccessAttempts = 10; // User settings options.User.RequireUniqueEmail = false; options.User.AllowedUserNameCharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._@+'#!/^%{}* "; }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureContainer(ServiceRegistry services) { services.Configure <CookiePolicyOptions>(options => { // This lambda determines whether user consent for non-essential cookies is needed for a given request. options.CheckConsentNeeded = context => true; options.MinimumSameSitePolicy = SameSiteMode.None; }); services.AddDbContext <FutureAgroIdentityDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")), ServiceLifetime.Transient); services.AddIdentityCore <IdentityUser>(options => { options.Password.RequireNonAlphanumeric = false; options.Password.RequireUppercase = false; options.Password.RequireLowercase = false; options.Password.RequireDigit = false; }) .AddDefaultTokenProviders() .AddSignInManager() .AddEntityFrameworkStores <FutureAgroIdentityDbContext>(); services.AddAuthentication(options => { options.DefaultAuthenticateScheme = IdentityConstants.ApplicationScheme; options.DefaultChallengeScheme = IdentityConstants.ApplicationScheme; options.DefaultSignInScheme = IdentityConstants.ExternalScheme; }) .AddCookie(cookieOptions => { cookieOptions.AccessDeniedPath = "/Account/Login"; cookieOptions.LoginPath = "/Account/Login"; cookieOptions.LogoutPath = "/Account/Login"; }) .AddGoogle(options => { // Provide the Google Client ID options.ClientId = "84213285064-3bu6c7f6iuov5e2nj71j8kp09ldsgg8p.apps.googleusercontent.com"; // Register with User Secrets using: // dotnet user-secrets set "Authentication:Google:ClientId" "{Client ID}" // Provide the Google Client Secret options.ClientSecret = "USukES39oKelSIhWjI5Nj2W6"; // Register with User Secrets using: // dotnet user-secrets set "Authentication:Google:ClientSecret" "{Client Secret}" options.ClaimActions.MapJsonKey("urn:google:picture", "picture", "url"); options.ClaimActions.MapJsonKey("urn:google:locale", "locale", "string"); options.SaveTokens = true; options.Events.OnCreatingTicket = ctx => { List <AuthenticationToken> tokens = ctx.Properties.GetTokens().ToList(); tokens.Add(new AuthenticationToken() { Name = "TicketCreated", Value = DateTime.UtcNow.ToString() }); ctx.Properties.StoreTokens(tokens); return(Task.CompletedTask); }; }) .AddIdentityCookies(); services.AddMvc() .SetCompatibilityVersion(CompatibilityVersion.Version_2_1); services.ConfigureApplicationCookie(options => { // Cookie settings options.Cookie.HttpOnly = true; options.ExpireTimeSpan = TimeSpan.FromMinutes(5); options.LoginPath = "/Account/Login"; options.AccessDeniedPath = "/Account/Login"; options.LogoutPath = "/Account/Login"; options.SlidingExpiration = true; }); services.AddSignalR(options => { //options.EnableDetailedErrors = true; }); // Also exposes Lamar specific registrations // and functionality services.Scan(s => { s.AssembliesAndExecutablesFromApplicationBaseDirectory(); s.WithDefaultConventions(); }); services.AddSingleton <ILector, LectorTemperatura>(); services.AddTransient <TemperaturaRepository>(); services.AddSingleton <ILector, LectorHumedad>(); services.AddTransient <HumedadRepository>(); services.AddSingleton <ILector, LectorLuminosidad>(); services.AddTransient <LuminosidadRepository>(); services.AddSingleton <ILector, LectorCrecimiento>(); services.AddSingleton <ILector, LectorPlantasMuertas>(); services.AddTransient <PlantasRepository>(); services.AddSingleton <ServicioCrecimiento>(); services.AddSingleton <ServicioTemperatura>(); services.AddSingleton <ServicioHumedad>(); services.AddSingleton <ServicioLuminosidad>(); }