Просмотр исходного кода

Fixed refresh token bug

pull/177/head
bronjaermin 3 лет назад
Родитель
Сommit
082897f548

+ 2
- 1
Diligent.WebAPI.Business/Services/AdService.cs Просмотреть файл

public async Task<List<AdResponseDto>> GetFilteredAdsAsync(AdFilterDto filters) public async Task<List<AdResponseDto>> GetFilteredAdsAsync(AdFilterDto filters)
{ {
_logger.LogInformation($"Start getting all filtered Ads"); _logger.LogInformation($"Start getting all filtered Ads");
var today = DateTime.Now;
_logger.LogInformation("Getting data from DB"); _logger.LogInformation("Getting data from DB");
var filteredAds = await _context.Ads.Include(x => x.Technologies).ToListAsync();
var filteredAds = await _context.Ads.Include(x => x.Technologies).Where(x => x.ExpiredAt > today).ToListAsync();
_logger.LogInformation($"Received {filteredAds.Count} ads from db."); _logger.LogInformation($"Received {filteredAds.Count} ads from db.");


_logger.LogInformation($"Mapping received ads to AdResponseDto"); _logger.LogInformation($"Mapping received ads to AdResponseDto");

+ 2
- 2
Diligent.WebAPI.Business/Services/AuthenticationService.cs Просмотреть файл

var expiryDateUnix = long.Parse(validatedToken.Claims.Single(x => x.Type == JwtRegisteredClaimNames.Exp).Value); var expiryDateUnix = long.Parse(validatedToken.Claims.Single(x => x.Type == JwtRegisteredClaimNames.Exp).Value);


var expiryDateTimeUtc = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc) var expiryDateTimeUtc = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)
.AddMinutes(expiryDateUnix);
.AddSeconds(expiryDateUnix);


if (expiryDateTimeUtc < DateTime.Now)
if (expiryDateTimeUtc > DateTime.UtcNow)
{ {
return new RefreshTokenResultDto return new RefreshTokenResultDto
{ {

+ 5
- 2
Diligent.WebAPI.Host/Middlewares/JwtMiddleware.cs Просмотреть файл

if (refreshToken == null) if (refreshToken == null)
return; return;


refreshToken.ExpiryDate = DateTime.Now.AddMinutes(30);
if(refreshToken.ExpiryDate > DateTime.Now)
{
refreshToken.ExpiryDate = DateTime.Now.AddMinutes(_authSettings.JwtRefreshExpiredTime);


await service.UpdateRefreshToken(refreshToken);
await service.UpdateRefreshToken(refreshToken);
}
} }
} }
} }

Загрузка…
Отмена
Сохранить