save
This commit is contained in:
parent
0c56897bca
commit
455a07ad83
@ -109,6 +109,7 @@
|
|||||||
#define LOGSEC_NEXTCLOUD "nextcloud: "
|
#define LOGSEC_NEXTCLOUD "nextcloud: "
|
||||||
#define LOGSEC_GREADER "greader: "
|
#define LOGSEC_GREADER "greader: "
|
||||||
#define LOGSEC_INOREADER "inoreader: "
|
#define LOGSEC_INOREADER "inoreader: "
|
||||||
|
#define LOGSEC_FEEDLY "feedly: "
|
||||||
#define LOGSEC_TTRSS "tt-rss: "
|
#define LOGSEC_TTRSS "tt-rss: "
|
||||||
#define LOGSEC_GMAIL "gmail: "
|
#define LOGSEC_GMAIL "gmail: "
|
||||||
#define LOGSEC_OAUTH "oauth: "
|
#define LOGSEC_OAUTH "oauth: "
|
||||||
|
@ -56,7 +56,10 @@ FeedReader::~FeedReader() {
|
|||||||
QList<ServiceEntryPoint*> FeedReader::feedServices() {
|
QList<ServiceEntryPoint*> FeedReader::feedServices() {
|
||||||
if (m_feedServices.isEmpty()) {
|
if (m_feedServices.isEmpty()) {
|
||||||
// NOTE: All installed services create their entry points here.
|
// NOTE: All installed services create their entry points here.
|
||||||
|
#if defined (DEBUG)
|
||||||
m_feedServices.append(new FeedlyEntryPoint());
|
m_feedServices.append(new FeedlyEntryPoint());
|
||||||
|
#endif
|
||||||
|
|
||||||
m_feedServices.append(new GmailEntryPoint());
|
m_feedServices.append(new GmailEntryPoint());
|
||||||
m_feedServices.append(new GreaderEntryPoint());
|
m_feedServices.append(new GreaderEntryPoint());
|
||||||
m_feedServices.append(new InoreaderEntryPoint());
|
m_feedServices.append(new InoreaderEntryPoint());
|
||||||
|
@ -46,8 +46,7 @@ OAuth2Service::OAuth2Service(const QString& auth_url, const QString& token_url,
|
|||||||
const QString& client_secret, const QString& scope, QObject* parent)
|
const QString& client_secret, const QString& scope, QObject* parent)
|
||||||
: QObject(parent),
|
: QObject(parent),
|
||||||
m_id(QString::number(QRandomGenerator::global()->generate())), m_timerId(-1),
|
m_id(QString::number(QRandomGenerator::global()->generate())), m_timerId(-1),
|
||||||
m_redirectionHandler(new OAuthHttpHandler(tr("You can close this window now. Go back to %1.").arg(APP_NAME),
|
m_redirectionHandler(new OAuthHttpHandler(tr("You can close this window now. Go back to %1.").arg(APP_NAME), this)) {
|
||||||
this)) {
|
|
||||||
m_tokenGrantType = QSL("authorization_code");
|
m_tokenGrantType = QSL("authorization_code");
|
||||||
m_tokenUrl = QUrl(token_url);
|
m_tokenUrl = QUrl(token_url);
|
||||||
m_authUrl = auth_url;
|
m_authUrl = auth_url;
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
#include <QUrlQuery>
|
#include <QUrlQuery>
|
||||||
|
|
||||||
OAuthHttpHandler::OAuthHttpHandler(const QString& success_text, QObject* parent)
|
OAuthHttpHandler::OAuthHttpHandler(const QString& success_text, QObject* parent)
|
||||||
: QObject(parent), m_successText(success_text) {
|
: QObject(parent), m_listenAddress(QHostAddress()), m_listenPort(0), m_successText(success_text) {
|
||||||
connect(&m_httpServer, &QTcpServer::newConnection, this, &OAuthHttpHandler::clientConnected);
|
connect(&m_httpServer, &QTcpServer::newConnection, this, &OAuthHttpHandler::clientConnected);
|
||||||
setListenAddressPort(QString(OAUTH_REDIRECT_URI) + QL1C(':') + QString::number(OAUTH_REDIRECT_URI_PORT));
|
setListenAddressPort(QString(OAUTH_REDIRECT_URI) + QL1C(':') + QString::number(OAUTH_REDIRECT_URI_PORT));
|
||||||
}
|
}
|
||||||
|
@ -10,5 +10,6 @@
|
|||||||
#define FEEDLY_API_URL_BASE "https://cloud.feedly.com/v3/"
|
#define FEEDLY_API_URL_BASE "https://cloud.feedly.com/v3/"
|
||||||
#define FEEDLY_API_URL_AUTH "auth/auth"
|
#define FEEDLY_API_URL_AUTH "auth/auth"
|
||||||
#define FEEDLY_API_URL_TOKEN "auth/token"
|
#define FEEDLY_API_URL_TOKEN "auth/token"
|
||||||
|
#define FEEDLY_API_URL_PROFILE "profile"
|
||||||
|
|
||||||
#endif // FEEDLY_DEFINITIONS_H
|
#endif // FEEDLY_DEFINITIONS_H
|
||||||
|
@ -35,7 +35,7 @@ FeedlyNetwork::FeedlyNetwork(QObject* parent)
|
|||||||
m_developerAccessToken(QString()), m_batchSize(FEEDLY_UNLIMITED_BATCH_SIZE) {
|
m_developerAccessToken(QString()), m_batchSize(FEEDLY_UNLIMITED_BATCH_SIZE) {
|
||||||
|
|
||||||
#if defined (FEEDLY_OFFICIAL_SUPPORT)
|
#if defined (FEEDLY_OFFICIAL_SUPPORT)
|
||||||
m_oauth->setRedirectUrl(QString(OAUTH_REDIRECT_URI) + QL1C(':') + QString::number(FEEDLY_API_REDIRECT_URI_PORT));
|
//m_oauth->setRedirectUrl(QString(OAUTH_REDIRECT_URI) + QL1C(':') + QString::number(FEEDLY_API_REDIRECT_URI_PORT));
|
||||||
|
|
||||||
connect(m_oauth, &OAuth2Service::tokensRetrieveError, this, &FeedlyNetwork::onTokensError);
|
connect(m_oauth, &OAuth2Service::tokensRetrieveError, this, &FeedlyNetwork::onTokensError);
|
||||||
connect(m_oauth, &OAuth2Service::authFailed, this, &FeedlyNetwork::onAuthFailed);
|
connect(m_oauth, &OAuth2Service::authFailed, this, &FeedlyNetwork::onAuthFailed);
|
||||||
@ -43,6 +43,34 @@ FeedlyNetwork::FeedlyNetwork(QObject* parent)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString FeedlyNetwork::profile(const QNetworkProxy& network_proxy) {
|
||||||
|
QString bear = bearer();
|
||||||
|
|
||||||
|
if (bear.isEmpty()) {
|
||||||
|
qCriticalNN << LOGSEC_FEEDLY
|
||||||
|
<< "Cannot obtain profile information, because bearer is empty.";
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
QString target_url = fullUrl(Service::Profile);
|
||||||
|
int timeout = qApp->settings()->value(GROUP(Feeds), SETTING(Feeds::UpdateTimeout)).toInt();
|
||||||
|
QByteArray output_msgs;
|
||||||
|
|
||||||
|
// This method uses proxy via parameter,
|
||||||
|
// not via "m_service" field.
|
||||||
|
auto result = NetworkFactory::performNetworkOperation(target_url,
|
||||||
|
timeout,
|
||||||
|
{},
|
||||||
|
output_msgs,
|
||||||
|
QNetworkAccessManager::Operation::GetOperation,
|
||||||
|
{ bearerHeader(bear) },
|
||||||
|
false,
|
||||||
|
{},
|
||||||
|
{},
|
||||||
|
network_proxy);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QString FeedlyNetwork::username() const {
|
QString FeedlyNetwork::username() const {
|
||||||
return m_username;
|
return m_username;
|
||||||
}
|
}
|
||||||
@ -108,6 +136,27 @@ void FeedlyNetwork::onTokensReceived(const QString& access_token, const QString&
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString FeedlyNetwork::fullUrl(FeedlyNetwork::Service service) const {
|
||||||
|
switch (service) {
|
||||||
|
case FeedlyNetwork::Service::Profile:
|
||||||
|
return QSL(FEEDLY_API_URL_BASE) + FEEDLY_API_URL_PROFILE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QString FeedlyNetwork::bearer() const {
|
||||||
|
#if defined (FEEDLY_OFFICIAL_SUPPORT)
|
||||||
|
if (m_developerAccessToken.simplified().isEmpty()) {
|
||||||
|
return m_oauth->bearer().toLocal8Bit();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return QString("Bearer %1").arg(m_developerAccessToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
QPair<QByteArray, QByteArray> FeedlyNetwork::bearerHeader(const QString& bearer) const {
|
||||||
|
return { QString(HTTP_HEADERS_AUTHORIZATION).toLocal8Bit(), bearer.toLocal8Bit() };
|
||||||
|
}
|
||||||
|
|
||||||
OAuth2Service* FeedlyNetwork::oauth() const {
|
OAuth2Service* FeedlyNetwork::oauth() const {
|
||||||
return m_oauth;
|
return m_oauth;
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,10 @@ class FeedlyNetwork : public QObject {
|
|||||||
public:
|
public:
|
||||||
explicit FeedlyNetwork(QObject* parent = nullptr);
|
explicit FeedlyNetwork(QObject* parent = nullptr);
|
||||||
|
|
||||||
|
// API operations.
|
||||||
|
QString profile(const QNetworkProxy& network_proxy);
|
||||||
|
|
||||||
|
// Getters and setters.
|
||||||
QString username() const;
|
QString username() const;
|
||||||
void setUsername(const QString& username);
|
void setUsername(const QString& username);
|
||||||
|
|
||||||
@ -41,6 +45,15 @@ class FeedlyNetwork : public QObject {
|
|||||||
void onTokensReceived(const QString& access_token, const QString& refresh_token, int expires_in);
|
void onTokensReceived(const QString& access_token, const QString& refresh_token, int expires_in);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
private:
|
||||||
|
enum class Service {
|
||||||
|
Profile
|
||||||
|
};
|
||||||
|
|
||||||
|
QString fullUrl(Service service) const;
|
||||||
|
QString bearer() const;
|
||||||
|
QPair<QByteArray, QByteArray> bearerHeader(const QString& bearer) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
FeedlyServiceRoot* m_service;
|
FeedlyServiceRoot* m_service;
|
||||||
|
|
||||||
|
@ -18,9 +18,11 @@ FeedlyAccountDetails::FeedlyAccountDetails(QWidget* parent) : QWidget(parent) {
|
|||||||
#if defined (FEEDLY_OFFICIAL_SUPPORT)
|
#if defined (FEEDLY_OFFICIAL_SUPPORT)
|
||||||
m_oauth = new OAuth2Service(QSL(FEEDLY_API_URL_BASE) + FEEDLY_API_URL_AUTH,
|
m_oauth = new OAuth2Service(QSL(FEEDLY_API_URL_BASE) + FEEDLY_API_URL_AUTH,
|
||||||
QSL(FEEDLY_API_URL_BASE) + FEEDLY_API_URL_TOKEN,
|
QSL(FEEDLY_API_URL_BASE) + FEEDLY_API_URL_TOKEN,
|
||||||
"dontknow",
|
FEEDLY_CLIENT_ID,
|
||||||
"dontknow",
|
FEEDLY_CLIENT_SECRET,
|
||||||
FEEDLY_API_SCOPE, this),
|
FEEDLY_API_SCOPE, this);
|
||||||
|
|
||||||
|
m_oauth->setRedirectUrl(QString(OAUTH_REDIRECT_URI) + QL1C(':') + QString::number(FEEDLY_API_REDIRECT_URI_PORT));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
m_ui.setupUi(this);
|
m_ui.setupUi(this);
|
||||||
@ -107,6 +109,7 @@ void FeedlyAccountDetails::onAuthGranted() {
|
|||||||
|
|
||||||
void FeedlyAccountDetails::performTest(const QNetworkProxy& custom_proxy) {
|
void FeedlyAccountDetails::performTest(const QNetworkProxy& custom_proxy) {
|
||||||
#if defined (FEEDLY_OFFICIAL_SUPPORT)
|
#if defined (FEEDLY_OFFICIAL_SUPPORT)
|
||||||
|
if (m_ui.m_txtDeveloperAccessToken->lineEdit()->text().simplified().isEmpty()) {
|
||||||
m_oauth->logout();
|
m_oauth->logout();
|
||||||
|
|
||||||
if (m_oauth->login()) {
|
if (m_oauth->login()) {
|
||||||
@ -114,14 +117,26 @@ void FeedlyAccountDetails::performTest(const QNetworkProxy& custom_proxy) {
|
|||||||
tr("You are already logged in."),
|
tr("You are already logged in."),
|
||||||
tr("Access granted."));
|
tr("Access granted."));
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
FeedlyNetwork factory;
|
FeedlyNetwork factory;
|
||||||
|
|
||||||
factory.setUsername(m_ui.m_txtUsername->lineEdit()->text());
|
factory.setUsername(m_ui.m_txtUsername->lineEdit()->text());
|
||||||
factory.setDeveloperAccessToken(m_ui.m_txtDeveloperAccessToken->lineEdit()->text());
|
factory.setDeveloperAccessToken(m_ui.m_txtDeveloperAccessToken->lineEdit()->text());
|
||||||
|
|
||||||
// TODO: todo
|
if (!factory.profile(custom_proxy).isEmpty()) {
|
||||||
#endif
|
m_ui.m_lblTestResult->setStatus(WidgetWithStatus::StatusType::Ok,
|
||||||
|
tr("Login was successful."),
|
||||||
|
tr("Access granted."));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
m_ui.m_lblTestResult->setStatus(WidgetWithStatus::StatusType::Error,
|
||||||
|
tr("Make sure your \"development access token\" is correct and your internet works."),
|
||||||
|
tr("Some problems."));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FeedlyAccountDetails::onUsernameChanged() {
|
void FeedlyAccountDetails::onUsernameChanged() {
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
FormEditFeedlyAccount::FormEditFeedlyAccount(QWidget* parent)
|
FormEditFeedlyAccount::FormEditFeedlyAccount(QWidget* parent)
|
||||||
: FormAccountDetails(qApp->icons()->miscIcon(QSL("google")), parent), m_details(new FeedlyAccountDetails(this)) {
|
: FormAccountDetails(qApp->icons()->miscIcon(QSL("feedly")), parent), m_details(new FeedlyAccountDetails(this)) {
|
||||||
insertCustomTab(m_details, tr("Service setup"), 0);
|
insertCustomTab(m_details, tr("Service setup"), 0);
|
||||||
activateTab(0);
|
activateTab(0);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user