diff --git a/src/ApiGateways/ApiGw-Base/Startup.cs b/src/ApiGateways/ApiGw-Base/Startup.cs index be845edca..f4b7eaff7 100644 --- a/src/ApiGateways/ApiGw-Base/Startup.cs +++ b/src/ApiGateways/ApiGw-Base/Startup.cs @@ -89,15 +89,18 @@ namespace OcelotApiGw app.UseDeveloperExceptionPage(); } - app.UseHealthChecks("/hc", new HealthCheckOptions() + app.UseRouting(); + app.UseEndpoints(endpoints => { - Predicate = _ => true, - ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse - }); - - app.UseHealthChecks("/liveness", new HealthCheckOptions - { - Predicate = r => r.Name.Contains("self") + endpoints.MapHealthChecks("/hc", new HealthCheckOptions() + { + Predicate = _ => true, + ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse + }); + endpoints.MapHealthChecks("/liveness", new HealthCheckOptions + { + Predicate = r => r.Name.Contains("self") + }); }); app.UseCors("CorsPolicy"); diff --git a/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Startup.cs b/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Startup.cs index a2997be05..efa9285c2 100644 --- a/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Startup.cs +++ b/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Startup.cs @@ -62,17 +62,6 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator app.UsePathBase(pathBase); } - app.UseHealthChecks("/hc", new HealthCheckOptions() - { - Predicate = _ => true, - ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse - }); - - app.UseHealthChecks("/liveness", new HealthCheckOptions - { - Predicate = r => r.Name.Contains("self") - }); - app.UseCors("CorsPolicy"); if (env.IsDevelopment()) @@ -87,7 +76,20 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator app.UseAuthentication(); app.UseHttpsRedirection(); - app.UseMvc(); + app.UseRouting(); + app.UseEndpoints(endpoints => + { + endpoints.MapHealthChecks("/hc", new HealthCheckOptions() + { + Predicate = _ => true, + ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse + }); + endpoints.MapHealthChecks("/liveness", new HealthCheckOptions + { + Predicate = r => r.Name.Contains("self") + }); + endpoints.MapDefaultControllerRoute(); + }); app.UseSwagger().UseSwaggerUI(c => { diff --git a/src/ApiGateways/Web.Bff.Shopping/aggregator/Startup.cs b/src/ApiGateways/Web.Bff.Shopping/aggregator/Startup.cs index 747269f50..b6d43b300 100644 --- a/src/ApiGateways/Web.Bff.Shopping/aggregator/Startup.cs +++ b/src/ApiGateways/Web.Bff.Shopping/aggregator/Startup.cs @@ -61,17 +61,6 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator app.UsePathBase(pathBase); } - app.UseHealthChecks("/hc", new HealthCheckOptions() - { - Predicate = _ => true, - ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse - }); - - app.UseHealthChecks("/liveness", new HealthCheckOptions - { - Predicate = r => r.Name.Contains("self") - }); - app.UseCors("CorsPolicy"); if (env.IsDevelopment()) @@ -86,7 +75,20 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator app.UseAuthentication(); app.UseHttpsRedirection(); - app.UseMvc(); + app.UseRouting(); + app.UseEndpoints(endpoints => + { + endpoints.MapHealthChecks("/hc", new HealthCheckOptions() + { + Predicate = _ => true, + ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse + }); + endpoints.MapHealthChecks("/liveness", new HealthCheckOptions + { + Predicate = r => r.Name.Contains("self") + }); + endpoints.MapDefaultControllerRoute(); + }); app.UseSwagger() .UseSwaggerUI(c => diff --git a/src/Services/Webhooks/Webhooks.API/Infrastructure/AuthorizeCheckOperationFilter.cs b/src/Services/Webhooks/Webhooks.API/Infrastructure/AuthorizeCheckOperationFilter.cs index 920f2ac8e..487a59981 100644 --- a/src/Services/Webhooks/Webhooks.API/Infrastructure/AuthorizeCheckOperationFilter.cs +++ b/src/Services/Webhooks/Webhooks.API/Infrastructure/AuthorizeCheckOperationFilter.cs @@ -1,16 +1,14 @@ using Microsoft.AspNetCore.Authorization; -using Swashbuckle.AspNetCore.Swagger; +using Microsoft.OpenApi.Models; using Swashbuckle.AspNetCore.SwaggerGen; -using System; using System.Collections.Generic; using System.Linq; -using System.Threading.Tasks; namespace Webhooks.API.Infrastructure { public class AuthorizeCheckOperationFilter : IOperationFilter { - public void Apply(Operation operation, OperationFilterContext context) + public void Apply(OpenApiOperation operation, OperationFilterContext context) { // Check for authorize attribute var hasAuthorize = context.MethodInfo.DeclaringType.GetCustomAttributes(true).OfType().Any() || @@ -18,16 +16,21 @@ namespace Webhooks.API.Infrastructure if (!hasAuthorize) return; - operation.Responses.TryAdd("401", new Response { Description = "Unauthorized" }); - operation.Responses.TryAdd("403", new Response { Description = "Forbidden" }); + operation.Responses.TryAdd("401", new OpenApiResponse { Description = "Unauthorized" }); + operation.Responses.TryAdd("403", new OpenApiResponse { Description = "Forbidden" }); - operation.Security = new List>> + var oAuthScheme = new OpenApiSecurityScheme { - new Dictionary> - { - { "oauth2", new [] { "webhooksapi" } } - } + Reference = new OpenApiReference { Type = ReferenceType.SecurityScheme, Id = "oauth2" } }; + + operation.Security = new List + { + new OpenApiSecurityRequirement + { + [ oAuthScheme ] = new [] { "webhooksapi" } + } + }; } } } diff --git a/src/Services/Webhooks/Webhooks.API/Startup.cs b/src/Services/Webhooks/Webhooks.API/Startup.cs index f1a89d329..dfeb36a79 100644 --- a/src/Services/Webhooks/Webhooks.API/Startup.cs +++ b/src/Services/Webhooks/Webhooks.API/Startup.cs @@ -1,21 +1,10 @@ -using System; -using System.Collections.Generic; -using System.Data.Common; -using System.IdentityModel.Tokens.Jwt; -using System.Linq; -using System.Reflection; -using System.Threading; -using System.Threading.Tasks; -using Autofac; +using Autofac; using Autofac.Extensions.DependencyInjection; using Devspaces.Support; using HealthChecks.UI.Client; -using Microsoft.ApplicationInsights.Extensibility; -using Microsoft.ApplicationInsights.ServiceFabric; using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Diagnostics.HealthChecks; -using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.Azure.ServiceBus; @@ -31,7 +20,12 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Diagnostics.HealthChecks; using Microsoft.Extensions.Logging; using RabbitMQ.Client; -using Swashbuckle.AspNetCore.Swagger; +using System; +using System.Collections.Generic; +using System.Data.Common; +using System.IdentityModel.Tokens.Jwt; +using System.Reflection; +using System.Threading; using Webhooks.API.Infrastructure; using Webhooks.API.IntegrationEvents; using Webhooks.API.Services; @@ -84,22 +78,25 @@ namespace Webhooks.API app.UsePathBase(pathBase); } - app.UseHealthChecks("/hc", new HealthCheckOptions() - { - Predicate = _ => true, - ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse - }); - - app.UseHealthChecks("/liveness", new HealthCheckOptions - { - Predicate = r => r.Name.Contains("self") - }); - app.UseCors("CorsPolicy"); ConfigureAuth(app); - app.UseMvcWithDefaultRoute(); + app.UseRouting(); + app.UseEndpoints(endpoints => + { + endpoints.MapHealthChecks("/hc", new HealthCheckOptions() + { + Predicate = _ => true, + ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse + }); + endpoints.MapHealthChecks("/liveness", new HealthCheckOptions + { + Predicate = r => r.Name.Contains("self") + }); + + endpoints.MapDefaultControllerRoute(); + }); app.UseSwagger() .UseSwaggerUI(c => @@ -138,19 +135,7 @@ namespace Webhooks.API public static IServiceCollection AddAppInsight(this IServiceCollection services, IConfiguration configuration) { services.AddApplicationInsightsTelemetry(configuration); - var orchestratorType = configuration.GetValue("OrchestratorType"); - - if (orchestratorType?.ToUpper() == "K8S") - { - // Enable K8s telemetry initializer - services.AddApplicationInsightsKubernetesEnricher(); - } - if (orchestratorType?.ToUpper() == "SF") - { - // Enable SF telemetry initializer - services.AddSingleton((serviceProvider) => - new FabricTelemetryInitializer()); - } + services.AddApplicationInsightsKubernetesEnricher(); return services; } @@ -161,7 +146,7 @@ namespace Webhooks.API { options.Filters.Add(typeof(HttpGlobalExceptionFilter)); }) - .SetCompatibilityVersion(CompatibilityVersion.Version_2_2) + .SetCompatibilityVersion(CompatibilityVersion.Version_3_0) .AddControllersAsServices(); services.AddCors(options => @@ -203,23 +188,26 @@ namespace Webhooks.API services.AddSwaggerGen(options => { options.DescribeAllEnumsAsStrings(); - options.SwaggerDoc("v1", new Swashbuckle.AspNetCore.Swagger.Info + options.SwaggerDoc("v1", new Microsoft.OpenApi.Models.OpenApiInfo { Title = "eShopOnContainers - Webhooks HTTP API", Version = "v1", - Description = "The Webhooks Microservice HTTP API. This is a simple webhooks CRUD registration entrypoint", - TermsOfService = "Terms Of Service" + Description = "The Webhooks Microservice HTTP API. This is a simple webhooks CRUD registration entrypoint" }); - options.AddSecurityDefinition("oauth2", new OAuth2Scheme + options.AddSecurityDefinition("oauth2", new Microsoft.OpenApi.Models.OpenApiSecurityScheme { - Type = "oauth2", - Flow = "implicit", - AuthorizationUrl = $"{configuration.GetValue("IdentityUrlExternal")}/connect/authorize", - TokenUrl = $"{configuration.GetValue("IdentityUrlExternal")}/connect/token", - Scopes = new Dictionary() + Flows = new Microsoft.OpenApi.Models.OpenApiOAuthFlows() { - { "webhooks", "Webhooks API" } + Implicit = new Microsoft.OpenApi.Models.OpenApiOAuthFlow() + { + AuthorizationUrl = new Uri($"{configuration.GetValue("IdentityUrlExternal")}/connect/authorize"), + TokenUrl = new Uri($"{configuration.GetValue("IdentityUrlExternal")}/connect/token"), + Scopes = new Dictionary() + { + { "marketing", "Marketing API" } + } + } } }); diff --git a/src/Services/Webhooks/Webhooks.API/Webhooks.API.csproj b/src/Services/Webhooks/Webhooks.API/Webhooks.API.csproj index 1dcf916f5..9ff40e01b 100644 --- a/src/Services/Webhooks/Webhooks.API/Webhooks.API.csproj +++ b/src/Services/Webhooks/Webhooks.API/Webhooks.API.csproj @@ -4,21 +4,24 @@ $(NetCoreTargetVersion) InProcess Linux + $(AssetTargetFallback);portable-net45+win8+wp8+wpa81; + false + 8.0 - - + + - + diff --git a/src/Web/WebMVC/Startup.cs b/src/Web/WebMVC/Startup.cs index 1d2908bf1..db53a23b9 100644 --- a/src/Web/WebMVC/Startup.cs +++ b/src/Web/WebMVC/Startup.cs @@ -108,13 +108,7 @@ namespace Microsoft.eShopOnContainers.WebMVC public static IServiceCollection AddAppInsight(this IServiceCollection services, IConfiguration configuration) { services.AddApplicationInsightsTelemetry(configuration); - var orchestratorType = configuration.GetValue("OrchestratorType"); - - if (orchestratorType?.ToUpper() == "K8S") - { - // Enable K8s telemetry initializer - services.AddApplicationInsightsKubernetesEnricher(); - } + services.AddApplicationInsightsKubernetesEnricher(); return services; } @@ -232,52 +226,25 @@ namespace Microsoft.eShopOnContainers.WebMVC options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; }) .AddCookie(setup => setup.ExpireTimeSpan = TimeSpan.FromMinutes(sessionCookieLifetime)) - .AddJwtBearer(options => + .AddOpenIdConnect(options => { - //options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme; - //options.Authority = identityUrl.ToString(); - //options.SignedOutRedirectUri = callBackUrl.ToString(); - //options.ClientId = useLoadTest ? "mvctest" : "mvc"; - //options.ClientSecret = "secret"; - //options.ResponseType = useLoadTest ? "code id_token token" : "code id_token"; - //options.SaveTokens = true; - //options.GetClaimsFromUserInfoEndpoint = true; - //options.RequireHttpsMetadata = false; - //options.Scope.Add("openid"); - //options.Scope.Add("profile"); - //options.Scope.Add("orders"); - //options.Scope.Add("basket"); - //options.Scope.Add("marketing"); - //options.Scope.Add("locations"); - //options.Scope.Add("webshoppingagg"); - //options.Scope.Add("orders.signalrhub"); - - //options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme; + options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme; options.Authority = identityUrl.ToString(); - options.ForwardSignOut = callBackUrl.ToString(); - //options.ClientId = useLoadTest ? "mvctest" : "mvc"; - //options.ClientSecret = "secret"; - - if (useLoadTest) - { - options.Configuration.ResponseTypesSupported.Add("code id_token token"); - } - else - { - options.Configuration.ResponseTypesSupported.Add("code id_token"); - } - - options.SaveToken = true; - //options.GetClaimsFromUserInfoEndpoint = true; + options.SignedOutRedirectUri = callBackUrl.ToString(); + options.ClientId = useLoadTest ? "mvctest" : "mvc"; + options.ClientSecret = "secret"; + options.ResponseType = useLoadTest ? "code id_token token" : "code id_token"; + options.SaveTokens = true; + options.GetClaimsFromUserInfoEndpoint = true; options.RequireHttpsMetadata = false; - options.Configuration.ScopesSupported.Add("openid"); - options.Configuration.ScopesSupported.Add("profile"); - options.Configuration.ScopesSupported.Add("orders"); - options.Configuration.ScopesSupported.Add("basket"); - options.Configuration.ScopesSupported.Add("marketing"); - options.Configuration.ScopesSupported.Add("locations"); - options.Configuration.ScopesSupported.Add("webshoppingagg"); - options.Configuration.ScopesSupported.Add("orders.signalrhub"); + options.Scope.Add("openid"); + options.Scope.Add("profile"); + options.Scope.Add("orders"); + options.Scope.Add("basket"); + options.Scope.Add("marketing"); + options.Scope.Add("locations"); + options.Scope.Add("webshoppingagg"); + options.Scope.Add("orders.signalrhub"); }); return services; diff --git a/src/Web/WebhookClient/Startup.cs b/src/Web/WebhookClient/Startup.cs index 13ff70362..3b56d20fb 100644 --- a/src/Web/WebhookClient/Startup.cs +++ b/src/Web/WebhookClient/Startup.cs @@ -36,7 +36,7 @@ namespace WebhookClient .AddCustomAuthentication(Configuration) .AddTransient() .AddSingleton() - .AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); + .AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_3_0); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. @@ -69,7 +69,7 @@ namespace WebhookClient var header = context.Request.Headers[HeaderNames.WebHookCheckHeader]; var value = header.FirstOrDefault(); var tokenToValidate = Configuration["Token"]; - if (!validateToken || value == tokenToValidate) + if (!validateToken || value == tokenToValidate) { if (!string.IsNullOrWhiteSpace(tokenToValidate)) { @@ -91,7 +91,11 @@ namespace WebhookClient }); app.UseStaticFiles(); app.UseSession(); - app.UseMvcWithDefaultRoute(); + app.UseRouting(); + app.UseEndpoints(endpoints => + { + endpoints.MapDefaultControllerRoute(); + }); } } diff --git a/src/Web/WebhookClient/WebhookClient.csproj b/src/Web/WebhookClient/WebhookClient.csproj index 3e4eb8ed3..f9d46a63a 100644 --- a/src/Web/WebhookClient/WebhookClient.csproj +++ b/src/Web/WebhookClient/WebhookClient.csproj @@ -5,12 +5,13 @@ InProcess Linux 36215d41-f31a-4aa6-9929-bd67d650e7b5 + $(AssetTargetFallback);portable-net45+win8+wp8+wpa81; + false 8.0 -