Commit faea32ee authored by Krzysztof Nowicki's avatar Krzysztof Nowicki Committed by Laurent Montel
Browse files

Fix unnecessary reauthentication prompts (try 2)



The original fix added a countermeasure to detect if reauthentication
is in progress and in such case avoid retrying it in case of failed
requests as it would confuse the state machine. Unfortunately the
initial state value was set to 0, which would still cause the above
countermeasure to fail in the initial state of the reauthemtication
procedure.

To fix this make the value of the initial state 1-based to fully
ensure that unwanted retriggering does not happen.

Additionally the state variable was implemented as an enum instead of
a plain integer.
Signed-off-by: Krzysztof Nowicki's avatarKrzysztof Nowicki <krissn@op.pl>
parent 4f902acf
......@@ -78,6 +78,8 @@ static Q_CONSTEXPR int ReconnectTimeout = 300;
EwsResource::EwsResource(const QString &id)
: Akonadi::ResourceBase(id)
, mAuthStage(AuthIdle)
, mTagsRetrieved(false)
, mReconnectTimeout(InitialReconnectTimeout)
, mSettings(new EwsSettings(winIdForDialogs()))
{
......@@ -1291,7 +1293,7 @@ void EwsResource::setUpAuth()
void EwsResource::authSucceeded()
{
mAuthStage = 0;
mAuthStage = AuthIdle;
resetUrl();
}
......@@ -1318,14 +1320,15 @@ void EwsResource::authFailed(const QString &error)
void EwsResource::reauthenticate()
{
switch (mAuthStage) {
case 0:
case AuthIdle:
mAuthStage = AuthRefreshToken;
qCWarningNC(EWSRES_LOG) << "reauthenticate: trying to refresh";
if (mAuth->authenticate(false)) {
break;
} else {
++mAuthStage;
}
/* fall through */
case 1: {
case AuthRefreshToken: {
mAuthStage = AuthAccessToken;
const auto reauthPrompt = mAuth->reauthPrompt();
if (!reauthPrompt.isNull()) {
mReauthNotification = new KNotification(QStringLiteral("auth-expired"), KNotification::Persistent, this);
......@@ -1343,19 +1346,21 @@ void EwsResource::reauthenticate()
}
}
/* fall through */
case 2:
case AuthAccessToken:
mAuthStage = AuthFailure;
Q_EMIT status(Broken, i18nc("@info:status", "Authentication failed"));
break;
case AuthFailure:
break;
}
++mAuthStage;
}
void EwsResource::requestAuthFailed()
{
qCWarningNC(EWSRES_LOG) << "requestAuthFailed - going offline";
if (mAuthStage == 0) {
if (mAuthStage == AuthIdle) {
QTimer::singleShot(0, this, [&]() {
setTemporaryOffline(reconnectTimeout());
});
......
......@@ -124,6 +124,8 @@ private Q_SLOTS:
#endif
private:
enum AuthStage { AuthIdle, AuthRefreshToken, AuthAccessToken, AuthFailure };
void finishItemsFetch(FetchItemState *state);
void fetchSpecialFolders();
void specialFoldersCollectionsRetrieved(const Akonadi::Collection::List &folders);
......@@ -147,7 +149,7 @@ private:
QHash<QString, EwsFetchItemsJob::QueuedUpdateList> mQueuedUpdates;
QString mPassword;
QScopedPointer<EwsAbstractAuth> mAuth;
int mAuthStage = 0;
AuthStage mAuthStage;
QPointer<KNotification> mReauthNotification;
bool mTagsRetrieved = false;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment