Skip to content

Commit f6e7a1d

Browse files
@W-20935841: Bug - P2 - [Android] Login Server Switching Misbehaving (#2822)
1 parent 6f30715 commit f6e7a1d

5 files changed

Lines changed: 4 additions & 46 deletions

File tree

libs/SalesforceSDK/res/values/strings.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
<string name="account_type">com.salesforce.androidsdk</string>
99
<string name="app_package">com.salesforce.androidsdk</string>
1010
<string name="cannot_use_another_apps_login_qr_code">Cannot use another app\'s login QR Code. Please log in to this app.</string>
11-
<string name="salesforce_welcome_is_disabled">This app doesn\'t support welcome.salesforce.com. Use another server.</string>
1211

1312
<!-- If you're only supporting recent versions of Android (e.g. 3.x and up), you can override this to be touch and get a better looking login UI -->
1413
<string name="oauth_display_type">touch</string>

libs/SalesforceSDK/src/com/salesforce/androidsdk/app/SalesforceSDKManager.kt

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -372,13 +372,6 @@ open class SalesforceSDKManager protected constructor(
372372
@set:Synchronized
373373
var useWebServerAuthentication = true
374374

375-
376-
/**
377-
* Whether or not the app supports welcome discovery. This should only be
378-
* enabled if the connected app is supported.
379-
*/
380-
var supportsWelcomeDiscovery = false
381-
382375
/**
383376
* Optionally, enables the hybrid authentication flow. Defaults to true
384377
*/

libs/SalesforceSDK/src/com/salesforce/androidsdk/ui/LoginActivity.kt

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ import com.salesforce.androidsdk.R.color.sf__background_dark
111111
import com.salesforce.androidsdk.R.color.sf__primary_color
112112
import com.salesforce.androidsdk.R.drawable.sf__action_back
113113
import com.salesforce.androidsdk.R.string.cannot_use_another_apps_login_qr_code
114-
import com.salesforce.androidsdk.R.string.salesforce_welcome_is_disabled
115114
import com.salesforce.androidsdk.R.string.sf__biometric_opt_in_title
116115
import com.salesforce.androidsdk.R.string.sf__generic_authentication_error_title
117116
import com.salesforce.androidsdk.R.string.sf__jwt_authentication_error
@@ -913,26 +912,6 @@ open class LoginActivity : FragmentActivity() {
913912
}
914913
}
915914

916-
/**
917-
* Alerts the user if Salesforce Welcome Discovery is disabled.
918-
* @param supportsWelcomeDiscovery Indicates if Salesforce Welcome Discovery
919-
* is supported.
920-
* @return Boolean true if the alert was displayed, false otherwise
921-
*/
922-
@VisibleForTesting
923-
internal fun displayWelcomeUnsupportedToastIfNeeded(
924-
supportsWelcomeDiscovery: Boolean
925-
) = if (!supportsWelcomeDiscovery) {
926-
runOnUiThread {
927-
makeText(
928-
this,
929-
getString(salesforce_welcome_is_disabled),
930-
LENGTH_LONG
931-
).show()
932-
}
933-
true
934-
} else false
935-
936915
/**
937916
* Creates a Salesforce Welcome Discovery mobile URL using the provided
938917
* Salesforce Welcome Discovery host and path URL.
@@ -1028,7 +1007,6 @@ open class LoginActivity : FragmentActivity() {
10281007
*/
10291008
private fun useSalesforceWelcomeDiscoveryMobileUrl(uri: Uri) {
10301009
if (isSalesforceWelcomeDiscoveryMobileUrl(uri)) {
1031-
displayWelcomeUnsupportedToastIfNeeded(SalesforceSDKManager.getInstance().supportsWelcomeDiscovery)
10321010
viewModel.loginUrl.postValue(uri.toString())
10331011
}
10341012
}
@@ -1470,11 +1448,6 @@ open class LoginActivity : FragmentActivity() {
14701448
if (!uri.isHierarchical) return false
14711449

14721450
val isDiscovery = isSalesforceWelcomeDiscoveryUrlPath(uri)
1473-
val discoveryEnabled = SalesforceSDKManager.getInstance().supportsWelcomeDiscovery
1474-
1475-
if (isDiscovery && !discoveryEnabled) {
1476-
w(TAG, "'${uri}' is a discovery domain, but welcome discovery isn't enabled.")
1477-
}
14781451

14791452
return isDiscovery && uri.queryParameterNames.contains(
14801453
SALESFORCE_WELCOME_DISCOVERY_MOBILE_URL_QUERY_PARAMETER_KEY_CLIENT_ID
@@ -1601,7 +1574,7 @@ open class LoginActivity : FragmentActivity() {
16011574
override fun onChanged(value: String) {
16021575
// Guard against observing a pending login server already provided by the intent data, such as a Salesforce Welcome Discovery mobile URL.
16031576
val pendingServerUri = value.toUri()
1604-
if (activity.intent.data?.host == pendingServerUri.host || activity.intent.getStringExtra(EXTRA_KEY_LOGIN_HOST) == pendingServerUri.host) {
1577+
if ((activity.intent.data?.host == pendingServerUri.host && activity.intent.data?.path == pendingServerUri.path) || activity.intent.getStringExtra(EXTRA_KEY_LOGIN_HOST) == pendingServerUri.host) {
16051578
activity.viewModel.previousPendingServer = value
16061579
return
16071580
}

libs/SalesforceSDK/src/com/salesforce/androidsdk/ui/LoginViewModel.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,9 @@ open class LoginViewModel(val bootConfig: BootConfig) : ViewModel() {
516516
) : Observer<String?> {
517517
override fun onChanged(value: String?) {
518518
if (!sdkManager.isBrowserLoginEnabled && !viewModel.isUsingFrontDoorBridge && value != null) {
519-
val isNewServer = viewModel.loginUrl.value?.startsWith(value) != true
519+
val valueUrl = value.toUri()
520+
val loginUrl = viewModel.loginUrl.value?.toUri()
521+
val isNewServer = loginUrl?.host != valueUrl.host || loginUrl?.path != valueUrl.path
520522
if (isNewServer) {
521523
scope.launch {
522524
viewModel.loginUrl.value = viewModel.getAuthorizationUrl(value)

libs/test/SalesforceSDKTest/src/com/salesforce/androidsdk/ui/LoginActivityTest.kt

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -195,15 +195,8 @@ class LoginActivityTest {
195195

196196
@Test
197197
fun testIsWelcomeDiscoveryUri() {
198-
val supportWelcomeDiscovery = SalesforceSDKManager.getInstance().supportsWelcomeDiscovery
199-
SalesforceSDKManager.getInstance().supportsWelcomeDiscovery = false
200-
201198
val validUrl = "https://welcome.salesforce.com$SALESFORCE_WELCOME_DISCOVERY_URL_PATH?$SALESFORCE_WELCOME_DISCOVERY_MOBILE_URL_QUERY_PARAMETER_KEY_CLIENT_ID=X&$SALESFORCE_WELCOME_DISCOVERY_MOBILE_URL_QUERY_PARAMETER_KEY_CLIENT_VERSION=Y&$SALESFORCE_WELCOME_DISCOVERY_MOBILE_URL_QUERY_PARAMETER_KEY_CALLBACK_URL=Z"
202199

203-
assertTrue(isSalesforceWelcomeDiscoveryMobileUrl(validUrl.toUri()))
204-
205-
SalesforceSDKManager.getInstance().supportsWelcomeDiscovery = true
206-
207200
val nonHierarchicalUri = "mailto:test@example.com"
208201

209202
val incorrectPathUrl = "https://welcome.salesforce.com/other/path?$SALESFORCE_WELCOME_DISCOVERY_MOBILE_URL_QUERY_PARAMETER_KEY_CLIENT_ID=X&$SALESFORCE_WELCOME_DISCOVERY_MOBILE_URL_QUERY_PARAMETER_KEY_CLIENT_VERSION=Y&$SALESFORCE_WELCOME_DISCOVERY_MOBILE_URL_QUERY_PARAMETER_KEY_CALLBACK_URL=Z"
@@ -231,7 +224,5 @@ class LoginActivityTest {
231224
assertFalse("Missing callback URL parameter should return false", isSalesforceWelcomeDiscoveryMobileUrl(missingCallbackUrl.toUri()))
232225

233226
assertFalse("Non-welcome URL should return false", isSalesforceWelcomeDiscoveryMobileUrl(otherUrl.toUri()))
234-
235-
SalesforceSDKManager.getInstance().supportsWelcomeDiscovery = supportWelcomeDiscovery
236227
}
237228
}

0 commit comments

Comments
 (0)