// This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers().AddNewtonsoftJson(options =>
                                                        options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore);
            services.AddControllersWithViews();
            services.AddIdentity <User, IdentityRole>(op =>
            {
                op.Password.RequireDigit                 = false;
                op.Password.RequireLowercase             = false;
                op.Password.RequireNonAlphanumeric       = false;
                op.Password.RequireUppercase             = false;
                op.Password.RequiredLength               = 6;
                op.Password.RequiredUniqueChars          = 0;
                op.Tokens.EmailConfirmationTokenProvider = "emailconfirmation";
            }).AddEntityFrameworkStores <StoreContext>().AddDefaultTokenProviders().AddTokenProvider <EmailConfirmationTokenProvider <User> >("emailconfirmation");

            BusinessConfiguration.ConfigureServices(services, Configuration);
            services.Configure <SendGridSenderOptions>(op => Configuration.GetSection("SendGridSenderOptions").Bind(op));
            services.AddTransient <IEmailSender, EmailSenderService>();
            services.Configure <EmailConfiramtionProviderOption>(op => op.TokenLifespan = TimeSpan.FromDays(5));

            services.AddAutoMapper(typeof(MappingProfile));

            services.AddMvc().SetCompatibilityVersion(Microsoft.AspNetCore.Mvc.CompatibilityVersion.Version_3_0);

            services.AddAuthentication().AddCookie(op => op.LoginPath = "/login");
        }
Exemple #2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer(
                options =>
            {
                options.RequireHttpsMetadata      = false;
                options.TokenValidationParameters = new TokenValidationParameters
                {
                    ValidateIssuer           = true,
                    ValidIssuer              = AccessTokenParameters.ISSUER,
                    ValidateAudience         = true,
                    ValidAudience            = AccessTokenParameters.AUDIENCE,
                    ValidateLifetime         = true,
                    IssuerSigningKey         = AccessTokenParameters.GetSymmetricSecurityKey(),
                    ValidateIssuerSigningKey = true
                };
            });

            services.
            AddControllers().
            AddNewtonsoftJson(options =>
            {
                options.SerializerSettings.Converters.Add(
                    new Newtonsoft.Json.Converters.StringEnumConverter());
            });

            BusinessConfiguration.ConfigureServices(services, Configuration);
            // In production, the React files will be served from this directory
            services.AddSpaStaticFiles(configuration =>
            {
                configuration.RootPath = "ClientApp/build";
            });
        }
Exemple #3
0
        public void ConfigureServices(IServiceCollection services)
        {
            BusinessConfiguration.ConfigureServices(services, Configuration);
            BusinessConfiguration.ConfigureIdentityInicializerAsync(services.BuildServiceProvider());

            JwtConfiguration.Configure(services, Configuration);

            services.AddControllers(mvcOtions =>
            {
                mvcOtions.EnableEndpointRouting = false;
            });

            services.AddScoped(typeof(UserService));

            services.AddScoped <ExceptionFilter>();

            services.AddSwaggerGen(c => {
                c.SwaggerDoc("v1", new OpenApiInfo {
                    Title = "TimeOffTrackerApi", Version = "v1"
                });
                c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
                {
                    Name         = "Authorization",
                    Type         = SecuritySchemeType.Http,
                    Scheme       = "Bearer",
                    BearerFormat = "JWT",
                    In           = ParameterLocation.Header,
                    Description  = "JWT Authorization header using the Bearer scheme."
                });
                c.AddSecurityRequirement(new OpenApiSecurityRequirement
                {
                    {
                        new OpenApiSecurityScheme
                        {
                            Reference = new OpenApiReference
                            {
                                Type = ReferenceType.SecurityScheme,
                                Id   = "Bearer"
                            }
                        },
                        new string[] {}
                    }
                });
            });
        }