summaryrefslogtreecommitdiffstats
path: root/src/oauth/qoauth2authorizationcodeflow.cpp
diff options
context:
space:
mode:
authorIvan Solovev <ivan.solovev@qt.io>2024-12-16 16:32:24 +0100
committerIvan Solovev <ivan.solovev@qt.io>2024-12-19 09:31:04 +0100
commitb05d99c937f7ea9226314eaaae628cdfdda36bbe (patch)
tree93cde0de798c07f0bd1955c575e2a0bbcf3577b4 /src/oauth/qoauth2authorizationcodeflow.cpp
parent82e516de8196b04f3240fa910b5997a076ce8e1e (diff)
Move tokenUrl property to QAbstractOAuth2
The property is common for both authorization code and device flows, so it makes sense to move it to the base class. And more broadly speaking, most OAuth2 flows use a token endpoint. One problem is that QOAuth2AuthorizationCodeFlow already has an accessTokenUrl property which is used for the same purpose. This patch implements this property in termes of the base tokenUrl property. The follow-up commit will deprecate the QOAuth2AuthorizationCodeFlow property and mark it for removal in Qt 7. There were no tests for the accessTokenUrl property and the related signal, so create a new test that checks both old and new properties. [ChangeLog][QAbstractOAuth2] Added tokenUrl property that holds the token endpoint URL. Task-number: QTBUG-132106 Pick-to: 6.9 Change-Id: I4e680e1013093041dcd3fa4f06e24b83cec83fc3 Reviewed-by: Juha Vuolle <juha.vuolle@qt.io>
Diffstat (limited to 'src/oauth/qoauth2authorizationcodeflow.cpp')
-rw-r--r--src/oauth/qoauth2authorizationcodeflow.cpp23
1 files changed, 12 insertions, 11 deletions
diff --git a/src/oauth/qoauth2authorizationcodeflow.cpp b/src/oauth/qoauth2authorizationcodeflow.cpp
index 1d86a42..2ea17fb 100644
--- a/src/oauth/qoauth2authorizationcodeflow.cpp
+++ b/src/oauth/qoauth2authorizationcodeflow.cpp
@@ -57,9 +57,9 @@ using namespace Qt::StringLiterals;
QOAuth2AuthorizationCodeFlowPrivate::QOAuth2AuthorizationCodeFlowPrivate(
const QUrl &authorizationUrl, const QUrl &accessTokenUrl, const QString &clientIdentifier,
QNetworkAccessManager *manager) :
- QAbstractOAuth2Private(qMakePair(clientIdentifier, QString()), authorizationUrl, manager),
- accessTokenUrl(accessTokenUrl)
+ QAbstractOAuth2Private(qMakePair(clientIdentifier, QString()), authorizationUrl, manager)
{
+ tokenUrl = accessTokenUrl;
responseType = QStringLiteral("code");
}
@@ -128,7 +128,7 @@ void QOAuth2AuthorizationCodeFlowPrivate::_q_authenticate(QNetworkReply *reply,
{
if (reply == currentReply){
const auto url = reply->url();
- if (url == accessTokenUrl) {
+ if (url == tokenUrl) {
authenticator->setUser(clientIdentifier);
authenticator->setPassword(QString());
}
@@ -269,7 +269,7 @@ QOAuth2AuthorizationCodeFlow::~QOAuth2AuthorizationCodeFlow()
QUrl QOAuth2AuthorizationCodeFlow::accessTokenUrl() const
{
Q_D(const QOAuth2AuthorizationCodeFlow);
- return d->accessTokenUrl;
+ return d->tokenUrl;
}
/*!
@@ -279,10 +279,11 @@ QUrl QOAuth2AuthorizationCodeFlow::accessTokenUrl() const
void QOAuth2AuthorizationCodeFlow::setAccessTokenUrl(const QUrl &accessTokenUrl)
{
Q_D(QOAuth2AuthorizationCodeFlow);
- if (d->accessTokenUrl != accessTokenUrl) {
- d->accessTokenUrl = accessTokenUrl;
- Q_EMIT accessTokenUrlChanged(accessTokenUrl);
- }
+ if (accessTokenUrl == d->tokenUrl)
+ return;
+
+ setTokenUrl(accessTokenUrl);
+ Q_EMIT accessTokenUrlChanged(accessTokenUrl);
}
/*!
@@ -367,7 +368,7 @@ void QOAuth2AuthorizationCodeFlow::grant()
qCWarning(d->loggingCategory, "No authenticate Url set");
return;
}
- if (d->accessTokenUrl.isEmpty()) {
+ if (d->tokenUrl.isEmpty()) {
qCWarning(d->loggingCategory, "No request access token Url set");
return;
}
@@ -402,7 +403,7 @@ void QOAuth2AuthorizationCodeFlow::refreshAccessToken()
return;
}
- const auto [request, body] = d->createRefreshRequestAndBody(d->accessTokenUrl);
+ const auto [request, body] = d->createRefreshRequestAndBody(d->tokenUrl);
d->currentReply = d->networkAccessManager()->post(request, body);
setStatus(Status::RefreshingToken);
@@ -475,7 +476,7 @@ void QOAuth2AuthorizationCodeFlow::requestAccessToken(const QString &code)
Q_D(QOAuth2AuthorizationCodeFlow);
QMultiMap<QString, QVariant> parameters;
- QNetworkRequest request(d->accessTokenUrl);
+ QNetworkRequest request(d->tokenUrl);
#ifndef QT_NO_SSL
if (d->sslConfiguration && !d->sslConfiguration->isNull())
request.setSslConfiguration(*d->sslConfiguration);