public async Task <IActionResult> Post([FromBody] LoginCredentials request) { if (request.UserName == string.Empty || request.Password == string.Empty) { return(Forbid("Login Failed")); } return(Ok(await _tokenService.AuthenticateAsync(request))); }
public async Task <IActionResult> AuthenticateAsync([FromBody] Account userParam) { var userToken = await _tokenService.AuthenticateAsync(userParam.Username, userParam.Password).ConfigureAwait(false); if (userToken == null) { return(BadRequest(new { message = "Username or password is incorrect." })); } return(Ok(userToken)); }
public async Task <IActionResult> CreateToken([FromBody] LoginModel model) { return(await OnActionWorkAsync(async() => { User user = await _tokenService.AuthenticateAsync(model); if (user == null) { throw new UnauthorizedException(); } var tokenString = await _tokenService.BuildTokenAsync(user); return Ok(new { token = tokenString }); })); }
public async Task <IActionResult> Login([FromBody] TokenAuthRequest model) { return(await OnActionAsync(async() => { _logger.LogInformation($"Executing TokenController.Login with values {model}"); var user = await _tokenService.AuthenticateAsync(model.Username, model.Password); if (user == null) { throw new BadRequestException("Username or Password is invalid"); } return Ok(user); })); }