From 4a5335effef971978cbd295e36738d849462a48f Mon Sep 17 00:00:00 2001 From: Scytlee Date: Sun, 23 Aug 2020 11:18:04 +0200 Subject: [PATCH 1/2] Add Auth0 --- src/Application/Application.csproj | 2 ++ src/Application/Startup.cs | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/Application/Application.csproj b/src/Application/Application.csproj index fa7d7f0..c2fcb36 100644 --- a/src/Application/Application.csproj +++ b/src/Application/Application.csproj @@ -12,7 +12,9 @@ + + diff --git a/src/Application/Startup.cs b/src/Application/Startup.cs index 662b44b..932477c 100644 --- a/src/Application/Startup.cs +++ b/src/Application/Startup.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Threading.Tasks; using Application.Infrastructure; +using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.HttpsPolicy; @@ -32,6 +33,17 @@ public void ConfigureServices(IServiceCollection services) services.AddSpaStaticFiles(options => options.RootPath = "ClientApp/build"); services.AddInfrastructure(Configuration); + + services.AddAuthentication(options => + { + options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; + options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; + }) + .AddJwtBearer(options => + { + options.Authority = "https://broad-sun-6187.eu.auth0.com/"; + options.Audience = "http://pre-hacknarock.herokuapp.com/api/"; + }); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. @@ -63,6 +75,13 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env) spa.UseReactDevelopmentServer("start"); } }); + + app.UseAuthentication(); + + app.UseMvc(routes => + { + routes.MapRoute(name: "default", template: "{controller=Home}/{action=Index}/{id?}"); + }); } } } From db0d43173d1cc4695662ef1b6350bf1a681dd2c1 Mon Sep 17 00:00:00 2001 From: Scytlee Date: Sun, 23 Aug 2020 11:50:43 +0200 Subject: [PATCH 2/2] Remove UseMvc and move UseAuthentication higher --- src/Application/Startup.cs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/Application/Startup.cs b/src/Application/Startup.cs index 932477c..6df80d4 100644 --- a/src/Application/Startup.cs +++ b/src/Application/Startup.cs @@ -58,6 +58,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env) app.UseRouting(); + app.UseAuthentication(); app.UseAuthorization(); app.UseEndpoints(endpoints => @@ -75,13 +76,6 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env) spa.UseReactDevelopmentServer("start"); } }); - - app.UseAuthentication(); - - app.UseMvc(routes => - { - routes.MapRoute(name: "default", template: "{controller=Home}/{action=Index}/{id?}"); - }); } } }