From 6b43d80c017e64a428363895a50a6fdae05721d9 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Sat, 25 Nov 2017 20:19:25 +0100 Subject: [PATCH] Start with persisting credentials Signed-off-by: Roeland Jago Douma --- src/gui/CMakeLists.txt | 1 + src/gui/creds/credentialsfactory.cpp | 3 ++ src/gui/creds/webflowcredentials.cpp | 74 ++++++++++++++++++++++++++++ src/gui/creds/webflowcredentials.h | 43 ++++++++++++++++ 4 files changed, 121 insertions(+) create mode 100644 src/gui/creds/webflowcredentials.cpp create mode 100644 src/gui/creds/webflowcredentials.h diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index e162b7cf9..fed053cc3 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -102,6 +102,7 @@ set(client_SRCS creds/credentialsfactory.cpp creds/httpcredentialsgui.cpp creds/oauth.cpp + creds/webflowcredentials.cpp wizard/postfixlineedit.cpp wizard/abstractcredswizardpage.cpp wizard/owncloudadvancedsetuppage.cpp diff --git a/src/gui/creds/credentialsfactory.cpp b/src/gui/creds/credentialsfactory.cpp index 52e003b57..6062f70eb 100644 --- a/src/gui/creds/credentialsfactory.cpp +++ b/src/gui/creds/credentialsfactory.cpp @@ -21,6 +21,7 @@ #ifndef NO_SHIBBOLETH #include "creds/shibbolethcredentials.h" #endif +#include "creds/webflowcredentials.h" namespace OCC { @@ -39,6 +40,8 @@ namespace CredentialsFactory { } else if (type == "shibboleth") { return new ShibbolethCredentials; #endif + } else if (type == "webflow") { + return new WebFlowCredentials; } else { qCWarning(lcGuiCredentials, "Unknown credentials type: %s", qPrintable(type)); return new DummyCredentials; diff --git a/src/gui/creds/webflowcredentials.cpp b/src/gui/creds/webflowcredentials.cpp new file mode 100644 index 000000000..f119586db --- /dev/null +++ b/src/gui/creds/webflowcredentials.cpp @@ -0,0 +1,74 @@ +#include "webflowcredentials.h" + +#include + +#include "accessmanager.h" +#include "account.h" +#include "theme.h" + +using namespace QKeychain; + +namespace OCC { + +WebFlowCredentials::WebFlowCredentials() + : _ready(false) +{ + +} + +WebFlowCredentials::WebFlowCredentials(const QString &user, const QString &password, const QSslCertificate &certificate, const QSslKey &key) + : _user(user) + , _password(password) + , _clientSslKey(key) + , _clientSslCertificate(certificate) + , _ready(true) +{ + +} + +QString WebFlowCredentials::authType() const { + return QString::fromLatin1("webflow"); +} + +QString WebFlowCredentials::user() const { + return _user; +} + +QNetworkAccessManager *WebFlowCredentials::createQNAM() const { + AccessManager *qnam = new AccessManager(); + return qnam; +} + +bool WebFlowCredentials::ready() const { + +} + +void WebFlowCredentials::fetchFromKeychain() { + +} +void WebFlowCredentials::askFromUser() { + +} + +bool WebFlowCredentials::stillValid(QNetworkReply *reply) { + +} + +void WebFlowCredentials::persist() { + //TODO: Add ssl cert and key storing + WritePasswordJob *job = new WritePasswordJob(Theme::instance()->appName()); + job->setInsecureFallback(false); + job->setKey(keychainKey(_account->url().toString(), _user, _account->id())); + job->setTextData(_password); + job->start(); +} + +void WebFlowCredentials::invalidateToken() { + +} + +void WebFlowCredentials::forgetSensitiveData(){ + +} + +} diff --git a/src/gui/creds/webflowcredentials.h b/src/gui/creds/webflowcredentials.h new file mode 100644 index 000000000..6c4a351b9 --- /dev/null +++ b/src/gui/creds/webflowcredentials.h @@ -0,0 +1,43 @@ +#ifndef WEBFLOWCREDENTIALS_H +#define WEBFLOWCREDENTIALS_H + +#include +#include + +#include "creds/abstractcredentials.h" + +namespace OCC { + +class WebFlowCredentials : public AbstractCredentials +{ + Q_OBJECT +public: + explicit WebFlowCredentials(); + WebFlowCredentials(const QString &user, const QString &password, const QSslCertificate &certificate = QSslCertificate(), const QSslKey &key = QSslKey()); + + QString authType() const Q_DECL_OVERRIDE; + QString user() const Q_DECL_OVERRIDE; + QNetworkAccessManager *createQNAM() const Q_DECL_OVERRIDE; + + bool ready() const Q_DECL_OVERRIDE; + + void fetchFromKeychain() Q_DECL_OVERRIDE; + void askFromUser() Q_DECL_OVERRIDE; + + bool stillValid(QNetworkReply *reply) Q_DECL_OVERRIDE; + void persist() Q_DECL_OVERRIDE; + void invalidateToken() Q_DECL_OVERRIDE; + void forgetSensitiveData() Q_DECL_OVERRIDE; + +private: + QString _user; + QString _password; + QSslKey _clientSslKey; + QSslCertificate _clientSslCertificate; + + bool _ready; +}; + +} + +#endif // WEBFLOWCREDENTIALS_H