1111 using Infrastructure . AutofacModules ;
1212 using Infrastructure . Filters ;
1313 using Infrastructure . Services ;
14+ using Microsoft . AspNetCore . Authentication . JwtBearer ;
1415 using Microsoft . AspNetCore . Builder ;
1516 using Microsoft . AspNetCore . Hosting ;
1617 using Microsoft . Azure . ServiceBus ;
@@ -170,7 +171,7 @@ public IServiceProvider ConfigureServices(IServiceCollection services)
170171 }
171172
172173 RegisterEventBus ( services ) ;
173-
174+ ConfigureAuthService ( services ) ;
174175 services . AddOptions ( ) ;
175176
176177 //configure autofac
@@ -225,22 +226,33 @@ private void ConfigureEventBus(IApplicationBuilder app)
225226 eventBus . Subscribe < OrderPaymentSuccededIntegrationEvent , IIntegrationEventHandler < OrderPaymentSuccededIntegrationEvent > > ( ) ;
226227 }
227228
228- protected virtual void ConfigureAuth ( IApplicationBuilder app )
229+ private void ConfigureAuthService ( IServiceCollection services )
229230 {
230231 var identityUrl = Configuration . GetValue < string > ( "IdentityUrl" ) ;
231- app . UseIdentityServerAuthentication ( new IdentityServerAuthenticationOptions
232+
233+ services . AddAuthentication ( options =>
234+ {
235+ options . DefaultAuthenticateScheme = JwtBearerDefaults . AuthenticationScheme ;
236+ options . DefaultChallengeScheme = JwtBearerDefaults . AuthenticationScheme ;
237+
238+ } ) . AddJwtBearer ( options =>
232239 {
233- Authority = identityUrl . ToString ( ) ,
234- ApiName = "orders" ,
235- RequireHttpsMetadata = false
240+ options . Authority = identityUrl ;
241+ options . RequireHttpsMetadata = false ;
242+ options . Audience = "orders" ;
236243 } ) ;
237244 }
238245
246+ protected virtual void ConfigureAuth ( IApplicationBuilder app )
247+ {
248+ app . UseAuthentication ( ) ;
249+ }
250+
239251 private void RegisterEventBus ( IServiceCollection services )
240252 {
241253 if ( Configuration . GetValue < bool > ( "AzureServiceBusEnabled" ) )
242254 {
243- services . AddSingleton < BuildingBlocks . EventBus . Abstractions . IEventBus , EventBusServiceBus > ( sp =>
255+ services . AddSingleton < IEventBus , EventBusServiceBus > ( sp =>
244256 {
245257 var serviceBusPersisterConnection = sp . GetRequiredService < IServiceBusPersisterConnection > ( ) ;
246258 var iLifetimeScope = sp . GetRequiredService < ILifetimeScope > ( ) ;
@@ -254,7 +266,7 @@ private void RegisterEventBus(IServiceCollection services)
254266 }
255267 else
256268 {
257- services . AddSingleton < BuildingBlocks . EventBus . Abstractions . IEventBus , EventBusRabbitMQ > ( ) ;
269+ services . AddSingleton < IEventBus , EventBusRabbitMQ > ( ) ;
258270 }
259271
260272 services . AddSingleton < IEventBusSubscriptionsManager , InMemoryEventBusSubscriptionsManager > ( ) ;
0 commit comments