Skip to content

Commit da6321d

Browse files
author
=
committed
Merge branch 'features/net3' into features/ep-migration-dotnet3
2 parents 66bee87 + e7f26be commit da6321d

5 files changed

Lines changed: 38 additions & 32 deletions

File tree

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
using Microsoft.AspNetCore.Authorization;
3-
using Swashbuckle.AspNetCore.Swagger;
3+
using Microsoft.OpenApi.Models;
44
using Swashbuckle.AspNetCore.SwaggerGen;
55
using System.Collections.Generic;
66
using System.Linq;
@@ -9,24 +9,29 @@ namespace Microsoft.eShopOnContainers.Services.Locations.API.Infrastructure.Filt
99
{
1010
internal class AuthorizeCheckOperationFilter : IOperationFilter
1111
{
12-
public void Apply(Operation operation, OperationFilterContext context)
12+
public void Apply(OpenApiOperation operation, OperationFilterContext context)
1313
{
1414
// Check for authorize attribute
1515
var hasAuthorize = context.MethodInfo.DeclaringType.GetCustomAttributes(true).OfType<AuthorizeAttribute>().Any() ||
1616
context.MethodInfo.GetCustomAttributes(true).OfType<AuthorizeAttribute>().Any();
1717

1818
if (!hasAuthorize) return;
1919

20-
operation.Responses.TryAdd("401", new Response { Description = "Unauthorized" });
21-
operation.Responses.TryAdd("403", new Response { Description = "Forbidden" });
20+
operation.Responses.TryAdd("401", new OpenApiResponse() { Description = "Unauthorized" });
21+
operation.Responses.TryAdd("403", new OpenApiResponse() { Description = "Forbidden" });
2222

23-
operation.Security = new List<IDictionary<string, IEnumerable<string>>>
23+
var oAuthScheme = new OpenApiSecurityScheme
2424
{
25-
new Dictionary<string, IEnumerable<string>>
26-
{
27-
{ "oauth2", new [] { "locationsapi" } }
28-
}
25+
Reference = new OpenApiReference { Type = ReferenceType.SecurityScheme, Id = "oauth2" }
2926
};
27+
28+
operation.Security = new List<OpenApiSecurityRequirement>
29+
{
30+
new OpenApiSecurityRequirement
31+
{
32+
[ oAuthScheme ] = new [] { "locationsapi" }
33+
}
34+
};
3035
}
3136
}
3237
}

src/Services/Location/Locations.API/Infrastructure/Filters/HttpGlobalExceptionFilter.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@
55
using Microsoft.AspNetCore.Mvc.Filters;
66
using Microsoft.eShopOnContainers.Services.Locations.API.Infrastructure.ActionResults;
77
using Microsoft.eShopOnContainers.Services.Locations.API.Infrastructure.Exceptions;
8+
using Microsoft.Extensions.Hosting;
89
using Microsoft.Extensions.Logging;
910
using System.Net;
1011

1112
public class HttpGlobalExceptionFilter : IExceptionFilter
1213
{
13-
private readonly IHostingEnvironment env;
14+
private readonly IHostEnvironment env;
1415
private readonly ILogger<HttpGlobalExceptionFilter> logger;
1516

16-
public HttpGlobalExceptionFilter(IHostingEnvironment env, ILogger<HttpGlobalExceptionFilter> logger)
17+
public HttpGlobalExceptionFilter(IHostEnvironment env, ILogger<HttpGlobalExceptionFilter> logger)
1718
{
1819
this.env = env;
1920
this.logger = logger;

src/Services/Location/Locations.API/Locations.API.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<TargetFramework>$(NetCoreTargetVersion)</TargetFramework>
55
<DockerComposeProjectPath>..\..\..\..\docker-compose.dcproj</DockerComposeProjectPath>
66
<UserSecretsId>aspnet-Locations.API-20161122013619</UserSecretsId>
7+
<LangVersion>$(LangVersion)</LangVersion>
78
</PropertyGroup>
89
<ItemGroup>
910
<PackageReference Include="AspNetCore.HealthChecks.AzureServiceBus" Version="$(AspNetCore_HealthChecks_AzureServiceBus)" />
@@ -14,6 +15,7 @@
1415
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="$(Microsoft_ApplicationInsights_AspNetCore)" />
1516
<PackageReference Include="Microsoft.ApplicationInsights.DependencyCollector" Version="$(Microsoft_ApplicationInsights_DependencyCollector)" />
1617
<PackageReference Include="Microsoft.ApplicationInsights.Kubernetes" Version="$(Microsoft_ApplicationInsights_Kubernetes)" />
18+
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="$(Microsoft_AspNetCore_Authentication_JwtBearer)" />
1719
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.HealthChecks" Version="$(Microsoft_AspNetCore_Diagnostics_HealthChecks)" />
1820
<PackageReference Include="Microsoft.AspNetCore.HealthChecks" Version="$(Microsoft_AspNetCore_HealthChecks)" />
1921
<PackageReference Include="Microsoft.Extensions.Configuration.AzureKeyVault" Version="$(Microsoft_Extensions_Configuration_AzureKeyVault)" />

src/Services/Location/Locations.API/Startup.cs

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
using Autofac;
22
using Autofac.Extensions.DependencyInjection;
33
using HealthChecks.UI.Client;
4-
using Microsoft.ApplicationInsights.Extensibility;
5-
using Microsoft.ApplicationInsights.ServiceFabric;
64
using Microsoft.AspNetCore.Authentication.JwtBearer;
75
using Microsoft.AspNetCore.Builder;
86
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
@@ -23,8 +21,8 @@
2321
using Microsoft.Extensions.DependencyInjection;
2422
using Microsoft.Extensions.Diagnostics.HealthChecks;
2523
using Microsoft.Extensions.Logging;
24+
using Microsoft.OpenApi.Models;
2625
using RabbitMQ.Client;
27-
using Swashbuckle.AspNetCore.Swagger;
2826
using System;
2927
using System.Collections.Generic;
3028
using System.IdentityModel.Tokens.Jwt;
@@ -50,7 +48,7 @@ public IServiceProvider ConfigureServices(IServiceCollection services)
5048
{
5149
options.Filters.Add(typeof(HttpGlobalExceptionFilter));
5250
})
53-
.SetCompatibilityVersion(CompatibilityVersion.Version_2_2)
51+
.SetCompatibilityVersion(CompatibilityVersion.Version_3_0)
5452
.AddControllersAsServices();
5553

5654
ConfigureAuthService(services);
@@ -99,31 +97,35 @@ public IServiceProvider ConfigureServices(IServiceCollection services)
9997

10098
return new DefaultRabbitMQPersistentConnection(factory, logger, retryCount);
10199
});
102-
}
100+
}
103101

