Skip to content

Commit d2de1e7

Browse files
@W-16814802: [iOS] Add Deep Link From External QR Code Reader To iOS Native Swift Template QR Code Login (Parity For Android) (#2628)
1 parent c998f71 commit d2de1e7

4 files changed

Lines changed: 60 additions & 43 deletions

File tree

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

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -215,18 +215,6 @@ open class SalesforceSDKManager protected constructor(
215215
*/
216216
val loginActivityClass: Class<out Activity> = nativeLoginActivity ?: webviewLoginActivityClass
217217

218-
/**
219-
* For Salesforce Identity API UI Bridge support, the overriding front door bridge URL to
220-
* use in place of the default initial login URL
221-
*/
222-
var frontDoorBridgeUrl: String? = null
223-
224-
/**
225-
* For Salesforce Identity API UI Bridge support, the overriding front door bridge URL's
226-
* optional web server flow code verifier
227-
*/
228-
var frontDoorBridgeCodeVerifier: String? = null
229-
230218
/** The class for the account switcher activity */
231219
var accountSwitcherActivityClass = AccountSwitcherActivity::class.java
232220

@@ -271,10 +259,6 @@ open class SalesforceSDKManager protected constructor(
271259
field = value
272260
}
273261

274-
/** Indicates if login via QR Code and UI bridge API is enabled */
275-
@set:Synchronized
276-
open var isQrCodeLoginEnabled = false
277-
278262
/** Indicates if logout is in progress */
279263
var isLoggingOut = false
280264
private set
@@ -963,9 +947,6 @@ open class SalesforceSDKManager protected constructor(
963947

964948
val accountToLogout = account ?: clientMgr.account
965949

966-
frontDoorBridgeUrl = null
967-
frontDoorBridgeCodeVerifier = null
968-
969950
isLoggingOut = true
970951
val mgr = AccountManager.get(appContext)
971952
var refreshToken: String? = null

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

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -146,16 +146,20 @@ open class LoginActivity : AppCompatActivity(), OAuthWebviewHelperEvents {
146146
val salesforceSDKManager = SalesforceSDKManager.getInstance()
147147

148148
/*
149-
* For Salesforce Identity API UI Bridge support, the overriding front door bridge URL to
150-
* use in place of the default initial login URL plus the optional web server flow code
151-
* verifier accompanying the front door bridge URL
149+
* For Salesforce Identity API UI Bridge support, the overriding
150+
* frontdoor bridge URL to use in place of the default initial login URL
151+
* plus the optional web server flow code verifier accompanying the
152+
* frontdoor bridge URL.
152153
*/
153-
val frontDoorBridgeUrl = salesforceSDKManager.frontDoorBridgeUrl
154-
val frontDoorBridgeCodeVerifier = salesforceSDKManager.frontDoorBridgeCodeVerifier
155-
val isUsingFrontDoorBridge = frontDoorBridgeUrl != null
156-
// Reset the the Salesforce SDK manager's UI bridge support.
157-
salesforceSDKManager.frontDoorBridgeUrl = null
158-
salesforceSDKManager.frontDoorBridgeCodeVerifier = null
154+
val isUsingFrontDoorBridge = isFrontdoorBridgeUrlIntent(intent) || isQrCodeLoginUrlIntent(intent)
155+
val uiBridgeApiParameters = if (isQrCodeLoginUrlIntent(intent)) {
156+
uiBridgeApiParametersFromQrCodeLoginUrl(intent.data?.toString())
157+
} else intent.getStringExtra(EXTRA_KEY_FRONTDOOR_BRIDGE_URL)?.let { frontdoorBridgeUrl ->
158+
UiBridgeApiParameters(
159+
frontdoorBridgeUrl,
160+
intent.getStringExtra(EXTRA_KEY_PKCE_CODE_VERIFIER)
161+
)
162+
}
159163

160164
accountAuthenticatorResponse = intent.getParcelableExtra<AccountAuthenticatorResponse?>(
161165
KEY_ACCOUNT_AUTHENTICATOR_RESPONSE
@@ -233,11 +237,10 @@ open class LoginActivity : AppCompatActivity(), OAuthWebviewHelperEvents {
233237
)
234238

235239
// Prompt user with the default login page or log in via other configurations such as using a Salesforce Identity API UI Bridge front door URL.
236-
@Suppress("KotlinConstantConditions") // Note: This is a cosmetic suppress until the Android Studio inspector can smart cast the front door bridge URL as the compiler does.
237240
when {
238-
isUsingFrontDoorBridge && frontDoorBridgeUrl != null -> loginWithFrontdoorBridgeUrl(
239-
frontDoorBridgeUrl,
240-
frontDoorBridgeCodeVerifier
241+
isUsingFrontDoorBridge && uiBridgeApiParameters?.frontdoorBridgeUrl != null -> loginWithFrontdoorBridgeUrl(
242+
uiBridgeApiParameters.frontdoorBridgeUrl,
243+
uiBridgeApiParameters.pkceCodeVerifier
241244
)
242245

243246
else -> certAuthOrLogin()
@@ -723,7 +726,7 @@ open class LoginActivity : AppCompatActivity(), OAuthWebviewHelperEvents {
723726
* [LoginActivity.loginWithFrontdoorBridgeUrl].
724727
*
725728
* @param qrCodeLoginUrl The QR code login URL
726-
* @return Boolean true if a log in attempt is possible using the provided QR code log in URL,
729+
* @return Boolean true if a log in attempt is possible using the provided QR code login URL,
727730
* false otherwise
728731
*/
729732
fun loginWithFrontdoorBridgeUrlFromQrCode(
@@ -799,15 +802,26 @@ open class LoginActivity : AppCompatActivity(), OAuthWebviewHelperEvents {
799802
var qrCodeLoginUrlJsonPkceCodeVerifierKey = "pkce_code_verifier"
800803

801804
/**
802-
* When QR code log in is enabled, determines if the provided intent has QR code login
803-
* parameters.
805+
* Determines if the provided intent has QR code login parameters.
804806
* @param intent The intent to determine QR code login enablement for
805-
* @return Boolean true if the intent has QR code login parameters or false otherwise
807+
* @return Boolean true if the intent has QR code login parameters or
808+
* false otherwise
806809
*/
807-
fun isQrCodeLoginIntent(
810+
fun isQrCodeLoginUrlIntent(
808811
intent: Intent
809-
) = SalesforceSDKManager.getInstance().isQrCodeLoginEnabled
810-
&& intent.data?.path?.contains(qrCodeLoginUrlPath) == true
812+
) = intent.data?.path?.contains(qrCodeLoginUrlPath) == true
813+
814+
/**
815+
* Determines if the provided intent has front door bridge URL
816+
* parameters.
817+
* @param intent The intent to determine front door bridge URL
818+
* enablement for
819+
* @return Boolean true if the intent has front door bridge URL
820+
* parameters or false otherwise
821+
*/
822+
private fun isFrontdoorBridgeUrlIntent(
823+
intent: Intent
824+
) = intent.hasExtra(EXTRA_KEY_FRONTDOOR_BRIDGE_URL)
811825

812826
/**
813827
* Parses Salesforce Identity API UI Bridge parameters from the provided login QR code login
@@ -839,6 +853,12 @@ open class LoginActivity : AppCompatActivity(), OAuthWebviewHelperEvents {
839853
// endregion
840854
// region QR Code Login Via Salesforce Identity API UI Bridge Private Implementation
841855

856+
/** Extras key for the Salesforce Identity API UI Bridge front door URL */
857+
const val EXTRA_KEY_FRONTDOOR_BRIDGE_URL = "frontdoor_bridge_url"
858+
859+
/** Extras key for the Salesforce Identity API UI PKCE code verifier */
860+
const val EXTRA_KEY_PKCE_CODE_VERIFIER = "pkce_code_verifier"
861+
842862
/**
843863
* For QR code login URLs, a regular expression to extract the Salesforce Identity API UI
844864
* Bridge parameter JSON string.

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ open class OAuthWebviewHelper : KeyChainAliasCallback {
330330
val instance = SalesforceSDKManager.getInstance()
331331

332332
// Reset state from previous log in attempt.
333-
// - Salesforce Identity UI Bridge API log in, such as QR code log in.
333+
// - Salesforce Identity UI Bridge API log in, such as QR code login.
334334
resetFrontDoorBridgeUrl()
335335

336336
e(TAG, "$error: $errorDesc", e)
@@ -527,7 +527,7 @@ open class OAuthWebviewHelper : KeyChainAliasCallback {
527527
): URI {
528528

529529
// Reset log in state,
530-
// - Salesforce Identity UI Bridge API log in, such as QR code log in.
530+
// - Salesforce Identity UI Bridge API log in, such as QR code login.
531531
resetFrontDoorBridgeUrl()
532532

533533
val loginOptions = loginOptions
@@ -754,7 +754,7 @@ open class OAuthWebviewHelper : KeyChainAliasCallback {
754754
CoroutineScope(IO).launch {
755755

756756
// Reset log in state,
757-
// - Salesforce Identity UI Bridge API log in, such as QR code log in.
757+
// - Salesforce Identity UI Bridge API log in, such as QR code login.
758758
resetFrontDoorBridgeUrl()
759759

760760
FinishAuthTask().execute(tr, nativeLogin)

libs/SalesforceSDK/src/com/salesforce/androidsdk/ui/SalesforceActivity.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,22 @@ public abstract class SalesforceActivity extends AppCompatActivity implements Sa
3838

3939
private final SalesforceActivityDelegate delegate;
4040

41+
/**
42+
* Determines if the Salesforce Mobile SDK (MSDK) REST Client is built when this activity
43+
* resumes. This defaults to true.
44+
* <p>
45+
* The default is beneficial so apps using this activity as their main activity will create the
46+
* MSDK networking client and start MSDK's default LoginActivity when no user is authenticated.
47+
* This provides a lower-code path to implementing an app which automatically authenticates a
48+
* user with Salesforce web login.
49+
* <p>
50+
* Whenever needed, an app may disable this feature. Disabling this feature gives the app
51+
* more control over when and which activities are presented to the user when this activity is
52+
* resumed. However, that does require the app start MSDK's LoginActivity when required and
53+
* with valid parameters for the app's authentication needs.
54+
*/
55+
protected boolean isBuildRestClientOnResumeEnabled = true;
56+
4157
public SalesforceActivity() {
4258
super();
4359
this.delegate = new SalesforceActivityDelegate(this);
@@ -52,7 +68,7 @@ protected void onCreate(Bundle savedInstanceState) {
5268
@Override
5369
public void onResume() {
5470
super.onResume();
55-
delegate.onResume(true);
71+
delegate.onResume(isBuildRestClientOnResumeEnabled);
5672
}
5773

5874
@Override

0 commit comments

Comments
 (0)