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 TEMPLATE = subdirs
SUBDIRS = qwt SUBDIRS = qwt
unix:!macx {
SUBDIRS += kqoauth
}
SUBDIRS += src SUBDIRS += src
CONFIG += ordered CONFIG += ordered

View File

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

View File

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

View File

@@ -25,11 +25,6 @@
#include "BodyMeasures.h" #include "BodyMeasures.h"
#include <QMessageBox> #include <QMessageBox>
#ifdef GC_HAVE_KQOAUTH
#include <kqoauthmanager.h>
#include <kqoauthrequest.h>
#endif
#ifndef WITHINGS_DEBUG #ifndef WITHINGS_DEBUG
#define WITHINGS_DEBUG true #define WITHINGS_DEBUG true
#endif #endif
@@ -57,49 +52,21 @@ WithingsDownload::WithingsDownload(Context *context) : context(context)
nam = new QNetworkAccessManager(this); nam = new QNetworkAccessManager(this);
connect(nam, SIGNAL(finished(QNetworkReply*)), this, SLOT(downloadFinished(QNetworkReply*))); 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 bool
WithingsDownload::getBodyMeasures(QString &error, QDateTime from, QDateTime to, QList<BodyMeasure> &data) WithingsDownload::getBodyMeasures(QString &error, QDateTime from, QDateTime to, QList<BodyMeasure> &data)
{ {
response = ""; response = "";
// New API (OAuth)
QString strToken = "";
QString strSecret = "";
QString strNokiaToken = ""; QString strNokiaToken = "";
QString strNokiaRefreshToken = ""; QString strNokiaRefreshToken = "";
QString access_token = ""; 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(); strNokiaToken = appsettings->cvalue(context->athlete->cyclist, GC_NOKIA_TOKEN).toString();
strNokiaRefreshToken = appsettings->cvalue(context->athlete->cyclist, GC_NOKIA_REFRESH_TOKEN).toString(); strNokiaRefreshToken = appsettings->cvalue(context->athlete->cyclist, GC_NOKIA_REFRESH_TOKEN).toString();
if(strNokiaRefreshToken.isEmpty() || strNokiaRefreshToken == "" || strNokiaRefreshToken == "0" ) {
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" ))
{
#ifdef Q_OS_MACX #ifdef Q_OS_MACX
#define GC_PREF tr("Golden Cheetah->Preferences") #define GC_PREF tr("Golden Cheetah->Preferences")
#else #else
@@ -111,10 +78,7 @@ WithingsDownload::getBodyMeasures(QString &error, QDateTime from, QDateTime to,
return false; return false;
} }
if(!strNokiaRefreshToken.isEmpty() || if(!strNokiaRefreshToken.isEmpty()) {
(!strToken.isEmpty() &&! strSecret.isEmpty() &&
strToken != "" && strToken != "0" &&
strSecret != "" && strSecret != "0" )) {
printd("OAuth 2.0 API\n"); printd("OAuth 2.0 API\n");
#if QT_VERSION > 0x050000 #if QT_VERSION > 0x050000
@@ -124,8 +88,6 @@ WithingsDownload::getBodyMeasures(QString &error, QDateTime from, QDateTime to,
#endif #endif
QString refresh_token = appsettings->cvalue(context->athlete->cyclist, GC_NOKIA_REFRESH_TOKEN).toString(); 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("grant_type", "refresh_token");
postData.addQueryItem("client_id", GC_NOKIA_CLIENT_ID ); postData.addQueryItem("client_id", GC_NOKIA_CLIENT_ID );
@@ -136,7 +98,6 @@ WithingsDownload::getBodyMeasures(QString &error, QDateTime from, QDateTime to,
emit downloadStarted(100); emit downloadStarted(100);
//oauthManager->executeRequest(oauthRequest);
QNetworkRequest request(url); QNetworkRequest request(url);
request.setRawHeader("Content-Type", "application/x-www-form-urlencoded"); request.setRawHeader("Content-Type", "application/x-www-form-urlencoded");
nam->post(request, postData.toString(QUrl::FullyEncoded).toUtf8()); 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()); printd("response: %s\n", response.toStdString().c_str());
QJsonParseError parseResult; QJsonParseError parseResult;
if (response.contains("\"status\":0", Qt::CaseInsensitive)) if (response.contains("\"status\":0", Qt::CaseInsensitive)) {
{
parseResult = parse(response, data); parseResult = parse(response, data);
} else { } else {
QMessageBox oautherr(QMessageBox::Critical, tr("Error"), QMessageBox oautherr(QMessageBox::Critical, tr("Error"),
@@ -410,20 +275,3 @@ WithingsDownload::downloadFinished(QNetworkReply *reply)
response = reply->readAll(); response = reply->readAll();
loop.exit(0); 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 "BodyMeasures.h"
#include "WithingsReading.h" #include "WithingsReading.h"
#ifdef GC_HAVE_KQOAUTH
#include <kqoauthmanager.h>
#endif
class WithingsDownload : public QObject class WithingsDownload : public QObject
{ {
Q_OBJECT Q_OBJECT
@@ -53,10 +49,6 @@ private:
QNetworkAccessManager *nam; QNetworkAccessManager *nam;
QString response; QString response;
#ifdef GC_HAVE_KQOAUTH
KQOAuthManager *oauthManager;
KQOAuthRequest *oauthRequest;
#endif
QEventLoop loop; QEventLoop loop;
QJsonParseError parse(QString text, QList<BodyMeasure> &bodyMeasures); QJsonParseError parse(QString text, QList<BodyMeasure> &bodyMeasures);
@@ -65,9 +57,5 @@ private:
private slots: private slots:
void downloadFinished(QNetworkReply *reply); void downloadFinished(QNetworkReply *reply);
#ifdef GC_HAVE_KQOAUTH
void onRequestReady(QByteArray);
void onAuthorizedRequestDone();
#endif
}; };
#endif #endif

View File

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

View File

@@ -331,33 +331,6 @@ contains(DEFINES, "GC_WANT_R") {
QT += opengl 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 ### 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 # cloud services
HEADERS += Cloud/BodyMeasuresDownload.h Cloud/CalDAVCloud.h Cloud/CalendarDownload.h Cloud/CloudService.h \ 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/WithingsDownload.h Cloud/Strava.h Cloud/CyclingAnalytics.h Cloud/RideWithGPS.h \
Cloud/TrainingsTageBuch.h Cloud/Selfloops.h Cloud/Velohero.h Cloud/SportsPlusHealth.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 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 ## Cloud Services / Web resources
SOURCES += Cloud/BodyMeasuresDownload.cpp Cloud/CalDAVCloud.cpp Cloud/CalendarDownload.cpp Cloud/CloudService.cpp \ 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/WithingsDownload.cpp Cloud/Strava.cpp Cloud/CyclingAnalytics.cpp Cloud/RideWithGPS.cpp \
Cloud/TrainingsTageBuch.cpp Cloud/Selfloops.cpp Cloud/Velohero.cpp Cloud/SportsPlusHealth.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 Cloud/AddCloudWizard.cpp Cloud/Withings.cpp Cloud/HrvMeasuresDownload.cpp Cloud/Xert.cpp