Work on oauth workflow.
This commit is contained in:
parent
b452c0d3f7
commit
e194a3ef08
4 changed files with 77 additions and 14 deletions
|
@ -25,5 +25,7 @@
|
||||||
#define INOREADER_OAUTH_AUTH_URL "https://www.inoreader.com/oauth2/auth"
|
#define INOREADER_OAUTH_AUTH_URL "https://www.inoreader.com/oauth2/auth"
|
||||||
#define INOREADER_OAUTH_CLI_ID "1000000604"
|
#define INOREADER_OAUTH_CLI_ID "1000000604"
|
||||||
#define INOREADER_OAUTH_CLI_KEY "gsStoZ3aAoQJCgQxoFSuXkWI7Sly87yK"
|
#define INOREADER_OAUTH_CLI_KEY "gsStoZ3aAoQJCgQxoFSuXkWI7Sly87yK"
|
||||||
|
#define INOREADER_REFRESH_TOKEN_KEY "refresh_token"
|
||||||
|
#define INOREADER_ACCESS_TOKEN_KEY "access_token"
|
||||||
|
|
||||||
#endif // INOREADER_DEFINITIONS_H
|
#endif // INOREADER_DEFINITIONS_H
|
||||||
|
|
|
@ -7,25 +7,44 @@
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>400</width>
|
<width>400</width>
|
||||||
<height>157</height>
|
<height>180</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
<string>Dialog</string>
|
<string>Dialog</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout">
|
<layout class="QFormLayout" name="formLayout">
|
||||||
<item row="1" column="0">
|
<item row="0" column="0">
|
||||||
<widget class="QDialogButtonBox" name="m_buttonBox">
|
<widget class="QLabel" name="label">
|
||||||
<property name="orientation">
|
<property name="text">
|
||||||
<enum>Qt::Horizontal</enum>
|
<string>Only download newest X messages per feed</string>
|
||||||
</property>
|
|
||||||
<property name="standardButtons">
|
|
||||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="0">
|
<item row="0" column="1">
|
||||||
<layout class="QFormLayout" name="formLayout">
|
<widget class="QSpinBox" name="m_spinLimitMessages">
|
||||||
|
<property name="maximumSize">
|
||||||
|
<size>
|
||||||
|
<width>140</width>
|
||||||
|
<height>16777215</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="suffix">
|
||||||
|
<string> = unlimited</string>
|
||||||
|
</property>
|
||||||
|
<property name="minimum">
|
||||||
|
<number>-1</number>
|
||||||
|
</property>
|
||||||
|
<property name="maximum">
|
||||||
|
<number>1000</number>
|
||||||
|
</property>
|
||||||
|
<property name="value">
|
||||||
|
<number>-1</number>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="0" colspan="2">
|
||||||
|
<layout class="QFormLayout" name="formLayout_2">
|
||||||
<item row="0" column="0">
|
<item row="0" column="0">
|
||||||
<widget class="QPushButton" name="m_btnTestSetup">
|
<widget class="QPushButton" name="m_btnTestSetup">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
|
@ -36,9 +55,9 @@
|
||||||
<item row="0" column="1">
|
<item row="0" column="1">
|
||||||
<widget class="LabelWithStatus" name="m_lblTestResult" native="true">
|
<widget class="LabelWithStatus" name="m_lblTestResult" native="true">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||||
<horstretch>0</horstretch>
|
<horstretch>0</horstretch>
|
||||||
<verstretch>0</verstretch>
|
<verstretch>1</verstretch>
|
||||||
</sizepolicy>
|
</sizepolicy>
|
||||||
</property>
|
</property>
|
||||||
<property name="layoutDirection">
|
<property name="layoutDirection">
|
||||||
|
@ -48,6 +67,29 @@
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="3" column="0" colspan="2">
|
||||||
|
<widget class="QDialogButtonBox" name="m_buttonBox">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="standardButtons">
|
||||||
|
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="0" colspan="2">
|
||||||
|
<spacer name="verticalSpacer">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Vertical</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>20</width>
|
||||||
|
<height>90</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<customwidgets>
|
<customwidgets>
|
||||||
|
@ -59,6 +101,7 @@
|
||||||
</customwidget>
|
</customwidget>
|
||||||
</customwidgets>
|
</customwidgets>
|
||||||
<tabstops>
|
<tabstops>
|
||||||
|
<tabstop>m_spinLimitMessages</tabstop>
|
||||||
<tabstop>m_btnTestSetup</tabstop>
|
<tabstop>m_btnTestSetup</tabstop>
|
||||||
</tabstops>
|
</tabstops>
|
||||||
<resources/>
|
<resources/>
|
||||||
|
|
|
@ -38,7 +38,8 @@ bool InoreaderNetworkFactory::isLoggedIn() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
void InoreaderNetworkFactory::logIn() {
|
void InoreaderNetworkFactory::logIn() {
|
||||||
if (!m_oauth2.expirationAt().isNull() && m_oauth2.expirationAt() <= QDateTime::currentDateTime()) {
|
if (!m_oauth2.expirationAt().isNull() && m_oauth2.expirationAt() <= QDateTime::currentDateTime() && !m_refreshToken.isEmpty()) {
|
||||||
|
// We have some refresh token which expired.
|
||||||
m_oauth2.refreshAccessToken();
|
m_oauth2.refreshAccessToken();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -73,6 +74,19 @@ void InoreaderNetworkFactory::initializeOauth() {
|
||||||
connect(&m_oauth2, &QOAuth2AuthorizationCodeFlow::statusChanged, [=](QAbstractOAuth::Status status) {
|
connect(&m_oauth2, &QOAuth2AuthorizationCodeFlow::statusChanged, [=](QAbstractOAuth::Status status) {
|
||||||
qDebug("Inoreader: Status changed to '%d'.", (int)status);
|
qDebug("Inoreader: Status changed to '%d'.", (int)status);
|
||||||
});
|
});
|
||||||
|
connect(oauth_reply_handler, &QOAuthHttpServerReplyHandler::tokensReceived, [this](QVariantMap tokens) {
|
||||||
|
qDebug() << "Inoreader: Tokens received:" << tokens;
|
||||||
|
|
||||||
|
if (tokens.contains(QSL(INOREADER_REFRESH_TOKEN_KEY))) {
|
||||||
|
m_refreshToken = tokens.value(QSL(INOREADER_REFRESH_TOKEN_KEY)).toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tokens.contains(QSL(INOREADER_ACCESS_TOKEN_KEY))) {
|
||||||
|
m_accessToken = tokens.value(QSL(INOREADER_ACCESS_TOKEN_KEY)).toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
emit tokensRefreshed();
|
||||||
|
});
|
||||||
m_oauth2.setModifyParametersFunction([&](QAbstractOAuth::Stage stage, QVariantMap* parameters) {
|
m_oauth2.setModifyParametersFunction([&](QAbstractOAuth::Stage stage, QVariantMap* parameters) {
|
||||||
qDebug() << "Inoreader: Set modify parameters for stage" << (int)stage << "called: \n" << parameters;
|
qDebug() << "Inoreader: Set modify parameters for stage" << (int)stage << "called: \n" << parameters;
|
||||||
});
|
});
|
||||||
|
@ -85,6 +99,7 @@ void InoreaderNetworkFactory::initializeOauth() {
|
||||||
Q_UNUSED(uri)
|
Q_UNUSED(uri)
|
||||||
|
|
||||||
qCritical("Inoreader: We have error: '%s'.", qPrintable(error_description));
|
qCritical("Inoreader: We have error: '%s'.", qPrintable(error_description));
|
||||||
|
m_accessToken = m_refreshToken = QString();
|
||||||
emit error(error_description);
|
emit error(error_description);
|
||||||
});
|
});
|
||||||
connect(&m_oauth2, &QOAuth2AuthorizationCodeFlow::authorizeWithBrowser, [](const QUrl& url) {
|
connect(&m_oauth2, &QOAuth2AuthorizationCodeFlow::authorizeWithBrowser, [](const QUrl& url) {
|
||||||
|
|
|
@ -37,6 +37,7 @@ class InoreaderNetworkFactory : public QObject {
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void accessGranted();
|
void accessGranted();
|
||||||
|
void tokensRefreshed();
|
||||||
void error(QString& description);
|
void error(QString& description);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -44,6 +45,8 @@ class InoreaderNetworkFactory : public QObject {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QOAuth2AuthorizationCodeFlow m_oauth2;
|
QOAuth2AuthorizationCodeFlow m_oauth2;
|
||||||
|
QString m_accessToken;
|
||||||
|
QString m_refreshToken;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // INOREADERNETWORKFACTORY_H
|
#endif // INOREADERNETWORKFACTORY_H
|
||||||
|
|
Loading…
Add table
Reference in a new issue