|
17 | 17 | namespace SampleWebApi |
18 | 18 | { |
19 | 19 | public class Startup |
20 | | -{ |
21 | | -public Startup(IConfiguration configuration) |
22 | | -{ |
23 | | -Configuration = configuration; |
24 | | -} |
| 20 | + { |
| 21 | + public Startup(IConfiguration configuration) |
| 22 | + { |
| 23 | + Configuration = configuration; |
| 24 | + } |
25 | 25 |
|
26 | | -public IConfiguration Configuration { get; } |
| 26 | + public IConfiguration Configuration { get; } |
27 | 27 |
|
28 | | -// This method gets called by the runtime. Use this method to add services to the container. |
29 | | -public void ConfigureServices(IServiceCollection services) |
30 | | -{ |
31 | | -// Add User repository to the dependency container. |
32 | | -services.AddTransient<IApiKeyRepository, InMemoryApiKeyRepository>(); |
| 28 | + // This method gets called by the runtime. Use this method to add services to the container. |
| 29 | + public void ConfigureServices(IServiceCollection services) |
| 30 | + { |
| 31 | + // Add User repository to the dependency container. |
| 32 | + services.AddTransient<IApiKeyRepository, InMemoryApiKeyRepository>(); |
33 | 33 |
|
34 | 34 | // Add the ApiKey scheme authentication here.. |
35 | 35 | // It requires Realm to be set in the options if SuppressWWWAuthenticateHeader is not set. |
@@ -150,32 +150,32 @@ public void ConfigureServices(IServiceCollection services) |
150 | 150 | }); |
151 | 151 |
|
152 | 152 | services.AddMvc(options => |
153 | | -{ |
154 | | -// ALWAYS USE HTTPS (SSL) protocol in production when using ApiKey authentication. |
155 | | -//options.Filters.Add<RequireHttpsAttribute>(); |
156 | | - |
157 | | -// All the requests will need to be authorized. |
158 | | -// Alternatively, add [Authorize] attribute to Controller or Action Method where necessary. |
159 | | -options.Filters.Add(new AuthorizeFilter(new AuthorizationPolicyBuilder().RequireAuthenticatedUser().Build())); |
160 | | -} |
161 | | -); //.AddXmlSerializerFormatters(); // To enable XML along with JSON |
162 | | -} |
163 | | - |
164 | | -// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. |
165 | | -public void Configure(IApplicationBuilder app, IHostingEnvironment env) |
166 | | -{ |
167 | | -if (env.IsDevelopment()) |
168 | | -{ |
169 | | -app.UseDeveloperExceptionPage(); |
170 | | -} |
171 | | -else |
172 | | -{ |
173 | | -// ALWAYS USE HTTPS (SSL) protocol in production when using ApiKey authentication. |
174 | | -app.UseRewriter(new RewriteOptions().AddRedirectToHttpsPermanent()); |
175 | | -} |
176 | | - |
177 | | -app.UseAuthentication(); |
178 | | -app.UseMvc(); |
179 | | -} |
180 | | -} |
| 153 | + { |
| 154 | + // ALWAYS USE HTTPS (SSL) protocol in production when using ApiKey authentication. |
| 155 | + //options.Filters.Add<RequireHttpsAttribute>(); |
| 156 | + |
| 157 | + // All the requests will need to be authorized. |
| 158 | + // Alternatively, add [Authorize] attribute to Controller or Action Method where necessary. |
| 159 | + options.Filters.Add(new AuthorizeFilter(new AuthorizationPolicyBuilder().RequireAuthenticatedUser().Build())); |
| 160 | + } |
| 161 | + ); //.AddXmlSerializerFormatters(); // To enable XML along with JSON |
| 162 | + } |
| 163 | + |
| 164 | + // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. |
| 165 | + public void Configure(IApplicationBuilder app, IHostingEnvironment env) |
| 166 | + { |
| 167 | + if (env.IsDevelopment()) |
| 168 | + { |
| 169 | + app.UseDeveloperExceptionPage(); |
| 170 | + } |
| 171 | + else |
| 172 | + { |
| 173 | + // ALWAYS USE HTTPS (SSL) protocol in production when using ApiKey authentication. |
| 174 | + app.UseRewriter(new RewriteOptions().AddRedirectToHttpsPermanent()); |
| 175 | + } |
| 176 | + |
| 177 | + app.UseAuthentication(); |
| 178 | + app.UseMvc(); |
| 179 | + } |
| 180 | + } |
181 | 181 | } |
0 commit comments