1
0
mirror of https://github.com/owncloud/android-library.git synced 2025-06-07 16:06:08 +00:00

get access token to update through connection validator

update token
This commit is contained in:
Christian Schabesberger 2021-09-14 15:01:45 +02:00
parent e27a968ddb
commit 5582097ca1
2 changed files with 14 additions and 11 deletions

View File

@ -4,7 +4,6 @@ import android.accounts.AccountManager
import android.accounts.AccountsException
import android.content.Context
import com.owncloud.android.lib.common.authentication.OwnCloudCredentials
import com.owncloud.android.lib.common.authentication.OwnCloudCredentialsFactory
import com.owncloud.android.lib.common.authentication.OwnCloudCredentialsFactory.OwnCloudAnonymousCredentials
import com.owncloud.android.lib.common.http.HttpConstants
import com.owncloud.android.lib.common.operations.RemoteOperationResult
@ -63,7 +62,8 @@ class ConnectionValidator (
}
}
if (successCounter >= failCounter) {
//update credentials in client
baseClient.credentials = client.credentials
baseClient.cookiesForBaseUri = client.cookiesForBaseUri
return true
}
validationRetryCount++
@ -89,11 +89,6 @@ class ConnectionValidator (
return remoteStatusOperation.execute(client)
}
private fun triggerAuthRefresh(): OwnCloudCredentials {
Timber.d("!!!!!!!!!!!!!!!!!!!!!!!!!!!! need to reauthenticate !!!!!!!!!!!!!!!!!!!!!!!!!!")
return OwnCloudCredentialsFactory.getAnonymousCredentials()
}
private fun canAccessRootFolder(client: OwnCloudClient): RemoteOperationResult<Boolean> {
val checkPathExistenceRemoteOperation = CheckPathExistenceRemoteOperation("/", true)
return checkPathExistenceRemoteOperation.execute(client)
@ -154,8 +149,10 @@ class ConnectionValidator (
val credentials = account.credentials
if (shouldInvalidateAccountCredentials(credentials, account, status)) {
invalidateAccountCredentials(account, credentials)
if (credentials.authTokenCanBeRefreshed()) {
try {
// This command does the actual refresh
account.loadCredentials(context)
// if mAccount.getCredentials().length() == 0 --> refresh failed
client.credentials = account.credentials

View File

@ -59,6 +59,7 @@ public class OwnCloudClient extends HttpClient {
public static final String STATUS_PATH = "/status.php";
private static final String WEBDAV_UPLOADS_PATH_4_0 = "/remote.php/dav/uploads/";
private static final int MAX_REDIRECTIONS_COUNT = 5;
private static final int MAX_RETRY_COUNT = 2;
private static int sIntanceCounter = 0;
private OwnCloudCredentials mCredentials = null;
@ -112,12 +113,12 @@ public class OwnCloudClient extends HttpClient {
}
private int saveExecuteHttpMethod(HttpBaseMethod method) throws Exception {
boolean repeatWithFreshCredentials;
int repeatCounter = 0;
int status;
boolean retry = false;
boolean retry;
do {
repeatCounter++;
retry = false;
String requestId = RandomUtils.generateRandomUUID();
@ -126,7 +127,7 @@ public class OwnCloudClient extends HttpClient {
method.setRequestHeader(HttpConstants.OC_X_REQUEST_ID, requestId);
method.setRequestHeader(HttpConstants.USER_AGENT_HEADER, SingleSessionManager.getUserAgent());
method.setRequestHeader(HttpConstants.ACCEPT_ENCODING_HEADER, HttpConstants.ACCEPT_ENCODING_IDENTITY);
if (mCredentials.getHeaderAuth() != null && method.getRequestHeader(AUTHORIZATION_HEADER) == null) {
if (mCredentials.getHeaderAuth() != null && !mCredentials.getHeaderAuth().isEmpty()) {
method.setRequestHeader(AUTHORIZATION_HEADER, mCredentials.getHeaderAuth());
}
@ -149,7 +150,7 @@ public class OwnCloudClient extends HttpClient {
}
*/
} while (retry);
} while (retry && repeatCounter < MAX_RETRY_COUNT);
return status;
}
@ -166,6 +167,11 @@ public class OwnCloudClient extends HttpClient {
"\nUrl: " + method.getHttpUrl() +
"\nCookeis: " + getCookiesForBaseUri().toString() +
"\nCredentials type: " + mCredentials.getClass().toString() +
"\ntoken: " + mCredentials.getAuthToken() +
"\nHeaders: ++++" +
"\n" + method.getRequest().headers().toString() +
"+++++++++++++" +
"\ntrace: " + ExceptionUtils.getStackTrace(e) +
"---------------------------");
}