@@ -42,9 +42,9 @@ import com.salesforce.androidsdk.analytics.SalesforceAnalyticsManager
4242import com.salesforce.androidsdk.app.Features.FEATURE_BIOMETRIC_AUTH
4343import com.salesforce.androidsdk.app.Features.FEATURE_SCREEN_LOCK
4444import com.salesforce.androidsdk.app.SalesforceSDKManager
45- import com.salesforce.androidsdk.auth.OAuth2.IdServiceResponse
4645import com.salesforce.androidsdk.auth.OAuth2.TokenEndpointResponse
4746import com.salesforce.androidsdk.auth.OAuth2.addAuthorizationHeader
47+ import com.salesforce.androidsdk.auth.OAuth2.callIdentityService
4848import com.salesforce.androidsdk.auth.OAuth2.revokeRefreshToken
4949import com.salesforce.androidsdk.config.RuntimeConfig.getRuntimeConfig
5050import com.salesforce.androidsdk.push.PushMessaging.register
@@ -55,8 +55,10 @@ import com.salesforce.androidsdk.security.ScreenLockManager
5555import com.salesforce.androidsdk.util.SalesforceSDKLogger.e
5656import com.salesforce.androidsdk.util.SalesforceSDKLogger.w
5757import kotlinx.coroutines.CoroutineScope
58+ import kotlinx.coroutines.Dispatchers.Default
5859import kotlinx.coroutines.Dispatchers.IO
5960import kotlinx.coroutines.launch
61+ import kotlinx.coroutines.withContext
6062import okhttp3.HttpUrl
6163import okhttp3.Interceptor
6264import okhttp3.Request.Builder
@@ -83,7 +85,7 @@ private const val TAG = "AuthenticationUtilities"
8385 * * Creates an Account.
8486 * * Checks for any CA/ECA settings such as Screen Lock or Biometric Authentication.
8587 */
86- internal fun onAuthFlowComplete (
88+ internal suspend fun onAuthFlowComplete (
8789 tokenResponse : TokenEndpointResponse ,
8890 loginServer : String ,
8991 consumerKey : String ,
@@ -113,14 +115,17 @@ internal fun onAuthFlowComplete(
113115 return
114116 }
115117
116- var userIdentity: IdServiceResponse ? = null
117- runCatching {
118- userIdentity = OAuth2 .callIdentityService(
119- HttpAccess .DEFAULT ,
120- tokenResponse.idUrlWithInstance,
121- tokenResponse.authToken,
122- )
123- }
118+ val userIdentity = runCatching {
119+ withContext(Default ) {
120+ callIdentityService(
121+ HttpAccess .DEFAULT ,
122+ tokenResponse.idUrlWithInstance,
123+ tokenResponse.authToken,
124+ )
125+ }
126+ }.onFailure { throwable ->
127+ w(TAG , " Cannot fetch user identity due to an error." , throwable)
128+ }.getOrNull()
124129
125130 val mustBeManagedApp = userIdentity?.customPermissions?.optBoolean(MUST_BE_MANAGED_APP_PERM ) ? : false
126131 if (mustBeManagedApp && ! getRuntimeConfig(context).isManagedApp) {
@@ -231,21 +236,21 @@ internal fun onAuthFlowComplete(
231236 // Screen lock required by mobile policy
232237 if (userIdentity?.screenLockTimeout?.compareTo(0 ) == 1 ) {
233238 SalesforceSDKManager .getInstance().registerUsedAppFeature(FEATURE_SCREEN_LOCK )
234- val timeoutInMills = ( userIdentity? .screenLockTimeout ? : 0 ) * 1000 * 60
239+ val timeoutInMills = userIdentity.screenLockTimeout * 1000 * 60
235240 (SalesforceSDKManager .getInstance().screenLockManager as ScreenLockManager ? )?.storeMobilePolicy(
236241 account,
237- userIdentity? .screenLock ? : false ,
242+ userIdentity.screenLock,
238243 timeoutInMills
239244 )
240245 }
241246
242247 // Biometric authorization required by mobile policy
243248 if (userIdentity?.biometricAuth == true ) {
244249 SalesforceSDKManager .getInstance().registerUsedAppFeature(FEATURE_BIOMETRIC_AUTH )
245- val timeoutInMills = ( userIdentity? .biometricAuthTimeout ? : 0 ) * 60 * 1000
250+ val timeoutInMills = userIdentity.biometricAuthTimeout * 60 * 1000
246251 (SalesforceSDKManager .getInstance().biometricAuthenticationManager as BiometricAuthenticationManager ? )?.storeMobilePolicy(
247252 account,
248- userIdentity? .biometricAuth ? : false ,
253+ userIdentity.biometricAuth,
249254 timeoutInMills
250255 )
251256 }
@@ -307,7 +312,7 @@ private fun HttpUrl.isSalesforceUrl(): Boolean {
307312 // List from https://help.salesforce.com/s/articleView?language=en_US&id=sf.domain_name_url_formats.htm&type=5
308313 val salesforceHosts = listOf (" .salesforce.com" , " .force.com" , " .sfdcopens.com" , " .site.com" , " .lightning.com" ,
309314 " .salesforce-sites.com" , " .force-user-content.com" , " .salesforce-experience.com" , " .salesforce-scrt.com" )
310- return salesforceHosts.map { host.endsWith(it) }.any() { it }
315+ return salesforceHosts.map { host.endsWith(it) }.any { it }
311316}
312317
313318private fun addAccount (account : UserAccount ? ) {
0 commit comments