@@ -102,6 +102,7 @@ import androidx.core.content.ContextCompat.getMainExecutor
102102import androidx.core.net.toUri
103103import androidx.core.view.WindowCompat
104104import androidx.fragment.app.FragmentActivity
105+ import androidx.lifecycle.lifecycleScope
105106import com.salesforce.androidsdk.R.color.sf__background
106107import com.salesforce.androidsdk.R.color.sf__background_dark
107108import com.salesforce.androidsdk.R.color.sf__primary_color
@@ -142,6 +143,7 @@ import com.salesforce.androidsdk.util.SalesforceSDKLogger.e
142143import com.salesforce.androidsdk.util.SalesforceSDKLogger.w
143144import com.salesforce.androidsdk.util.UriFragmentParser
144145import kotlinx.coroutines.CoroutineScope
146+ import kotlinx.coroutines.Dispatchers
145147import kotlinx.coroutines.Dispatchers.Default
146148import kotlinx.coroutines.Dispatchers.IO
147149import kotlinx.coroutines.launch
@@ -293,11 +295,18 @@ open class LoginActivity : FragmentActivity() {
293295 }
294296 } else {
295297 with (SalesforceSDKManager .getInstance()) {
296- if (useWebServerAuthentication) {
297- // Fetch well known config and load in custom tab if required.
298- fetchAuthenticationConfiguration {
299- if (isBrowserLoginEnabled ) {
298+ // Fetch well known config and load in custom tab if required.
299+ fetchAuthenticationConfiguration {
300+ if (isBrowserLoginEnabled) {
301+ if (useWebServerAuthentication ) {
300302 viewModel.loginUrl.value?.let { url -> loadLoginPageInCustomTab(url, customTabLauncher) }
303+ } else {
304+ /* Reload the webview now that isBrowserLoginEnabled has been set
305+ to true so that we generate an authorization URL with PKCE values. */
306+ lifecycleScope.launch(Dispatchers .Main ) {
307+ viewModel.reloadWebView()
308+ viewModel.loginUrl.value?.let { url -> loadLoginPageInCustomTab(url, customTabLauncher) }
309+ }
301310 }
302311 }
303312 }
@@ -900,25 +909,19 @@ open class LoginActivity : FragmentActivity() {
900909 // Show loading while we PKCE and/or create user account.
901910 viewModel.authFinished.value = true
902911
903- // Determine if presence of override parameters require the user agent flow.
904- val overrideWithUserAgentFlow = viewModel.isUsingFrontDoorBridge
905- && viewModel.frontdoorBridgeCodeVerifier == null
906912 when {
907- SalesforceSDKManager .getInstance().useWebServerAuthentication
908- && ! overrideWithUserAgentFlow ->
909-
913+ viewModel.useWebServerFlow ->
910914 viewModel.onWebServerFlowComplete(
911915 params[" code" ],
912916 ::onAuthFlowError,
913- ::onAuthFlowSuccess
917+ ::onAuthFlowSuccess,
914918 )
915-
916919 else ->
917920 CoroutineScope (Default ).launch {
918921 viewModel.onAuthFlowComplete(
919922 TokenEndpointResponse (params),
920923 ::onAuthFlowError,
921- ::onAuthFlowSuccess
924+ ::onAuthFlowSuccess,
922925 )
923926 }
924927 }
0 commit comments