require a valid access token and expiry to attempt refresh

This commit is contained in:
Stephen Birarda 2017-05-24 13:16:26 -07:00
parent f9c6cecb23
commit 14ff6a06b4

View file

@ -193,7 +193,6 @@ void AccountManager::setAuthURL(const QUrl& authURL) {
// prepare to refresh our token if it is about to expire
if (needsToRefreshToken()) {
qCDebug(networking) << "Refreshing access token since it will be expiring soon.";
refreshAccessToken();
}
@ -457,7 +456,6 @@ bool AccountManager::hasValidAccessToken() {
} else {
if (!_isWaitingForTokenRefresh && needsToRefreshToken()) {
qCDebug(networking) << "Refreshing access token since it will be expiring soon.";
refreshAccessToken();
}
@ -477,7 +475,7 @@ bool AccountManager::checkAndSignalForAccessToken() {
}
bool AccountManager::needsToRefreshToken() {
if (!_accountInfo.getAccessToken().token.isEmpty()) {
if (!_accountInfo.getAccessToken().token.isEmpty() && _accountInfo.getAccessToken().expiryTimestamp > 0) {
qlonglong expireThreshold = QDateTime::currentDateTime().addSecs(1 * 60 * 60).toMSecsSinceEpoch();
return _accountInfo.getAccessToken().expiryTimestamp < expireThreshold;
} else {
@ -555,6 +553,10 @@ void AccountManager::requestAccessTokenWithSteam(QByteArray authSessionTicket) {
void AccountManager::refreshAccessToken() {
// we can't refresh our access token if we don't have a refresh token, so check for that first
if (!_accountInfo.getAccessToken().refreshToken.isEmpty()) {
qCDebug(networking) << "Refreshing access token since it will be expiring soon.";
_isWaitingForTokenRefresh = true;
QNetworkAccessManager& networkAccessManager = NetworkAccessManager::getInstance();
@ -578,6 +580,7 @@ void AccountManager::refreshAccessToken() {
connect(requestReply, &QNetworkReply::finished, this, &AccountManager::refreshAccessTokenFinished);
connect(requestReply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(refreshAccessTokenError(QNetworkReply::NetworkError)));
}
}
void AccountManager::requestAccessTokenFinished() {
QNetworkReply* requestReply = reinterpret_cast<QNetworkReply*>(sender());