Deprecate KQOauth

.. its dead (not updated for 5 years)

.. it introduces dependency issues with openssl/crypto/icu
   on Linux distros

.. we don't need it, since OAuthDialog does the heavy
   lifting we need (ok, its not pretty but it works).

.. old code moved into the deprecated folder

Fixes #2881
This commit is contained in:
Mark Liversedge
2018-06-02 11:01:43 +01:00
parent 9e21ececff
commit cdd99da9c9
29 changed files with 20 additions and 248 deletions

View File

@@ -1,7 +1,4 @@
TEMPLATE = subdirs
SUBDIRS = qwt
unix:!macx {
SUBDIRS += kqoauth
}
SUBDIRS += src
CONFIG += ordered

View File

@@ -25,7 +25,6 @@
#include "Colors.h"
#include "CloudService.h"
#include "OAuthDialog.h"
#include "OAuthManager.h"
#include <QMessageBox>
#include <QRegExp>
@@ -317,48 +316,27 @@ AddAuth::doAuth()
updateServiceSettings();
if (wizard->cloudService->capabilities() & CloudService::OAuth) {
if (wizard->cloudService->capabilities() & CloudService::UserPass) {
OAuthManager *oauthManager = new OAuthManager(wizard->context, OAuthManager::NONE, wizard->cloudService);
if (oauthManager->sslLibMissing()) {
delete oauthManager;
} else {
OAuthDialog *oauthDialog = new OAuthDialog(wizard->context, OAuthDialog::NONE, wizard->cloudService);
if (oauthDialog->sslLibMissing()) {
delete oauthDialog;
} else {
oauthDialog->setWindowModality(Qt::ApplicationModal);
oauthDialog->exec();
token->setText(wizard->cloudService->getSetting(cname, "").toString());
QString msg = wizard->cloudService->message;
if (msg != "") {
message->setText(msg);
messageLabel->show();
message->show();
message->setText(QString("Connecting with %1...").arg(wizard->cloudService->id()));
oauthManager->authorize();
token->setText(wizard->cloudService->getSetting(cname, "").toString());
QString msg = wizard->cloudService->message;
if (msg != "") {
message->setText(msg);
wizard->cloudService->message = "";
}
wizard->cloudService->message = "";
}
} else {
OAuthDialog *oauthDialog = new OAuthDialog(wizard->context, OAuthDialog::NONE, wizard->cloudService);
if (oauthDialog->sslLibMissing()) {
delete oauthDialog;
} else {
oauthDialog->setWindowModality(Qt::ApplicationModal);
oauthDialog->exec();
token->setText(wizard->cloudService->getSetting(cname, "").toString());
QString msg = wizard->cloudService->message;
if (msg != "") {
message->setText(msg);
messageLabel->show();
message->show();
wizard->cloudService->message = "";
}
// Due to the OAuth dialog being modal, the order of the background windows can get out of order
// This ensures the wizard is back on top
wizard->raise();
}
// Due to the OAuth dialog being modal, the order of the background windows can get out of order
// This ensures the wizard is back on top
wizard->raise();
}
}
}
void

View File

@@ -21,9 +21,6 @@
#include "GoldenCheetah.h"
#include "Pages.h"
#include "CloudService.h"
#ifdef GC_HAVE_KQOAUTH
#include <kqoauthmanager.h>
#endif
#include <QObject>
#include <QtGui>
#include <QWidget>
@@ -108,11 +105,6 @@ private:
QNetworkAccessManager* manager;
QUrl url;
#ifdef GC_HAVE_KQOAUTH
KQOAuthManager *oauthManager;
KQOAuthRequest *oauthRequest;
#endif
};
#endif // OAUTHDIALOG_H

View File

