|
|
@ -21,8 +21,6 @@ |
|
|
|
using Infrastructure.Services; |
|
|
|
using IntegrationEvents.Events; |
|
|
|
using Marketing.API.IntegrationEvents.Handlers; |
|
|
|
using Microsoft.ApplicationInsights.Extensibility; |
|
|
|
using Microsoft.ApplicationInsights.ServiceFabric; |
|
|
|
using Microsoft.AspNetCore.Authentication.JwtBearer; |
|
|
|
using Microsoft.AspNetCore.Diagnostics.HealthChecks; |
|
|
|
using Microsoft.AspNetCore.Mvc; |
|
|
@ -30,7 +28,6 @@ |
|
|
|
using Microsoft.eShopOnContainers.Services.Marketing.API.Infrastructure.Middlewares; |
|
|
|
using Microsoft.Extensions.Diagnostics.HealthChecks; |
|
|
|
using RabbitMQ.Client; |
|
|
|
using Swashbuckle.AspNetCore.Swagger; |
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.IdentityModel.Tokens.Jwt; |
|
|
@ -63,7 +60,7 @@ |
|
|
|
|
|
|
|
services.Configure<MarketingSettings>(Configuration); |
|
|
|
|
|
|
|
ConfigureAuthService(services); |
|
|
|
ConfigureAuthService(services); |
|
|
|
|
|
|
|
services.AddDbContext<MarketingContext>(options => |
|
|
|
{ |
|
|
@ -123,29 +120,32 @@ |
|
|
|
|
|
|
|
return new DefaultRabbitMQPersistentConnection(factory, logger, retryCount); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// Add framework services.
|
|
|
|
services.AddSwaggerGen(options => |
|
|
|
{ |
|
|
|
options.DescribeAllEnumsAsStrings(); |
|
|
|
options.SwaggerDoc("v1", new Swashbuckle.AspNetCore.Swagger.Info |
|
|
|
options.SwaggerDoc("v1", new OpenApi.Models.OpenApiInfo |
|
|
|
{ |
|
|
|
Title = "Marketing HTTP API", |
|
|
|
Version = "v1", |
|
|
|
Description = "The Marketing Service HTTP API", |
|
|
|
TermsOfService = "Terms Of Service" |
|
|
|
Description = "The Marketing Service HTTP API" |
|
|
|
}); |
|
|
|
|
|
|
|
options.AddSecurityDefinition("oauth2", new OAuth2Scheme |
|
|
|
options.AddSecurityDefinition("oauth2", new OpenApi.Models.OpenApiSecurityScheme |
|
|
|
{ |
|
|
|
Type = "oauth2", |
|
|
|
Flow = "implicit", |
|
|
|
AuthorizationUrl = $"{Configuration.GetValue<string>("IdentityUrlExternal")}/connect/authorize", |
|
|
|
TokenUrl = $"{Configuration.GetValue<string>("IdentityUrlExternal")}/connect/token", |
|
|
|
Scopes = new Dictionary<string, string>() |
|
|
|
Flows = new OpenApi.Models.OpenApiOAuthFlows() |
|
|
|
{ |
|
|
|
{ "marketing", "Marketing API" } |
|
|
|
Implicit = new OpenApi.Models.OpenApiOAuthFlow() |
|
|
|
{ |
|
|
|
AuthorizationUrl = new Uri($"{Configuration.GetValue<string>("IdentityUrlExternal")}/connect/authorize"), |
|
|
|
TokenUrl = new Uri($"{Configuration.GetValue<string>("IdentityUrlExternal")}/connect/token"), |
|
|
|
Scopes = new Dictionary<string, string>() |
|
|
|
{ |
|
|
|
{ "marketing", "Marketing API" } |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
@ -178,7 +178,7 @@ |
|
|
|
} |
|
|
|
|
|
|
|
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
|
|
|
public void Configure(IApplicationBuilder app, IHostingEnvironment env,ILoggerFactory loggerFactory) |
|
|
|
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) |
|
|
|
{ |
|
|
|
//loggerFactory.AddAzureWebAppDiagnostics();
|
|
|
|
//loggerFactory.AddApplicationInsights(app.ApplicationServices, LogLevel.Trace);
|
|
|
@ -213,7 +213,7 @@ |
|
|
|
c.SwaggerEndpoint($"{ (!string.IsNullOrEmpty(pathBase) ? pathBase : string.Empty) }/swagger/v1/swagger.json", "Marketing.API V1"); |
|
|
|
c.OAuthClientId("marketingswaggerui"); |
|
|
|
c.OAuthAppName("Marketing Swagger UI"); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
ConfigureEventBus(app); |
|
|
|
} |
|
|
@ -228,12 +228,6 @@ |
|
|
|
// Enable K8s telemetry initializer
|
|
|
|
services.AddApplicationInsightsKubernetesEnricher(); |
|
|
|
} |
|
|
|
if (orchestratorType?.ToUpper() == "SF") |
|
|
|
{ |
|
|
|
// Enable SF telemetry initializer
|
|
|
|
services.AddSingleton<ITelemetryInitializer>((serviceProvider) => |
|
|
|
new FabricTelemetryInitializer()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void ConfigureAuthService(IServiceCollection services) |
|
|
@ -241,7 +235,7 @@ |
|
|
|
// prevent from mapping "sub" claim to nameidentifier.
|
|
|
|
JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear(); |
|
|
|
|
|
|
|
services.AddAuthentication(options=> |
|
|
|
services.AddAuthentication(options => |
|
|
|
{ |
|
|
|
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; |
|
|
|
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; |
|
|
@ -265,7 +259,7 @@ |
|
|
|
var serviceBusPersisterConnection = sp.GetRequiredService<IServiceBusPersisterConnection>(); |
|
|
|
var iLifetimeScope = sp.GetRequiredService<ILifetimeScope>(); |
|
|
|
var logger = sp.GetRequiredService<ILogger<EventBusServiceBus>>(); |
|
|
|
var eventBusSubcriptionsManager = sp.GetRequiredService<IEventBusSubscriptionsManager>(); |
|
|
|
var eventBusSubcriptionsManager = sp.GetRequiredService<IEventBusSubscriptionsManager>(); |
|
|
|
|
|
|
|
return new EventBusServiceBus(serviceBusPersisterConnection, logger, |
|
|
|
eventBusSubcriptionsManager, subscriptionClientName, iLifetimeScope); |
|
|
|