@@ -48,6 +48,9 @@ public void ConfigureServices(IServiceCollection services)
48
48
//// Optional option to suppress the browser login dialog for ajax calls.
49
49
//options.SuppressWWWAuthenticateHeader = true;
50
50
51
+ //// Optional option to ignore authentication if AllowAnonumous metadata/filter attribute is added to an endpoint.
52
+ //options.IgnoreAuthenticationIfAllowAnonymous = true;
53
+
51
54
//// Optional events to override the basic original logic with custom logic.
52
55
//// Only use this if you know what you are doing at your own risk. Any of the events can be assigned.
53
56
options . Events = new BasicEvents
@@ -149,13 +152,19 @@ public void ConfigureServices(IServiceCollection services)
149
152
150
153
services . AddControllers ( options =>
151
154
{
152
- // ALWAYS USE HTTPS (SSL) protocol in production when using Basic authentication.
155
+ // ALWAYS USE HTTPS (SSL) protocol in production when using ApiKey authentication.
153
156
//options.Filters.Add<RequireHttpsAttribute>();
154
157
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 ( ) ) ) ;
158
158
} ) ; //.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
+ } ) ;
159
168
}
160
169
161
170
// 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)
170
179
171
180
app . UseHttpsRedirection ( ) ;
172
181
app . UseRouting ( ) ;
173
-
182
+
174
183
app . UseAuthentication ( ) ; // NOTE: DEFAULT TEMPLATE DOES NOT HAVE THIS, THIS LINE IS REQUIRED AND HAS TO BE ADDED!!!
175
184
176
185
app . UseAuthorization ( ) ;
0 commit comments