AuthController - Authenticate action
[HttpPost("authenticate")]
public async Task<ActionResult<Login>> Authenticate([FromBody] Login login)
{
// login will come in from the device with basic auth
var c = 0;
string token = string.Empty;
try
{
bool isAuth = _unitOfWork.Logins.GetAuthenticateUser(username, password);
if(isAuth == false)
{
var msg = "Authentication Failed";
login.Message = msg;
return new JsonResult(login);
}
Jwt j = new Jwt(_unitOfWork);
try
{
login.Token = j.CreateToken(username);
SessionModel session = new SessionModel();
session.SessionStart = DateTime.Now;
login.SessionStart = session.SessionStart;
session.UserName = username;
session.Token = login.Token;
await _unitOfWork.Sessions.AddAsync(session);
}
catch (Exception ex)
{
//delete session if there is jwt error
var msg = $"Error message from create token - Inner Exception: {ex.InnerException} Exception Message: {ex.Message} Source: {ex.Source}";
return UnAuthorized;
}
}
catch (Exception ex)
{
var msg = $"Error message from Header Auth decode - Inner Exception: {ex.InnerException} Exception Message: {ex.Message} Source: {ex.Source}";
login.Message = msg;
return new JsonResult(login);
}
//return login obj with token, msg, session datetime
return new JsonResult(login);
}
The above code all runs as expected until it reached the line at the end
return new JsonResult(login);
At that point Visual Studio exits debugging in IIS Express without warning or error.
I am testing the api with Postman.
When I execute in Postman, I get a status 200 but I do not get the expected Json result. That is at the point where Visual Studio drops out and terminates the debugging session.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…