@@ -47,7 +47,6 @@ import com.salesforce.androidsdk.app.SalesforceSDKManager
4747import com.salesforce.androidsdk.auth.OAuth2.TokenEndpointResponse
4848import com.salesforce.androidsdk.auth.OAuth2.addAuthorizationHeader
4949import com.salesforce.androidsdk.auth.OAuth2.callIdentityService
50- import com.salesforce.androidsdk.auth.OAuth2.revokeRefreshToken
5150import com.salesforce.androidsdk.config.LoginServerManager
5251import com.salesforce.androidsdk.config.RuntimeConfig
5352import com.salesforce.androidsdk.config.RuntimeConfig.getRuntimeConfig
@@ -98,6 +97,7 @@ internal suspend fun onAuthFlowComplete(
9897 onAuthFlowSuccess : (userAccount: UserAccount ) -> Unit ,
9998 buildAccountName : (username: String? , instanceServer: String? ) -> String = ::defaultBuildAccountName,
10099 nativeLogin : Boolean = false,
100+ tokenMigration : Boolean = false,
101101 context : Context = SalesforceSDKManager .getInstance().appContext,
102102 userAccountManager : UserAccountManager = SalesforceSDKManager .getInstance().userAccountManager,
103103 blockIntegrationUser : Boolean = (SalesforceSDKManager .getInstance().shouldBlockSalesforceIntegrationUser &&
@@ -110,7 +110,8 @@ internal suspend fun onAuthFlowComplete(
110110 addAccount : (account: UserAccount ) -> Unit = ::addAccountHelper,
111111 handleScreenLockPolicy : (userIdentity: OAuth2 .IdServiceResponse ? , account: UserAccount ) -> Unit = ::handleScreenLockPolicy,
112112 handleBiometricAuthPolicy : (userIdentity: OAuth2 .IdServiceResponse ? , account: UserAccount ) -> Unit = ::handleBiometricAuthPolicy,
113- handleDuplicateUserAccount : (userAccountManager: UserAccountManager , account: UserAccount , userIdentity: OAuth2 .IdServiceResponse ? ) -> Unit = ::handleDuplicateUserAccount,
113+ handleDuplicateUserAccount : (userAccountManager: UserAccountManager , account: UserAccount , userIdentity: OAuth2 .IdServiceResponse ? ) -> Unit
114+ = { uam, acct, identity -> com.salesforce.androidsdk.auth.handleDuplicateUserAccount(uam, acct, identity) },
114115) {
115116 // Reset Dev Support LoginOptionsActivity override
116117 SalesforceSDKManager .getInstance().debugOverrideAppConfig = null
@@ -189,9 +190,11 @@ internal suspend fun onAuthFlowComplete(
189190 }
190191 userAccountManager.sendUserSwitchIntent(userSwitchType, null )
191192
192- // Kickoff the end of the flow before storing mobile policy to prevent launching
193- // the main activity over/after the screen lock.
194- startMainActivity()
193+ if (! tokenMigration) {
194+ // Kickoff the end of the flow before storing mobile policy to prevent launching
195+ // the main activity over/after the screen lock.
196+ startMainActivity()
197+ }
195198
196199 // Let the calling process resume
197200 onAuthFlowSuccess(account)
@@ -371,36 +374,51 @@ private fun updateLoggingPrefsHelper(account: UserAccount) {
371374/* *
372375 * Helper method to handle screen lock mobile policy.
373376 */
374- private fun handleScreenLockPolicy (
377+ @VisibleForTesting
378+ internal fun handleScreenLockPolicy (
375379 userIdentity : OAuth2 .IdServiceResponse ? ,
376- account : UserAccount
380+ account : UserAccount ,
377381) {
382+ val internalScreenLockManager =
383+ SalesforceSDKManager .getInstance().screenLockManager as ScreenLockManager ?
384+
385+ // compareTo(0) is used to check if screenLockTimeout is non-null and greater than 0.
378386 if (userIdentity?.screenLockTimeout?.compareTo(0 ) == 1 ) {
379387 SalesforceSDKManager .getInstance().registerUsedAppFeature(FEATURE_SCREEN_LOCK )
380388 val timeoutInMills = userIdentity.screenLockTimeout * 1000 * 60
381- ( SalesforceSDKManager .getInstance().screenLockManager as ScreenLockManager ? ) ?.storeMobilePolicy(
389+ internalScreenLockManager ?.storeMobilePolicy(
382390 account,
383- userIdentity.screenLock,
384- timeoutInMills
391+ enabled = userIdentity.screenLock,
392+ timeoutInMills,
385393 )
394+ } else if (internalScreenLockManager?.enabled == true ) {
395+ SalesforceSDKManager .getInstance().unregisterUsedAppFeature(FEATURE_SCREEN_LOCK )
396+ internalScreenLockManager.cleanUp(account)
386397 }
387398}
388399
389400/* *
390401 * Helper method to handle biometric authentication mobile policy.
391402 */
392- private fun handleBiometricAuthPolicy (
403+ @VisibleForTesting
404+ internal fun handleBiometricAuthPolicy (
393405 userIdentity : OAuth2 .IdServiceResponse ? ,
394- account : UserAccount
406+ account : UserAccount ,
395407) {
408+ val internalBiometricAuthenticationManager =
409+ SalesforceSDKManager .getInstance().biometricAuthenticationManager as BiometricAuthenticationManager ?
410+
396411 if (userIdentity?.biometricAuth == true ) {
397412 SalesforceSDKManager .getInstance().registerUsedAppFeature(FEATURE_BIOMETRIC_AUTH )
398413 val timeoutInMills = userIdentity.biometricAuthTimeout * 60 * 1000
399- ( SalesforceSDKManager .getInstance().biometricAuthenticationManager as BiometricAuthenticationManager ? ) ?.storeMobilePolicy(
414+ internalBiometricAuthenticationManager ?.storeMobilePolicy(
400415 account,
401- userIdentity.biometricAuth,
416+ enabled = userIdentity.biometricAuth,
402417 timeoutInMills
403418 )
419+ } else if (internalBiometricAuthenticationManager?.enabled == true ) {
420+ SalesforceSDKManager .getInstance().unregisterUsedAppFeature(FEATURE_BIOMETRIC_AUTH )
421+ internalBiometricAuthenticationManager.cleanUp(account)
404422 }
405423}
406424
@@ -426,10 +444,12 @@ private fun addAccountHelper(
426444 * - Unlocking biometric authentication for the duplicate user
427445 * - Signing out other users with biometric auth when a new biometric user is added
428446 */
429- private fun handleDuplicateUserAccount (
447+ @VisibleForTesting
448+ internal fun handleDuplicateUserAccount (
430449 userAccountManager : UserAccountManager ,
431450 account : UserAccount ,
432- userIdentity : OAuth2 .IdServiceResponse ?
451+ userIdentity : OAuth2 .IdServiceResponse ? ,
452+ revokeRefreshToken : (HttpAccess , URI , String , OAuth2 .LogoutReason ) -> Unit = OAuth2 : :revokeRefreshToken,
433453) {
434454 userAccountManager.authenticatedUsers?.let { existingUsers ->
435455 // Check if the user already exists
@@ -451,14 +471,12 @@ private fun handleDuplicateUserAccount(
451471 as ? BiometricAuthenticationManager )?.onUnlock()
452472 }
453473 CoroutineScope (IO ).launch {
454- CoroutineScope (IO ).launch {
455- revokeRefreshToken(
456- HttpAccess .DEFAULT ,
457- uri,
458- duplicateUserAccount.refreshToken,
459- OAuth2 .LogoutReason .REFRESH_TOKEN_ROTATED ,
460- )
461- }
474+ revokeRefreshToken(
475+ HttpAccess .DEFAULT ,
476+ uri,
477+ duplicateUserAccount.refreshToken,
478+ OAuth2 .LogoutReason .REFRESH_TOKEN_ROTATED ,
479+ )
462480 }
463481 }
464482 }
0 commit comments