mirror of
https://github.com/martinrotter/rssguard.git
synced 2025-02-06 04:14:22 +01:00
Store new tokens.
This commit is contained in:
parent
f0d9f31f50
commit
a7359e3a95
@ -1522,7 +1522,8 @@ Assignment DatabaseQueries::getInoreaderFeeds(QSqlDatabase db, int account_id, b
|
||||
return feeds;
|
||||
}
|
||||
|
||||
bool DatabaseQueries::storeNewInoreaderTokens(QSqlDatabase db, const QString& access_token, const QString& refresh_token, int account_id) {
|
||||
bool DatabaseQueries::storeNewInoreaderTokens(QSqlDatabase db, const QString& access_token,
|
||||
const QString& refresh_token, int account_id) {
|
||||
QSqlQuery query(db);
|
||||
|
||||
query.prepare("UPDATE InoreaderAccounts "
|
||||
|
@ -38,6 +38,7 @@ InoreaderServiceRoot::InoreaderServiceRoot(InoreaderNetworkFactory* network, Roo
|
||||
m_network->setParent(this);
|
||||
}
|
||||
|
||||
m_network->setService(this);
|
||||
setIcon(InoreaderEntryPoint().icon());
|
||||
}
|
||||
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include "gui/dialogs/formmain.h"
|
||||
#include "gui/tabwidget.h"
|
||||
#include "miscellaneous/application.h"
|
||||
#include "miscellaneous/databasequeries.h"
|
||||
#include "network-web/networkfactory.h"
|
||||
#include "network-web/oauth2service.h"
|
||||
#include "network-web/silentnetworkaccessmanager.h"
|
||||
@ -29,6 +30,7 @@
|
||||
#include "services/abstract/category.h"
|
||||
#include "services/inoreader/definitions.h"
|
||||
#include "services/inoreader/inoreaderfeed.h"
|
||||
#include "services/inoreader/inoreaderserviceroot.h"
|
||||
|
||||
#include <QJsonArray>
|
||||
#include <QJsonDocument>
|
||||
@ -36,12 +38,16 @@
|
||||
#include <QUrl>
|
||||
|
||||
InoreaderNetworkFactory::InoreaderNetworkFactory(QObject* parent) : QObject(parent),
|
||||
m_username(QString()), m_batchSize(INOREADER_DEFAULT_BATCH_SIZE),
|
||||
m_service(nullptr), m_username(QString()), m_batchSize(INOREADER_DEFAULT_BATCH_SIZE),
|
||||
m_oauth2(new OAuth2Service(INOREADER_OAUTH_AUTH_URL, INOREADER_OAUTH_TOKEN_URL,
|
||||
INOREADER_OAUTH_CLI_ID, INOREADER_OAUTH_CLI_KEY, INOREADER_OAUTH_SCOPE)) {
|
||||
initializeOauth();
|
||||
}
|
||||
|
||||
void InoreaderNetworkFactory::setService(InoreaderServiceRoot* service) {
|
||||
m_service = service;
|
||||
}
|
||||
|
||||
OAuth2Service* InoreaderNetworkFactory::oauth() const {
|
||||
return m_oauth2;
|
||||
}
|
||||
@ -64,6 +70,14 @@ void InoreaderNetworkFactory::initializeOauth() {
|
||||
|
||||
qApp->showGuiMessage("Authentication error - Inoreader", error_description, QSystemTrayIcon::Critical);
|
||||
});
|
||||
connect(m_oauth2, &OAuth2Service::tokensReceived, [this](QString access_token, QString refresh_token, int expires_in) {
|
||||
Q_UNUSED(expires_in)
|
||||
|
||||
if (m_service != nullptr && !access_token.isEmpty() && !refresh_token.isEmpty()) {
|
||||
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings);
|
||||
DatabaseQueries::storeNewInoreaderTokens(database, access_token, refresh_token, m_service->accountId());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void InoreaderNetworkFactory::setUsername(const QString& username) {
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include <QNetworkReply>
|
||||
|
||||
class RootItem;
|
||||
class InoreaderServiceRoot;
|
||||
class OAuth2Service;
|
||||
|
||||
class InoreaderNetworkFactory : public QObject {
|
||||
@ -34,6 +35,8 @@ class InoreaderNetworkFactory : public QObject {
|
||||
public:
|
||||
explicit InoreaderNetworkFactory(QObject* parent = nullptr);
|
||||
|
||||
void setService(InoreaderServiceRoot* service);
|
||||
|
||||
OAuth2Service* oauth() const;
|
||||
|
||||
QString userName() const;
|
||||
@ -57,6 +60,7 @@ class InoreaderNetworkFactory : public QObject {
|
||||
void initializeOauth();
|
||||
|
||||
private:
|
||||
InoreaderServiceRoot* m_service;
|
||||
QString m_username;
|
||||
int m_batchSize;
|
||||
OAuth2Service* m_oauth2;
|
||||
|
Loading…
x
Reference in New Issue
Block a user