public async Task AddUserTokenStorageAsync(UserTokenStorage userTokenStorage) { if (!_bearerTokensOptions.AllowMultipleLoginsFromTheSameUser) { await InvalidateUserTokenStoragesAsync(userTokenStorage.UserId); } await DeleteTokensWithSameRefreshTokenSourceAsync(userTokenStorage.RefreshTokenIdHashSource); _userTokenStorages.Add(userTokenStorage); }
public async Task AddUserTokenStorageAsync(User user, string refreshTokenSerial, string accessToken, string refreshTokenSourceSerial) { var now = DateTimeOffset.UtcNow; var token = new UserTokenStorage { UserId = user.Id, // Refresh token handles should be treated as secrets and should be stored hashed RefreshTokenIdHash = _securityService.GetSha256Hash(refreshTokenSerial), RefreshTokenIdHashSource = string.IsNullOrWhiteSpace(refreshTokenSourceSerial) ? null : _securityService.GetSha256Hash(refreshTokenSourceSerial), AccessTokenHash = _securityService.GetSha256Hash(accessToken), RefreshTokenExpiresDateTimeOn = now.AddMinutes(_bearerTokensOptions.RefreshTokenExpirationMinutes), AccessTokenExpiresDateTimeOn = now.AddMinutes(_bearerTokensOptions.AccessTokenExpirationMinutes) }; await AddUserTokenStorageAsync(token); }