package com.owncloud.android.authentication;\r
\r
import java.security.cert.X509Certificate;\r
+import java.util.Map;\r
\r
import android.accounts.Account;\r
import android.accounts.AccountManager;\r
private int mAuthMessageVisibility, mServerStatusText, mServerStatusIcon;\r
private boolean mServerIsChecked, mServerIsValid, mIsSslConn;\r
private AuthenticationMethod mServerAuthMethod = AuthenticationMethod.UNKNOWN;\r
+\r
private int mGetServerInfoOpId = -1;\r
+ private int mOauth2GetAccessTokenOpId = -1;\r
\r
private int mAuthStatusText, mAuthStatusIcon; \r
private TextView mAuthStatusLayout;\r
/// Showing the dialog with instructions for the user.\r
showDialog(DIALOG_OAUTH2_LOGIN_PROGRESS);\r
\r
- /// GET ACCESS TOKEN to the oAuth server \r
+ /// GET ACCESS TOKEN to the oAuth server\r
+ Intent getServerInfoIntent = new Intent();\r
+ getServerInfoIntent.setAction(OperationsService.ACTION_OAUTH2_GET_ACCESS_TOKEN);\r
+ \r
+ getServerInfoIntent.putExtra(\r
+ OperationsService.EXTRA_SERVER_URL, \r
+ mOAuthTokenEndpointText.getText().toString().trim());\r
+ \r
+ getServerInfoIntent.putExtra(\r
+ OperationsService.EXTRA_OAUTH2_QUERY_PARAMETERS, \r
+ queryParameters);\r
+ \r
+ if (mOperationsServiceBinder != null) {\r
+ //Log.wtf(TAG, "getting access token..." );\r
+ mOauth2GetAccessTokenOpId = mOperationsServiceBinder.newOperation(getServerInfoIntent);\r
+ }\r
+ \r
+ /*\r
RemoteOperation operation = new OAuth2GetAccessToken( getString(R.string.oauth2_client_id), \r
getString(R.string.oauth2_redirect_uri), \r
getString(R.string.oauth2_grant_type),\r
//OwnCloudClient client = OwnCloudClientUtils.createOwnCloudClient(Uri.parse(getString(R.string.oauth2_url_endpoint_access)), getApplicationContext());\r
OwnCloudClient client = OwnCloudClientFactory.createOwnCloudClient(Uri.parse(mOAuthTokenEndpointText.getText().toString().trim()), getApplicationContext(), true);\r
operation.execute(client, this, mHandler);\r
+ */\r
+ \r
}\r
\r
\r
mServerStatusIcon = R.drawable.progress_small;\r
showServerStatus();\r
\r
- /*\r
- mServerInfoOperation = new GetServerInfoOperation(uri, mAuthTokenType, this);\r
- OwnCloudClient client = OwnCloudClientFactory.createOwnCloudClient(Uri.parse(uri), this, true);\r
- mServerInfoOperation.execute(client, this, mHandler);\r
- */\r
- \r
Intent getServerInfoIntent = new Intent();\r
getServerInfoIntent.setAction(OperationsService.ACTION_GET_SERVER_INFO);\r
getServerInfoIntent.putExtra(OperationsService.EXTRA_SERVER_URL, uri);\r
mAuthStatusText = R.string.oauth_login_connection;\r
showAuthStatus();\r
\r
-\r
// GET AUTHORIZATION request\r
//Uri uri = Uri.parse(getString(R.string.oauth2_url_endpoint_auth));\r
Uri uri = Uri.parse(mOAuthAuthEndpointText.getText().toString().trim());\r
// multiple can be started if the user amends a URL quickly\r
\r
} else if (operation instanceof OAuth2GetAccessToken) {\r
- onGetOAuthAccessTokenFinish((OAuth2GetAccessToken)operation, result);\r
+ onGetOAuthAccessTokenFinish(result);\r
\r
} else if (operation instanceof ExistenceCheckRemoteOperation) {\r
if (AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(MainApp.getAccountType()).equals(mAuthTokenType)) {\r
* Processes the result of the request for and access token send \r
* to an OAuth authorization server.\r
* \r
- * @param operation Operation performed requesting the access token.\r
* @param result Result of the operation.\r
*/\r
- private void onGetOAuthAccessTokenFinish(OAuth2GetAccessToken operation, RemoteOperationResult result) {\r
+ private void onGetOAuthAccessTokenFinish(RemoteOperationResult result) {\r
+ mOauth2GetAccessTokenOpId = -1;\r
try {\r
dismissDialog(DIALOG_OAUTH2_LOGIN_PROGRESS);\r
} catch (IllegalArgumentException e) {\r
showDialog(DIALOG_LOGIN_PROGRESS);\r
\r
/// time to test the retrieved access token on the ownCloud server\r
- mAuthToken = ((OAuth2GetAccessToken)operation).getResultTokenMap().get(OAuth2Constants.KEY_ACCESS_TOKEN);\r
+ @SuppressWarnings("unchecked")\r
+ Map<String, String> tokens = (Map<String, String>)(result.getData().get(0));\r
+ mAuthToken = tokens.get(OAuth2Constants.KEY_ACCESS_TOKEN);\r
+ //mAuthToken = ((OAuth2GetAccessToken)operation).getResultTokenMap().get(OAuth2Constants.KEY_ACCESS_TOKEN);\r
Log_OC.d(TAG, "Got ACCESS TOKEN: " + mAuthToken);\r
mAuthCheckOperation = new ExistenceCheckRemoteOperation("", this, false);\r
OwnCloudClient client = OwnCloudClientFactory.createOwnCloudClient(Uri.parse(mHostBaseUrl + webdav_path), this, true);\r
//Log.wtf(TAG, "found result of operation finished while rotating");\r
onGetServerInfoFinish(result);\r
}\r
+ \r
+ } else if (mOauth2GetAccessTokenOpId != -1) {\r
+ RemoteOperationResult result = \r
+ mOperationsServiceBinder.getOperationResultIfFinished(\r
+ mOauth2GetAccessTokenOpId);\r
+ if (result != null) {\r
+ //Log.wtf(TAG, "found result of operation finished while rotating");\r
+ onGetOAuthAccessTokenFinish(result);\r
+ }\r
}\r
}\r
\r
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ConcurrentMap;
+import com.owncloud.android.R;
import com.owncloud.android.datamodel.FileDataStorageManager;
import com.owncloud.android.lib.common.OwnCloudClientFactory;
import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.resources.shares.ShareType;
import com.owncloud.android.operations.common.SyncOperation;
import com.owncloud.android.operations.CreateShareOperation;
-import com.owncloud.android.operations.DetectAuthenticationMethodOperation;
import com.owncloud.android.operations.GetServerInfoOperation;
+import com.owncloud.android.operations.OAuth2GetAccessToken;
import com.owncloud.android.operations.UnshareLinkOperation;
import com.owncloud.android.utils.Log_OC;
public static final String EXTRA_ACCOUNT = "ACCOUNT";
public static final String EXTRA_SERVER_URL = "SERVER_URL";
public static final String EXTRA_AUTH_TOKEN_TYPE = "AUTH_TOKEN_TYPE";
+ public static final String EXTRA_OAUTH2_QUERY_PARAMETERS = "OAUTH2_QUERY_PARAMETERS";
public static final String EXTRA_REMOTE_PATH = "REMOTE_PATH";
public static final String EXTRA_SEND_INTENT = "SEND_INTENT";
public static final String EXTRA_RESULT = "RESULT";
public static final String ACTION_CREATE_SHARE = "CREATE_SHARE";
public static final String ACTION_UNSHARE = "UNSHARE";
- //public static final String ACTION_DETECT_AUTHENTICATION_METHOD = "DETECT_AUTHENTICATION_METHOD";
public static final String ACTION_GET_SERVER_INFO = "GET_SERVER_INFO";
+ public static final String ACTION_OAUTH2_GET_ACCESS_TOKEN = "OAUTH2_GET_ACCESS_TOKEN";
public static final String ACTION_OPERATION_ADDED = OperationsService.class.getName() + ".OPERATION_ADDED";
public static final String ACTION_OPERATION_FINISHED = OperationsService.class.getName() + ".OPERATION_FINISHED";
operationIntent.getStringExtra(EXTRA_AUTH_TOKEN_TYPE);
operation = new GetServerInfoOperation(
serverUrl, authTokenType, OperationsService.this);
+
+ } else if (action.equals(ACTION_OAUTH2_GET_ACCESS_TOKEN)) {
+ /// GET ACCESS TOKEN to the OAuth server
+ String oauth2QueryParameters =
+ operationIntent.getStringExtra(EXTRA_OAUTH2_QUERY_PARAMETERS);
+ operation = new OAuth2GetAccessToken(
+ getString(R.string.oauth2_client_id),
+ getString(R.string.oauth2_redirect_uri),
+ getString(R.string.oauth2_grant_type),
+ oauth2QueryParameters);
}
}