public Task <SwaggerResponse <AuthResponse> > AuthenticateAsync(CredentialDto credentials) { var headers = new Dictionary <string, IEnumerable <string> >(); try { var authResponse = _appUser.Authenticate(credentials); return(Task.FromResult( new SwaggerResponse <AuthResponse>( StatusCodes.Status200OK, headers, new AuthResponse { Token = authResponse.authToken, ValidFor = authResponse.expiresIn, Id = authResponse.id, Refreshtoken = authResponse.refreshToken, Status = new OpResult { Success = true, Result = "Authentication successful" } }))); } catch (RepositoryException exception) { return(Task.FromResult( new SwaggerResponse <AuthResponse>( exception.StatusCode, headers, new AuthResponse { Token = "", Status = new OpResult { Success = false, Result = "Authentication failed" } }, exception.Message))); } }
public IActionResult RequestToken([FromBody] UserLogin login) { IActionResult response = Unauthorized(); var user = AppUser.Authenticate(login); if (user != null) { var tokenString = BuildToken(user); response = Ok(new { token = tokenString }); } return(response); }