Correct some paths of oauth login flow.
This commit is contained in:
parent
947720a4af
commit
44b46b8542
@ -164,16 +164,24 @@ void OAuth2Service::setRefreshToken(const QString& refresh_token) {
|
|||||||
m_refreshToken = refresh_token;
|
m_refreshToken = refresh_token;
|
||||||
}
|
}
|
||||||
|
|
||||||
void OAuth2Service::login() {
|
bool OAuth2Service::login() {
|
||||||
|
bool did_token_expire = m_tokensExpireIn.isNull() || m_tokensExpireIn < QDateTime::currentDateTime();
|
||||||
|
bool does_token_exist = !m_refreshToken.isEmpty();
|
||||||
|
|
||||||
// We refresh current tokens only if:
|
// We refresh current tokens only if:
|
||||||
// 1. We have some existing refresh token.
|
// 1. We have some existing refresh token.
|
||||||
// AND
|
// AND
|
||||||
// 2. We do not know its expiration date or it passed.
|
// 2. We do not know its expiration date or it passed.
|
||||||
if (!m_refreshToken.isEmpty() && (m_tokensExpireIn.isNull() || m_tokensExpireIn < QDateTime::currentDateTime())) {
|
if (does_token_exist && did_token_expire) {
|
||||||
refreshAccessToken();
|
refreshAccessToken();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else if (!does_token_exist) {
|
||||||
|
retrieveAuthCode();
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
retrieveAuthCode();
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,7 +81,9 @@ class OAuth2Service : public QObject {
|
|||||||
// Performs login if needed. If some refresh token is set, then
|
// Performs login if needed. If some refresh token is set, then
|
||||||
// the initial "auth" step is skipped and attempt to refresh
|
// the initial "auth" step is skipped and attempt to refresh
|
||||||
// access token is made.
|
// access token is made.
|
||||||
void login();
|
// Returns true, if user is already logged in (final state).
|
||||||
|
// Returns false, if user is NOT logged in (asynchronous flow).
|
||||||
|
bool login();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void cleanTokens();
|
void cleanTokens();
|
||||||
|
@ -61,11 +61,17 @@ FormEditInoreaderAccount::FormEditInoreaderAccount(QWidget* parent) : QDialog(pa
|
|||||||
FormEditInoreaderAccount::~FormEditInoreaderAccount() {}
|
FormEditInoreaderAccount::~FormEditInoreaderAccount() {}
|
||||||
|
|
||||||
void FormEditInoreaderAccount::testSetup() {
|
void FormEditInoreaderAccount::testSetup() {
|
||||||
m_network->login();
|
if (m_network->oauth()->login()) {
|
||||||
|
m_ui.m_lblTestResult->setStatus(WidgetWithStatus::StatusType::Ok,
|
||||||
|
tr("You are already logged in."),
|
||||||
|
tr("Access granted."));
|
||||||
|
}
|
||||||
|
else {
|
||||||
m_ui.m_lblTestResult->setStatus(WidgetWithStatus::StatusType::Progress,
|
m_ui.m_lblTestResult->setStatus(WidgetWithStatus::StatusType::Progress,
|
||||||
tr("Requested access approval. Respond to it, please."),
|
tr("Requested access approval. Respond to it, please."),
|
||||||
tr("Access approval was requested via OAuth 2.0 protocol."));
|
tr("Access approval was requested via OAuth 2.0 protocol."));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void FormEditInoreaderAccount::onClickedOk() {
|
void FormEditInoreaderAccount::onClickedOk() {
|
||||||
bool editing_account = true;
|
bool editing_account = true;
|
||||||
|
@ -114,7 +114,7 @@ void InoreaderServiceRoot::start(bool freshly_activated) {
|
|||||||
|
|
||||||
//loadCacheFromFile(accountId());
|
//loadCacheFromFile(accountId());
|
||||||
|
|
||||||
m_network->login();
|
m_network->oauth()->login();
|
||||||
}
|
}
|
||||||
|
|
||||||
void InoreaderServiceRoot::stop() {}
|
void InoreaderServiceRoot::stop() {}
|
||||||
|
@ -45,10 +45,6 @@ OAuth2Service* InoreaderNetworkFactory::oauth() const {
|
|||||||
return m_oauth2;
|
return m_oauth2;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool InoreaderNetworkFactory::isLoggedIn() const {
|
|
||||||
return !m_oauth2->refreshToken().isEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
QString InoreaderNetworkFactory::userName() const {
|
QString InoreaderNetworkFactory::userName() const {
|
||||||
return m_username;
|
return m_username;
|
||||||
}
|
}
|
||||||
@ -61,10 +57,6 @@ void InoreaderNetworkFactory::setBatchSize(int batch_size) {
|
|||||||
m_batchSize = batch_size;
|
m_batchSize = batch_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
void InoreaderNetworkFactory::login() {
|
|
||||||
m_oauth2->login();
|
|
||||||
}
|
|
||||||
|
|
||||||
void InoreaderNetworkFactory::initializeOauth() {
|
void InoreaderNetworkFactory::initializeOauth() {
|
||||||
connect(m_oauth2, &OAuth2Service::tokensRetrieveError, [](QString error, QString error_description) {
|
connect(m_oauth2, &OAuth2Service::tokensRetrieveError, [](QString error, QString error_description) {
|
||||||
Q_UNUSED(error)
|
Q_UNUSED(error)
|
||||||
|
@ -34,8 +34,6 @@ class InoreaderNetworkFactory : public QObject {
|
|||||||
|
|
||||||
OAuth2Service* oauth() const;
|
OAuth2Service* oauth() const;
|
||||||
|
|
||||||
bool isLoggedIn() const;
|
|
||||||
|
|
||||||
QString userName() const;
|
QString userName() const;
|
||||||
void setUsername(const QString& username);
|
void setUsername(const QString& username);
|
||||||
|
|
||||||
@ -48,9 +46,6 @@ class InoreaderNetworkFactory : public QObject {
|
|||||||
// Returned items do not have primary IDs assigned.
|
// Returned items do not have primary IDs assigned.
|
||||||
RootItem* feedsCategories(bool obtain_icons);
|
RootItem* feedsCategories(bool obtain_icons);
|
||||||
|
|
||||||
public slots:
|
|
||||||
void login();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void initializeOauth();
|
void initializeOauth();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user