Skip to content

Commit b44f65c

Browse files
@W-20173671/@W-20005462: [Android] Extra session on logout/add account when upgrading from Mobile SDK 12 to 13/[Android] Toggle for clearCookies after login (#2806)
* @W-20173671: [Android] Extra session on logout/add account when upgrading from Mobile SDK 12 to 13 * @W-20005462: [Android] Toggle for clearCookies after login * @W-20005462: [Android] Toggle for clearCookies after login (Code Review Updates)
1 parent da45b1f commit b44f65c

2 files changed

Lines changed: 17 additions & 7 deletions

File tree

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ import kotlinx.coroutines.Dispatchers.Main
149149
import kotlinx.coroutines.launch
150150
import kotlinx.coroutines.withTimeoutOrNull
151151
import okhttp3.HttpUrl.Companion.toHttpUrlOrNull
152-
import org.jetbrains.annotations.Debug
153152
import java.lang.String.CASE_INSENSITIVE_ORDER
154153
import java.net.URI
155154
import java.util.Locale.US
@@ -336,6 +335,15 @@ open class SalesforceSDKManager protected constructor(
336335
*/
337336
var additionalOauthKeys: List<String>? = null
338337

338+
/**
339+
* Determines if the authentication web view's cookies will be cleared after
340+
* authentication. The default behavior is true to protect against re-use
341+
* of authentication related cookies and duplication authentication action.
342+
* Only apps the specifically require persistent cookies should set this to
343+
* false.
344+
*/
345+
var clearCookiesAfterLogin = true
346+
339347
/**
340348
* The login brand. In the following example, "<brand>" should be set here.
341349
* https://community.force.com/services/oauth2/authorize/<brand>?response_type=code&...
@@ -829,9 +837,6 @@ open class SalesforceSDKManager protected constructor(
829837
*/
830838
private fun startSwitcherActivityIfRequired() {
831839

832-
// Clear cookies
833-
CookieManager.getInstance().removeAllCookies(null)
834-
835840
/*
836841
* If the number of accounts remaining is 0, show the login page.
837842
*
@@ -1106,6 +1111,10 @@ open class SalesforceSDKManager protected constructor(
11061111
)
11071112
clientMgr.removeAccount(account)
11081113
isLoggingOut = false
1114+
1115+
// Clear cookies to ensure those used during previous log in will not be re-used to log the user in again.
1116+
CookieManager.getInstance().removeAllCookies(null)
1117+
11091118
notifyLogoutComplete(showLoginPage, logoutReason, userAccount)
11101119

11111120
// Revoke the existing refresh token

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,9 +318,10 @@ open class LoginViewModel(val bootConfig: BootConfig) : ViewModel() {
318318
onAuthFlowError: (error: String, errorDesc: String?, e: Throwable?) -> Unit,
319319
onAuthFlowSuccess: (userAccount: UserAccount) -> Unit,
320320
) {
321-
// Clear cookies when we finish auth to prevent automatic re-login
322-
// if the user tries to add another user right away.
323-
clearCookies()
321+
// Clear cookies after successful authentication to prevent automatic re-login if the user tries to add another user right away.
322+
if (SalesforceSDKManager.getInstance().clearCookiesAfterLogin) {
323+
clearCookies()
324+
}
324325
authCodeForJwtFlow = null
325326
onAuthFlowComplete(
326327
tokenResponse = tr,

0 commit comments

Comments
 (0)