Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/src/org/commcare/activities/LoginActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,10 @@ public void handlePullTaskResult(ResultAndError<DataPullTask.PullTaskResult> res
raiseLoginMessage(StockMessages.Empty_Url, true);
break;
case AUTH_FAILED:
if(ConnectManager.checkForFailedConnectIdAuth(uiController.getEnteredUsername())) {
Logger.exception("Token auth error for connect managed app",
new Throwable("Token Auth failed during login for a ConnectID managed app"));
}
raiseLoginMessage(StockMessages.Auth_BadCredentials, false);
break;
case BAD_DATA_REQUIRES_INTERVENTION:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.commcare.views.dialogs.StandardAlertDialog;
import org.commcare.views.notifications.NotificationActionButtonInfo;
import org.commcare.views.notifications.NotificationMessageFactory;
import org.javarosa.core.services.Logger;
import org.javarosa.core.services.locale.Localization;

public abstract class SyncCapableCommCareActivity<T> extends SessionAwareCommCareActivity<T>
Expand Down Expand Up @@ -103,9 +104,13 @@ public void handlePullTaskResult(ResultAndError<DataPullTask.PullTaskResult> res
updateUiAfterDataPullOrSend(Localization.get("sync.fail.empty.url"), FAIL);
break;
case AUTH_FAILED:
String seatedAppId = CommCareApplication.instance().getCurrentApp().getUniqueId();
String username = CommCareApplication.instance().getRecordForCurrentUser().getUsername();
ConnectManager.forgetAppCredentials(seatedAppId, username);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is intentional ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, getting rid of that on purpose. It was added with ConnectID-managed traditional apps in mind. But now that we know the token auth could fail for other reasons, we don't want to take the unnecessary step of forcing the app credentials to be setup again. The improved messaging is a better reaction to this error.


if(ConnectManager.checkForFailedConnectIdAuth(username)) {
Logger.exception("Token auth error for connect managed app",
new Throwable("Token Auth failed during sync for a ConnectID managed app"));
}

updateUiAfterDataPullOrSend(Localization.get("sync.fail.auth.loggedin"), FAIL);
break;
case BAD_DATA:
Expand Down
15 changes: 15 additions & 0 deletions app/src/org/commcare/connect/ConnectManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,21 @@ public static void checkConnectIdLink(CommCareActivity<?> activity, boolean auto
callback.connectActivityComplete(false);
}

public static boolean checkForFailedConnectIdAuth(String username) {
try {
if (isConnectIdConfigured()) {
String seatedAppId = CommCareApplication.instance().getCurrentApp().getUniqueId();
ConnectLinkedAppRecord appRecord = ConnectDatabaseHelper.getAppData(
CommCareApplication.instance(), seatedAppId, username);
return appRecord != null && appRecord.getWorkerLinked();
}
} catch (Exception e){
Logger.exception("Error while checking ConnectId status after failed token auth", e);
}

return false;
}

public static ConnectAppMangement getAppManagement(Context context, String appId, String userId) {
ConnectAppRecord record = getAppRecord(context, appId);
if(record != null) {
Expand Down
16 changes: 3 additions & 13 deletions app/src/org/commcare/network/CommcareRequestGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -183,19 +183,9 @@ private AuthInfo buildAuth() {
Logger.log(LogTypes.TYPE_MAINTENANCE, "Applying token auth");
return tokenAuth;
} else {
try {
if (ConnectManager.isConnectIdConfigured()) {
String seatedAppId = CommCareApplication.instance().getCurrentApp().getUniqueId();
ConnectLinkedAppRecord appRecord = ConnectDatabaseHelper.getAppData(
CommCareApplication.instance(), seatedAppId, username);
if (appRecord != null && appRecord.getWorkerLinked()) {
Logger.exception("Critical auth error for connect managed app",
new Throwable("No token Auth available for a connect managed app"));
}
}
Logger.log(LogTypes.TYPE_MAINTENANCE, "Applying current auth");
} catch (Exception e){
Logger.exception("error while checking connect status when trying to build auth", e);
if(ConnectManager.checkForFailedConnectIdAuth(username)) {
Logger.exception("Token auth error for connect managed app",
new Throwable("No token Auth available for a connect managed app"));
}

CommCareApplication.instance().getSession().getLoggedInUser();
Expand Down