diff --git a/src/Services/Ordering/Ordering.API/Ordering.API.csproj b/src/Services/Ordering/Ordering.API/Ordering.API.csproj
index ce6a77ca6..4b02a4abd 100644
--- a/src/Services/Ordering/Ordering.API/Ordering.API.csproj
+++ b/src/Services/Ordering/Ordering.API/Ordering.API.csproj
@@ -36,32 +36,13 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
+
+
diff --git a/src/Services/Ordering/Ordering.API/Program.cs b/src/Services/Ordering/Ordering.API/Program.cs
index ba92a2da9..3ee6f6500 100644
--- a/src/Services/Ordering/Ordering.API/Program.cs
+++ b/src/Services/Ordering/Ordering.API/Program.cs
@@ -1,6 +1,5 @@
-using Microsoft.AspNetCore.Builder;
+using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
-using System.IO;
namespace Microsoft.eShopOnContainers.Services.Ordering.API
{
@@ -8,15 +7,12 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API
{
public static void Main(string[] args)
{
- var host = new WebHostBuilder()
- .UseKestrel()
- .UseHealthChecks("/hc")
- .UseContentRoot(Directory.GetCurrentDirectory())
- .UseIISIntegration()
+ BuildWebHost(args).Run();
+ }
+
+ public static IWebHost BuildWebHost(string[] args) =>
+ WebHost.CreateDefaultBuilder(args)
.UseStartup()
.Build();
-
- host.Run();
- }
}
}
diff --git a/src/Services/Ordering/Ordering.API/Startup.cs b/src/Services/Ordering/Ordering.API/Startup.cs
index 3f2bbe43b..c793a3950 100644
--- a/src/Services/Ordering/Ordering.API/Startup.cs
+++ b/src/Services/Ordering/Ordering.API/Startup.cs
@@ -11,6 +11,7 @@
using Infrastructure.AutofacModules;
using Infrastructure.Filters;
using Infrastructure.Services;
+ using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Azure.ServiceBus;
@@ -170,7 +171,7 @@
}
RegisterEventBus(services);
-
+ ConfigureAuthService(services);
services.AddOptions();
//configure autofac
@@ -225,22 +226,33 @@
eventBus.Subscribe>();
}
- protected virtual void ConfigureAuth(IApplicationBuilder app)
+ private void ConfigureAuthService(IServiceCollection services)
{
var identityUrl = Configuration.GetValue("IdentityUrl");
- app.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions
+
+ services.AddAuthentication(options =>
+ {
+ options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
+ options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
+
+ }).AddJwtBearer(options =>
{
- Authority = identityUrl.ToString(),
- ApiName = "orders",
- RequireHttpsMetadata = false
+ options.Authority = identityUrl;
+ options.RequireHttpsMetadata = false;
+ options.Audience = "orders";
});
}
+ protected virtual void ConfigureAuth(IApplicationBuilder app)
+ {
+ app.UseAuthentication();
+ }
+
private void RegisterEventBus(IServiceCollection services)
{
if (Configuration.GetValue("AzureServiceBusEnabled"))
{
- services.AddSingleton(sp =>
+ services.AddSingleton(sp =>
{
var serviceBusPersisterConnection = sp.GetRequiredService();
var iLifetimeScope = sp.GetRequiredService();
@@ -254,7 +266,7 @@
}
else
{
- services.AddSingleton();
+ services.AddSingleton();
}
services.AddSingleton();