summaryrefslogtreecommitdiffstats
path: root/src/oauth/qoauth2authorizationcodeflow.cpp
diff options
context:
space:
mode:
authorJuha Vuolle <juha.vuolle@qt.io>2024-11-05 13:10:23 +0200
committerJuha Vuolle <juha.vuolle@qt.io>2024-11-21 12:17:39 +0200
commit45a7b3f3ecdd29357f5aaed2708c5c9710c04a35 (patch)
tree235666db90f01e4dd01397ec35b4739f083c7832 /src/oauth/qoauth2authorizationcodeflow.cpp
parent51bd6cb75c92849ace5e7c94ce713fd54b4d5a8b (diff)
Move token request fail handling to baseclass private
This way it can be shared with the upcoming device flow implementation. Change-Id: Ia1cc64f88e216ed6206695aa70d71b60b2f90fec Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Diffstat (limited to 'src/oauth/qoauth2authorizationcodeflow.cpp')
-rw-r--r--src/oauth/qoauth2authorizationcodeflow.cpp27
1 files changed, 5 insertions, 22 deletions
diff --git a/src/oauth/qoauth2authorizationcodeflow.cpp b/src/oauth/qoauth2authorizationcodeflow.cpp
index 7109361..5778eb2 100644
--- a/src/oauth/qoauth2authorizationcodeflow.cpp
+++ b/src/oauth/qoauth2authorizationcodeflow.cpp
@@ -145,7 +145,7 @@ void QOAuth2AuthorizationCodeFlowPrivate::_q_accessTokenRequestFinished(const QV
using Key = QAbstractOAuth2Private::OAuth2KeyString;
if (values.contains(Key::error)) {
- _q_accessTokenRequestFailed(QAbstractOAuth::Error::ServerError,
+ _q_tokenRequestFailed(QAbstractOAuth::Error::ServerError,
values.value(Key::error).toString());
return;
}
@@ -160,7 +160,7 @@ void QOAuth2AuthorizationCodeFlowPrivate::_q_accessTokenRequestFinished(const QV
q->setRefreshToken(values.value(Key::refreshToken).toString());
if (accessToken.isEmpty()) {
- _q_accessTokenRequestFailed(QAbstractOAuth::Error::OAuthTokenNotFoundError,
+ _q_tokenRequestFailed(QAbstractOAuth::Error::OAuthTokenNotFoundError,
"Access token not received"_L1);
return;
}
@@ -193,7 +193,7 @@ void QOAuth2AuthorizationCodeFlowPrivate::_q_accessTokenRequestFinished(const QV
const QString receivedIdToken = values.value(Key::idToken).toString();
if (grantedScope.contains("openid"_L1) && receivedIdToken.isEmpty()) {
setIdToken({});
- _q_accessTokenRequestFailed(QAbstractOAuth::Error::OAuthTokenNotFoundError,
+ _q_tokenRequestFailed(QAbstractOAuth::Error::OAuthTokenNotFoundError,
"ID token not received"_L1);
return;
}
@@ -219,23 +219,6 @@ void QOAuth2AuthorizationCodeFlowPrivate::_q_accessTokenRequestFinished(const QV
setStatus(QAbstractOAuth::Status::Granted);
}
-void QOAuth2AuthorizationCodeFlowPrivate::_q_accessTokenRequestFailed(QAbstractOAuth::Error error,
- const QString& errorString)
-{
- Q_Q(QOAuth2AuthorizationCodeFlow);
- qCWarning(loggingCategory) << "Token request failed:" << errorString;
- // If we were refreshing, reset status to Granted if we have an access token.
- // The access token might still be valid, and even if it wouldn't be,
- // refreshing can be attempted again.
- if (q->status() == QAbstractOAuth::Status::RefreshingToken) {
- if (!q->token().isEmpty())
- setStatus(QAbstractOAuth::Status::Granted);
- else
- setStatus(QAbstractOAuth::Status::NotAuthenticated);
- }
- emit q->requestFailed(error);
-}
-
void QOAuth2AuthorizationCodeFlowPrivate::_q_authenticate(QNetworkReply *reply,
QAuthenticator *authenticator)
{
@@ -535,7 +518,7 @@ void QOAuth2AuthorizationCodeFlow::refreshAccessToken()
d, &QOAuth2AuthorizationCodeFlowPrivate::_q_authenticate,
Qt::UniqueConnection);
QObjectPrivate::connect(handler, &QAbstractOAuthReplyHandler::tokenRequestErrorOccurred,
- d, &QOAuth2AuthorizationCodeFlowPrivate::_q_accessTokenRequestFailed,
+ d, &QOAuth2AuthorizationCodeFlowPrivate::_q_tokenRequestFailed,
Qt::UniqueConnection);
}
@@ -638,7 +621,7 @@ void QOAuth2AuthorizationCodeFlow::requestAccessToken(const QString &code)
Qt::UniqueConnection);
QObjectPrivate::connect(handler,
&QAbstractOAuthReplyHandler::tokenRequestErrorOccurred,
- d, &QOAuth2AuthorizationCodeFlowPrivate::_q_accessTokenRequestFailed,
+ d, &QOAuth2AuthorizationCodeFlowPrivate::_q_tokenRequestFailed,
Qt::UniqueConnection);
}