mirror of
				https://github.com/owncloud/android-library.git
				synced 2025-10-31 10:27:45 +00:00 
			
		
		
		
	Fix renewal of OAuth2 token
This commit is contained in:
		
							parent
							
								
									eaa645ab3c
								
							
						
					
					
						commit
						800c075bd1
					
				| @ -27,7 +27,6 @@ package com.owncloud.android.lib.common; | |||||||
| 
 | 
 | ||||||
| import android.accounts.AccountManager; | import android.accounts.AccountManager; | ||||||
| import android.accounts.AccountsException; | import android.accounts.AccountsException; | ||||||
| import android.content.Context; |  | ||||||
| import android.net.Uri; | import android.net.Uri; | ||||||
| 
 | 
 | ||||||
| import com.owncloud.android.lib.common.authentication.OwnCloudCredentials; | import com.owncloud.android.lib.common.authentication.OwnCloudCredentials; | ||||||
| @ -65,18 +64,11 @@ public class OwnCloudClient extends HttpClient { | |||||||
|     private static final String PARAM_PROTOCOL_VERSION = "http.protocol.version"; |     private static final String PARAM_PROTOCOL_VERSION = "http.protocol.version"; | ||||||
| 
 | 
 | ||||||
|     private static byte[] sExhaustBuffer = new byte[1024]; |     private static byte[] sExhaustBuffer = new byte[1024]; | ||||||
| 
 |  | ||||||
|     private static int sIntanceCounter = 0; |     private static int sIntanceCounter = 0; | ||||||
|     private OwnCloudCredentials mCredentials = null; |     private OwnCloudCredentials mCredentials = null; | ||||||
|     private int mInstanceNumber = 0; |     private int mInstanceNumber = 0; | ||||||
| 
 |  | ||||||
|     private Uri mBaseUri; |     private Uri mBaseUri; | ||||||
| 
 |  | ||||||
|     private OwnCloudVersion mVersion = null; |     private OwnCloudVersion mVersion = null; | ||||||
| 
 |  | ||||||
|     /// next too attributes are a very ugly dependency, added to grant silent retry of OAuth token when needed ; |  | ||||||
|     /// see #shouldInvalidateCredentials and #invalidateCredentials for more details |  | ||||||
|     private Context mContext; |  | ||||||
|     private OwnCloudAccount mAccount; |     private OwnCloudAccount mAccount; | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
| @ -344,10 +336,6 @@ public class OwnCloudClient extends HttpClient { | |||||||
|         return mVersion; |         return mVersion; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public Context getContext() { |  | ||||||
|         return mContext; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public void setAccount(OwnCloudAccount account) { |     public void setAccount(OwnCloudAccount account) { | ||||||
|         this.mAccount = account; |         this.mAccount = account; | ||||||
|     } |     } | ||||||
| @ -378,7 +366,7 @@ public class OwnCloudClient extends HttpClient { | |||||||
|                         repeatCounter < MAX_REPEAT_COUNT_WITH_FRESH_CREDENTIALS) { |                         repeatCounter < MAX_REPEAT_COUNT_WITH_FRESH_CREDENTIALS) { | ||||||
| 
 | 
 | ||||||
|                     try { |                     try { | ||||||
|                         mAccount.loadCredentials(mContext); |                         mAccount.loadCredentials(getContext()); | ||||||
|                         // if mAccount.getCredentials().length() == 0 --> refresh failed |                         // if mAccount.getCredentials().length() == 0 --> refresh failed | ||||||
|                         setCredentials(mAccount.getCredentials()); |                         setCredentials(mAccount.getCredentials()); | ||||||
|                         credentialsWereRefreshed = true; |                         credentialsWereRefreshed = true; | ||||||
| @ -421,7 +409,7 @@ public class OwnCloudClient extends HttpClient { | |||||||
|                 !(mCredentials instanceof OwnCloudCredentialsFactory.OwnCloudAnonymousCredentials)); |                 !(mCredentials instanceof OwnCloudCredentialsFactory.OwnCloudAnonymousCredentials)); | ||||||
| 
 | 
 | ||||||
|         // test if have all the needed to effectively invalidate ... |         // test if have all the needed to effectively invalidate ... | ||||||
|         should &= (mAccount != null && mAccount.getSavedAccount() != null && mContext != null); |         should &= (mAccount != null && mAccount.getSavedAccount() != null && getContext() != null); | ||||||
| 
 | 
 | ||||||
|         return should; |         return should; | ||||||
|     } |     } | ||||||
| @ -435,7 +423,7 @@ public class OwnCloudClient extends HttpClient { | |||||||
|      * @return                  'True' if invalidation was successful, 'false' otherwise. |      * @return                  'True' if invalidation was successful, 'false' otherwise. | ||||||
|      */ |      */ | ||||||
|     private boolean invalidateAccountCredentials() { |     private boolean invalidateAccountCredentials() { | ||||||
|         AccountManager am = AccountManager.get(mContext); |         AccountManager am = AccountManager.get(getContext()); | ||||||
|         am.invalidateAuthToken( |         am.invalidateAuthToken( | ||||||
|                 mAccount.getSavedAccount().type, |                 mAccount.getSavedAccount().type, | ||||||
|                 mCredentials.getAuthToken() |                 mCredentials.getAuthToken() | ||||||
|  | |||||||
| @ -154,7 +154,8 @@ public class OwnCloudClientFactory { | |||||||
|      * @param context   Android context where the OwnCloudClient is being created. |      * @param context   Android context where the OwnCloudClient is being created. | ||||||
|      * @return          A OwnCloudClient object ready to be used |      * @return          A OwnCloudClient object ready to be used | ||||||
|      */ |      */ | ||||||
|     public static OwnCloudClient createOwnCloudClient(Uri uri, Context context, boolean followRedirects) { |     public static OwnCloudClient createOwnCloudClient(Uri uri, Context context, | ||||||
|  |                                                       boolean followRedirects) { | ||||||
|         OwnCloudClient client = new OwnCloudClient(uri); |         OwnCloudClient client = new OwnCloudClient(uri); | ||||||
| 
 | 
 | ||||||
|         client.setDefaultTimeouts(DEFAULT_DATA_TIMEOUT, DEFAULT_CONNECTION_TIMEOUT); |         client.setDefaultTimeouts(DEFAULT_DATA_TIMEOUT, DEFAULT_CONNECTION_TIMEOUT); | ||||||
|  | |||||||
| @ -59,6 +59,10 @@ public class HttpClient { | |||||||
|         sContext = context; |         sContext = context; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     public Context getContext() { | ||||||
|  |         return sContext; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     public static OkHttpClient getOkHttpClient() { |     public static OkHttpClient getOkHttpClient() { | ||||||
|         if (sOkHttpClient == null) { |         if (sOkHttpClient == null) { | ||||||
|             try { |             try { | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user