Skip to content

Commit

Permalink
Merge pull request #751 from nextcloud/backport/638
Browse files Browse the repository at this point in the history
[stable-2.8] Fix for failed logins / app crashes
  • Loading branch information
AlvaroBrey authored Nov 9, 2021
2 parents d79116e + 8f5f260 commit da770c2
Showing 1 changed file with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@
import android.os.Bundle;

import com.nextcloud.common.NextcloudClient;
import com.nextcloud.common.OkHttpCredentialsUtil;
import com.owncloud.android.lib.common.accounts.AccountTypeUtils;
import com.owncloud.android.lib.common.accounts.AccountUtils;
import com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException;
import com.owncloud.android.lib.common.network.NetworkUtils;
import com.owncloud.android.lib.common.utils.Log_OC;
import com.nextcloud.common.OkHttpCredentialsUtil;

import java.io.IOException;
import java.security.GeneralSecurityException;
Expand Down Expand Up @@ -206,9 +206,19 @@ public static NextcloudClient createNextcloudClient(Account account, Context app
// TODO avoid calling to getUserData here
String userId = am.getUserData(account, AccountUtils.Constants.KEY_USER_ID);
String username = AccountUtils.getUsernameForAccount(account);
String password = am.peekAuthToken(account, AccountTypeUtils.getAuthTokenTypePass(account.type));
String password;
try {
password = am.blockingGetAuthToken(account, AccountTypeUtils.getAuthTokenTypePass(account.type), false);
if (password == null) {
Log_OC.e(TAG, "Error receiving password token (password==null)");
throw new AccountNotFoundException(account, "Error receiving password token (password==null)", null);
}
} catch (Exception e) {
Log_OC.e(TAG, "Error receiving password token", e);
throw new AccountNotFoundException(account, "Error receiving password token", e);
}

if (username == null || username.isEmpty() || password == null || password.isEmpty()) {
if (username == null || username.isEmpty() || password.isEmpty()) {
throw new AccountNotFoundException(
account,
"Username or password could not be retrieved",
Expand Down

0 comments on commit da770c2

Please sign in to comment.