private async Task <OAuthAccessToken> GetTokenFromServiceUsingRefreshTokenAsync(OAuthAccessToken token) { try { _logger.Debug($"Refreshing token (expired {token.ExpiresAt})"); var oneTimePassword = await GetOneTimePassword(); var newToken = await _executionPolicy.ExecuteAsync(async() => await _tokenService.GetAccessTokenFromRefreshToken(oneTimePassword, token.RefreshToken)); _logger.Debug($"Refresh token successful (new expiry {newToken?.ExpiresAt.ToString("yy-MMM-dd ddd HH:mm:ss") ?? "not available - new token is null"})"); return(newToken); } catch (Exception ex) { _logger.Warn(ex, $"Error trying to refresh access token - {ex.Message}"); return(null); } }
private async Task <OAuthAccessToken> GetTokenFromServiceUsingRefreshToken(string refreshToken) { try { _logger.Debug("Attempting to get privileged access token from service using refresh token"); var secret = await _secretRepository.GetSecretAsync(PrivilegedAccessSecretName); var totp = _totpService.Generate(secret); var token = await _tokenService.GetAccessTokenFromRefreshToken(totp, refreshToken); _logger.Debug("Got privileged access token from service using refresh token"); return(token); } catch (Exception ex) { _logger.Warn(ex, $"Error trying to refresh access token - {ex.Message}"); return(null); } }