diff --git a/LaDOSE.Src/LaDOSE.Api/Controllers/GameController.cs b/LaDOSE.Src/LaDOSE.Api/Controllers/GameController.cs index 2fcc707..aeb53cd 100644 --- a/LaDOSE.Src/LaDOSE.Api/Controllers/GameController.cs +++ b/LaDOSE.Src/LaDOSE.Api/Controllers/GameController.cs @@ -11,7 +11,7 @@ namespace LaDOSE.Api.Controllers { [Authorize] [Route("api/[controller]")] - [ApiController] + [Produces("application/json")] public class GameController : ControllerBase { @@ -23,7 +23,7 @@ namespace LaDOSE.Api.Controllers } // GET api/Config [HttpGet] - public ActionResult> Get() + public List Get() { return _db.Game.ToList(); diff --git a/LaDOSE.Src/LaDOSE.Api/Controllers/UsersController.cs b/LaDOSE.Src/LaDOSE.Api/Controllers/UsersController.cs index 865c573..28d6958 100644 --- a/LaDOSE.Src/LaDOSE.Api/Controllers/UsersController.cs +++ b/LaDOSE.Src/LaDOSE.Api/Controllers/UsersController.cs @@ -9,25 +9,27 @@ using LaDOSE.Api.Services; using LaDOSE.Entity; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Options; using Microsoft.IdentityModel.Tokens; namespace LaDOSE.Api.Controllers { [Authorize] - [ApiController] + [Produces("application/json")] [Route("[controller]")] public class UsersController : ControllerBase { private IUserService _userService; - + private readonly IConfiguration _configuration; public UsersController( - IUserService userService + IUserService userService, + IConfiguration configuration ) { _userService = userService; - + _configuration = configuration; } [AllowAnonymous] @@ -56,7 +58,7 @@ namespace LaDOSE.Api.Controllers return BadRequest(new { message = "Username or password is incorrect" }); var tokenHandler = new JwtSecurityTokenHandler(); - var key = Encoding.ASCII.GetBytes("this is my custom Secret key for authnetication"); + var key = Encoding.ASCII.GetBytes(this._configuration["JWTTokenSecret"]); var tokenDescriptor = new SecurityTokenDescriptor { Subject = new ClaimsIdentity(new Claim[] diff --git a/LaDOSE.Src/LaDOSE.Api/LaDOSE.Api.csproj b/LaDOSE.Src/LaDOSE.Api/LaDOSE.Api.csproj index 15e1856..343ba8b 100644 --- a/LaDOSE.Src/LaDOSE.Api/LaDOSE.Api.csproj +++ b/LaDOSE.Src/LaDOSE.Api/LaDOSE.Api.csproj @@ -1,7 +1,7 @@ - + - netcoreapp2.1 + netcoreapp2.0 @@ -9,7 +9,7 @@ - + @@ -17,4 +17,10 @@ + + + Always + + + diff --git a/LaDOSE.Src/LaDOSE.Api/Program.cs b/LaDOSE.Src/LaDOSE.Api/Program.cs index d2745c2..5a2dcad 100644 --- a/LaDOSE.Src/LaDOSE.Api/Program.cs +++ b/LaDOSE.Src/LaDOSE.Api/Program.cs @@ -2,6 +2,8 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Net; +using System.Security.Cryptography.X509Certificates; using System.Threading.Tasks; using Microsoft.AspNetCore; using Microsoft.AspNetCore.Hosting; @@ -12,13 +14,30 @@ namespace LaDOSE.Api { public class Program { + public static IConfiguration config { get; private set; } + public static void Main(string[] args) { - CreateWebHostBuilder(args).Build().Run(); + + + config = new ConfigurationBuilder() + .SetBasePath(Directory.GetCurrentDirectory()) + .AddJsonFile("appSettings.json", optional: true, reloadOnChange: true) + .Build(); + var certificateSettings = config.GetSection("certificateSettings"); + string certificateFileName = certificateSettings.GetValue("filename"); + string certificatePassword = certificateSettings.GetValue("password"); + + X509Certificate2 certificate = new X509Certificate2(certificateFileName, certificatePassword); + CreateWebHostBuilder(certificate,args).Build().Run(); } - public static IWebHostBuilder CreateWebHostBuilder(string[] args) => - WebHost.CreateDefaultBuilder(args) - .UseStartup(); + public static IWebHostBuilder CreateWebHostBuilder(X509Certificate2 certificate, string[] args) + { + return WebHost.CreateDefaultBuilder(args) + .UseConfiguration(config) + .UseKestrel(options => options.Listen(IPAddress.Loopback,int.Parse(config["Port"]),config=> config.UseHttps(certificate))) + .UseStartup(); + } } } diff --git a/LaDOSE.Src/LaDOSE.Api/Startup.cs b/LaDOSE.Src/LaDOSE.Api/Startup.cs index f169ca2..1f08ad9 100644 --- a/LaDOSE.Src/LaDOSE.Api/Startup.cs +++ b/LaDOSE.Src/LaDOSE.Api/Startup.cs @@ -9,7 +9,7 @@ using LaDOSE.Entity; using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.HttpsPolicy; +//using Microsoft.AspNetCore.HttpsPolicy; using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; @@ -36,7 +36,7 @@ namespace LaDOSE.Api public void ConfigureServices(IServiceCollection services) { services.AddCors(); - services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); + services.AddMvc(); services.AddDbContextPool( // replace "YourDbContext" with the class name of your DbContext options => options.UseMySql("Server=localhost;Database=ladose;User=root;Password=;", // replace with your Connection String mysqlOptions => @@ -45,7 +45,7 @@ namespace LaDOSE.Api } )); - var key = Encoding.ASCII.GetBytes("this is my custom Secret key for authnetication"); + var key = Encoding.ASCII.GetBytes(this.Configuration["JWTTokenSecret"]); services.AddAuthentication(x => { x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; @@ -95,17 +95,14 @@ namespace LaDOSE.Api { app.UseDeveloperExceptionPage(); } - else - { - app.UseHsts(); - } + app.UseCors(x => x .AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader() .AllowCredentials()); - app.UseHttpsRedirection(); + //app.UseHttpsRedirection(); app.UseAuthentication(); app.UseMvc(); } diff --git a/LaDOSE.Src/LaDOSE.Api/appsettings.json b/LaDOSE.Src/LaDOSE.Api/appsettings.json index def9159..d3c07c5 100644 --- a/LaDOSE.Src/LaDOSE.Api/appsettings.json +++ b/LaDOSE.Src/LaDOSE.Api/appsettings.json @@ -4,5 +4,11 @@ "Default": "Warning" } }, - "AllowedHosts": "*" + "certificateSettings": { + "fileName": "localhost.pfx", + "password": "YourSecurePassword" + }, + "AllowedHosts": "*", + "Port": 5000, + "JWTTokenSecret": "here goes the custom Secret key for authnetication" } diff --git a/LaDOSE.Src/LaDOSE.DiscordBot/LaDOSE.DiscordBot.csproj b/LaDOSE.Src/LaDOSE.DiscordBot/LaDOSE.DiscordBot.csproj index bcf31fd..2c13af2 100644 --- a/LaDOSE.Src/LaDOSE.DiscordBot/LaDOSE.DiscordBot.csproj +++ b/LaDOSE.Src/LaDOSE.DiscordBot/LaDOSE.DiscordBot.csproj @@ -2,7 +2,7 @@ Exe - netcoreapp2.1 + netcoreapp2.0 diff --git a/LaDOSE.Src/LaDOSE.DiscordBot/Program.cs b/LaDOSE.Src/LaDOSE.DiscordBot/Program.cs index d63d37f..4abc574 100644 --- a/LaDOSE.Src/LaDOSE.DiscordBot/Program.cs +++ b/LaDOSE.Src/LaDOSE.DiscordBot/Program.cs @@ -24,6 +24,7 @@ namespace LaDOSE.DiscordBot static async Task MainAsync(string[] args) { + Console.WriteLine(Directory.GetCurrentDirectory()); var builder = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("settings.json", optional: true, reloadOnChange: true).Build(); diff --git a/LaDOSE.Src/LaDOSE.Entity/LaDOSE.Entity.csproj b/LaDOSE.Src/LaDOSE.Entity/LaDOSE.Entity.csproj index 86ea3bb..5766db6 100644 --- a/LaDOSE.Src/LaDOSE.Entity/LaDOSE.Entity.csproj +++ b/LaDOSE.Src/LaDOSE.Entity/LaDOSE.Entity.csproj @@ -1,7 +1,7 @@ - netcoreapp2.1 + netcoreapp2.0 diff --git a/LaDOSE.Src/LaDOSE.sln b/LaDOSE.Src/LaDOSE.sln index 728de3e..9f51940 100644 --- a/LaDOSE.Src/LaDOSE.sln +++ b/LaDOSE.Src/LaDOSE.sln @@ -7,7 +7,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LaDOSE.DiscordBot", "LaDOSE EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LaDOSE.Api", "LaDOSE.Api\LaDOSE.Api.csproj", "{4D7ED4CC-F78F-4860-B8CE-DA01DCACCBB9}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LaDOSE.Entity", "LaDOSE.Entity\LaDOSE.Entity.csproj", "{B32A4AD5-9A4B-4D12-AAD5-55541F170E2A}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LaDOSE.Entity", "LaDOSE.Entity\LaDOSE.Entity.csproj", "{B32A4AD5-9A4B-4D12-AAD5-55541F170E2A}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/Library/ChallongeCSharpDriver.dll b/Library/ChallongeCSharpDriver.dll index ad6a5f3..0e1f2b5 100644 Binary files a/Library/ChallongeCSharpDriver.dll and b/Library/ChallongeCSharpDriver.dll differ