salesforce-mobilesdk-cordova-plugin 13.2.0 → 13.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/plugin.xml +7 -7
- package/src/android/libs/mobile_sdk/README.md +1 -1
- package/src/android/libs/mobile_sdk/build.gradle.kts +1 -1
- package/src/android/libs/mobile_sdk/libs/MobileSync/AndroidManifest.xml +2 -2
- package/src/android/libs/mobile_sdk/libs/MobileSync/build.gradle.kts +1 -1
- package/src/android/libs/mobile_sdk/libs/SalesforceAnalytics/AndroidManifest.xml +2 -2
- package/src/android/libs/mobile_sdk/libs/SalesforceAnalytics/build.gradle.kts +1 -1
- package/src/android/libs/mobile_sdk/libs/SalesforceHybrid/AndroidManifest.xml +2 -2
- package/src/android/libs/mobile_sdk/libs/SalesforceHybrid/build.gradle.kts +1 -1
- package/src/android/libs/mobile_sdk/libs/SalesforceHybrid/res/xml/config.xml +1 -1
- package/src/android/libs/mobile_sdk/libs/SalesforceSDK/AndroidManifest.xml +2 -2
- package/src/android/libs/mobile_sdk/libs/SalesforceSDK/build.gradle.kts +1 -1
- package/src/android/libs/mobile_sdk/libs/SalesforceSDK/res/values/sf__strings.xml +1 -0
- package/src/android/libs/mobile_sdk/libs/SalesforceSDK/src/com/salesforce/androidsdk/accounts/UserAccount.java +44 -2
- package/src/android/libs/mobile_sdk/libs/SalesforceSDK/src/com/salesforce/androidsdk/accounts/UserAccountManager.java +11 -1
- package/src/android/libs/mobile_sdk/libs/SalesforceSDK/src/com/salesforce/androidsdk/app/SalesforceSDKManager.kt +1 -1
- package/src/android/libs/mobile_sdk/libs/SalesforceSDK/src/com/salesforce/androidsdk/auth/AuthenticationUtilities.kt +10 -4
- package/src/android/libs/mobile_sdk/libs/SalesforceSDK/src/com/salesforce/androidsdk/auth/OAuth2.java +1 -2
- package/src/android/libs/mobile_sdk/libs/SalesforceSDK/src/com/salesforce/androidsdk/rest/ClientManager.java +8 -1
- package/src/android/libs/mobile_sdk/libs/SalesforceSDK/src/com/salesforce/androidsdk/ui/LoginActivity.kt +59 -59
- package/src/android/libs/mobile_sdk/libs/SalesforceSDK/src/com/salesforce/androidsdk/ui/LoginViewModel.kt +154 -97
- package/src/android/libs/mobile_sdk/libs/SalesforceSDK/src/com/salesforce/androidsdk/ui/TokenMigrationActivity.kt +8 -21
- package/src/android/libs/mobile_sdk/libs/SalesforceSDK/src/com/salesforce/androidsdk/ui/components/LoginView.kt +18 -2
- package/src/android/libs/mobile_sdk/libs/SmartStore/AndroidManifest.xml +2 -2
- package/src/android/libs/mobile_sdk/libs/SmartStore/build.gradle.kts +1 -1
- package/src/android/libs/mobile_sdk/libs/test/SalesforceHybridTest/res/xml/config.xml +1 -1
- package/src/android/libs/mobile_sdk/libs/test/SalesforceSDKTest/src/com/salesforce/androidsdk/accounts/UserAccountManagerTest.java +83 -0
- package/src/android/libs/mobile_sdk/libs/test/SalesforceSDKTest/src/com/salesforce/androidsdk/auth/LoginViewModelMockTest.kt +67 -0
- package/src/android/libs/mobile_sdk/libs/test/SalesforceSDKTest/src/com/salesforce/androidsdk/auth/LoginViewModelTest.kt +250 -344
- package/src/android/libs/mobile_sdk/libs/test/SalesforceSDKTest/src/com/salesforce/androidsdk/rest/ClientManagerMockTest.kt +142 -0
- package/src/android/libs/mobile_sdk/libs/test/SalesforceSDKTest/src/com/salesforce/androidsdk/ui/LoginActivityScenarioTest.kt +22 -109
- package/src/android/libs/mobile_sdk/libs/test/SalesforceSDKTest/src/com/salesforce/androidsdk/ui/LoginActivityTest.kt +60 -31
- package/src/android/libs/mobile_sdk/libs/test/SalesforceSDKTest/src/com/salesforce/androidsdk/ui/LoginViewActivityTest.kt +41 -2
- package/src/ios/resources/SalesforceSDKResources.bundle/en.lproj/Localizable.strings +1 -0
- package/tools/postinstall-android.js +1 -1
- package/www/com.salesforce.plugin.mobilesync.js +1 -1
- package/www/com.salesforce.plugin.network.js +1 -1
- package/www/com.salesforce.plugin.oauth.js +1 -1
- package/www/com.salesforce.plugin.sdkinfo.js +1 -1
- package/www/com.salesforce.plugin.sfaccountmanager.js +1 -1
- package/www/com.salesforce.plugin.smartstore.client.js +1 -1
- package/www/com.salesforce.plugin.smartstore.js +1 -1
- package/www/com.salesforce.util.bootstrap.js +1 -1
- package/www/com.salesforce.util.event.js +1 -1
- package/www/com.salesforce.util.exec.js +1 -1
- package/www/com.salesforce.util.logger.js +1 -1
- package/www/com.salesforce.util.promiser.js +1 -1
- package/www/com.salesforce.util.push.js +1 -1
package/package.json
CHANGED
package/plugin.xml
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
|
|
4
4
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
|
5
5
|
id="com.salesforce"
|
|
6
|
-
version="13.2.
|
|
6
|
+
version="13.2.1">
|
|
7
7
|
|
|
8
8
|
<name>SalesforceMobileSDK Plugins</name>
|
|
9
9
|
<description>SalesforceMobileSDK Plugins</description>
|
|
@@ -94,12 +94,12 @@
|
|
|
94
94
|
<source url="https://cdn.cocoapods.org"/>
|
|
95
95
|
</config>
|
|
96
96
|
<pods use-frameworks="true">
|
|
97
|
-
<pod name="SalesforceHybridSDK" git="https://github.com/forcedotcom/SalesforceMobileSDK-iOS-Hybrid" tag="v13.2.
|
|
98
|
-
<pod name="MobileSync" git="https://github.com/forcedotcom/SalesforceMobileSDK-iOS" tag="v13.2.
|
|
99
|
-
<pod name="SmartStore" git="https://github.com/forcedotcom/SalesforceMobileSDK-iOS" tag="v13.2.
|
|
100
|
-
<pod name="SalesforceSDKCore" git="https://github.com/forcedotcom/SalesforceMobileSDK-iOS" tag="v13.2.
|
|
101
|
-
<pod name="SalesforceAnalytics" git="https://github.com/forcedotcom/SalesforceMobileSDK-iOS" tag="v13.2.
|
|
102
|
-
<pod name="SalesforceSDKCommon" git="https://github.com/forcedotcom/SalesforceMobileSDK-iOS" tag="v13.2.
|
|
97
|
+
<pod name="SalesforceHybridSDK" git="https://github.com/forcedotcom/SalesforceMobileSDK-iOS-Hybrid" tag="v13.2.1" />
|
|
98
|
+
<pod name="MobileSync" git="https://github.com/forcedotcom/SalesforceMobileSDK-iOS" tag="v13.2.1" />
|
|
99
|
+
<pod name="SmartStore" git="https://github.com/forcedotcom/SalesforceMobileSDK-iOS" tag="v13.2.1" />
|
|
100
|
+
<pod name="SalesforceSDKCore" git="https://github.com/forcedotcom/SalesforceMobileSDK-iOS" tag="v13.2.1" />
|
|
101
|
+
<pod name="SalesforceAnalytics" git="https://github.com/forcedotcom/SalesforceMobileSDK-iOS" tag="v13.2.1" />
|
|
102
|
+
<pod name="SalesforceSDKCommon" git="https://github.com/forcedotcom/SalesforceMobileSDK-iOS" tag="v13.2.1" />
|
|
103
103
|
<!-- Needed until cordova-ios gets posted to cocoapod.org -->
|
|
104
104
|
<pod name="Cordova" git="https://github.com/apache/cordova-ios" tag="7.1.1" />
|
|
105
105
|
</pods>
|
|
@@ -18,7 +18,7 @@ buildscript {
|
|
|
18
18
|
|
|
19
19
|
allprojects {
|
|
20
20
|
group = "com.salesforce.mobilesdk"
|
|
21
|
-
version = "13.2.
|
|
21
|
+
version = "13.2.1"
|
|
22
22
|
|
|
23
23
|
// Ensure that we do not use newer language features that would make the SDK incompatible with
|
|
24
24
|
// apps that do not target the latest version of Kotlin.
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
<?xml version="1.0" encoding="utf-8"?>
|
|
2
2
|
|
|
3
3
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
|
4
|
-
android:versionCode="
|
|
5
|
-
android:versionName="13.2.
|
|
4
|
+
android:versionCode="93"
|
|
5
|
+
android:versionName="13.2.1">
|
|
6
6
|
|
|
7
7
|
<uses-permission android:name="android.permission.INTERNET" />
|
|
8
8
|
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
<?xml version="1.0" encoding="utf-8"?>
|
|
2
2
|
|
|
3
3
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
|
4
|
-
android:versionCode="
|
|
5
|
-
android:versionName="13.2.
|
|
4
|
+
android:versionCode="93"
|
|
5
|
+
android:versionName="13.2.1">
|
|
6
6
|
|
|
7
7
|
<application>
|
|
8
8
|
<activity android:name="com.salesforce.androidsdk.phonegap.ui.SalesforceDroidGapActivity"
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
@file:Suppress("UnstableApiUsage")
|
|
2
2
|
|
|
3
3
|
rootProject.ext["PUBLISH_GROUP_ID"] = "com.salesforce.mobilesdk"
|
|
4
|
-
rootProject.ext["PUBLISH_VERSION"] = "13.2.
|
|
4
|
+
rootProject.ext["PUBLISH_VERSION"] = "13.2.1"
|
|
5
5
|
rootProject.ext["PUBLISH_ARTIFACT_ID"] = "SalesforceHybrid"
|
|
6
6
|
|
|
7
7
|
plugins {
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
|
4
4
|
xmlns:tools="http://schemas.android.com/tools"
|
|
5
|
-
android:versionCode="
|
|
6
|
-
android:versionName="13.2.
|
|
5
|
+
android:versionCode="93"
|
|
6
|
+
android:versionName="13.2.1">
|
|
7
7
|
|
|
8
8
|
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
|
|
9
9
|
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
|
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
<string name="sf__clear_cache">Clear cache</string>
|
|
28
28
|
<string name="sf__reload">Reload</string>
|
|
29
29
|
<string name="sf__launch_idp">Log In with IDP App</string>
|
|
30
|
+
<string name="sf__login_for_admins">Login for Admin</string>
|
|
30
31
|
<string name="sf__login_with_biometric">Log In with Biometric</string>
|
|
31
32
|
<string name="sf__setup_biometric_unlock">Setup Biometric Unlock</string>
|
|
32
33
|
<string name="sf__back_button_content_description">Back</string>
|
|
@@ -26,6 +26,8 @@
|
|
|
26
26
|
*/
|
|
27
27
|
package com.salesforce.androidsdk.accounts;
|
|
28
28
|
|
|
29
|
+
import android.accounts.Account;
|
|
30
|
+
import android.accounts.AccountManager;
|
|
29
31
|
import android.app.DownloadManager;
|
|
30
32
|
import android.content.Context;
|
|
31
33
|
import android.content.pm.PackageManager;
|
|
@@ -372,6 +374,46 @@ public class UserAccount {
|
|
|
372
374
|
* @return Refresh token.
|
|
373
375
|
*/
|
|
374
376
|
public String getRefreshToken() {
|
|
377
|
+
if (accountName != null) {
|
|
378
|
+
try {
|
|
379
|
+
final AccountManager accMrg = AccountManager.get(SalesforceSDKManager.getInstance().getAppContext());
|
|
380
|
+
final String accountType = SalesforceSDKManager.getInstance().getAccountType();
|
|
381
|
+
for (Account account : accMrg.getAccountsByType(accountType)) {
|
|
382
|
+
if (accountName.equals(account.name)) {
|
|
383
|
+
final String encryptedPassword = accMrg.getPassword(account);
|
|
384
|
+
if (encryptedPassword != null) {
|
|
385
|
+
final String newestRefreshToken = SalesforceSDKManager.decrypt(
|
|
386
|
+
encryptedPassword, SalesforceSDKManager.getEncryptionKey());
|
|
387
|
+
if (newestRefreshToken != null) {
|
|
388
|
+
return newestRefreshToken;
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
break;
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
} catch (Exception e) {
|
|
395
|
+
SalesforceSDKLogger.w(TAG,
|
|
396
|
+
"Failed to read latest refresh token from AccountManager; using in-memory value",
|
|
397
|
+
e);
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
return refreshToken;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
/**
|
|
404
|
+
* Returns the in-memory refresh token snapshot, without consulting
|
|
405
|
+
* {@link AccountManager}.
|
|
406
|
+
*
|
|
407
|
+
* Intended for persistence call sites that are about to write a refresh
|
|
408
|
+
* token to storage (account creation, update, token migration, duplicate
|
|
409
|
+
* user reconciliation). Using {@link #getRefreshToken()} at those sites
|
|
410
|
+
* would read back the value currently persisted in {@link AccountManager}
|
|
411
|
+
* — i.e. the value we are about to overwrite — instead of the value the
|
|
412
|
+
* caller built this {@code UserAccount} with.
|
|
413
|
+
*
|
|
414
|
+
* @return The refresh token field as set at construction time.
|
|
415
|
+
*/
|
|
416
|
+
public String getRefreshTokenForPersistence() {
|
|
375
417
|
return refreshToken;
|
|
376
418
|
}
|
|
377
419
|
|
|
@@ -948,7 +990,7 @@ public class UserAccount {
|
|
|
948
990
|
JSONObject object = new JSONObject();
|
|
949
991
|
try {
|
|
950
992
|
object.put(AUTH_TOKEN, authToken);
|
|
951
|
-
object.put(REFRESH_TOKEN,
|
|
993
|
+
object.put(REFRESH_TOKEN, getRefreshToken());
|
|
952
994
|
object.put(LOGIN_SERVER, loginServer);
|
|
953
995
|
object.put(ID_URL, idUrl);
|
|
954
996
|
object.put(INSTANCE_SERVER, instanceServer);
|
|
@@ -1007,7 +1049,7 @@ public class UserAccount {
|
|
|
1007
1049
|
Bundle toBundle(List<String> additionalOauthKeys) {
|
|
1008
1050
|
Bundle object = new Bundle();
|
|
1009
1051
|
object.putString(AUTH_TOKEN, authToken);
|
|
1010
|
-
object.putString(REFRESH_TOKEN,
|
|
1052
|
+
object.putString(REFRESH_TOKEN, getRefreshToken());
|
|
1011
1053
|
object.putString(LOGIN_SERVER, loginServer);
|
|
1012
1054
|
object.putString(ID_URL, idUrl);
|
|
1013
1055
|
object.putString(INSTANCE_SERVER, instanceServer);
|
|
@@ -442,7 +442,7 @@ public class UserAccountManager {
|
|
|
442
442
|
final Bundle extras = buildAuthBundle(userAccount);
|
|
443
443
|
|
|
444
444
|
Account acc = new Account(userAccount.getAccountName(), accountType);
|
|
445
|
-
String password = SalesforceSDKManager.encrypt(userAccount.
|
|
445
|
+
String password = SalesforceSDKManager.encrypt(userAccount.getRefreshTokenForPersistence(), encryptionKey);
|
|
446
446
|
boolean success = accountManager.addAccountExplicitly(acc, password, new Bundle());
|
|
447
447
|
|
|
448
448
|
// Add account will fail if the account already exists, so update refresh token.
|
|
@@ -488,6 +488,16 @@ public class UserAccountManager {
|
|
|
488
488
|
accountManager.setUserData(account, key, extras.getString(key));
|
|
489
489
|
}
|
|
490
490
|
|
|
491
|
+
// The refresh token is stored as the Account's password (see createAccount), not as user data,
|
|
492
|
+
// so buildAuthBundle does not include it. Persist it explicitly here so that server-side
|
|
493
|
+
// Use the in-memory snapshot rather than getRefreshToken(), which now performs a live lookup
|
|
494
|
+
// against AccountManager and would return the updated value we may be about to write.
|
|
495
|
+
final String refreshToken = userAccount.getRefreshTokenForPersistence();
|
|
496
|
+
if (refreshToken != null) {
|
|
497
|
+
final String encryptionKey = SalesforceSDKManager.getEncryptionKey();
|
|
498
|
+
accountManager.setPassword(account, SalesforceSDKManager.encrypt(refreshToken, encryptionKey));
|
|
499
|
+
}
|
|
500
|
+
|
|
491
501
|
return extras;
|
|
492
502
|
}
|
|
493
503
|
|
|
@@ -1599,7 +1599,7 @@ open class SalesforceSDKManager protected constructor(
|
|
|
1599
1599
|
protected var INSTANCE: SalesforceSDKManager? = null
|
|
1600
1600
|
|
|
1601
1601
|
/** The current version of this SDK */
|
|
1602
|
-
const val SDK_VERSION = "13.2.
|
|
1602
|
+
const val SDK_VERSION = "13.2.1"
|
|
1603
1603
|
|
|
1604
1604
|
/**
|
|
1605
1605
|
* An intent action meant for instances of Salesforce SDK manager
|
|
@@ -465,8 +465,13 @@ internal fun handleDuplicateUserAccount(
|
|
|
465
465
|
clearCaches()
|
|
466
466
|
userAccountManager.clearCachedCurrentUser()
|
|
467
467
|
|
|
468
|
-
// Revoke existing refresh token
|
|
469
|
-
|
|
468
|
+
// Revoke existing refresh token. Compare the new account's in-memory
|
|
469
|
+
// snapshot (the value just issued by the server) against the duplicate
|
|
470
|
+
// account's snapshot (the value currently persisted). Using
|
|
471
|
+
// getRefreshToken() here would do a live AccountManager lookup for
|
|
472
|
+
// both UserAccounts and return the same persisted value, suppressing
|
|
473
|
+
// the revocation and leaking the prior refresh token.
|
|
474
|
+
if (account.refreshTokenForPersistence != duplicateUserAccount.refreshTokenForPersistence) {
|
|
470
475
|
runCatching {
|
|
471
476
|
URI(duplicateUserAccount.instanceServer)
|
|
472
477
|
}.onFailure { throwable ->
|
|
@@ -481,7 +486,7 @@ internal fun handleDuplicateUserAccount(
|
|
|
481
486
|
revokeRefreshToken(
|
|
482
487
|
HttpAccess.DEFAULT,
|
|
483
488
|
uri,
|
|
484
|
-
duplicateUserAccount.
|
|
489
|
+
duplicateUserAccount.refreshTokenForPersistence,
|
|
485
490
|
OAuth2.LogoutReason.REFRESH_TOKEN_ROTATED,
|
|
486
491
|
)
|
|
487
492
|
}
|
|
@@ -515,7 +520,8 @@ private fun UserAccountManager.persistAccount(
|
|
|
515
520
|
acctManager: AccountManager = AccountManager.get(SalesforceSDKManager.getInstance().appContext),
|
|
516
521
|
) {
|
|
517
522
|
val account = Account(userAccount.accountName, accountType)
|
|
518
|
-
|
|
523
|
+
// Encrypt the in-memory snapshot rather than getRefreshToken(), which performs a lookup.
|
|
524
|
+
val password = SalesforceSDKManager.encrypt(userAccount.refreshTokenForPersistence, encryptionKey)
|
|
519
525
|
val created = acctManager.addAccountExplicitly(account, password, /* userdata = */ Bundle())
|
|
520
526
|
|
|
521
527
|
// addAccountExplicitly fails if the account already exists, so update the refresh token.
|
|
@@ -28,7 +28,6 @@ package com.salesforce.androidsdk.auth;
|
|
|
28
28
|
|
|
29
29
|
import android.net.Uri;
|
|
30
30
|
import android.text.TextUtils;
|
|
31
|
-
import android.util.Log;
|
|
32
31
|
|
|
33
32
|
import androidx.annotation.NonNull;
|
|
34
33
|
import androidx.annotation.VisibleForTesting;
|
|
@@ -911,7 +910,7 @@ public class OAuth2 {
|
|
|
911
910
|
public TokenEndpointResponse(Response response, List<String> additionalOauthKeys) {
|
|
912
911
|
try {
|
|
913
912
|
final JSONObject parsedResponse = (new RestResponse(response)).asJSONObject();
|
|
914
|
-
|
|
913
|
+
SalesforceSDKLogger.d(TAG, "parsedResponse-->" + parsedResponse);
|
|
915
914
|
authToken = parsedResponse.getString(ACCESS_TOKEN);
|
|
916
915
|
instanceUrl = parsedResponse.getString(INSTANCE_URL);
|
|
917
916
|
if (parsedResponse.has(API_INSTANCE_URL)) {
|
|
@@ -354,7 +354,8 @@ public class ClientManager {
|
|
|
354
354
|
private final Object lock = new Object();
|
|
355
355
|
private final ClientManager clientManager;
|
|
356
356
|
private String lastNewAuthToken;
|
|
357
|
-
|
|
357
|
+
// Mutable to support server-side Refresh Token Rotation (RTR).
|
|
358
|
+
private String refreshToken;
|
|
358
359
|
private String lastNewInstanceUrl;
|
|
359
360
|
private long lastRefreshTime = -1 /* never refreshed */;
|
|
360
361
|
|
|
@@ -506,6 +507,12 @@ public class ClientManager {
|
|
|
506
507
|
updatedUserAccount.downloadProfilePhoto();
|
|
507
508
|
UserAccountManager.getInstance().clearCachedCurrentUser();
|
|
508
509
|
|
|
510
|
+
// Handle server-side Refresh Token Rotation: if the response contained a new refresh token,
|
|
511
|
+
// update this provider's cached copy.
|
|
512
|
+
if (tr.refreshToken != null && !tr.refreshToken.equals(refreshToken)) {
|
|
513
|
+
refreshToken = tr.refreshToken;
|
|
514
|
+
}
|
|
515
|
+
|
|
509
516
|
return updatedUserAccount;
|
|
510
517
|
} catch (OAuth2.OAuthFailedException ofe) {
|
|
511
518
|
if (ofe.isRefreshTokenInvalid()) {
|
|
@@ -108,7 +108,6 @@ import androidx.fragment.app.FragmentActivity
|
|
|
108
108
|
import androidx.lifecycle.Observer
|
|
109
109
|
import com.salesforce.androidsdk.R.color.sf__background
|
|
110
110
|
import com.salesforce.androidsdk.R.color.sf__background_dark
|
|
111
|
-
import com.salesforce.androidsdk.R.color.sf__primary_color
|
|
112
111
|
import com.salesforce.androidsdk.R.drawable.sf__action_back
|
|
113
112
|
import com.salesforce.androidsdk.R.string.cannot_use_another_apps_login_qr_code
|
|
114
113
|
import com.salesforce.androidsdk.R.string.sf__biometric_opt_in_title
|
|
@@ -175,9 +174,27 @@ import java.security.cert.X509Certificate
|
|
|
175
174
|
*/
|
|
176
175
|
open class LoginActivity : FragmentActivity() {
|
|
177
176
|
|
|
178
|
-
/**
|
|
177
|
+
/**
|
|
178
|
+
* The activity result launcher used when browser-based authentication loads
|
|
179
|
+
* the OAuth authorization URL in the external browser custom tab activity
|
|
180
|
+
* */
|
|
181
|
+
@VisibleForTesting
|
|
182
|
+
internal val customTabLauncher = registerForActivityResult(
|
|
183
|
+
/* contract = */ StartActivityForResult(),
|
|
184
|
+
/* callback = */ CustomTabActivityResult(),
|
|
185
|
+
)
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* The activity result launcher used by the "Login for Admin" flow.
|
|
189
|
+
*
|
|
190
|
+
* Unlike [customTabLauncher], cancelling here leaves the existing WebView
|
|
191
|
+
* login page intact and does not reveal the server picker.
|
|
192
|
+
*/
|
|
179
193
|
@VisibleForTesting
|
|
180
|
-
internal val
|
|
194
|
+
internal val adminLoginCustomTabLauncher = registerForActivityResult(
|
|
195
|
+
/* contract = */ StartActivityForResult(),
|
|
196
|
+
/* callback = */ AdminCustomTabActivityResult(),
|
|
197
|
+
)
|
|
181
198
|
|
|
182
199
|
// View Model
|
|
183
200
|
@VisibleForTesting(otherwise = PROTECTED)
|
|
@@ -276,6 +293,13 @@ open class LoginActivity : FragmentActivity() {
|
|
|
276
293
|
certAuthOrLogin()
|
|
277
294
|
}
|
|
278
295
|
|
|
296
|
+
// Observe front door bridge URL to load in the WebView when present.
|
|
297
|
+
viewModel.frontDoorBridgeUrl.observe(this) { url ->
|
|
298
|
+
if (url != null) {
|
|
299
|
+
viewModel.loading.value = true
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
279
303
|
// Take control of the back logic if the device is locked.
|
|
280
304
|
// TODO: Remove SDK_INT check when min API > 33
|
|
281
305
|
if (SDK_INT >= TIRAMISU && biometricAuthenticationManager?.locked == true) {
|
|
@@ -283,9 +307,13 @@ open class LoginActivity : FragmentActivity() {
|
|
|
283
307
|
}
|
|
284
308
|
|
|
285
309
|
// Add view model observers.
|
|
286
|
-
viewModel.browserCustomTabUrl.observe(this, BrowserCustomTabUrlObserver())
|
|
287
310
|
viewModel.pendingServer.observe(this, PendingServerObserver())
|
|
288
311
|
|
|
312
|
+
// Set callback for when browser custom tab URL is ready to launch.
|
|
313
|
+
viewModel.onBrowserCustomTabReady = { url ->
|
|
314
|
+
loadLoginPageInCustomTab(url, customTabLauncher)
|
|
315
|
+
}
|
|
316
|
+
|
|
289
317
|
// Support magic links
|
|
290
318
|
if (viewModel.jwt != null) {
|
|
291
319
|
swapJWTForAccessToken()
|
|
@@ -559,7 +587,6 @@ open class LoginActivity : FragmentActivity() {
|
|
|
559
587
|
)
|
|
560
588
|
|
|
561
589
|
viewModel.clearCookies()
|
|
562
|
-
viewModel.resetFrontDoorBridgeUrl()
|
|
563
590
|
// Displays the error in a toast, clears cookies and reloads the login page
|
|
564
591
|
runOnUiThread {
|
|
565
592
|
makeText(this, "$error : $errorDesc", LENGTH_LONG).show()
|
|
@@ -751,7 +778,19 @@ open class LoginActivity : FragmentActivity() {
|
|
|
751
778
|
)
|
|
752
779
|
}
|
|
753
780
|
|
|
754
|
-
|
|
781
|
+
/**
|
|
782
|
+
* Launches the current login server in a Custom Tab. This allows Admins
|
|
783
|
+
* to authenticate with a Passkey or by other methods that require
|
|
784
|
+
* Advanced/Browser Authentication.
|
|
785
|
+
*/
|
|
786
|
+
@Deprecated(message = "This function will be replaced by a permanent solution in 14.0.")
|
|
787
|
+
fun launchLoginForAdminsAction() {
|
|
788
|
+
val loginUrl = viewModel.browserCustomTabUrl.value ?: return
|
|
789
|
+
loadLoginPageInCustomTab(loginUrl, adminLoginCustomTabLauncher)
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
@VisibleForTesting
|
|
793
|
+
internal fun loadLoginPageInCustomTab(loginUrl: String, customTabLauncher: ActivityResultLauncher<Intent>) {
|
|
755
794
|
val customTabsIntent = CustomTabsIntent.Builder().apply {
|
|
756
795
|
/*
|
|
757
796
|
* Set a custom animation to slide in and out for Chrome custom tab
|
|
@@ -763,8 +802,11 @@ open class LoginActivity : FragmentActivity() {
|
|
|
763
802
|
// Replace the default 'Close Tab' button with a custom back arrow instead of 'x'
|
|
764
803
|
setCloseButtonIcon(decodeResource(resources, sf__action_back))
|
|
765
804
|
setShareState(CustomTabsIntent.SHARE_STATE_OFF)
|
|
805
|
+
|
|
806
|
+
// Use app provided color if set. Fallback to dynamic color.
|
|
807
|
+
val background: Color = viewModel.topBarColor ?: viewModel.dynamicBackgroundColor.value
|
|
766
808
|
setDefaultColorSchemeParams(
|
|
767
|
-
CustomTabColorSchemeParams.Builder().setToolbarColor(
|
|
809
|
+
CustomTabColorSchemeParams.Builder().setToolbarColor(background.toArgb()).build()
|
|
768
810
|
)
|
|
769
811
|
}.build()
|
|
770
812
|
|
|
@@ -874,7 +916,7 @@ open class LoginActivity : FragmentActivity() {
|
|
|
874
916
|
|
|
875
917
|
// Choose front door bridge use by verifying intent data and such that only front door bridge URLs with matching consumer keys are used.
|
|
876
918
|
val uiBridgeApiParametersFrontDoorBridgeUrlMismatchedConsumerKey = uiBridgeApiParametersConsumerKey != null && uiBridgeApiParametersConsumerKey != viewModel.bootConfig.remoteAccessConsumerKey
|
|
877
|
-
|
|
919
|
+
val shouldUseFrontDoorBridge = (isFrontdoorBridgeUrlIntent(intent) || isQrCodeLoginUrlIntent(intent)) && !uiBridgeApiParametersFrontDoorBridgeUrlMismatchedConsumerKey
|
|
878
920
|
|
|
879
921
|
// Alert the user if the front door bridge URL is not for this app and was discarded.
|
|
880
922
|
if (uiBridgeApiParametersFrontDoorBridgeUrlMismatchedConsumerKey) {
|
|
@@ -888,7 +930,7 @@ open class LoginActivity : FragmentActivity() {
|
|
|
888
930
|
}
|
|
889
931
|
|
|
890
932
|
// Use the front door URL as the login page if applicable.
|
|
891
|
-
if (
|
|
933
|
+
if (shouldUseFrontDoorBridge && uiBridgeApiParameters?.frontdoorBridgeUrl != null) {
|
|
892
934
|
loginWithFrontdoorBridgeUrl(
|
|
893
935
|
uiBridgeApiParameters.frontdoorBridgeUrl,
|
|
894
936
|
uiBridgeApiParameters.pkceCodeVerifier
|
|
@@ -1079,35 +1121,6 @@ open class LoginActivity : FragmentActivity() {
|
|
|
1079
1121
|
applyUiBridgeApiFrontDoorUrl(intent)
|
|
1080
1122
|
}
|
|
1081
1123
|
|
|
1082
|
-
/**
|
|
1083
|
-
* Starts a browser custom tab for the OAuth authorization URL according to
|
|
1084
|
-
* the authentication configuration. The activity only takes action when
|
|
1085
|
-
* browser-based authentication requires a browser custom tab to be started.
|
|
1086
|
-
* UI front-door bridge use bypasses the need for browser custom tab.
|
|
1087
|
-
* @param authorizationUrl The selected login server's OAuth authorization
|
|
1088
|
-
* URL
|
|
1089
|
-
* @param activityResultLauncher The activity result launcher to use when
|
|
1090
|
-
* browser-based authentication requires a browser custom tab
|
|
1091
|
-
* @param isBrowserLoginEnabled Indicates if browser-based authentication is
|
|
1092
|
-
* enabled
|
|
1093
|
-
* @param isUsingFrontDoorBridge Indicates if a UI bridge API front door
|
|
1094
|
-
* bridge URL is in use
|
|
1095
|
-
* @param singleServerCustomTabActivity Indicates single server custom
|
|
1096
|
-
* browser tab authentication is active
|
|
1097
|
-
*/
|
|
1098
|
-
@VisibleForTesting
|
|
1099
|
-
internal open fun startBrowserCustomTabAuthorization(
|
|
1100
|
-
authorizationUrl: String,
|
|
1101
|
-
activityResultLauncher: ActivityResultLauncher<Intent>,
|
|
1102
|
-
isBrowserLoginEnabled: Boolean = SalesforceSDKManager.getInstance().isBrowserLoginEnabled,
|
|
1103
|
-
isUsingFrontDoorBridge: Boolean = viewModel.isUsingFrontDoorBridge,
|
|
1104
|
-
singleServerCustomTabActivity: Boolean = viewModel.singleServerCustomTabActivity,
|
|
1105
|
-
) {
|
|
1106
|
-
if ((singleServerCustomTabActivity.or(isBrowserLoginEnabled)).and(!isUsingFrontDoorBridge)) {
|
|
1107
|
-
loadLoginPageInCustomTab(authorizationUrl, activityResultLauncher)
|
|
1108
|
-
}
|
|
1109
|
-
}
|
|
1110
|
-
|
|
1111
1124
|
/**
|
|
1112
1125
|
* A web view client which intercepts the redirect to the OAuth callback URL. That redirect marks the end of
|
|
1113
1126
|
* the user facing portion of the authentication flow.
|
|
@@ -1591,32 +1604,19 @@ open class LoginActivity : FragmentActivity() {
|
|
|
1591
1604
|
}
|
|
1592
1605
|
}
|
|
1593
1606
|
|
|
1594
|
-
// endregion
|
|
1595
|
-
// region Observer Classes
|
|
1596
|
-
|
|
1597
1607
|
/**
|
|
1598
|
-
*
|
|
1599
|
-
* flow by loading the login URL in a web browser custom tab when browser-
|
|
1600
|
-
* based authentication is required.
|
|
1601
|
-
* @param activity The login activity. This parameter is intended for
|
|
1602
|
-
* testing purposes only. Defaults to this inner class receiver
|
|
1608
|
+
* Activity result callback for the "Login for Admin" custom tab.
|
|
1603
1609
|
*/
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
if (value == "about:blank") {
|
|
1609
|
-
return
|
|
1610
|
-
}
|
|
1611
|
-
|
|
1612
|
-
activity.startBrowserCustomTabAuthorization(
|
|
1613
|
-
authorizationUrl = value,
|
|
1614
|
-
activityResultLauncher = activity.customTabLauncher,
|
|
1615
|
-
isBrowserLoginEnabled = SalesforceSDKManager.getInstance().isBrowserLoginEnabled,
|
|
1616
|
-
)
|
|
1610
|
+
@VisibleForTesting
|
|
1611
|
+
internal inner class AdminCustomTabActivityResult : ActivityResultCallback<ActivityResult> {
|
|
1612
|
+
override fun onActivityResult(result: ActivityResult) {
|
|
1613
|
+
// Intentional no-op: keep the existing WebView visible on cancel.
|
|
1617
1614
|
}
|
|
1618
1615
|
}
|
|
1619
1616
|
|
|
1617
|
+
// endregion
|
|
1618
|
+
// region Observer Classes
|
|
1619
|
+
|
|
1620
1620
|
/**
|
|
1621
1621
|
* An observer for pending login server that continues the authentication
|
|
1622
1622
|
* flow by determining the switch between default login and Salesforce
|