From 9fe564d452af7d5023cc410cd26761ba05730dc3 Mon Sep 17 00:00:00 2001 From: transtrike Date: Sat, 12 Dec 2020 15:58:55 +0200 Subject: Last push cleanup --- API/Startup.cs | 45 +-------------------------------------------- 1 file changed, 1 insertion(+), 44 deletions(-) (limited to 'API/Startup.cs') diff --git a/API/Startup.cs b/API/Startup.cs index de108a5..100e2e2 100644 --- a/API/Startup.cs +++ b/API/Startup.cs @@ -5,17 +5,7 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; -using Microsoft.OpenApi.Models; -using Data.Models.Classes; -using Data.Models.Options; -using Microsoft.IdentityModel.Tokens; -using Microsoft.AspNetCore.Authentication.JwtBearer; -using System.Text; -using System.Threading.Tasks; using API.Extensions; -using API.Database; -using Microsoft.EntityFrameworkCore; -using Microsoft.AspNetCore.Identity; namespace API { @@ -33,41 +23,9 @@ namespace API { services.AddControllers(); - services.AddSingleton( - new JWTOptions(Configuration.GetSection("AppSettings").GetSection("Secret").Value)); - - // Get key from appsettings.json - var key = Encoding.ASCII.GetBytes(Configuration.GetSection("AppSettings").GetSection("Secret").Value); - // Setup Jwt Authentication - services.AddAuthentication(x => - { - x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; - x.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; - }) - .AddJwtBearer(x => - { - x.Events = new JwtBearerEvents - { - OnTokenValidated = context => - { - // TODO: add more authentication - return Task.CompletedTask; - } - }; - x.RequireHttpsMetadata = false; - x.SaveToken = true; - x.TokenValidationParameters = new TokenValidationParameters - { - ValidateIssuerSigningKey = true, - IssuerSigningKey = new SymmetricSecurityKey(key), - ValidateIssuer = false, - ValidateAudience = false - }; - }); - services.DatabaseConfiguration(Configuration); services.SwaggerConfiguration(); - services.JWTConfiguration(); + services.JWTConfiguration(Configuration); services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies()); } @@ -88,7 +46,6 @@ namespace API } app.UseDatabaseConfiguration(); - app.UseJWTConfiguration(); app.UseEndpoints(endpoints => { -- cgit v1.2.3