Start with persisting credentials

Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
This commit is contained in:
Roeland Jago Douma 2017-11-25 20:19:25 +01:00
parent 356f9b4831
commit 6b43d80c01
No known key found for this signature in database
GPG key ID: F941078878347C0C
4 changed files with 121 additions and 0 deletions

View file

@ -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

View file

@ -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;

View file

@ -0,0 +1,74 @@
#include "webflowcredentials.h"
#include <keychain.h>
#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(){
}
}

View file

@ -0,0 +1,43 @@
#ifndef WEBFLOWCREDENTIALS_H
#define WEBFLOWCREDENTIALS_H
#include <QSslCertificate>
#include <QSslKey>
#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