public async Task <ActionResult> Logout() { try { string token = HttpContext.Request.Headers["authorization"].Single().Split(" ")[1]; if (!(await _repository.ValidateToken(token))) { return(Unauthorized()); } InvalidToken invalidToken = new InvalidToken(); var identity = HttpContext.User.Identity as ClaimsIdentity; IList <Claim> claim = identity.Claims.ToList(); DateTime expirationDate = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc); expirationDate = expirationDate.AddSeconds(Double.Parse(claim[3].Value)).ToLocalTime(); invalidToken.userId = Int32.Parse(claim[0].Value); invalidToken.expirationDate = expirationDate; invalidToken.token = token; await _repository.CreateInvalidToken(invalidToken); await _repository.SaveChanges(); return(Ok()); } catch (Exception) { return(new StatusCodeResult(StatusCodes.Status500InternalServerError)); } }