diff --git a/src/Services/Location/Locations.API/Infrastructure/Filters/AuthorizeCheckOperationFilter.cs b/src/Services/Location/Locations.API/Infrastructure/Filters/AuthorizeCheckOperationFilter.cs index e4194daeb..e2d4c9aed 100644 --- a/src/Services/Location/Locations.API/Infrastructure/Filters/AuthorizeCheckOperationFilter.cs +++ b/src/Services/Location/Locations.API/Infrastructure/Filters/AuthorizeCheckOperationFilter.cs @@ -1,6 +1,6 @@  using Microsoft.AspNetCore.Authorization; -using Swashbuckle.AspNetCore.Swagger; +using Microsoft.OpenApi.Models; using Swashbuckle.AspNetCore.SwaggerGen; using System.Collections.Generic; using System.Linq; @@ -9,7 +9,7 @@ namespace Microsoft.eShopOnContainers.Services.Locations.API.Infrastructure.Filt { internal 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() || @@ -17,16 +17,21 @@ namespace Microsoft.eShopOnContainers.Services.Locations.API.Infrastructure.Filt 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 [] { "locationsapi" } } - } + Reference = new OpenApiReference { Type = ReferenceType.SecurityScheme, Id = "oauth2" } }; + + operation.Security = new List + { + new OpenApiSecurityRequirement + { + [ oAuthScheme ] = new [] { "locationsapi" } + } + }; } } } diff --git a/src/Services/Location/Locations.API/Infrastructure/Filters/HttpGlobalExceptionFilter.cs b/src/Services/Location/Locations.API/Infrastructure/Filters/HttpGlobalExceptionFilter.cs index 30b9df1fa..12cffe878 100644 --- a/src/Services/Location/Locations.API/Infrastructure/Filters/HttpGlobalExceptionFilter.cs +++ b/src/Services/Location/Locations.API/Infrastructure/Filters/HttpGlobalExceptionFilter.cs @@ -5,15 +5,16 @@ using Microsoft.AspNetCore.Mvc.Filters; using Microsoft.eShopOnContainers.Services.Locations.API.Infrastructure.ActionResults; using Microsoft.eShopOnContainers.Services.Locations.API.Infrastructure.Exceptions; + using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using System.Net; public class HttpGlobalExceptionFilter : IExceptionFilter { - private readonly IHostingEnvironment env; + private readonly IHostEnvironment env; private readonly ILogger logger; - public HttpGlobalExceptionFilter(IHostingEnvironment env, ILogger logger) + public HttpGlobalExceptionFilter(IHostEnvironment env, ILogger logger) { this.env = env; this.logger = logger; diff --git a/src/Services/Location/Locations.API/Locations.API.csproj b/src/Services/Location/Locations.API/Locations.API.csproj index 7f658ee2d..653b7b7b5 100644 --- a/src/Services/Location/Locations.API/Locations.API.csproj +++ b/src/Services/Location/Locations.API/Locations.API.csproj @@ -4,6 +4,7 @@ $(NetCoreTargetVersion) ..\..\..\..\docker-compose.dcproj aspnet-Locations.API-20161122013619 + $(LangVersion) @@ -14,6 +15,7 @@ + diff --git a/src/Services/Location/Locations.API/Startup.cs b/src/Services/Location/Locations.API/Startup.cs index 4664381d0..cfb9d7e22 100644 --- a/src/Services/Location/Locations.API/Startup.cs +++ b/src/Services/Location/Locations.API/Startup.cs @@ -1,8 +1,6 @@ using Autofac; using Autofac.Extensions.DependencyInjection; 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; @@ -23,8 +21,8 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Diagnostics.HealthChecks; using Microsoft.Extensions.Logging; +using Microsoft.OpenApi.Models; using RabbitMQ.Client; -using Swashbuckle.AspNetCore.Swagger; using System; using System.Collections.Generic; using System.IdentityModel.Tokens.Jwt; @@ -50,7 +48,7 @@ namespace Microsoft.eShopOnContainers.Services.Locations.API { options.Filters.Add(typeof(HttpGlobalExceptionFilter)); }) - .SetCompatibilityVersion(CompatibilityVersion.Version_2_2) + .SetCompatibilityVersion(CompatibilityVersion.Version_3_0) .AddControllersAsServices(); ConfigureAuthService(services); @@ -99,7 +97,7 @@ namespace Microsoft.eShopOnContainers.Services.Locations.API return new DefaultRabbitMQPersistentConnection(factory, logger, retryCount); }); - } + } RegisterEventBus(services); @@ -107,23 +105,27 @@ namespace Microsoft.eShopOnContainers.Services.Locations.API services.AddSwaggerGen(options => { options.DescribeAllEnumsAsStrings(); - options.SwaggerDoc("v1", new Swashbuckle.AspNetCore.Swagger.Info + options.SwaggerDoc("v1", new OpenApiInfo { Title = "eShopOnContainers - Location HTTP API", Version = "v1", Description = "The Location Microservice HTTP API. This is a Data-Driven/CRUD microservice sample", - TermsOfService = "Terms Of Service" }); - options.AddSecurityDefinition("oauth2", new OAuth2Scheme + options.AddSecurityDefinition("oauth2", new OpenApiSecurityScheme { - Type = "oauth2", - Flow = "implicit", - AuthorizationUrl = $"{Configuration.GetValue("IdentityUrlExternal")}/connect/authorize", - TokenUrl = $"{Configuration.GetValue("IdentityUrlExternal")}/connect/token", - Scopes = new Dictionary() + Type = SecuritySchemeType.OAuth2, + Flows = new OpenApiOAuthFlows() { - { "locations", "Locations API" } + Implicit = new OpenApiOAuthFlow() + { + AuthorizationUrl = new Uri($"{Configuration.GetValue("IdentityUrlExternal")}/connect/authorize"), + TokenUrl = new Uri($"{Configuration.GetValue("IdentityUrlExternal")}/connect/token"), + Scopes = new Dictionary() + { + { "locations", "Locations API" } + } + } } }); @@ -204,12 +206,6 @@ namespace Microsoft.eShopOnContainers.Services.Locations.API // Enable K8s telemetry initializer services.AddApplicationInsightsKubernetesEnricher(); } - if (orchestratorType?.ToUpper() == "SF") - { - // Enable SF telemetry initializer - services.AddSingleton((serviceProvider) => - new FabricTelemetryInitializer()); - } } private void ConfigureAuthService(IServiceCollection services) diff --git a/src/_build/dependencies.props b/src/_build/dependencies.props index 6a91b3f6a..e9a425ee8 100644 --- a/src/_build/dependencies.props +++ b/src/_build/dependencies.props @@ -3,7 +3,7 @@ netstandard2.1 netcoreapp3.0 15.8.0 - latest + preview @@ -37,9 +37,11 @@ 2.6.1 1.0.2 3.0.0-preview6.19307.2 + 3.0.0-preview6.19307.2 2.2.0 1.0.0 2.2.0 + 3.0.0-preview6.19307.2 3.0.0-preview6.19307.2 3.0.0 4.5.0