use of com.owncloud.android.lib.common.OwnCloudCredentials in project android by owncloud.
the class AuthenticatorActivity method checkBasicAuthorization.
/**
* Tests the credentials entered by the user performing a check of existence on
* the root folder of the ownCloud server.
*/
private void checkBasicAuthorization() {
/// get basic credentials entered by user
String username = mUsernameInput.getText().toString().trim();
String password = mPasswordInput.getText().toString();
/// be gentle with the user
LoadingDialog dialog = LoadingDialog.newInstance(R.string.auth_trying_to_login, true);
dialog.show(getSupportFragmentManager(), WAIT_DIALOG_TAG);
/// validate credentials accessing the root folder
OwnCloudCredentials credentials = OwnCloudCredentialsFactory.newBasicCredentials(username, password, (mServerInfo != null && mServerInfo.mVersion != null && mServerInfo.mVersion.isPreemptiveAuthenticationPreferred()));
accessRootFolder(credentials);
}
use of com.owncloud.android.lib.common.OwnCloudCredentials in project android by owncloud.
the class AuthenticatorActivity method onGetOAuthAccessTokenFinish.
/**
* Processes the result of the request for and access token send
* to an OAuth authorization server.
*
* @param result Result of the operation.
*/
private void onGetOAuthAccessTokenFinish(RemoteOperationResult result) {
mWaitingForOpId = Long.MAX_VALUE;
dismissDialog(WAIT_DIALOG_TAG);
if (result.isSuccess()) {
/// be gentle with the user
LoadingDialog dialog = LoadingDialog.newInstance(R.string.auth_trying_to_login, true);
dialog.show(getSupportFragmentManager(), WAIT_DIALOG_TAG);
/// time to test the retrieved access token on the ownCloud server
@SuppressWarnings("unchecked") Map<String, String> tokens = (Map<String, String>) (result.getData().get(0));
mAuthToken = tokens.get(OAuth2Constants.KEY_ACCESS_TOKEN);
Log_OC.d(TAG, "Got ACCESS TOKEN: " + mAuthToken);
/// validate token accessing to root folder / getting session
OwnCloudCredentials credentials = OwnCloudCredentialsFactory.newBearerCredentials(mAuthToken);
accessRootFolder(credentials);
} else {
updateAuthStatusIconAndText(result);
showAuthStatus();
Log_OC.d(TAG, "Access failed: " + result.getLogMessage());
}
}
use of com.owncloud.android.lib.common.OwnCloudCredentials in project android by owncloud.
the class FileActivity method requestCredentialsUpdate.
/**
* Invalidates the credentials stored for the given OC account and requests new credentials to the user,
* navigating to {@link AuthenticatorActivity}
*
* @param context Android Context needed to access the {@link AccountManager}. Received as a parameter
* to make the method accessible to {@link android.content.BroadcastReceiver}s.
* @param account Stored OC account to request credentials update for. If null, current account will
* be used.
*/
protected void requestCredentialsUpdate(Context context, Account account) {
try {
/// step 1 - invalidate credentials of current account
if (account == null) {
account = getAccount();
}
OwnCloudClient client;
OwnCloudAccount ocAccount = new OwnCloudAccount(account, context);
client = (OwnCloudClientManagerFactory.getDefaultSingleton().removeClientFor(ocAccount));
if (client != null) {
OwnCloudCredentials cred = client.getCredentials();
if (cred != null) {
AccountManager am = AccountManager.get(context);
if (cred.authTokenExpires()) {
am.invalidateAuthToken(account.type, cred.getAuthToken());
} else {
am.clearPassword(account);
}
}
}
/// step 2 - request credentials to user
Intent updateAccountCredentials = new Intent(this, AuthenticatorActivity.class);
updateAccountCredentials.putExtra(AuthenticatorActivity.EXTRA_ACCOUNT, account);
updateAccountCredentials.putExtra(AuthenticatorActivity.EXTRA_ACTION, AuthenticatorActivity.ACTION_UPDATE_EXPIRED_TOKEN);
updateAccountCredentials.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
startActivityForResult(updateAccountCredentials, REQUEST_CODE__UPDATE_CREDENTIALS);
} catch (com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException e) {
showSnackMessage(getString(R.string.auth_account_does_not_exist));
}
}
use of com.owncloud.android.lib.common.OwnCloudCredentials in project android by nextcloud.
the class FileActivity method requestCredentialsUpdate.
/**
* Invalidates the credentials stored for the given OC account and requests new credentials to the user,
* navigating to {@link AuthenticatorActivity}
*
* @param context Android Context needed to access the {@link AccountManager}. Received as a parameter
* to make the method accessible to {@link android.content.BroadcastReceiver}s.
* @param account Stored OC account to request credentials update for. If null, current account will
* be used.
*/
protected void requestCredentialsUpdate(Context context, Account account) {
try {
// / step 1 - invalidate credentials of current account
if (account == null) {
account = getAccount();
}
OwnCloudClient client;
OwnCloudAccount ocAccount = new OwnCloudAccount(account, context);
client = (OwnCloudClientManagerFactory.getDefaultSingleton().removeClientFor(ocAccount));
if (client != null) {
OwnCloudCredentials cred = client.getCredentials();
if (cred != null) {
AccountManager am = AccountManager.get(context);
if (cred.authTokenExpires()) {
am.invalidateAuthToken(account.type, cred.getAuthToken());
} else {
am.clearPassword(account);
}
}
}
// / step 2 - request credentials to user
Intent updateAccountCredentials = new Intent(this, AuthenticatorActivity.class);
updateAccountCredentials.putExtra(AuthenticatorActivity.EXTRA_ACCOUNT, account);
updateAccountCredentials.putExtra(AuthenticatorActivity.EXTRA_ACTION, AuthenticatorActivity.ACTION_UPDATE_EXPIRED_TOKEN);
updateAccountCredentials.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
startActivityForResult(updateAccountCredentials, REQUEST_CODE__UPDATE_CREDENTIALS);
} catch (com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException e) {
DisplayUtils.showSnackMessage(this, R.string.auth_account_does_not_exist);
}
}
use of com.owncloud.android.lib.common.OwnCloudCredentials in project android by nextcloud.
the class AuthenticatorActivity method checkBasicAuthorization.
/**
* Tests the credentials entered by the user performing a check of existence on
* the root folder of the ownCloud server.
*/
private void checkBasicAuthorization(@Nullable String webViewUsername, @Nullable String webViewPassword) {
// / get basic credentials entered by user
String username;
String password;
if (!webViewLoginMethod) {
username = mUsernameInput.getText().toString().trim();
password = mPasswordInput.getText().toString();
} else {
username = webViewUsername;
password = webViewPassword;
}
// / be gentle with the user
IndeterminateProgressDialog dialog = IndeterminateProgressDialog.newInstance(R.string.auth_trying_to_login, true);
dialog.show(getSupportFragmentManager(), WAIT_DIALOG_TAG);
// / validate credentials accessing the root folder
OwnCloudCredentials credentials = OwnCloudCredentialsFactory.newBasicCredentials(username, password);
accessRootFolder(credentials);
}
Aggregations