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:
parent
e27a968ddb
commit
5582097ca1
@ -4,7 +4,6 @@ import android.accounts.AccountManager
|
|||||||
import android.accounts.AccountsException
|
import android.accounts.AccountsException
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import com.owncloud.android.lib.common.authentication.OwnCloudCredentials
|
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.authentication.OwnCloudCredentialsFactory.OwnCloudAnonymousCredentials
|
||||||
import com.owncloud.android.lib.common.http.HttpConstants
|
import com.owncloud.android.lib.common.http.HttpConstants
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult
|
||||||
@ -63,7 +62,8 @@ class ConnectionValidator (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (successCounter >= failCounter) {
|
if (successCounter >= failCounter) {
|
||||||
//update credentials in client
|
baseClient.credentials = client.credentials
|
||||||
|
baseClient.cookiesForBaseUri = client.cookiesForBaseUri
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
validationRetryCount++
|
validationRetryCount++
|
||||||
@ -89,11 +89,6 @@ class ConnectionValidator (
|
|||||||
return remoteStatusOperation.execute(client)
|
return remoteStatusOperation.execute(client)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun triggerAuthRefresh(): OwnCloudCredentials {
|
|
||||||
Timber.d("!!!!!!!!!!!!!!!!!!!!!!!!!!!! need to reauthenticate !!!!!!!!!!!!!!!!!!!!!!!!!!")
|
|
||||||
return OwnCloudCredentialsFactory.getAnonymousCredentials()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun canAccessRootFolder(client: OwnCloudClient): RemoteOperationResult<Boolean> {
|
private fun canAccessRootFolder(client: OwnCloudClient): RemoteOperationResult<Boolean> {
|
||||||
val checkPathExistenceRemoteOperation = CheckPathExistenceRemoteOperation("/", true)
|
val checkPathExistenceRemoteOperation = CheckPathExistenceRemoteOperation("/", true)
|
||||||
return checkPathExistenceRemoteOperation.execute(client)
|
return checkPathExistenceRemoteOperation.execute(client)
|
||||||
@ -154,8 +149,10 @@ class ConnectionValidator (
|
|||||||
val credentials = account.credentials
|
val credentials = account.credentials
|
||||||
if (shouldInvalidateAccountCredentials(credentials, account, status)) {
|
if (shouldInvalidateAccountCredentials(credentials, account, status)) {
|
||||||
invalidateAccountCredentials(account, credentials)
|
invalidateAccountCredentials(account, credentials)
|
||||||
|
|
||||||
if (credentials.authTokenCanBeRefreshed()) {
|
if (credentials.authTokenCanBeRefreshed()) {
|
||||||
try {
|
try {
|
||||||
|
// This command does the actual refresh
|
||||||
account.loadCredentials(context)
|
account.loadCredentials(context)
|
||||||
// if mAccount.getCredentials().length() == 0 --> refresh failed
|
// if mAccount.getCredentials().length() == 0 --> refresh failed
|
||||||
client.credentials = account.credentials
|
client.credentials = account.credentials
|
||||||
|
@ -59,6 +59,7 @@ public class OwnCloudClient extends HttpClient {
|
|||||||
public static final String STATUS_PATH = "/status.php";
|
public static final String STATUS_PATH = "/status.php";
|
||||||
private static final String WEBDAV_UPLOADS_PATH_4_0 = "/remote.php/dav/uploads/";
|
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_REDIRECTIONS_COUNT = 5;
|
||||||
|
private static final int MAX_RETRY_COUNT = 2;
|
||||||
|
|
||||||
private static int sIntanceCounter = 0;
|
private static int sIntanceCounter = 0;
|
||||||
private OwnCloudCredentials mCredentials = null;
|
private OwnCloudCredentials mCredentials = null;
|
||||||
@ -112,12 +113,12 @@ public class OwnCloudClient extends HttpClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private int saveExecuteHttpMethod(HttpBaseMethod method) throws Exception {
|
private int saveExecuteHttpMethod(HttpBaseMethod method) throws Exception {
|
||||||
boolean repeatWithFreshCredentials;
|
|
||||||
int repeatCounter = 0;
|
int repeatCounter = 0;
|
||||||
int status;
|
int status;
|
||||||
|
|
||||||
boolean retry = false;
|
boolean retry;
|
||||||
do {
|
do {
|
||||||
|
repeatCounter++;
|
||||||
retry = false;
|
retry = false;
|
||||||
String requestId = RandomUtils.generateRandomUUID();
|
String requestId = RandomUtils.generateRandomUUID();
|
||||||
|
|
||||||
@ -126,7 +127,7 @@ public class OwnCloudClient extends HttpClient {
|
|||||||
method.setRequestHeader(HttpConstants.OC_X_REQUEST_ID, requestId);
|
method.setRequestHeader(HttpConstants.OC_X_REQUEST_ID, requestId);
|
||||||
method.setRequestHeader(HttpConstants.USER_AGENT_HEADER, SingleSessionManager.getUserAgent());
|
method.setRequestHeader(HttpConstants.USER_AGENT_HEADER, SingleSessionManager.getUserAgent());
|
||||||
method.setRequestHeader(HttpConstants.ACCEPT_ENCODING_HEADER, HttpConstants.ACCEPT_ENCODING_IDENTITY);
|
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());
|
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;
|
return status;
|
||||||
}
|
}
|
||||||
@ -166,6 +167,11 @@ public class OwnCloudClient extends HttpClient {
|
|||||||
"\nUrl: " + method.getHttpUrl() +
|
"\nUrl: " + method.getHttpUrl() +
|
||||||
"\nCookeis: " + getCookiesForBaseUri().toString() +
|
"\nCookeis: " + getCookiesForBaseUri().toString() +
|
||||||
"\nCredentials type: " + mCredentials.getClass().toString() +
|
"\nCredentials type: " + mCredentials.getClass().toString() +
|
||||||
|
"\ntoken: " + mCredentials.getAuthToken() +
|
||||||
|
|
||||||
|
"\nHeaders: ++++" +
|
||||||
|
"\n" + method.getRequest().headers().toString() +
|
||||||
|
"+++++++++++++" +
|
||||||
"\ntrace: " + ExceptionUtils.getStackTrace(e) +
|
"\ntrace: " + ExceptionUtils.getStackTrace(e) +
|
||||||
"---------------------------");
|
"---------------------------");
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user