aboutsummaryrefslogtreecommitdiff
path: root/src/Web/DevHive.Web/Configurations/Extensions
diff options
context:
space:
mode:
authorSyndamia <kamen.d.mladenov@protonmail.com>2021-03-13 15:07:51 +0200
committerSyndamia <kamen.d.mladenov@protonmail.com>2021-03-13 15:07:51 +0200
commit75d57f305f2ed1ecf8b82bd62d4bb8f17c06303b (patch)
treeb721fe307d22a7a89f8ee13b3e557df4a2e2bbab /src/Web/DevHive.Web/Configurations/Extensions
parent503a23c04355624b133161c9356b139f2e4500f6 (diff)
parent4add0831649f6e534d3883aa0e0e7f380d8042c7 (diff)
downloadDevHive-75d57f305f2ed1ecf8b82bd62d4bb8f17c06303b.tar
DevHive-75d57f305f2ed1ecf8b82bd62d4bb8f17c06303b.tar.gz
DevHive-75d57f305f2ed1ecf8b82bd62d4bb8f17c06303b.zip
Merge branch 'dev' of github.com:Team-Kaleidoscope/DevHive into unit_test_refactoring
Diffstat (limited to 'src/Web/DevHive.Web/Configurations/Extensions')
-rw-r--r--src/Web/DevHive.Web/Configurations/Extensions/ConfigureAutoMapper.cs3
-rw-r--r--src/Web/DevHive.Web/Configurations/Extensions/ConfigureDependencyInjection.cs13
-rw-r--r--src/Web/DevHive.Web/Configurations/Extensions/ConfigureJwt.cs14
-rw-r--r--src/Web/DevHive.Web/Configurations/Extensions/ConfigureSwagger.cs54
4 files changed, 67 insertions, 17 deletions
diff --git a/src/Web/DevHive.Web/Configurations/Extensions/ConfigureAutoMapper.cs b/src/Web/DevHive.Web/Configurations/Extensions/ConfigureAutoMapper.cs
index 0b8194e..cd5679f 100644
--- a/src/Web/DevHive.Web/Configurations/Extensions/ConfigureAutoMapper.cs
+++ b/src/Web/DevHive.Web/Configurations/Extensions/ConfigureAutoMapper.cs
@@ -1,4 +1,7 @@
using System;
+using System.Linq;
+using System.Reflection;
+using System.Reflection.Emit;
using AutoMapper;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
diff --git a/src/Web/DevHive.Web/Configurations/Extensions/ConfigureDependencyInjection.cs b/src/Web/DevHive.Web/Configurations/Extensions/ConfigureDependencyInjection.cs
index c547951..a0d0979 100644
--- a/src/Web/DevHive.Web/Configurations/Extensions/ConfigureDependencyInjection.cs
+++ b/src/Web/DevHive.Web/Configurations/Extensions/ConfigureDependencyInjection.cs
@@ -1,3 +1,6 @@
+using System.Text;
+using DevHive.Common.Jwt;
+using DevHive.Common.Jwt.Interfaces;
using DevHive.Data.Interfaces;
using DevHive.Data.Repositories;
using DevHive.Services.Interfaces;
@@ -27,12 +30,20 @@ namespace DevHive.Web.Configurations.Extensions
services.AddTransient<IPostService, PostService>();
services.AddTransient<ICommentService, CommentService>();
services.AddTransient<IFeedService, FeedService>();
+ services.AddTransient<IRatingService, RatingService>();
+
services.AddTransient<ICloudService, CloudinaryService>(options =>
new CloudinaryService(
cloudName: configuration.GetSection("Cloud").GetSection("cloudName").Value,
apiKey: configuration.GetSection("Cloud").GetSection("apiKey").Value,
apiSecret: configuration.GetSection("Cloud").GetSection("apiSecret").Value));
- services.AddTransient<IRateService, RateService>();
+
+ services.AddSingleton<IJwtService, JwtService>(options =>
+ new JwtService(
+ signingKey: Encoding.ASCII.GetBytes(configuration.GetSection("Jwt").GetSection("signingKey").Value),
+ validationIssuer: configuration.GetSection("Jwt").GetSection("validationIssuer").Value,
+ audience: configuration.GetSection("Jwt").GetSection("audience").Value));
+ services.AddTransient<IRatingService, RatingService>();
}
}
}
diff --git a/src/Web/DevHive.Web/Configurations/Extensions/ConfigureJwt.cs b/src/Web/DevHive.Web/Configurations/Extensions/ConfigureJwt.cs
index 8d387bd..18127bc 100644
--- a/src/Web/DevHive.Web/Configurations/Extensions/ConfigureJwt.cs
+++ b/src/Web/DevHive.Web/Configurations/Extensions/ConfigureJwt.cs
@@ -1,6 +1,5 @@
using System.Text;
using System.Threading.Tasks;
-using DevHive.Services.Options;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
@@ -12,15 +11,10 @@ namespace DevHive.Web.Configurations.Extensions
{
public static void JWTConfiguration(this IServiceCollection services, IConfiguration configuration)
{
- 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")
+ var signingKey = Encoding.ASCII.GetBytes(configuration
+ .GetSection("Jwt")
+ .GetSection("signingKey")
.Value);
// Setup Jwt Authentication
@@ -42,7 +36,7 @@ namespace DevHive.Web.Configurations.Extensions
x.SaveToken = true;
x.TokenValidationParameters = new TokenValidationParameters
{
- IssuerSigningKey = new SymmetricSecurityKey(key),
+ IssuerSigningKey = new SymmetricSecurityKey(signingKey),
ValidateIssuer = false,
ValidateAudience = false
};
diff --git a/src/Web/DevHive.Web/Configurations/Extensions/ConfigureSwagger.cs b/src/Web/DevHive.Web/Configurations/Extensions/ConfigureSwagger.cs
index a0641ab..9387561 100644
--- a/src/Web/DevHive.Web/Configurations/Extensions/ConfigureSwagger.cs
+++ b/src/Web/DevHive.Web/Configurations/Extensions/ConfigureSwagger.cs
@@ -1,23 +1,65 @@
+using System.Linq;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
-using Microsoft.OpenApi.Models;
+using NSwag;
+using NSwag.Generation.Processors.Security;
namespace DevHive.Web.Configurations.Extensions
{
public static class SwaggerExtensions
{
+#pragma warning disable S1075
+ private const string LicenseName = "GPL-3.0 License";
+ private const string LicenseUri = "https://github.com/Team-Kaleidoscope/DevHive/blob/main/LICENSE";
+ private const string TermsOfServiceUri = "https://example.com/terms";
+#pragma warning restore S1075
+
public static void SwaggerConfiguration(this IServiceCollection services)
{
- services.AddSwaggerGen(c =>
+ services.AddOpenApiDocument(c =>
{
- c.SwaggerDoc("v1", new OpenApiInfo { Title = "API", Version = "v1" });
+ c.GenerateXmlObjects = true;
+ c.UseControllerSummaryAsTagDescription = true;
+
+ c.AllowNullableBodyParameters = false;
+ c.Description = "DevHive Social Media's API Endpoints";
+
+ c.PostProcess = doc =>
+ {
+ doc.Info.Version = "v0.1";
+ doc.Info.Title = "API";
+ doc.Info.Description = "DevHive Social Media's first official API release";
+ doc.Info.TermsOfService = TermsOfServiceUri;
+ doc.Info.License = new NSwag.OpenApiLicense
+ {
+ Name = LicenseName,
+ Url = LicenseUri
+ };
+ };
+
+ c.AddSecurity("Bearer", Enumerable.Empty<string>(), new OpenApiSecurityScheme
+ {
+ Type = OpenApiSecuritySchemeType.ApiKey,
+ Name = "Authorization",
+ In = OpenApiSecurityApiKeyLocation.Header,
+ Description = "Type into the textbox: Bearer {your JWT token}."
+ });
+ c.OperationProcessors.Add(new AspNetCoreOperationSecurityScopeProcessor("Bearer"));
});
}
public static void UseSwaggerConfiguration(this IApplicationBuilder app)
{
- app.UseSwagger();
- app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "API v1"));
+ app.UseOpenApi(c =>
+ {
+ c.DocumentName = "v0.1";
+ });
+ app.UseSwaggerUi3(c =>
+ {
+ c.DocumentTitle = "DevHive API";
+ c.EnableTryItOut = false;
+ c.DocExpansion = "list";
+ });
}
}
-} \ No newline at end of file
+}