This commit is contained in:
Martin Rotter 2021-02-08 15:40:34 +01:00
parent 0c56897bca
commit 455a07ad83
9 changed files with 100 additions and 19 deletions

View File

@ -109,6 +109,7 @@
#define LOGSEC_NEXTCLOUD "nextcloud: "
#define LOGSEC_GREADER "greader: "
#define LOGSEC_INOREADER "inoreader: "
#define LOGSEC_FEEDLY "feedly: "
#define LOGSEC_TTRSS "tt-rss: "
#define LOGSEC_GMAIL "gmail: "
#define LOGSEC_OAUTH "oauth: "

View File

@ -56,7 +56,10 @@ FeedReader::~FeedReader() {
QList<ServiceEntryPoint*> FeedReader::feedServices() {
if (m_feedServices.isEmpty()) {
// NOTE: All installed services create their entry points here.
#if defined (DEBUG)
m_feedServices.append(new FeedlyEntryPoint());
#endif
m_feedServices.append(new GmailEntryPoint());
m_feedServices.append(new GreaderEntryPoint());
m_feedServices.append(new InoreaderEntryPoint());

View File

@ -46,8 +46,7 @@ OAuth2Service::OAuth2Service(const QString& auth_url, const QString& token_url,
const QString& client_secret, const QString& scope, QObject* parent)
: QObject(parent),
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),
this)) {
m_redirectionHandler(new OAuthHttpHandler(tr("You can close this window now. Go back to %1.").arg(APP_NAME), this)) {
m_tokenGrantType = QSL("authorization_code");
m_tokenUrl = QUrl(token_url);
m_authUrl = auth_url;

View File

@ -11,7 +11,7 @@
#include <QUrlQuery>
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);
setListenAddressPort(QString(OAUTH_REDIRECT_URI) + QL1C(':') + QString::number(OAUTH_REDIRECT_URI_PORT));
}

View File

@ -10,5 +10,6 @@
#define FEEDLY_API_URL_BASE "https://cloud.feedly.com/v3/"
#define FEEDLY_API_URL_AUTH "auth/auth"
#define FEEDLY_API_URL_TOKEN "auth/token"
#define FEEDLY_API_URL_PROFILE "profile"
#endif // FEEDLY_DEFINITIONS_H

View File

@ -35,7 +35,7 @@ FeedlyNetwork::FeedlyNetwork(QObject* parent)
m_developerAccessToken(QString()), m_batchSize(FEEDLY_UNLIMITED_BATCH_SIZE) {
#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::authFailed, this, &FeedlyNetwork::onAuthFailed);
@ -43,6 +43,34 @@ FeedlyNetwork::FeedlyNetwork(QObject* parent)
#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 {
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 {
return m_oauth;
}

View File

@ -20,6 +20,10 @@ class FeedlyNetwork : public QObject {
public:
explicit FeedlyNetwork(QObject* parent = nullptr);
// API operations.
QString profile(const QNetworkProxy& network_proxy);
// Getters and setters.
QString username() const;
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);
#endif
private:
enum class Service {
Profile
};
QString fullUrl(Service service) const;
QString bearer() const;
QPair<QByteArray, QByteArray> bearerHeader(const QString& bearer) const;
private:
FeedlyServiceRoot* m_service;

View File

@ -18,9 +18,11 @@ FeedlyAccountDetails::FeedlyAccountDetails(QWidget* parent) : QWidget(parent) {
#if defined (FEEDLY_OFFICIAL_SUPPORT)
m_oauth = new OAuth2Service(QSL(FEEDLY_API_URL_BASE) + FEEDLY_API_URL_AUTH,
QSL(FEEDLY_API_URL_BASE) + FEEDLY_API_URL_TOKEN,
"dontknow",
"dontknow",
FEEDLY_API_SCOPE, this),
FEEDLY_CLIENT_ID,
FEEDLY_CLIENT_SECRET,
FEEDLY_API_SCOPE, this);
m_oauth->setRedirectUrl(QString(OAUTH_REDIRECT_URI) + QL1C(':') + QString::number(FEEDLY_API_REDIRECT_URI_PORT));
#endif
m_ui.setupUi(this);
@ -107,6 +109,7 @@ void FeedlyAccountDetails::onAuthGranted() {
void FeedlyAccountDetails::performTest(const QNetworkProxy& custom_proxy) {
#if defined (FEEDLY_OFFICIAL_SUPPORT)
if (m_ui.m_txtDeveloperAccessToken->lineEdit()->text().simplified().isEmpty()) {
m_oauth->logout();
if (m_oauth->login()) {
@ -114,14 +117,26 @@ void FeedlyAccountDetails::performTest(const QNetworkProxy& custom_proxy) {
tr("You are already logged in."),
tr("Access granted."));
}
#else
return;
}
#endif
FeedlyNetwork factory;
factory.setUsername(m_ui.m_txtUsername->lineEdit()->text());
factory.setDeveloperAccessToken(m_ui.m_txtDeveloperAccessToken->lineEdit()->text());
// TODO: todo
#endif
if (!factory.profile(custom_proxy).isEmpty()) {
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() {

View File

@ -15,7 +15,7 @@
#endif
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);
activateTab(0);