@@ -25,11 +25,6 @@
#include "BodyMeasures.h"
#include <QMessageBox>
#ifdef GC_HAVE_KQOAUTH
#include <kqoauthmanager.h>
#include <kqoauthrequest.h>
#endif
#ifndef WITHINGS_DEBUG
#define WITHINGS_DEBUG true
#endif
@@ -57,49 +52,21 @@ WithingsDownload::WithingsDownload(Context *context) : context(context)
nam = new QNetworkAccessManager(this);
connect(nam, SIGNAL(finished(QNetworkReply*)), this, SLOT(downloadFinished(QNetworkReply*)));
#ifdef GC_HAVE_KQOAUTH
oauthRequest = new KQOAuthRequest();
oauthManager = new KQOAuthManager();
connect(oauthManager, SIGNAL(authorizedRequestDone()),
this, SLOT(onAuthorizedRequestDone()));
connect(oauthManager, SIGNAL(requestReady(QByteArray)),
this, SLOT(onRequestReady(QByteArray)));
#endif
}
bool
WithingsDownload::getBodyMeasures(QString &error, QDateTime from, QDateTime to, QList<BodyMeasure> &data)
{
response = "";
// New API (OAuth)
QString strToken = "";
QString strSecret = "";
QString strNokiaToken = "";
QString strNokiaRefreshToken = "";
QString access_token = "";
#ifdef GC_HAVE_KQOAUTH
strToken = appsettings->cvalue(context->athlete->cyclist, GC_WITHINGS_TOKEN).toString();
strSecret= appsettings->cvalue(context->athlete->cyclist, GC_WITHINGS_SECRET).toString();
#endif
strNokiaToken = appsettings->cvalue(context->athlete->cyclist, GC_NOKIA_TOKEN).toString();
strNokiaRefreshToken = appsettings->cvalue(context->athlete->cyclist, GC_NOKIA_REFRESH_TOKEN).toString();
QString strOldKey = appsettings->cvalue(context->athlete->cyclist, GC_WIKEY).toString();
if((strToken.isEmpty() || strSecret.isEmpty() ||
strToken == "" || strToken == "0" ||
strSecret == "" || strSecret == "0" ) &&
(strOldKey.isEmpty() || strOldKey == "" || strOldKey == "0" ) &&
(strNokiaRefreshToken.isEmpty() || strNokiaRefreshToken == "" || strNokiaRefreshToken == "0" ))
{
if(strNokiaRefreshToken.isEmpty() || strNokiaRefreshToken == "" || strNokiaRefreshToken == "0" ) {
#ifdef Q_OS_MACX
#define GC_PREF tr("Golden Cheetah->Preferences")
#else
@@ -111,10 +78,7 @@ WithingsDownload::getBodyMeasures(QString &error, QDateTime from, QDateTime to,
return false;
}
if(!strNokiaRefreshToken.isEmpty() ||
(!strToken.isEmpty() &&! strSecret.isEmpty() &&
strToken != "" && strToken != "0" &&
strSecret != "" && strSecret != "0" )) {
if(!strNokiaRefreshToken.isEmpty()) {
printd("OAuth 2.0 API\n");
#if QT_VERSION > 0x050000
@@ -124,8 +88,6 @@ WithingsDownload::getBodyMeasures(QString &error, QDateTime from, QDateTime to,
#endif
QString refresh_token = appsettings->cvalue(context->athlete->cyclist, GC_NOKIA_REFRESH_TOKEN).toString();
if (refresh_token.isEmpty())
refresh_token = QString("%1:%2").arg(strToken).arg(strSecret);
postData.addQueryItem("grant_type", "refresh_token");
postData.addQueryItem("client_id", GC_NOKIA_CLIENT_ID );
@@ -136,7 +98,6 @@ WithingsDownload::getBodyMeasures(QString &error, QDateTime from, QDateTime to,
emit downloadStarted(100);
//oauthManager->executeRequest(oauthRequest);
QNetworkRequest request(url);
request.setRawHeader("Content-Type", "application/x-www-form-urlencoded");
nam->post(request, postData.toString(QUrl::FullyEncoded).toUtf8());
@@ -197,106 +158,10 @@ WithingsDownload::getBodyMeasures(QString &error, QDateTime from, QDateTime to,
}
}
if(access_token.isEmpty() && !strToken.isEmpty() &&! strSecret.isEmpty() &&
strToken != "" && strToken != "0" &&
strSecret != "" && strSecret != "0" ) {
printd("OAuth 1.0 API\n");
#ifdef GC_HAVE_KQOAUTH
oauthRequest->initRequest(KQOAuthRequest::AuthorizedRequest, QUrl("http://wbsapi.withings.net/measure"));
oauthRequest->setHttpMethod(KQOAuthRequest::GET);
//oauthRequest->setEnableDebugOutput(true);
oauthRequest->setConsumerKey(GC_WITHINGS_CONSUMER_KEY);
oauthRequest->setConsumerSecretKey(GC_WITHINGS_CONSUMER_SECRET);
// set the user token and secret
oauthRequest->setToken(strToken);
oauthRequest->setTokenSecret(strSecret);
KQOAuthParameters params;
params.insert("action", "getmeas");
params.insert("userid", appsettings->cvalue(context->athlete->cyclist, GC_WIUSER, "").toString());
params.insert("startdate", QString::number(from.toMSecsSinceEpoch()/1000));
params.insert("enddate", QString::number(to.toMSecsSinceEpoch()/1000));
oauthRequest->setAdditionalParameters(params);
// Hack...
// Why should we add params manually (GET) ????
// We can use KQOAuth because Nokia/Withings expect token in url.
QList<QByteArray> requestParameters = oauthRequest->requestParameters();
#if QT_VERSION > 0x050000
QUrlQuery params2;
#else
QUrl params2;
#endif
for (int i=0; i<requestParameters.count(); i++) {
QString _rp = requestParameters.at(i);
_rp = _rp;
QString key = _rp.left(_rp.indexOf("="));
QString value = _rp.right(_rp.length()-key.length()-1).replace("\"", "");
params2.addQueryItem(key, value);
}
params2.addQueryItem("action", "getmeas");
params2.addQueryItem("userid", appsettings->cvalue(context->athlete->cyclist, GC_WIUSER, "").toString());
params2.addQueryItem("startdate", QString::number(from.toMSecsSinceEpoch()/1000));
params2.addQueryItem("enddate", QString::number(to.toMSecsSinceEpoch()/1000));
QUrl url = QUrl( "https://wbsapi.withings.net/measure?" + params2.toString() );
printd("URL : %s\n", url.url().toStdString().c_str());
emit downloadStarted(100);
//oauthManager->executeRequest(oauthRequest);
QNetworkRequest request(url);
nam->get(request);
emit downloadProgress(50);
// blocking request
loop.exec(); // we go on after receiving the data in SLOT(onRequestReady(QByteArray))
emit downloadEnded(100);
#endif
} else if (access_token.isEmpty()) {
printd("Withings password API\n");
// account for trailing slash, remove it if it is there (it was the default in preferences)
QString server = appsettings->cvalue(context->athlete->cyclist, GC_WIURL, "http://wbsapi.withings.net").toString();
if (server.endsWith("/")) server=server.mid(0, server.length()-1);
QString request = QString("%1/measure?action=getmeas&userid=%2&publickey=%3&startdate=%4&enddate=%5")
.arg(server)
.arg(appsettings->cvalue(context->athlete->cyclist, GC_WIUSER, "").toString())
.arg(appsettings->cvalue(context->athlete->cyclist, GC_WIKEY, "").toString())
.arg(QString::number(from.toMSecsSinceEpoch()/1000))
.arg(QString::number(to.toMSecsSinceEpoch()/1000));
emit downloadStarted(100);
QNetworkReply *reply = nam->get(QNetworkRequest(QUrl(request)));
emit downloadProgress(50);
// blocking request
loop.exec(); // we go on after receiving the data in SLOT(downloadFinished(QNetworkReply))
emit downloadEnded(100);
if (reply->error() != QNetworkReply::NoError) {
QMessageBox::warning(context->mainWindow, tr("Nokia Health (Withings) Data Download"), reply->errorString());
return false;
}
}
printd("response: %s\n", response.toStdString().c_str());
QJsonParseError parseResult;
if (response.contains("\"status\":0", Qt::CaseInsensitive))
{
if (response.contains("\"status\":0", Qt::CaseInsensitive)) {
parseResult = parse(response, data);
} else {
QMessageBox oautherr(QMessageBox::Critical, tr("Error"),
@@ -410,20 +275,3 @@ WithingsDownload::downloadFinished(QNetworkReply *reply)
response = reply->readAll();
loop.exit(0);
}
#ifdef GC_HAVE_KQOAUTH
void
WithingsDownload::onAuthorizedRequestDone() {
// printd("Request sent to Withings!\n");
}
void
WithingsDownload::onRequestReady(QByteArray r) {
//printd("Response from the Withings's service: %s\n", response..toStdString().c_str());
response = r;
loop.exit(0);
}
#endif

View File

@@ -29,10 +29,6 @@
#include "BodyMeasures.h"
#include "WithingsReading.h"
#ifdef GC_HAVE_KQOAUTH
#include <kqoauthmanager.h>
#endif
class WithingsDownload : public QObject
{
Q_OBJECT
@@ -53,10 +49,6 @@ private:
QNetworkAccessManager *nam;
QString response;
#ifdef GC_HAVE_KQOAUTH
KQOAuthManager *oauthManager;
KQOAuthRequest *oauthRequest;
#endif
QEventLoop loop;
QJsonParseError parse(QString text, QList<BodyMeasure> &bodyMeasures);
@@ -65,9 +57,5 @@ private:
private slots:
void downloadFinished(QNetworkReply *reply);
#ifdef GC_HAVE_KQOAUTH
void onRequestReady(QByteArray);
void onAuthorizedRequestDone();
#endif
};
#endif

View File

@@ -59,10 +59,6 @@
#include "srmio.h"
#endif
#ifdef GC_HAVE_KQOAUTH
#include "kqoauthmanager.h"
#endif
#ifdef GC_HAVE_SAMPLERATE
#include <samplerate.h>
#endif

View File

@@ -331,33 +331,6 @@ contains(DEFINES, "GC_WANT_R") {
QT += opengl
}
###====================
### OPTIONAL => KQOAUTH
###====================
unix:!macx {
# build from version in repo for Linux builds since
# kqoauth is not packaged for the Debian and this makes
# life much easier for the package maintainer
INCLUDEPATH += $${PWD}/../kqoauth
LIBS += $${PWD}/../kqoauth/libkqoauth.a
DEFINES += GC_HAVE_KQOAUTH
} else {
!isEmpty(KQOAUTH_INSTALL) {
# we will work out the rest if you tell us where it is installed
isEmpty(KQOAUTH_INCLUDE) { KQOAUTH_INCLUDE = $${KQOAUTH_INSTALL}/src }
isEmpty(KQOAUTH_LIBS) { KQOAUTH_LIBS = -L$${KQOAUTH_INSTALL}/lib -lkqoauth }
INCLUDEPATH += $${KQOAUTH_INCLUDE}
LIBS += $${KQOAUTH_LIBS}
DEFINES += GC_HAVE_KQOAUTH
}
}
###=======================================================
### OPTIONAL => D2XX FOR FTDI DRIVERS ON WINDOWS PLATFORMS
###=======================================================
@@ -707,7 +680,7 @@ HEADERS += Charts/Aerolab.h Charts/AerolabWindow.h Charts/AllPlot.h Charts/AllPl
# cloud services
HEADERS += Cloud/BodyMeasuresDownload.h Cloud/CalDAVCloud.h Cloud/CalendarDownload.h Cloud/CloudService.h \
Cloud/LocalFileStore.h Cloud/OAuthDialog.h Cloud/OAuthManager.h Cloud/TodaysPlanBodyMeasures.h \
Cloud/LocalFileStore.h Cloud/OAuthDialog.h Cloud/TodaysPlanBodyMeasures.h \
Cloud/WithingsDownload.h Cloud/Strava.h Cloud/CyclingAnalytics.h Cloud/RideWithGPS.h \
Cloud/TrainingsTageBuch.h Cloud/Selfloops.h Cloud/Velohero.h Cloud/SportsPlusHealth.h \
Cloud/AddCloudWizard.h Cloud/Withings.h Cloud/HrvMeasuresDownload.h Cloud/Xert.h
@@ -800,7 +773,7 @@ SOURCES += Charts/Aerolab.cpp Charts/AerolabWindow.cpp Charts/AllPlot.cpp Charts
## Cloud Services / Web resources
SOURCES += Cloud/BodyMeasuresDownload.cpp Cloud/CalDAVCloud.cpp Cloud/CalendarDownload.cpp Cloud/CloudService.cpp \
Cloud/LocalFileStore.cpp Cloud/OAuthDialog.cpp Cloud/OAuthManager.cpp Cloud/TodaysPlanBodyMeasures.cpp \
Cloud/LocalFileStore.cpp Cloud/OAuthDialog.cpp Cloud/TodaysPlanBodyMeasures.cpp \
Cloud/WithingsDownload.cpp Cloud/Strava.cpp Cloud/CyclingAnalytics.cpp Cloud/RideWithGPS.cpp \
Cloud/TrainingsTageBuch.cpp Cloud/Selfloops.cpp Cloud/Velohero.cpp Cloud/SportsPlusHealth.cpp \
Cloud/AddCloudWizard.cpp Cloud/Withings.cpp Cloud/HrvMeasuresDownload.cpp Cloud/Xert.cpp