@@ -48,6 +48,9 @@ public void ConfigureServices(IServiceCollection services)
4848 //// Optional option to suppress the browser login dialog for ajax calls.
4949 //options.SuppressWWWAuthenticateHeader = true;
5050
51+ //// Optional option to ignore authentication if AllowAnonumous metadata/filter attribute is added to an endpoint.
52+ //options.IgnoreAuthenticationIfAllowAnonymous = true;
53+
5154 //// Optional events to override the basic original logic with custom logic.
5255 //// Only use this if you know what you are doing at your own risk. Any of the events can be assigned.
5356 options . Events = new BasicEvents
@@ -149,13 +152,19 @@ public void ConfigureServices(IServiceCollection services)
149152
150153 services . AddControllers ( options =>
151154 {
152- // ALWAYS USE HTTPS (SSL) protocol in production when using Basic authentication.
155+ // ALWAYS USE HTTPS (SSL) protocol in production when using ApiKey authentication.
153156 //options.Filters.Add<RequireHttpsAttribute>();
154157
155- // All the requests will need to be authorized.
156- // Alternatively, add [Authorize] attribute to Controller or Action Method where necessary.
157- options . Filters . Add ( new AuthorizeFilter ( new AuthorizationPolicyBuilder ( ) . RequireAuthenticatedUser ( ) . Build ( ) ) ) ;
158158 } ) ; //.AddXmlSerializerFormatters() // To enable XML along with JSON;
159+
160+ // All the requests will need to be authorized.
161+ // Alternatively, add [Authorize] attribute to Controller or Action Method where necessary.
162+ services . AddAuthorization ( options =>
163+ {
164+ options . FallbackPolicy = new AuthorizationPolicyBuilder ( )
165+ . RequireAuthenticatedUser ( )
166+ . Build ( ) ;
167+ } ) ;
159168 }
160169
161170 // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
@@ -170,7 +179,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
170179
171180 app . UseHttpsRedirection ( ) ;
172181 app . UseRouting ( ) ;
173-
182+
174183 app . UseAuthentication ( ) ; // NOTE: DEFAULT TEMPLATE DOES NOT HAVE THIS, THIS LINE IS REQUIRED AND HAS TO BE ADDED!!!
175184
176185 app . UseAuthorization ( ) ;
0 commit comments