public async Task <IActionResult> Authenticate([FromBody] LoginViewModel loginViewModel) { try { var user = await _usersService.Authenticate(loginViewModel); if (user == null) { return(BadRequest(new { message = "Username or password is incorrect" })); } HttpContext.User = await _applicationSignInManager.CreateUserPrincipalAsync(user); var tokens = _antiforgery.GetAndStoreTokens(HttpContext); Response.Headers.Add("Access-Control-Expose-Headers", "XSRF-REQUEST-TOKEN"); Response.Headers.Add("XSRF-REQUEST-TOKEN", tokens.RequestToken); _logger.LogInformation($"{Environment.NewLine} Authenticate function"); return(Ok(user)); } catch (Exception ex) { _logger.LogError($"{Environment.NewLine} {ex.Message}"); throw; } }
public async Task <IActionResult> Authenticate([FromBody] LoginViewModel loginViewModel) { var user = await _usersService.Authenticate(loginViewModel); if (user == null) { return(BadRequest(new { message = "Username or password is incorrect" })); } HttpContext.User = await _applicationSignInManager.CreateUserPrincipalAsync(user); var tokens = _antiforgery.GetAndStoreTokens(HttpContext); Response.Headers.Add("Access-Control-Expose-Headers", "XSRF-REQUEST-TOKEN"); Response.Headers.Add("XSRF-REQUEST-TOKEN", tokens.RequestToken); return(Ok(user)); }