Updated the Login code so it responds with a set-cookie header for the session token. Still looking into if this is the right thing to do however.
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System;
|
||||
using System.Web;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
@@ -15,8 +17,19 @@ namespace SecureCore.Controllers
|
||||
public IActionResult Login(LoginInfo info)
|
||||
{
|
||||
var (hash, salt) = Authentication.HashPassword(info.Password);
|
||||
var options = new CookieOptions
|
||||
{
|
||||
Domain = "copyrightcrusader.org",
|
||||
Expires = DateTime.Now.AddDays(7),
|
||||
HttpOnly = true,
|
||||
Secure = true,
|
||||
Path = "/",
|
||||
SameSite = SameSiteMode.Strict
|
||||
};
|
||||
|
||||
return Ok($"Session Key: {Authentication.CreateSessionId()}{Environment.NewLine}Password Hash: {hash}{Environment.NewLine}Salt: {salt}{Environment.NewLine}");
|
||||
HttpContext.Response.Cookies.Append("Session", Authentication.CreateSessionToken(), options);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,15 +33,6 @@ namespace SecureCore.Controllers
|
||||
{
|
||||
return Ok(DataService.GetById(id));
|
||||
}
|
||||
|
||||
//[HttpPost("login")]
|
||||
//[AcceptVerbs("POST")]
|
||||
//public IActionResult Login(LoginInfo info)
|
||||
//{
|
||||
// var (Hash, Salt) = Auth.HashPassword(info.Password);
|
||||
|
||||
// return Ok($"Session Key: {Auth.CreateSessionId()}{Environment.NewLine}Password Hash: {Hash}{Environment.NewLine}Salt: {Salt}{Environment.NewLine}");
|
||||
//}
|
||||
}
|
||||
|
||||
public class AuthenticatedUser
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SecureCore.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("[controller]")]
|
||||
public class WeatherForecastController : ControllerBase
|
||||
{
|
||||
private static readonly string[] Summaries = new[]
|
||||
{
|
||||
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
|
||||
};
|
||||
|
||||
private readonly ILogger<WeatherForecastController> _logger;
|
||||
|
||||
public WeatherForecastController(ILogger<WeatherForecastController> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IEnumerable<WeatherForecast> Get()
|
||||
{
|
||||
var rng = new Random();
|
||||
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
|
||||
{
|
||||
Date = DateTime.Now.AddDays(index),
|
||||
TemperatureC = rng.Next(-20, 55),
|
||||
Summary = Summaries[rng.Next(Summaries.Length)]
|
||||
})
|
||||
.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user