Configuring Advanced Authentication in Android Apps
In Salesforce orgs
that use My Domain for advanced authentication, Mobile SDK requires a
small amount of configuration in the client app. Android apps that use certificate-based
authentication don’t require configuration within the Mobile SDK
app.
Android Implementation
For advanced authentication support in Android applications, Mobile SDK
uses a Chrome custom tab. If Chrome isn’t available at runtime, Mobile SDK
uses the default system browser. Browser-based authentication requires the
following.
- A browser must be installed on the device.
- If you use MDM, the browser must be installed in the work partition.
Optionally, you can configure which browser the application selects by using this
method.
1SalesforceSDKManager.getInstance().setCustomTabBrowser(browserPackage);To see the currently selected custom tab browser, use this
method.
1browserPackage = SalesforceSDKManager.getInstance().getCustomTabBrowser();Certificated-Based App Configuration
Certificate-based authentication relies on an MDM vendor. This vendor brokers identification services between Salesforce and the client mobile device. Certificate-based authentication doesn’t require configuration in Mobile SDK Android projects.
Browser-Based App Configuration
- In Android Studio, open your app’s AndroidManifest.xml file.
- In the LoginActivity declaration, uncomment
the following
lines:
1<activity android:name="com.salesforce.androidsdk.ui.LoginActivity" 2 android:theme="@style/SalesforceSDK.ActionBarTheme" 3 android:launchMode="singleInstance"> 4 5 <!-- 6 <intent-filter> 7 <data android:scheme="testsfdc" 8 android:host="*" 9 android:path="/mobilesdk/detect/oauth/done" /> 10 <action android:name="android.intent.action.VIEW" /> 11 <category android:name="android.intent.category.BROWSABLE" /> 12 <category android:name="android.intent.category.DEFAULT" /> 13 </intent-filter> 14 --> 15</activity> -
Replace the values for android:scheme, android:host, and android:path with their corresponding values from your connected app. Here's a couple of examples.
If the callback URL of your connected app is testsfdc:///mobilesdk/detect/oauth/done:
- android:scheme is testsfdc.
- android:host is *, meaning that it doesn't exist.
- android:path is /mobilesdk/detect/oauth/done.
- android:scheme is sfdc.
- android:host is login.salesforce.com.
- android:path is /oauth/done.
Here’s the updated portion of your AndroidManifest.xml, using
the testsfdc:///mobilesdk/detect/oauth/done
scheme.
1<!-- Login activity -->
2 <!--
3 Launch mode of "singleInstance" ensures that the activity isn't restarted
4 by a callback from Chrome custom tab when auth flow is complete. This is
5 required for the Chrome custom tab auth flow to work correctly.
6 -->
7
8 <!--
9 To enable browser bath authentication, uncomment the lines below and replace
10 'scheme', 'host' and 'path' with their corresponding values from your connected app.
11
12 For example, if the callback URL of your connected app is
13 "testsfdc:///mobilesdk/detect/oauth/done",
14 'scheme' would be "testsfdc", 'host' would be "*" since it doesn't exist, and
15 'path' would be "/mobilesdk/detect/oauth/done".
16
17 If the callback URL is "sfdc://login.salesforce.com/oauth/done",
18 'scheme' would be "sfdc", 'host' would be "login.salesforce.com",
19 and 'path' would be "/oauth/done".
20 -->
21<activity android:name="com.salesforce.androidsdk.ui.LoginActivity"
22 android:theme="@style/SalesforceSDK.ActionBarTheme"
23 android:launchMode="singleInstance">
24 <intent-filter>
25 <data android:scheme="testsfdc"
26 android:host="*"
27 android:path="/mobilesdk/detect/oauth/done" />
28 <action android:name="android.intent.action.VIEW" />
29 <category android:name="android.intent.category.BROWSABLE" />
30 <category android:name="android.intent.category.DEFAULT" />
31 </intent-filter>
32</activity>You're all set!
See Also
- Customize Your My Domain Login Page with Your Brand in Salesforce Help.
- “Mobile Device Management (MDM)” in Salesforce Mobile App Security Guide.
- For information on configuring iOS URL schemes, see “Inter-App Communication” or “Custom URL Schemes” in the App Programming Guide for iOS at developer.apple.com/documentation/..