Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,23 @@ import android.net.Uri
import android.os.SystemClock
import android.webkit.CookieManager
import com.salesforce.androidsdk.accounts.UserAccount
import com.salesforce.androidsdk.auth.ScopeParser
import com.salesforce.androidsdk.phonegap.util.SalesforceHybridLogger.d
import com.salesforce.androidsdk.phonegap.util.SalesforceHybridLogger.w
import java.net.URI

class SalesforceWebViewCookieManager {
private val cookieManager = CookieManager.getInstance()

fun setCookies(userAccount: UserAccount) {
fun setCookies(userAccount: UserAccount,
// Optional lambda parameters to facilitate testing
setCookieValue: (String, String?, Boolean, String?, String?) -> Unit = ::setCookieValue,
syncCookies: () -> Unit = ::syncCookies) {
d(TAG, "setCookies for userAccount:${userAccount.toJson()}")

// Warn if expected scopes are missing
userAccount.scope?.let { inspectScopes(it) }

val instanceUrl = userAccount.instanceServer
val lightningDomain = userAccount.lightningDomain
val lightningSid = userAccount.lightningSid
Expand Down Expand Up @@ -83,6 +90,30 @@ class SalesforceWebViewCookieManager {
syncCookies()
}

internal fun inspectScopes(scope: String, warn: (String) -> Unit = { w(TAG, it)}) {
val scopeParser = ScopeParser(scope)

// full encompasses all other scopes except for refresh
if (!scopeParser.hasScope("full")) {
if (!scopeParser.hasScope("web")) {
warn("Missing web scope: will not be able to access web content.")

// web encompasses visualforce scope
if (!scopeParser.hasScope("visualforce")) {
warn("Missing visualforce scope: will not be able to access Visualforce pages.")
}
}

if (!scopeParser.hasScope("lightning")) {
warn("Missing lightning scope: will not be able to access Lightning applications.")
}

if (!scopeParser.hasScope("content")) {
warn("Missing content scope: will not be able to access Content resources.")
}
}
}

private fun setCookieValue(
cookieType: String, domain: String?, setDomain: Boolean, name: String?, value: String?
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,7 @@ public void testGetSDKInfo() throws NameNotFoundException, JSONException {
Assert.assertEquals("Wrong bootconfig shouldAuthenticate", bootconfig.shouldAuthenticate(), sdkInfoBootConfig.getBoolean("shouldAuthenticate"));
Assert.assertEquals("Wrong bootconfig attemptOfflineLoad", bootconfig.attemptOfflineLoad(), sdkInfoBootConfig.getBoolean("attemptOfflineLoad"));
Assert.assertEquals("Wrong bootconfig isLocal", bootconfig.isLocal(), sdkInfoBootConfig.getBoolean("isLocal"));
List<String> sdkInfoOAuthScopes = toList(sdkInfoBootConfig.getJSONArray("oauthScopes"));
Assert.assertEquals("Wrong bootconfig oauthScopes", 1, sdkInfoOAuthScopes.size());
Assert.assertTrue("Wrong bootconfig oauthScopes", sdkInfoOAuthScopes.contains("api"));
Assert.assertNull("Wrong bootconfig oauthScopes", sdkInfoBootConfig.optJSONArray("oauthScopes"));
Assert.assertEquals("Wrong bootconfig oauthRedirectURI", bootconfig.getOauthRedirectURI(), sdkInfoBootConfig.getString("oauthRedirectURI"));
Assert.assertEquals("Wrong bootconfig remoteAccessConsumerKey", bootconfig.getRemoteAccessConsumerKey(), sdkInfoBootConfig.getString("remoteAccessConsumerKey"));
Assert.assertEquals("Wrong bootconfig startPage", "index.html", sdkInfoBootConfig.optString("startPage"));
Expand Down
Loading