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_CLI_ID "1000000604"
|
||||
#define INOREADER_OAUTH_CLI_KEY "gsStoZ3aAoQJCgQxoFSuXkWI7Sly87yK"
|
||||
#define INOREADER_REFRESH_TOKEN_KEY "refresh_token"
|
||||
#define INOREADER_ACCESS_TOKEN_KEY "access_token"
|
||||
|
||||
#endif // INOREADER_DEFINITIONS_H
|
||||
|
|
|
@ -7,25 +7,44 @@
|
|||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>157</height>
|
||||
<height>180</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Dialog</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="1" column="0">
|
||||
<widget class="QDialogButtonBox" name="m_buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Only download newest X messages per feed</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<item row="0" column="1">
|
||||
<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">
|
||||
<widget class="QPushButton" name="m_btnTestSetup">
|
||||
<property name="text">
|
||||
|
@ -36,9 +55,9 @@
|
|||
<item row="0" column="1">
|
||||
<widget class="LabelWithStatus" name="m_lblTestResult" native="true">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
<verstretch>1</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="layoutDirection">
|
||||
|
@ -48,6 +67,29 @@
|
|||
</item>
|
||||
</layout>
|
||||
</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>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
|
@ -59,6 +101,7 @@
|
|||
</customwidget>
|
||||
</customwidgets>
|
||||
<tabstops>
|
||||
<tabstop>m_spinLimitMessages</tabstop>
|
||||
<tabstop>m_btnTestSetup</tabstop>
|
||||
</tabstops>
|
||||
<resources/>
|
||||
|
|
|
@ -38,7 +38,8 @@ bool InoreaderNetworkFactory::isLoggedIn() const {
|
|||
}
|
||||
|
||||
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();
|
||||
}
|
||||
else {
|
||||
|
@ -73,6 +74,19 @@ void InoreaderNetworkFactory::initializeOauth() {
|
|||
connect(&m_oauth2, &QOAuth2AuthorizationCodeFlow::statusChanged, [=](QAbstractOAuth::Status 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) {
|
||||
qDebug() << "Inoreader: Set modify parameters for stage" << (int)stage << "called: \n" << parameters;
|
||||
});
|
||||
|
@ -85,6 +99,7 @@ void InoreaderNetworkFactory::initializeOauth() {
|
|||
Q_UNUSED(uri)
|
||||
|
||||
qCritical("Inoreader: We have error: '%s'.", qPrintable(error_description));
|
||||
m_accessToken = m_refreshToken = QString();
|
||||
emit error(error_description);
|
||||
});
|
||||
connect(&m_oauth2, &QOAuth2AuthorizationCodeFlow::authorizeWithBrowser, [](const QUrl& url) {
|
||||
|
|
|
@ -37,6 +37,7 @@ class InoreaderNetworkFactory : public QObject {
|
|||
|
||||
signals:
|
||||
void accessGranted();
|
||||
void tokensRefreshed();
|
||||
void error(QString& description);
|
||||
|
||||
private:
|
||||
|
@ -44,6 +45,8 @@ class InoreaderNetworkFactory : public QObject {
|
|||
|
||||
private:
|
||||
QOAuth2AuthorizationCodeFlow m_oauth2;
|
||||
QString m_accessToken;
|
||||
QString m_refreshToken;
|
||||
};
|
||||
|
||||
#endif // INOREADERNETWORKFACTORY_H
|
||||
|
|
Loading…
Add table
Reference in a new issue