Commit b069ade1 authored by Jesus Fernandez's avatar Jesus Fernandez

Minor changes

parent e3fc27ca
...@@ -8,5 +8,6 @@ win32:CONFIG(release, debug|release): { ...@@ -8,5 +8,6 @@ win32:CONFIG(release, debug|release): {
} else:win32:CONFIG(debug, debug|release): { } else:win32:CONFIG(debug, debug|release): {
DESTDIR = $$OUT_PWD/../../debug DESTDIR = $$OUT_PWD/../../debug
LIBS += $$OUT_PWD/../../debug/QtOAuth.lib LIBS += $$OUT_PWD/../../debug/QtOAuth.lib
} else:unix: {
LIBS += -L$$OUT_PWD/../../QtOAuth/ -lQtOAuth
} }
else:unix: LIBS += -L$$OUT_PWD/../../QtOAuth/ -lQtOAuth
...@@ -81,8 +81,8 @@ public: ...@@ -81,8 +81,8 @@ public:
QString token; QString token;
QString scope; QString scope;
QString state = generateRandomState(); QString state = generateRandomState();
QString userAgent = "qoauth/0.1"; QString userAgent = "QtOAuth/1.0 (+https://www.qt.io)";
const QString bearerFormat = QStringLiteral("Bearer %1"); const QString bearerFormat = QStringLiteral("Bearer %1"); // Case sensitive
QDateTime expiresAt; QDateTime expiresAt;
QString refreshToken; QString refreshToken;
......
...@@ -80,6 +80,7 @@ public: ...@@ -80,6 +80,7 @@ public:
QNetworkAccessManager *networkAccessManager(); QNetworkAccessManager *networkAccessManager();
void setStatus(QAbstractOAuth::Status status); void setStatus(QAbstractOAuth::Status status);
// Resource Owner Authorization: https://tools.ietf.org/html/rfc5849#section-2.2
QUrl authorizationUrl; QUrl authorizationUrl;
QVariantMap extraTokens; QVariantMap extraTokens;
QAbstractOAuth::Status status = QAbstractOAuth::Status::NotAuthenticated; QAbstractOAuth::Status status = QAbstractOAuth::Status::NotAuthenticated;
......
...@@ -72,21 +72,6 @@ class OAUTH_EXPORT QOAuth1Private : public QAbstractOAuthPrivate ...@@ -72,21 +72,6 @@ class OAUTH_EXPORT QOAuth1Private : public QAbstractOAuthPrivate
public: public:
QOAuth1Private(QNetworkAccessManager *networkAccessManager = nullptr); QOAuth1Private(QNetworkAccessManager *networkAccessManager = nullptr);
QPair<QString, QString> clientCredentials;
QPair<QString, QString> tokenCredentials;
QString verifier;
QUrl temporaryCredentialsUrl;
QUrl tokenCredentialsUrl;
QOAuth1::SignatureMethod signatureMethod = QOAuth1::SignatureMethod::Hmac_Sha1;
const QString oauthVersion = QStringLiteral("1.0");
// private slots
void _q_onTokenRequestFinished();
void _q_onTokenRequestError(QNetworkReply::NetworkError error);
void _q_onTokenExchangeError(QNetworkReply::NetworkError error);
void _q_requestAuthorizationGrantAnswer();
void _q_tokensReceived(const QVariantMap &tokens);
void appendCommonHeaders(QVariantMap *headers); void appendCommonHeaders(QVariantMap *headers);
void appendSignature(QAbstractOAuth::Stage stage, void appendSignature(QAbstractOAuth::Stage stage,
QVariantMap *headers, QVariantMap *headers,
...@@ -102,6 +87,17 @@ public: ...@@ -102,6 +87,17 @@ public:
QString signatureMethodString() const; QString signatureMethodString() const;
static QString operationName(QNetworkAccessManager::Operation op); static QString operationName(QNetworkAccessManager::Operation op);
void _q_onTokenRequestError(QNetworkReply::NetworkError error);
void _q_requestAuthorizationGrantAnswer();
void _q_tokensReceived(const QVariantMap &tokens);
QPair<QString, QString> clientCredentials;
QPair<QString, QString> tokenCredentials;
QString verifier;
QUrl temporaryCredentialsUrl;
QUrl tokenCredentialsUrl;
QOAuth1::SignatureMethod signatureMethod = QOAuth1::SignatureMethod::Hmac_Sha1;
const QString oauthVersion = QStringLiteral("1.0");
struct OAuth1KeyString struct OAuth1KeyString
{ {
......
...@@ -69,9 +69,9 @@ class OAUTH_EXPORT QOAuth2AuthorizationCodeFlowPrivate : public QAbstractOAuth2P ...@@ -69,9 +69,9 @@ class OAUTH_EXPORT QOAuth2AuthorizationCodeFlowPrivate : public QAbstractOAuth2P
public: public:
QOAuth2AuthorizationCodeFlowPrivate(QNetworkAccessManager *manager = nullptr); QOAuth2AuthorizationCodeFlowPrivate(QNetworkAccessManager *manager = nullptr);
void handleCallback(const QVariantMap &data); void _q_handleCallback(const QVariantMap &data);
void accessTokenRequestFinished(QNetworkReply *reply); void _q_accessTokenRequestFinished(QNetworkReply *reply);
void authenticate(QNetworkReply *reply, QAuthenticator *authenticator); void _q_authenticate(QNetworkReply *reply, QAuthenticator *authenticator);
QUrl accessTokenUrl; QUrl accessTokenUrl;
QString tokenType; QString tokenType;
......
...@@ -73,8 +73,8 @@ public: ...@@ -73,8 +73,8 @@ public:
QString text; QString text;
private: private:
void onClientConnected(); void _q_clientConnected();
void answerClient(); void _q_answerClient();
}; };
QT_END_NAMESPACE QT_END_NAMESPACE
......
...@@ -186,6 +186,13 @@ QString QAbstractOAuth::callback() const ...@@ -186,6 +186,13 @@ QString QAbstractOAuth::callback() const
: d->defaultReplyHandler->callback(); : d->defaultReplyHandler->callback();
} }
void QAbstractOAuth::resourceOwnerAuthorization(const QUrl &url, const QVariantMap &parameters)
{
QUrl u = url;
u.setQuery(QAbstractOAuthPrivate::createQuery(parameters));
Q_EMIT authorizeWithBrowser(u);
}
QT_END_NAMESPACE QT_END_NAMESPACE
#endif // QT_NO_HTTP #endif // QT_NO_HTTP
...@@ -116,7 +116,6 @@ public: ...@@ -116,7 +116,6 @@ public:
Status status() const; Status status() const;
// Resource Owner Authorization: https://tools.ietf.org/html/rfc5849#section-2.2
QUrl authorizationUrl() const; QUrl authorizationUrl() const;
void setAuthorizationUrl(const QUrl &url); void setAuthorizationUrl(const QUrl &url);
...@@ -148,7 +147,7 @@ Q_SIGNALS: ...@@ -148,7 +147,7 @@ Q_SIGNALS:
void extraTokensChanged(const QVariantMap &tokens); void extraTokensChanged(const QVariantMap &tokens);
void requestFailed(const Error error); void requestFailed(const Error error);
void authorizationRequested(const QUrl &url); void authorizeWithBrowser(const QUrl &url);
void granted(); void granted();
void finished(QNetworkReply *reply); void finished(QNetworkReply *reply);
void replyDataReceived(const QByteArray &data); void replyDataReceived(const QByteArray &data);
...@@ -160,6 +159,8 @@ protected: ...@@ -160,6 +159,8 @@ protected:
QString callback() const; QString callback() const;
virtual void resourceOwnerAuthorization(const QUrl &url, const QVariantMap &parameters);
private: private:
Q_DISABLE_COPY(QAbstractOAuth) Q_DISABLE_COPY(QAbstractOAuth)
Q_DECLARE_PRIVATE(QAbstractOAuth) Q_DECLARE_PRIVATE(QAbstractOAuth)
......
...@@ -72,7 +72,6 @@ const QString Key::scope = QStringLiteral("scope"); ...@@ -72,7 +72,6 @@ const QString Key::scope = QStringLiteral("scope");
const QString Key::state = QStringLiteral("state"); const QString Key::state = QStringLiteral("state");
const QString Key::tokenType = QStringLiteral("token_type"); const QString Key::tokenType = QStringLiteral("token_type");
QAbstractOAuth2Private::QAbstractOAuth2Private(QNetworkAccessManager *manager) : QAbstractOAuth2Private::QAbstractOAuth2Private(QNetworkAccessManager *manager) :
QAbstractOAuthPrivate(manager) QAbstractOAuthPrivate(manager)
{} {}
......
...@@ -80,83 +80,6 @@ QOAuth1Private::QOAuth1Private(QNetworkAccessManager *networkAccessManager) ...@@ -80,83 +80,6 @@ QOAuth1Private::QOAuth1Private(QNetworkAccessManager *networkAccessManager)
qRegisterMetaType<QNetworkReply::NetworkError>("QNetworkReply::NetworkError"); qRegisterMetaType<QNetworkReply::NetworkError>("QNetworkReply::NetworkError");
} }
void QOAuth1Private::_q_onTokenRequestError(QNetworkReply::NetworkError error)
{
Q_Q(QOAuth1);
Q_UNUSED(error);
Q_EMIT q->requestFailed(QAbstractOAuth::Error::NetworkError);
}
void QOAuth1Private::_q_onTokenExchangeError(QNetworkReply::NetworkError)
{
Q_Q(QOAuth1);
Q_EMIT q->requestFailed(QAbstractOAuth::Error::NetworkError);
}
void QOAuth1Private::_q_requestAuthorizationGrantAnswer()
{
Q_Q(QOAuth1);
typedef OAuth1KeyString Key;
QNetworkReply *reply = static_cast<QNetworkReply *>(currentSender->sender);
if (reply->error() != QNetworkReply::NoError) {
qWarning("Reply error: %s: %s", qPrintable(reply->errorString()),
reply->readAll().data());
Q_EMIT q->requestFailed(QAbstractOAuth::Error::NetworkError);
return;
}
QByteArray data = reply->readAll();
QMap<QString, QString> response = q->parseResponse(data);
if (response.contains(Key::oauthToken) && response.contains(Key::oauthTokenSecret)) {
if (!response.isEmpty()) {
extraTokens.clear();
for (auto it = response.begin(), end = response.end(); it != end; ++it)
extraTokens.insert(it.key(), it.value());
const QString oauthToken = response.value(Key::oauthToken);
const QString oauthTokenSecret = response.value(Key::oauthTokenSecret);
q->setTokenCredentials(qMakePair(oauthToken, oauthTokenSecret));
response.remove(Key::oauthToken);
response.remove(Key::oauthTokenSecret);
q->setStatus(QAbstractOAuth::Status::Granted);
Q_EMIT q->extraTokensChanged(extraTokens);
Q_EMIT q->granted();
}
else {
q->setStatus(QAbstractOAuth::Status::NotAuthenticated);
q->setTokenCredentials(QPair<QString, QString>());
}
} else {
Q_EMIT q->requestFailed(QAbstractOAuth::Error::OAuthTokenNotFoundError);
}
}
void QOAuth1Private::_q_tokensReceived(const QVariantMap &tokens)
{
Q_Q(QOAuth1);
typedef OAuth1KeyString Key;
QPair<QString, QString> credential(tokens.value(Key::oauthToken).toString(),
tokens.value(Key::oauthTokenSecret).toString());
switch (status) {
case QAbstractOAuth::Status::NotAuthenticated:
if (tokens.value(Key::oauthCallbackConfirmed, true).toBool()) {
q->setTokenCredentials(credential);
setStatus(QAbstractOAuth::Status::TemporaryTokenReceived);
}
else
Q_EMIT q->requestFailed(QAbstractOAuth::Error::OAuthCallbackNotVerified);
break;
case QAbstractOAuth::Status::TemporaryTokenReceived:
q->setTokenCredentials(credential);
setStatus(QAbstractOAuth::Status::Granted);
break;
case QAbstractOAuth::Status::Granted:
break;
}
}
void QOAuth1Private::appendCommonHeaders(QVariantMap *headers) void QOAuth1Private::appendCommonHeaders(QVariantMap *headers)
{ {
typedef OAuth1KeyString Key; typedef OAuth1KeyString Key;
...@@ -279,6 +202,77 @@ QString QOAuth1Private::operationName(QNetworkAccessManager::Operation op) ...@@ -279,6 +202,77 @@ QString QOAuth1Private::operationName(QNetworkAccessManager::Operation op)
return QString(); return QString();
} }
void QOAuth1Private::_q_onTokenRequestError(QNetworkReply::NetworkError error)
{
Q_Q(QOAuth1);
Q_UNUSED(error);
Q_EMIT q->requestFailed(QAbstractOAuth::Error::NetworkError);
}
void QOAuth1Private::_q_requestAuthorizationGrantAnswer()
{
Q_Q(QOAuth1);
typedef OAuth1KeyString Key;
QNetworkReply *reply = static_cast<QNetworkReply *>(currentSender->sender);
if (reply->error() != QNetworkReply::NoError) {
qWarning("Reply error: %s: %s", qPrintable(reply->errorString()),
reply->readAll().data());
Q_EMIT q->requestFailed(QAbstractOAuth::Error::NetworkError);
return;
}
QByteArray data = reply->readAll();
QMap<QString, QString> response = q->parseResponse(data);
if (response.contains(Key::oauthToken) && response.contains(Key::oauthTokenSecret)) {
if (!response.isEmpty()) {
extraTokens.clear();
for (auto it = response.begin(), end = response.end(); it != end; ++it)
extraTokens.insert(it.key(), it.value());
const QString oauthToken = response.value(Key::oauthToken);
const QString oauthTokenSecret = response.value(Key::oauthTokenSecret);
q->setTokenCredentials(qMakePair(oauthToken, oauthTokenSecret));
response.remove(Key::oauthToken);
response.remove(Key::oauthTokenSecret);
q->setStatus(QAbstractOAuth::Status::Granted);
Q_EMIT q->extraTokensChanged(extraTokens);
Q_EMIT q->granted();
}
else {
q->setStatus(QAbstractOAuth::Status::NotAuthenticated);
q->setTokenCredentials(QPair<QString, QString>());
}
} else {
Q_EMIT q->requestFailed(QAbstractOAuth::Error::OAuthTokenNotFoundError);
}
}
void QOAuth1Private::_q_tokensReceived(const QVariantMap &tokens)
{
Q_Q(QOAuth1);
typedef OAuth1KeyString Key;
QPair<QString, QString> credential(tokens.value(Key::oauthToken).toString(),
tokens.value(Key::oauthTokenSecret).toString());
switch (status) {
case QAbstractOAuth::Status::NotAuthenticated:
if (tokens.value(Key::oauthCallbackConfirmed, true).toBool()) {
q->setTokenCredentials(credential);
setStatus(QAbstractOAuth::Status::TemporaryTokenReceived);
}
else
Q_EMIT q->requestFailed(QAbstractOAuth::Error::OAuthCallbackNotVerified);
break;
case QAbstractOAuth::Status::TemporaryTokenReceived:
q->setTokenCredentials(credential);
setStatus(QAbstractOAuth::Status::Granted);
break;
case QAbstractOAuth::Status::Granted:
break;
}
}
QOAuth1::QOAuth1(QObject *parent) QOAuth1::QOAuth1(QObject *parent)
: QAbstractOAuth(*new QOAuth1Private, parent) : QAbstractOAuth(*new QOAuth1Private, parent)
{} {}
...@@ -504,16 +498,15 @@ QNetworkReply *QOAuth1::requestTemporaryCredentials(QNetworkAccessManager::Opera ...@@ -504,16 +498,15 @@ QNetworkReply *QOAuth1::requestTemporaryCredentials(QNetworkAccessManager::Opera
const QUrl &url, const QUrl &url,
const QVariantMap &parameters) const QVariantMap &parameters)
{ {
// https://tools.ietf.org/html/rfc5849#section-2.1
Q_D(QOAuth1); Q_D(QOAuth1);
if (Q_UNLIKELY(!d->networkAccessManager())) { if (Q_UNLIKELY(!d->networkAccessManager())) {
qCritical("QNetworkAccessManager not available"); qCritical("QNetworkAccessManager not available");
return nullptr; return nullptr;
} } else if (Q_UNLIKELY(url.isEmpty())) {
if (Q_UNLIKELY(url.isEmpty())) {
qCritical() << "Request Url not set"; qCritical() << "Request Url not set";
return nullptr; return nullptr;
} } else if (Q_UNLIKELY(operation != QNetworkAccessManager::GetOperation &&
if (Q_UNLIKELY(operation != QNetworkAccessManager::GetOperation &&
operation != QNetworkAccessManager::PostOperation)) { operation != QNetworkAccessManager::PostOperation)) {
qCritical("Operation not supported"); qCritical("Operation not supported");
return nullptr; return nullptr;
...@@ -644,6 +637,7 @@ QByteArray QOAuth1::parameterString(const QVariantMap &parameters) ...@@ -644,6 +637,7 @@ QByteArray QOAuth1::parameterString(const QVariantMap &parameters)
QByteArray QOAuth1::nonce() QByteArray QOAuth1::nonce()
{ {
// https://tools.ietf.org/html/rfc5849#section-3.3
QString u = QString::number(QDateTime::currentDateTimeUtc().toTime_t()); QString u = QString::number(QDateTime::currentDateTimeUtc().toTime_t());
u.append(QString::number(qrand())); u.append(QString::number(qrand()));
return u.toUtf8(); return u.toUtf8();
...@@ -653,6 +647,7 @@ QByteArray QOAuth1::signatureBaseString(const QVariantMap &parameters, ...@@ -653,6 +647,7 @@ QByteArray QOAuth1::signatureBaseString(const QVariantMap &parameters,
const QUrl &url, const QUrl &url,
QNetworkAccessManager::Operation op) QNetworkAccessManager::Operation op)
{ {
// https://tools.ietf.org/html/rfc5849#section-3.4.1
QByteArray base; QByteArray base;
base.append(QOAuth1Private::operationName(op).toUtf8() + "&"); base.append(QOAuth1Private::operationName(op).toUtf8() + "&");
...@@ -679,6 +674,7 @@ QByteArray QOAuth1::signature(const QVariantMap &parameters, ...@@ -679,6 +674,7 @@ QByteArray QOAuth1::signature(const QVariantMap &parameters,
const QString &consumerSecret, const QString &consumerSecret,
const QString &tokenSecret) const QString &tokenSecret)
{ {
// https://tools.ietf.org/html/rfc5849#section-3.4
const QByteArray baseString = signatureBaseString(parameters, url, op); const QByteArray baseString = signatureBaseString(parameters, url, op);
QByteArray secret; QByteArray secret;
...@@ -693,6 +689,8 @@ QByteArray QOAuth1::signature(const QVariantMap &parameters, ...@@ -693,6 +689,8 @@ QByteArray QOAuth1::signature(const QVariantMap &parameters,
QByteArray QOAuth1::generateAuthorizationHeader(const QVariantMap &oauthParams) QByteArray QOAuth1::generateAuthorizationHeader(const QVariantMap &oauthParams)
{ {
// https://tools.ietf.org/html/rfc5849#section-3.5.1
// TODO Add realm parameter support
bool first = true; bool first = true;
QString ret(QStringLiteral("OAuth ")); QString ret(QStringLiteral("OAuth "));
QVariantMap headers(oauthParams); QVariantMap headers(oauthParams);
...@@ -712,6 +710,7 @@ QByteArray QOAuth1::generateAuthorizationHeader(const QVariantMap &oauthParams) ...@@ -712,6 +710,7 @@ QByteArray QOAuth1::generateAuthorizationHeader(const QVariantMap &oauthParams)
void QOAuth1::grant() void QOAuth1::grant()
{ {
// https://tools.ietf.org/html/rfc5849#section-2
Q_D(QOAuth1); Q_D(QOAuth1);
typedef QOAuth1Private::OAuth1KeyString Key; typedef QOAuth1Private::OAuth1KeyString Key;
...@@ -733,9 +732,8 @@ void QOAuth1::grant() ...@@ -733,9 +732,8 @@ void QOAuth1::grant()
if (d->modifyParametersFunction) if (d->modifyParametersFunction)
d->modifyParametersFunction(Stage::RequestingAuthorization, &parameters); d->modifyParametersFunction(Stage::RequestingAuthorization, &parameters);
QUrl url = d->authorizationUrl; // https://tools.ietf.org/html/rfc5849#section-2.2
url.setQuery(QAbstractOAuthPrivate::createQuery(parameters)); resourceOwnerAuthorization(d->authorizationUrl, parameters);
Q_EMIT authorizationRequested(url);
} }
else { else {
// try upgrading token without verifier // try upgrading token without verifier
...@@ -767,6 +765,7 @@ void QOAuth1::grant() ...@@ -767,6 +765,7 @@ void QOAuth1::grant()
void QOAuth1::continueGrantWithVerifier(const QString &verifier) void QOAuth1::continueGrantWithVerifier(const QString &verifier)
{ {
// https://tools.ietf.org/html/rfc5849#section-2.3
Q_D(QOAuth1); Q_D(QOAuth1);
typedef QOAuth1Private::OAuth1KeyString Key; typedef QOAuth1Private::OAuth1KeyString Key;
......
...@@ -59,7 +59,7 @@ QOAuth2AuthorizationCodeFlowPrivate::QOAuth2AuthorizationCodeFlowPrivate( ...@@ -59,7 +59,7 @@ QOAuth2AuthorizationCodeFlowPrivate::QOAuth2AuthorizationCodeFlowPrivate(
QNetworkAccessManager *manager) : QAbstractOAuth2Private(manager) QNetworkAccessManager *manager) : QAbstractOAuth2Private(manager)
{} {}
void QOAuth2AuthorizationCodeFlowPrivate::handleCallback(const QVariantMap &data) void QOAuth2AuthorizationCodeFlowPrivate::_q_handleCallback(const QVariantMap &data)
{ {
Q_Q(QOAuth2AuthorizationCodeFlow); Q_Q(QOAuth2AuthorizationCodeFlow);
typedef QAbstractOAuth2Private::OAuth2KeyString Key; typedef QAbstractOAuth2Private::OAuth2KeyString Key;
...@@ -99,7 +99,7 @@ void QOAuth2AuthorizationCodeFlowPrivate::handleCallback(const QVariantMap &data ...@@ -99,7 +99,7 @@ void QOAuth2AuthorizationCodeFlowPrivate::handleCallback(const QVariantMap &data
q->requestAccessToken(code); q->requestAccessToken(code);
} }
void QOAuth2AuthorizationCodeFlowPrivate::accessTokenRequestFinished(QNetworkReply *reply) void QOAuth2AuthorizationCodeFlowPrivate::_q_accessTokenRequestFinished(QNetworkReply *reply)
{ {
Q_Q(QOAuth2AuthorizationCodeFlow); Q_Q(QOAuth2AuthorizationCodeFlow);
typedef QAbstractOAuth2Private::OAuth2KeyString Key; typedef QAbstractOAuth2Private::OAuth2KeyString Key;
...@@ -107,7 +107,6 @@ void QOAuth2AuthorizationCodeFlowPrivate::accessTokenRequestFinished(QNetworkRep ...@@ -107,7 +107,6 @@ void QOAuth2AuthorizationCodeFlowPrivate::accessTokenRequestFinished(QNetworkRep
if (reply != currentReply) if (reply != currentReply)
return; return;
if (reply->error() == QNetworkReply::UnknownNetworkError) { if (reply->error() == QNetworkReply::UnknownNetworkError) {
return;
qWarning("QOAuth2AuthorizationCodeFlow: %s", qPrintable(reply->errorString())); qWarning("QOAuth2AuthorizationCodeFlow: %s", qPrintable(reply->errorString()));
setStatus(QAbstractOAuth::Status::NotAuthenticated); setStatus(QAbstractOAuth::Status::NotAuthenticated);
return; return;
...@@ -146,7 +145,7 @@ void QOAuth2AuthorizationCodeFlowPrivate::accessTokenRequestFinished(QNetworkRep ...@@ -146,7 +145,7 @@ void QOAuth2AuthorizationCodeFlowPrivate::accessTokenRequestFinished(QNetworkRep
setStatus(QAbstractOAuth::Status::Granted); setStatus(QAbstractOAuth::Status::Granted);
} }
void QOAuth2AuthorizationCodeFlowPrivate::authenticate(QNetworkReply *reply, void QOAuth2AuthorizationCodeFlowPrivate::_q_authenticate(QNetworkReply *reply,
QAuthenticator *authenticator) QAuthenticator *authenticator)
{ {
if (reply == currentReply){ if (reply == currentReply){
...@@ -234,10 +233,7 @@ void QOAuth2AuthorizationCodeFlow::grant() ...@@ -234,10 +233,7 @@ void QOAuth2AuthorizationCodeFlow::grant()
return; return;
} }
const QUrl url = buildAuthenticateUrl(); resourceOwnerAuthorization(d->authorizationUrl);
QObjectPrivate::connect(this, &QOAuth2AuthorizationCodeFlow::authorizationCallbackReceived, d,
&QOAuth2AuthorizationCodeFlowPrivate::handleCallback);
Q_EMIT authorizationRequested(url);
} }
void QOAuth2AuthorizationCodeFlow::refreshAccessToken() void QOAuth2AuthorizationCodeFlow::refreshAccessToken()
...@@ -266,10 +262,10 @@ void QOAuth2AuthorizationCodeFlow::refreshAccessToken() ...@@ -266,10 +262,10 @@ void QOAuth2AuthorizationCodeFlow::refreshAccessToken()
d->currentReply = d->networkAccessManager()->post(request, data.toUtf8()); d->currentReply = d->networkAccessManager()->post(request, data.toUtf8());
QObjectPrivate::connect(d->networkAccessManager(), &QNetworkAccessManager::finished, QObjectPrivate::connect(d->networkAccessManager(), &QNetworkAccessManager::finished,
d, &QOAuth2AuthorizationCodeFlowPrivate::accessTokenRequestFinished); d, &QOAuth2AuthorizationCodeFlowPrivate::_q_accessTokenRequestFinished);
QObjectPrivate::connect(d->networkAccessManager(), QObjectPrivate::connect(d->networkAccessManager(),
&QNetworkAccessManager::authenticationRequired, &QNetworkAccessManager::authenticationRequired,
d, &QOAuth2AuthorizationCodeFlowPrivate::authenticate, d, &QOAuth2AuthorizationCodeFlowPrivate::_q_authenticate,
Qt::UniqueConnection); Qt::UniqueConnection);
} }
...@@ -294,9 +290,9 @@ QUrl QOAuth2AuthorizationCodeFlow::buildAuthenticateUrl(const QVariantMap &param ...@@ -294,9 +290,9 @@ QUrl QOAuth2AuthorizationCodeFlow::buildAuthenticateUrl(const QVariantMap &param
d->modifyParametersFunction(Stage::RequestingAuthorization, &p); d->modifyParametersFunction(Stage::RequestingAuthorization, &p);
url.setQuery(d->createQuery(p)); url.setQuery(d->createQuery(p));
connect(d->replyHandler.data(), &QAbstractOAuthReplyHandler::callbackReceived, this, connect(d->replyHandler.data(), &QAbstractOAuthReplyHandler::callbackReceived, this,
&QOAuth2AuthorizationCodeFlow::authorizationCallbackReceived); &QOAuth2AuthorizationCodeFlow::authorizationCallbackReceived, Qt::UniqueConnection);
setStatus(QAbstractOAuth::Status::NotAuthenticated); setStatus(QAbstractOAuth::Status::NotAuthenticated);
qDebug() << url; qDebug("QOAuth2AuthorizationCodeFlow::buildAuthenticateUrl: %s", qPrintable(url.toString()));
return url; return url;
} }
...@@ -323,11 +319,23 @@ void QOAuth2AuthorizationCodeFlow::requestAccessToken(const QString &code) ...@@ -323,11 +319,23 @@ void QOAuth2AuthorizationCodeFlow::requestAccessToken(const QString &code)
const QString data = query.toString(QUrl::FullyEncoded); const QString data = query.toString(QUrl::FullyEncoded);
d->currentReply = d->networkAccessManager()->post(request, data.toUtf8()); d->currentReply = d->networkAccessManager()->post(request, data.toUtf8());
QObjectPrivate::connect(d->networkAccessManager(), &QNetworkAccessManager::finished, QObjectPrivate::connect(d->networkAccessManager(), &QNetworkAccessManager::finished,
d, &QOAuth2AuthorizationCodeFlowPrivate::accessTokenRequestFinished); d, &QOAuth2AuthorizationCodeFlowPrivate::_q_accessTokenRequestFinished);
QObjectPrivate::connect(d->networkAccessManager(), QObjectPrivate::connect(d->networkAccessManager(),
&QNetworkAccessManager::authenticationRequired, &QNetworkAccessManager::authenticationRequired,
d, &QOAuth2AuthorizationCodeFlowPrivate::authenticate, d, &QOAuth2AuthorizationCodeFlowPrivate::_q_authenticate,
Qt::UniqueConnection);
}
void QOAuth2AuthorizationCodeFlow::resourceOwnerAuthorization(const QUrl &url,
const QVariantMap &parameters)
{
Q_D(QOAuth2AuthorizationCodeFlow);
Q_ASSERT(url == d->authorizationUrl);
const QUrl u = buildAuthenticateUrl(parameters);
QObjectPrivate::connect(this, &QOAuth2AuthorizationCodeFlow::authorizationCallbackReceived, d,
&QOAuth2AuthorizationCodeFlowPrivate::_q_handleCallback,
Qt::UniqueConnection); Qt::UniqueConnection);
Q_EMIT authorizeWithBrowser(u);
} }
QT_END_NAMESPACE QT_END_NAMESPACE
......
...@@ -93,6 +93,8 @@ public Q_SLOTS: ...@@ -93,6 +93,8 @@ public Q_SLOTS:
protected: protected:
QUrl buildAuthenticateUrl(const QVariantMap &parameters = QVariantMap()); QUrl buildAuthenticateUrl(const QVariantMap &parameters = QVariantMap());
void requestAccessToken(const QString &code);