summaryrefslogtreecommitdiffstats
path: root/src/oauth/qoauth2authorizationcodeflow.cpp
diff options
context:
space:
mode:
authorMagdalena Stojek <magdalena.stojek@qt.io>2024-11-21 11:48:48 +0100
committerMagdalena Stojek <magdalena.stojek@qt.io>2024-11-21 19:55:08 +0100
commit58c92af6e870fde2718a2aa9a6631a9c7ab40fad (patch)
tree610607239bcc06477c1695f44a6e7572c5a0983c /src/oauth/qoauth2authorizationcodeflow.cpp
parented5e6769212dbc2aadb1f3031fc216f04df2ab75 (diff)
Add access token expiration convenience functionality
Add the convenience of automatically refreshing an expiring access token, if a refresh token is available. QAbstractOAuth2 class provides accessTokenAboutToExpire signal and autoRefresh and refreshThreshold properties for this. [ChangeLog][QAbstractOAuth2] Added new accessTokenAboutToExpire() signal, and autorefresh and refreshThreshold properties. Fixes: QTBUG-124332 Change-Id: I55f4333abfbed25de11688d5c20650d433a650de Reviewed-by: Juha Vuolle <juha.vuolle@qt.io>
Diffstat (limited to 'src/oauth/qoauth2authorizationcodeflow.cpp')
-rw-r--r--src/oauth/qoauth2authorizationcodeflow.cpp24
1 files changed, 21 insertions, 3 deletions
diff --git a/src/oauth/qoauth2authorizationcodeflow.cpp b/src/oauth/qoauth2authorizationcodeflow.cpp
index 7d3f035..dfb2061 100644
--- a/src/oauth/qoauth2authorizationcodeflow.cpp
+++ b/src/oauth/qoauth2authorizationcodeflow.cpp
@@ -173,6 +173,15 @@ QByteArray QOAuth2AuthorizationCodeFlowPrivate::createPKCEChallenge()
Q_UNREACHABLE_RETURN({});
}
+void QOAuth2AuthorizationCodeFlowPrivate::initializeAutoRefresh()
+{
+ Q_Q(QOAuth2AuthorizationCodeFlow);
+ QObject::connect(q, &QAbstractOAuth2::accessTokenAboutToExpire, q, [q] {
+ if (q->autoRefresh() && !(q->refreshToken().isEmpty()))
+ q->refreshAccessToken();
+ });
+}
+
/*!
Constructs a QOAuth2AuthorizationCodeFlow object with parent
object \a parent.
@@ -204,7 +213,10 @@ QOAuth2AuthorizationCodeFlow::QOAuth2AuthorizationCodeFlow(const QString &client
QAbstractOAuth2(*new QOAuth2AuthorizationCodeFlowPrivate(QUrl(), QUrl(), clientIdentifier,
manager),
parent)
-{}
+{
+ Q_D(QOAuth2AuthorizationCodeFlow);
+ d->initializeAutoRefresh();
+}
/*!
Constructs a QOAuth2AuthorizationCodeFlow object using \a parent
@@ -219,7 +231,10 @@ QOAuth2AuthorizationCodeFlow::QOAuth2AuthorizationCodeFlow(const QUrl &authentic
QAbstractOAuth2(*new QOAuth2AuthorizationCodeFlowPrivate(authenticateUrl, accessTokenUrl,
QString(), manager),
parent)
-{}
+{
+ Q_D(QOAuth2AuthorizationCodeFlow);
+ d->initializeAutoRefresh();
+}
/*!
Constructs a QOAuth2AuthorizationCodeFlow object using \a parent
@@ -236,7 +251,10 @@ QOAuth2AuthorizationCodeFlow::QOAuth2AuthorizationCodeFlow(const QString &client
QAbstractOAuth2(*new QOAuth2AuthorizationCodeFlowPrivate(authenticateUrl, accessTokenUrl,
clientIdentifier, manager),
parent)
-{}
+{
+ Q_D(QOAuth2AuthorizationCodeFlow);
+ d->initializeAutoRefresh();
+}
/*!
Destroys the QOAuth2AuthorizationCodeFlow instance.