diff options
| author | Syndamia <kamen.d.mladenov@protonmail.com> | 2020-12-12 15:07:44 +0200 |
|---|---|---|
| committer | Syndamia <kamen.d.mladenov@protonmail.com> | 2020-12-12 15:07:44 +0200 |
| commit | e7912e18285f0381e66e78da948c0cd37a06fbd7 (patch) | |
| tree | cf68b2f7778a22c901604c86603b5455af63bc80 | |
| parent | 811ac5c6ea42174854cd525f0dee9ce6363ee739 (diff) | |
| parent | 8bd7295dc4694c1c0ed6fbc05d390223bfc4ef05 (diff) | |
| download | DevHive-e7912e18285f0381e66e78da948c0cd37a06fbd7.tar DevHive-e7912e18285f0381e66e78da948c0cd37a06fbd7.tar.gz DevHive-e7912e18285f0381e66e78da948c0cd37a06fbd7.zip | |
Merge branch 'dev' of github.com:Team-Kaleidoscope/DevHive into autorization-dev
| -rw-r--r-- | API/Controllers/ErrorController.cs | 2 | ||||
| -rw-r--r-- | API/Extensions/ConfigureDatabase.cs | 42 | ||||
| -rw-r--r-- | API/Extensions/ConfigureJWT.cs | 21 | ||||
| -rw-r--r-- | API/Extensions/ConfigureSwagger.cs | 23 | ||||
| -rw-r--r-- | API/Program.cs | 1 | ||||
| -rw-r--r-- | API/Startup.cs | 32 |
6 files changed, 105 insertions, 16 deletions
diff --git a/API/Controllers/ErrorController.cs b/API/Controllers/ErrorController.cs index 792d8cd..ffe2159 100644 --- a/API/Controllers/ErrorController.cs +++ b/API/Controllers/ErrorController.cs @@ -6,10 +6,10 @@ using Microsoft.AspNetCore.Mvc; namespace API.Controllers { [ApiController] + [Route("/api/[controller]")] public class ErrorController { [HttpGet] - [Route("HttpError")] public HttpStatusCode HttpError(HttpRequestException exception) { Console.WriteLine("WE HERE, BOIIIIIII"); diff --git a/API/Extensions/ConfigureDatabase.cs b/API/Extensions/ConfigureDatabase.cs new file mode 100644 index 0000000..57560e2 --- /dev/null +++ b/API/Extensions/ConfigureDatabase.cs @@ -0,0 +1,42 @@ +using Microsoft.Extensions.DependencyInjection; +using API.Database; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Configuration; +using Data.Models.Classes; +using Microsoft.AspNetCore.Identity; +using Microsoft.AspNetCore.Builder; + +namespace API.Extensions +{ + public static class DatabaseExtensions + { + public static void DatabaseConfiguration(this IServiceCollection services, IConfiguration configuration) + { + services.AddDbContext<DevHiveContext>(options => + options.UseNpgsql(configuration.GetConnectionString("DEV"))) + .AddAuthentication() + .AddJwtBearer(); + + services.AddIdentity<User, Roles>() + .AddEntityFrameworkStores<DevHiveContext>(); + + services.AddAuthentication(); + + services.Configure<IdentityOptions>(options => + { + options.User.RequireUniqueEmail = true; + + options.Password.RequiredLength = 5; + }); + } + + public static void UseDatabaseConfiguration(this IApplicationBuilder app) + { + app.UseHttpsRedirection(); + app.UseRouting(); + + app.UseAuthentication(); + app.UseAuthorization(); + } + } +}
\ No newline at end of file diff --git a/API/Extensions/ConfigureJWT.cs b/API/Extensions/ConfigureJWT.cs new file mode 100644 index 0000000..f5862f5 --- /dev/null +++ b/API/Extensions/ConfigureJWT.cs @@ -0,0 +1,21 @@ +using Microsoft.AspNetCore.Builder; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.OpenApi.Models; + +namespace API.Extensions +{ + public static class JWTExtensions + { + public static void JWTConfiguration(this IServiceCollection services) + { + + } + + public static void UseJWTConfiguration(this IApplicationBuilder app) + { + + + + } + } +}
\ No newline at end of file diff --git a/API/Extensions/ConfigureSwagger.cs b/API/Extensions/ConfigureSwagger.cs new file mode 100644 index 0000000..249eca0 --- /dev/null +++ b/API/Extensions/ConfigureSwagger.cs @@ -0,0 +1,23 @@ +using Microsoft.AspNetCore.Builder; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.OpenApi.Models; + +namespace API.Extensions +{ + public static class SwaggerExtensions + { + public static void SwaggerConfiguration(this IServiceCollection services) + { + services.AddSwaggerGen(c => + { + c.SwaggerDoc("v1", new OpenApiInfo { Title = "API", Version = "v1" }); + }); + } + + public static void UseSwaggerConfiguration(this IApplicationBuilder app) + { + app.UseSwagger(); + app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "API v1")); + } + } +}
\ No newline at end of file diff --git a/API/Program.cs b/API/Program.cs index eedd5e1..99ca6e6 100644 --- a/API/Program.cs +++ b/API/Program.cs @@ -17,7 +17,6 @@ namespace API .ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.ConfigureKestrel(opt => opt.ListenLocalhost(HTTPS_PORT));
-
webBuilder.UseStartup<Startup>();
});
}
diff --git a/API/Startup.cs b/API/Startup.cs index b58311d..49dd794 100644 --- a/API/Startup.cs +++ b/API/Startup.cs @@ -1,13 +1,11 @@ using System;
-using API.Database;
using AutoMapper;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
-using Microsoft.AspNetCore.Identity;
-using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
+<<<<<<< HEAD
using Microsoft.OpenApi.Models;
using Data.Models.Classes;
using Data.Models.Options;
@@ -15,6 +13,9 @@ using Microsoft.IdentityModel.Tokens; using Microsoft.AspNetCore.Authentication.JwtBearer;
using System.Text;
using System.Threading.Tasks;
+=======
+using API.Extensions;
+>>>>>>> 8bd7295dc4694c1c0ed6fbc05d390223bfc4ef05
namespace API
{
@@ -82,6 +83,10 @@ namespace API c.SwaggerDoc("v1", new OpenApiInfo { Title = "API", Version = "v1" });
});
+ services.DatabaseConfiguration(Configuration);
+ services.SwaggerConfiguration();
+ services.JWTConfiguration();
+
services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies());
}
@@ -90,25 +95,24 @@ namespace API {
if (env.IsDevelopment())
{
- //app.UseDeveloperExceptionPage();
- app.UseExceptionHandler("/api/Error"); //TESTING
- app.UseSwagger();
- app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "API v1"));
+ app.UseDeveloperExceptionPage();
+ //app.UseExceptionHandler("/api/HttpError");
+ app.UseSwaggerConfiguration();
}
else
{
- app.UseExceptionHandler("/Error");
+ app.UseExceptionHandler("/api/HttpError");
+ app.UseHsts();
}
- app.UseHttpsRedirection();
- app.UseRouting();
-
- app.UseAuthentication();
- app.UseAuthorization();
+ app.UseJWTConfiguration();
app.UseEndpoints(endpoints =>
{
- endpoints.MapControllers();
+ endpoints.MapControllerRoute(
+ name: "default",
+ pattern: "api/{controller}/{action}"
+ );
});
}
}
|
