2929using WebApi . Repositories ;
3030using WebApi . Helpers ;
3131using Hubs . BroadcastHub ;
32+ using Microsoft . AspNetCore . Antiforgery ;
3233
3334namespace WebApi
3435{
@@ -106,28 +107,29 @@ public void ConfigureServices(IServiceCollection services)
106107 } ) ;
107108
108109 // Add Identity
109- var builder = services . AddIdentityCore < User > ( o =>
110+ services . AddIdentityCore < User > ( o =>
110111 {
111- // configure identity options
112+ // Configure identity options
112113 o . Password . RequireDigit = false ;
113114 o . Password . RequireLowercase = false ;
114115 o . Password . RequireUppercase = false ;
115116 o . Password . RequireNonAlphanumeric = false ;
116117 o . Password . RequiredLength = 6 ;
117- } ) . AddRoles < IdentityRole > ( ) ;
118- builder = new IdentityBuilder ( builder . UserType , typeof ( IdentityRole ) , builder . Services ) ;
119- builder . AddEntityFrameworkStores < ApplicationDbContext > ( ) . AddDefaultTokenProviders ( ) ;
118+ } )
119+ . AddRoles < IdentityRole > ( )
120+ . AddEntityFrameworkStores < ApplicationDbContext > ( )
121+ . AddDefaultTokenProviders ( ) ;
120122
121123 services . AddAutoMapper ( ) ;
122- services . AddMvc ( options =>
123- {
124- // Add automatic model validation
125- options . Filters . Add ( typeof ( ValidateModelStateAttribute ) ) ;
126- // options.Filters.Add(new AutoValidateAntiforgeryTokenAttribute());
127- } )
128- . SetCompatibilityVersion ( CompatibilityVersion . Version_2_1 ) ;
124+ services . AddMvc ( ) . SetCompatibilityVersion ( CompatibilityVersion . Version_2_1 ) ;
129125
130- // services.AddAntiforgery(options => options.HeaderName = "X-XSRF-TOKEN");
126+ // X-CSRF-Token
127+ services . AddAntiforgery ( options=>
128+ {
129+ options . HeaderName = "X-XSRF-Token" ;
130+ options . SuppressXFrameOptionsHeader = false ;
131+ } ) ;
132+
131133 services . AddCors ( ) ;
132134 services . AddSignalR ( ) ;
133135
@@ -192,6 +194,7 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, IService
192194 } ) ;
193195 } ) ;
194196
197+ // Enable CORS
195198 app . UseCors ( builder =>
196199 builder . AllowAnyOrigin ( )
197200 . AllowAnyHeader ( )
@@ -201,25 +204,32 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, IService
201204
202205 app . UseAuthentication ( ) ;
203206 app . UseMvc ( ) ;
207+
204208 app . Use ( async ( context , next ) =>
205209 {
206- await next ( ) ;
210+ await next ( ) ;
211+
207212 if ( context . Response . StatusCode == 404 && ! Path . HasExtension ( context . Request . Path . Value ) )
208213 {
209214 context . Request . Path = "/index.html" ;
210215 await next ( ) ;
211216 }
212217 } ) ;
213218
219+ // Single Page Application set up
214220 app . UseDefaultFiles ( ) ;
215221 app . UseStaticFiles ( ) ;
216222
223+ // Set up SignalR Hubs
217224 app . UseSignalR ( routes =>
218225 {
219226 routes . MapHub < BroadcastHub > ( "/broadcast" ) ;
220227 } ) ;
221228
229+ // Identity user seed
222230 CreateUsersAndRoles ( services ) . Wait ( ) ;
231+
232+ // Default Attendance Configuration
223233 AttendanceConfiguration ( services ) . Wait ( ) ;
224234 }
225235
0 commit comments