33using Microsoft . AspNetCore . Builder ;
44using Microsoft . AspNetCore . Hosting ;
55using Microsoft . AspNetCore . Http ;
6+ using Microsoft . Azure . ServiceBus ;
67using Microsoft . eShopOnContainers . BuildingBlocks . EventBus ;
78using Microsoft . eShopOnContainers . BuildingBlocks . EventBus . Abstractions ;
89using Microsoft . eShopOnContainers . BuildingBlocks . EventBusRabbitMQ ;
10+ using Microsoft . eShopOnContainers . BuildingBlocks . EventBusServiceBus ;
911using Microsoft . eShopOnContainers . Services . Locations . API . Infrastructure ;
1012using Microsoft . eShopOnContainers . Services . Locations . API . Infrastructure . Filters ;
1113using Microsoft . eShopOnContainers . Services . Locations . API . Infrastructure . Repositories ;
1214using Microsoft . eShopOnContainers . Services . Locations . API . Infrastructure . Services ;
1315using Microsoft . Extensions . Configuration ;
1416using Microsoft . Extensions . DependencyInjection ;
17+ using Microsoft . Extensions . HealthChecks ;
1518using Microsoft . Extensions . Logging ;
1619using RabbitMQ . Client ;
17- using System . Reflection ;
20+ using Swashbuckle . AspNetCore . Swagger ;
1821using System ;
19- using Microsoft . eShopOnContainers . BuildingBlocks . EventBusServiceBus ;
20- using Microsoft . Azure . ServiceBus ;
2122using System . Collections . Generic ;
22- using Swashbuckle . AspNetCore . Swagger ;
23- using Microsoft . Extensions . HealthChecks ;
2423using System . Threading . Tasks ;
2524
2625namespace Microsoft . eShopOnContainers . Services . Locations . API
2726{
2827 public class Startup
2928 {
30- public IConfigurationRoot Configuration { get ; }
31-
32- public Startup ( IHostingEnvironment env )
29+ public Startup ( IConfiguration configuration )
3330 {
34- var builder = new ConfigurationBuilder ( )
35- . SetBasePath ( env . ContentRootPath )
36- . AddJsonFile ( "appsettings.json" , optional : false , reloadOnChange : true )
37- . AddJsonFile ( $ "appsettings.{ env . EnvironmentName } .json", optional : true ) ;
38-
39- if ( env . IsDevelopment ( ) )
40- {
41- builder . AddUserSecrets ( typeof ( Startup ) . GetTypeInfo ( ) . Assembly ) ;
42- }
43-
44- builder . AddEnvironmentVariables ( ) ;
45-
46- Configuration = builder . Build ( ) ;
31+ Configuration = configuration ;
4732 }
4833
49- // This method gets called by the runtime. Use this method to add services to the container.
34+ public IConfiguration Configuration { get ; }
35+
5036 public IServiceProvider ConfigureServices ( IServiceCollection services )
5137 {
52- // Add framework services.
5338 services . AddMvc ( options =>
5439 {
5540 options . Filters . Add ( typeof ( HttpGlobalExceptionFilter ) ) ;
5641 } ) . AddControllersAsServices ( ) ;
5742
43+ services . AddAuthentication ( )
44+ . AddJwtBearer ( options =>
45+ {
46+ options . Authority = Configuration . GetValue < string > ( "IdentityUrl" ) ;
47+ options . Audience = "locations" ;
48+ options . RequireHttpsMetadata = false ;
49+ } ) ;
50+
5851 services . Configure < LocationSettings > ( Configuration ) ;
5952
6053 if ( Configuration . GetValue < bool > ( "AzureServiceBusEnabled" ) )
@@ -143,14 +136,9 @@ public IServiceProvider ConfigureServices(IServiceCollection services)
143136 // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
144137 public void Configure ( IApplicationBuilder app , IHostingEnvironment env , ILoggerFactory loggerFactory )
145138 {
146- //Configure logs
147-
148- loggerFactory . AddConsole ( Configuration . GetSection ( "Logging" ) ) ;
149- loggerFactory . AddDebug ( ) ;
150-
151139 app . UseCors ( "CorsPolicy" ) ;
152140
153- ConfigureAuth ( app ) ;
141+ app . UseAuthentication ( ) ;
154142
155143 app . UseMvcWithDefaultRoute ( ) ;
156144
@@ -165,17 +153,6 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerF
165153 . Wait ( ) ;
166154 }
167155
168- protected virtual void ConfigureAuth ( IApplicationBuilder app )
169- {
170- var identityUrl = Configuration . GetValue < string > ( "IdentityUrl" ) ;
171- app . UseIdentityServerAuthentication ( new IdentityServerAuthenticationOptions
172- {
173- Authority = identityUrl . ToString ( ) ,
174- ApiName = "locations" ,
175- RequireHttpsMetadata = false
176- } ) ;
177- }
178-
179156 private void RegisterEventBus ( IServiceCollection services )
180157 {
181158 if ( Configuration . GetValue < bool > ( "AzureServiceBusEnabled" ) )
0 commit comments