104102
RegisterEventBus(services);
105103

106104
// Add framework services.
107105
services.AddSwaggerGen(options =>
108106
{
109107
options.DescribeAllEnumsAsStrings();
110-
options.SwaggerDoc("v1", new Swashbuckle.AspNetCore.Swagger.Info
108+
options.SwaggerDoc("v1", new OpenApiInfo
111109
{
112110
Title = "eShopOnContainers - Location HTTP API",
113111
Version = "v1",
114112
Description = "The Location Microservice HTTP API. This is a Data-Driven/CRUD microservice sample",
115-
TermsOfService = "Terms Of Service"
116113
});
117114

118-
options.AddSecurityDefinition("oauth2", new OAuth2Scheme
115+
options.AddSecurityDefinition("oauth2", new OpenApiSecurityScheme
119116
{
120-
Type = "oauth2",
121-
Flow = "implicit",
122-
AuthorizationUrl = $"{Configuration.GetValue<string>("IdentityUrlExternal")}/connect/authorize",
123-
TokenUrl = $"{Configuration.GetValue<string>("IdentityUrlExternal")}/connect/token",
124-
Scopes = new Dictionary<string, string>()
117+
Type = SecuritySchemeType.OAuth2,
118+
Flows = new OpenApiOAuthFlows()
125119
{
126-
{ "locations", "Locations API" }
120+
Implicit = new OpenApiOAuthFlow()
121+
{
122+
AuthorizationUrl = new Uri($"{Configuration.GetValue<string>("IdentityUrlExternal")}/connect/authorize"),
123+
TokenUrl = new Uri($"{Configuration.GetValue<string>("IdentityUrlExternal")}/connect/token"),
124+
Scopes = new Dictionary<string, string>()
125+
{
126+
{ "locations", "Locations API" }
127+
}
128+
}
127129
}
128130
});
129131

@@ -204,12 +206,6 @@ private void RegisterAppInsights(IServiceCollection services)
204206
// Enable K8s telemetry initializer
205207
services.AddApplicationInsightsKubernetesEnricher();
206208
}
207-
if (orchestratorType?.ToUpper() == "SF")
208-
{
209-
// Enable SF telemetry initializer
210-
services.AddSingleton<ITelemetryInitializer>((serviceProvider) =>
211-
new FabricTelemetryInitializer());
212-
}
213209
}
214210

215211
private void ConfigureAuthService(IServiceCollection services)

src/_build/dependencies.props

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<NetStandardTargetVersion>netstandard2.1</NetStandardTargetVersion>
44
<NetCoreTargetVersion>netcoreapp3.0</NetCoreTargetVersion>
55
<MicrosoftNETTestSdkPackageVersion>15.8.0</MicrosoftNETTestSdkPackageVersion>
6-
<LangVersion>latest</LangVersion>
6+
<LangVersion>preview</LangVersion>
77
</PropertyGroup>
88

99
<PropertyGroup Label="Package Versions">
@@ -37,9 +37,11 @@
3737
<Microsoft_ApplicationInsights_DependencyCollector>2.6.1</Microsoft_ApplicationInsights_DependencyCollector>
3838
<Microsoft_ApplicationInsights_Kubernetes>1.0.2</Microsoft_ApplicationInsights_Kubernetes>
3939
<Microsoft_AspNetCore_Authentication_JwtBearer>3.0.0-preview6.19307.2</Microsoft_AspNetCore_Authentication_JwtBearer>
40+
<Microsoft_AspNetCore_Authentication_OpenIdConnect>3.0.0-preview6.19307.2</Microsoft_AspNetCore_Authentication_OpenIdConnect>
4041
<Microsoft_AspNetCore_Diagnostics_HealthChecks>2.2.0</Microsoft_AspNetCore_Diagnostics_HealthChecks>
4142
<Microsoft_AspNetCore_HealthChecks>1.0.0</Microsoft_AspNetCore_HealthChecks>
4243
<Microsoft_AspNetCore_Http_Abstractions>2.2.0</Microsoft_AspNetCore_Http_Abstractions>
44+
<Microsoft_AspNetCore_Mvc_Testing>3.0.0-preview6.19307.2</Microsoft_AspNetCore_Mvc_Testing>
4345
<Microsoft_AspNetCore_TestHost>3.0.0-preview6.19307.2</Microsoft_AspNetCore_TestHost>
4446
<Microsoft_Azure_ServiceBus>3.0.0</Microsoft_Azure_ServiceBus>
4547
<Microsoft_CSharp>4.5.0</Microsoft_CSharp>

0 commit comments

Comments
 (0)