From 148a97cd32619c8868923f8473c11e5ff7b73b07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Abel=20Garc=C3=ADa=20de=20Prada?= Date: Mon, 23 Jan 2023 13:58:02 +0100 Subject: [PATCH] Potential fix to oauth error after logging in for first time that makes user to reauthenticate --- .../lib/common/SingleSessionManager.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/SingleSessionManager.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/SingleSessionManager.java index 7e40c16f..9a7925ed 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/SingleSessionManager.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/SingleSessionManager.java @@ -31,7 +31,6 @@ import android.net.Uri; import com.owncloud.android.lib.common.accounts.AccountUtils; import com.owncloud.android.lib.common.authentication.OwnCloudCredentials; -import com.owncloud.android.lib.common.http.HttpClient; import timber.log.Timber; import java.io.IOException; @@ -124,6 +123,24 @@ public class SingleSessionManager { } } else { Timber.v("reusing client for account %s", accountName); + if (client.getAccount() != null && + client.getAccount().getCredentials() != null && + (client.getAccount().getCredentials().getAuthToken() == null || client.getAccount().getCredentials().getAuthToken().isEmpty()) + ) { + Timber.i("Client " + client.getAccount().getName() + " needs to refresh credentials"); + + //the next two lines are a hack because okHttpclient is used as a singleton instead of being an + //injected instance that can be deleted when required + client.clearCookies(); + client.clearCredentials(); + + client.setAccount(account); + + account.loadCredentials(context); + client.setCredentials(account.getCredentials()); + + Timber.i("Client " + account.getName() + " with credentials size" + client.getAccount().getCredentials().getAuthToken().length()); + } reusingKnown = true; }