Skip to content

@W-17964655: [Android] WSC discovery endpoint to postpone OAuth flow #2736

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2 changes: 1 addition & 1 deletion libs/SalesforceSDK/res/xml/servers.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<servers>
<server name="Production" url="https://login.salesforce.com" />
<server name="Welcome" url="https://welcome.salesforce.com" />
<server name="Welcome" url="https://welcome.salesforce.com/discovery" />
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@wmathurin - I've set up the MSDK logic to distinguish Salesforce Welcome Discovery URLs by the path element. According to our convention, that works and doesn't require us to add an UX for the user to specify if they're entering discovery URL in the "Add Connection" bottom sheet.

Alternately, we could add some way for the user to check-off that the scheme and host they've entered is for discovery and then add this path in the MSDK logic. That seemed more intrusive to the user, though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm open to other ideas. This seemed to keep it simple, at first blush.

Copy link
Contributor

Choose a reason for hiding this comment

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

The end user wouldn't know if the app developer is using a scheme and host for discovery, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct. We also don't have a specification for what this will look like beyond internal use, so it might change.

<server name="Sandbox" url="https://test.salesforce.com" />
</servers>
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.res.XmlResourceParser;
import android.os.Looper;

import androidx.annotation.NonNull;
import androidx.lifecycle.MutableLiveData;
Expand Down Expand Up @@ -61,7 +62,7 @@ public class LoginServerManager {

// Default login servers.
public static final String PRODUCTION_LOGIN_URL = "https://login.salesforce.com";
public static final String WELCOME_LOGIN_URL = "https://welcome.salesforce.com";
public static final String WELCOME_LOGIN_URL = "https://welcome.salesforce.com/discovery";
public static final String SANDBOX_LOGIN_URL = "https://test.salesforce.com";

// Keys used in shared preferences.
Expand Down Expand Up @@ -167,7 +168,11 @@ public void setSelectedLoginServer(LoginServer server) {
edit.putString(SERVER_URL, server.url);
edit.putBoolean(IS_CUSTOM, server.isCustom);
edit.apply();
selectedServer.postValue(server);
if (Looper.myLooper() == Looper.getMainLooper()) {
selectedServer.setValue(server);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This optimization uses the synchronous setValue on the main thread, when applicable, and falls back to the asynchronous postValue when off main. In LoginActivity, this makes the UX smoother since we're already on the main thread.

} else {
selectedServer.postValue(server);
}
}

/**
Expand Down
Loading