diff options
| author | Juha Vuolle <juha.vuolle@qt.io> | 2025-01-10 12:20:07 +0200 |
|---|---|---|
| committer | Juha Vuolle <juha.vuolle@qt.io> | 2025-01-16 08:19:26 +0200 |
| commit | 1aca648496e4b41c5ae8198f4e683ec72b6bf067 (patch) | |
| tree | 62bb687d28783e42babe848cc2c607929d88af47 /src/oauth/qoauth2authorizationcodeflow.cpp | |
| parent | 0506848dbf61696499f2b94364ffd14993c15041 (diff) | |
Use refreshTokens() as an NVI already in Qt 6
This allows having a common baseclass method for refreshing
tokens already in Qt 6. This should minimize the user impact
of removing the leaf class "refreshAccessToken()" function
in Qt 7.
Furthermore this simplifies the automatic token refresh
implementation, which is implemented at the common baseclass
level; the implementation can inokve/call the refreshTokens()
directly, as opposed to the leaf class connecting to the
accessTokenAboutToExpire() signal.
Lastly this allows removing the (new in Qt 6.9)
"QOAuth2DeviceAuthorizationFlow::refresAccessTokens()"
function which would have been replaced in Qt 7.
Found in API review.
Amends 2b1e3419c5ef43e964f40dbe79d7a7da0de5aa57
Pick-to: 6.9
Change-Id: I3ad94486543bdcb5ef5a7afd41f9cbb249ac92fb
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Diffstat (limited to 'src/oauth/qoauth2authorizationcodeflow.cpp')
| -rw-r--r-- | src/oauth/qoauth2authorizationcodeflow.cpp | 61 |
1 files changed, 26 insertions, 35 deletions
diff --git a/src/oauth/qoauth2authorizationcodeflow.cpp b/src/oauth/qoauth2authorizationcodeflow.cpp index cdb1a32..f533287 100644 --- a/src/oauth/qoauth2authorizationcodeflow.cpp +++ b/src/oauth/qoauth2authorizationcodeflow.cpp @@ -176,17 +176,6 @@ QByteArray QOAuth2AuthorizationCodeFlowPrivate::createPKCEChallenge() Q_UNREACHABLE_RETURN({}); } -#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0) -void QOAuth2AuthorizationCodeFlowPrivate::initializeAutoRefresh() -{ - Q_Q(QOAuth2AuthorizationCodeFlow); - QObject::connect(q, &QAbstractOAuth2::accessTokenAboutToExpire, q, [q] { - if (q->autoRefresh() && !q->refreshToken().isEmpty()) - q->refreshAccessToken(); - }); -} -#endif - /*! Constructs a QOAuth2AuthorizationCodeFlow object with parent object \a parent. @@ -219,10 +208,6 @@ QOAuth2AuthorizationCodeFlow::QOAuth2AuthorizationCodeFlow(const QString &client manager), parent) { -#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0) - Q_D(QOAuth2AuthorizationCodeFlow); - d->initializeAutoRefresh(); -#endif } /*! @@ -239,10 +224,6 @@ QOAuth2AuthorizationCodeFlow::QOAuth2AuthorizationCodeFlow(const QUrl &authentic QString(), manager), parent) { -#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0) - Q_D(QOAuth2AuthorizationCodeFlow); - d->initializeAutoRefresh(); -#endif } /*! @@ -261,10 +242,6 @@ QOAuth2AuthorizationCodeFlow::QOAuth2AuthorizationCodeFlow(const QString &client clientIdentifier, manager), parent) { -#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0) - Q_D(QOAuth2AuthorizationCodeFlow); - d->initializeAutoRefresh(); -#endif } /*! @@ -394,23 +371,37 @@ void QOAuth2AuthorizationCodeFlow::grant() } /*! - Call this function to refresh the token. Access tokens are not - permanent. After a time specified along with the access token - when it was obtained, the access token will become invalid. - - If refreshing the token fails and an access token exists, the status is - set to QAbstractOAuth::Status::Granted, and to - QAbstractOAuth::Status::NotAuthenticated otherwise. + Call this function to refresh the token. - \sa QAbstractOAuth::requestFailed() - \sa {https://tools.ietf.org/html/rfc6749#section-1.5}{Refresh - Token} + This function calls \l {refreshTokensImplementation()}. */ #if QT_VERSION < QT_VERSION_CHECK(7, 0, 0) void QOAuth2AuthorizationCodeFlow::refreshAccessToken() -#else -void QOAuth2AuthorizationCodeFlow::refreshTokens() +{ + refreshTokensImplementation(); +} #endif + +/*! + \since 6.9 + + This function sends a token refresh request. + + If the refresh request was initiated successfully, the status is set to + \l QAbstractOAuth::Status::RefreshingToken; otherwise the \l requestFailed() + signal is emitted and the status is not changed. + + This function has no effect if the token refresh process is already in + progress. + + If refreshing the token fails and an access token exists, the status is + set to \l QAbstractOAuth::Status::Granted, and to + \l QAbstractOAuth::Status::NotAuthenticated if an access token + does not exist. + + \sa QAbstractOAuth::requestFailed(), QAbstractOAuth2::refreshTokens() +*/ +void QOAuth2AuthorizationCodeFlow::refreshTokensImplementation() { Q_D(QOAuth2AuthorizationCodeFlow); |
