DotNetCore 2.1 -> 2.0
Certificate Kettel instead of IISExpress
This commit is contained in:
@@ -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<IEnumerable<Game>> Get()
|
||||
public List<Game> Get()
|
||||
{
|
||||
|
||||
return _db.Game.ToList();
|
||||
|
||||
@@ -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[]
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp2.1</TargetFramework>
|
||||
<TargetFramework>netcoreapp2.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@@ -9,7 +9,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.App" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.9" />
|
||||
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="2.1.2" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -17,4 +17,10 @@
|
||||
<ProjectReference Include="..\LaDOSE.Entity\LaDOSE.Entity.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="localhost.pfx">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -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<string>("filename");
|
||||
string certificatePassword = certificateSettings.GetValue<string>("password");
|
||||
|
||||
X509Certificate2 certificate = new X509Certificate2(certificateFileName, certificatePassword);
|
||||
CreateWebHostBuilder(certificate,args).Build().Run();
|
||||
}
|
||||
|
||||
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
|
||||
WebHost.CreateDefaultBuilder(args)
|
||||
.UseStartup<Startup>();
|
||||
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<Startup>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<LaDOSEDbContext>( // 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();
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp2.1</TargetFramework>
|
||||
<TargetFramework>netcoreapp2.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp2.1</TargetFramework>
|
||||
<TargetFramework>netcoreapp2.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user