public async Task <IActionResult> RenewTokens([FromBody] AuthenticationTokens authenticationTokens) { int userId; try { userId = authenticationTokens.GetUserIdFromClaims(_configuration.GetSecretKey()); await _loggingService.SaveAuditLog($"Refreshing tokens for user with user id {userId}", AuditActionEnum.TokenRefresh); } catch (Exception) { return(BadRequest()); } var refreshToken = await RetrieveRefreshToken(authenticationTokens.RefreshToken, userId); if (refreshToken == null || !_authenticationService.IsRefreshTokenValid(refreshToken)) { return(BadRequest()); } var newTokens = await _authenticationService.GenerateTokens(userId); await _loggingService.SaveAuditLog($"Deleting old refresh token for user with user id {userId}", AuditActionEnum.Delete); await _authenticationRepository.DeleteToken(refreshToken); return(Ok(newTokens)); }