@@ -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
@@ -143,6 +144,7 @@ import com.salesforce.androidsdk.util.SalesforceSDKLogger.e
143144import com.salesforce.androidsdk.util.SalesforceSDKLogger.w
144145import com.salesforce.androidsdk.util.UriFragmentParser
145146import kotlinx.coroutines.CoroutineScope
147+ import kotlinx.coroutines.Dispatchers
146148import kotlinx.coroutines.Dispatchers.Default
147149import kotlinx.coroutines.Dispatchers.IO
148150import kotlinx.coroutines.launch
@@ -316,11 +318,18 @@ open class LoginActivity : FragmentActivity() {
316318 }
317319 } else {
318320 with (SalesforceSDKManager .getInstance()) {
319- if (useWebServerAuthentication) {
320- // Fetch well known config and load in custom tab if required.
321- fetchAuthenticationConfiguration {
322- if (isBrowserLoginEnabled ) {
321+ // Fetch well known config and load in custom tab if required.
322+ fetchAuthenticationConfiguration {
323+ if (isBrowserLoginEnabled) {
324+ if (useWebServerAuthentication ) {
323325 viewModel.loginUrl.value?.let { url -> loadLoginPageInCustomTab(url, customTabLauncher) }
326+ } else {
327+ /* Reload the webview now that isBrowserLoginEnabled has been set
328+ to true so that we generate an authorization URL with PKCE values. */
329+ lifecycleScope.launch(Dispatchers .Main ) {
330+ viewModel.reloadWebView()
331+ viewModel.loginUrl.value?.let { url -> loadLoginPageInCustomTab(url, customTabLauncher) }
332+ }
324333 }
325334 }
326335 }
@@ -923,25 +932,19 @@ open class LoginActivity : FragmentActivity() {
923932 // Show loading while we PKCE and/or create user account.
924933 viewModel.authFinished.value = true
925934
926- // Determine if presence of override parameters require the user agent flow.
927- val overrideWithUserAgentFlow = viewModel.isUsingFrontDoorBridge
928- && viewModel.frontdoorBridgeCodeVerifier == null
929935 when {
930- SalesforceSDKManager .getInstance().useWebServerAuthentication
931- && ! overrideWithUserAgentFlow ->
932-
936+ viewModel.useWebServerFlow ->
933937 viewModel.onWebServerFlowComplete(
934938 params[" code" ],
935939 ::onAuthFlowError,
936- ::onAuthFlowSuccess
940+ ::onAuthFlowSuccess,
937941 )
938-
939942 else ->
940943 CoroutineScope (Default ).launch {
941944 viewModel.onAuthFlowComplete(
942945 TokenEndpointResponse (params),
943946 ::onAuthFlowError,
944- ::onAuthFlowSuccess
947+ ::onAuthFlowSuccess,
945948 )
946949 }
947950 }
0 commit comments