From 3c39a0788f4d4ea2f69cea6a99126d9ad1f18c52 Mon Sep 17 00:00:00 2001 From: Carlos Munoz Date: Sun, 22 Dec 2024 21:34:59 +0100 Subject: [PATCH] Passes app id. --- .../android/financialconnections/domain/LookupAccount.kt | 6 ++++-- .../model/FinancialConnectionsSessionManifest.kt | 3 +-- .../FinancialConnectionsSheetNativeViewModel.kt | 9 +++++++++ .../FinancialConnectionsConsumerSessionRepository.kt | 7 +++++-- .../com/stripe/android/repository/ConsumersApiService.kt | 8 +++++++- 5 files changed, 26 insertions(+), 7 deletions(-) diff --git a/financial-connections/src/main/java/com/stripe/android/financialconnections/domain/LookupAccount.kt b/financial-connections/src/main/java/com/stripe/android/financialconnections/domain/LookupAccount.kt index fa154bbeb65..2d4ab3c0e0b 100644 --- a/financial-connections/src/main/java/com/stripe/android/financialconnections/domain/LookupAccount.kt +++ b/financial-connections/src/main/java/com/stripe/android/financialconnections/domain/LookupAccount.kt @@ -1,5 +1,6 @@ package com.stripe.android.financialconnections.domain +import android.app.Application import com.stripe.android.financialconnections.FinancialConnectionsSheet import com.stripe.android.financialconnections.repository.FinancialConnectionsConsumerSessionRepository import com.stripe.android.model.ConsumerSessionLookup @@ -7,6 +8,7 @@ import com.stripe.attestation.IntegrityRequestManager import javax.inject.Inject internal class LookupAccount @Inject constructor( + private val application: Application, private val integrityRequestManager: IntegrityRequestManager, private val consumerSessionRepository: FinancialConnectionsConsumerSessionRepository, val configuration: FinancialConnectionsSheet.Configuration, @@ -17,11 +19,11 @@ internal class LookupAccount @Inject constructor( verifiedFlow: Boolean ): ConsumerSessionLookup { return if (verifiedFlow) { - val token = integrityRequestManager.requestToken() requireNotNull( consumerSessionRepository.mobileLookupConsumerSession( email = email.lowercase().trim(), - verificationToken = token.getOrThrow(), + verificationToken = integrityRequestManager.requestToken().getOrThrow(), + appId = application.packageName ) ) } else { diff --git a/financial-connections/src/main/java/com/stripe/android/financialconnections/model/FinancialConnectionsSessionManifest.kt b/financial-connections/src/main/java/com/stripe/android/financialconnections/model/FinancialConnectionsSessionManifest.kt index 87897989356..69c7bfedd5f 100644 --- a/financial-connections/src/main/java/com/stripe/android/financialconnections/model/FinancialConnectionsSessionManifest.kt +++ b/financial-connections/src/main/java/com/stripe/android/financialconnections/model/FinancialConnectionsSessionManifest.kt @@ -72,8 +72,7 @@ internal data class FinancialConnectionsSessionManifest( @SerialName(value = "institution_search_disabled") val institutionSearchDisabled: Boolean, - @SerialName(value = "app_verification_enabled") - val appVerificationEnabled: Boolean, + val appVerificationEnabled: Boolean = true, @SerialName(value = "livemode") val livemode: Boolean, diff --git a/financial-connections/src/main/java/com/stripe/android/financialconnections/presentation/FinancialConnectionsSheetNativeViewModel.kt b/financial-connections/src/main/java/com/stripe/android/financialconnections/presentation/FinancialConnectionsSheetNativeViewModel.kt index 09d5023a004..8b75b28ba8c 100644 --- a/financial-connections/src/main/java/com/stripe/android/financialconnections/presentation/FinancialConnectionsSheetNativeViewModel.kt +++ b/financial-connections/src/main/java/com/stripe/android/financialconnections/presentation/FinancialConnectionsSheetNativeViewModel.kt @@ -65,6 +65,7 @@ import com.stripe.android.financialconnections.ui.toLocalTheme import com.stripe.android.financialconnections.utils.UriUtils import com.stripe.android.financialconnections.utils.get import com.stripe.android.financialconnections.utils.updateWithNewEntry +import com.stripe.attestation.IntegrityRequestManager import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.StateFlow @@ -86,6 +87,7 @@ internal class FinancialConnectionsSheetNativeViewModel @Inject constructor( savedStateHandle: SavedStateHandle, private val nativeAuthFlowCoordinator: NativeAuthFlowCoordinator, private val uriUtils: UriUtils, + private val integrityRequestManager: IntegrityRequestManager, private val completeFinancialConnectionsSession: CompleteFinancialConnectionsSession, private val createInstantDebitsResult: CreateInstantDebitsResult, private val eventTracker: FinancialConnectionsAnalyticsTracker, @@ -124,6 +126,7 @@ internal class FinancialConnectionsSheetNativeViewModel @Inject constructor( init { savedStateHandle.registerSavedStateProvider() setState { copy(firstInit = false) } + prepareIntegrityRequestManager() viewModelScope.launch { nativeAuthFlowCoordinator().collect { message -> when (message) { @@ -147,6 +150,12 @@ internal class FinancialConnectionsSheetNativeViewModel @Inject constructor( } } + private fun prepareIntegrityRequestManager() { + viewModelScope.launch { + integrityRequestManager.prepare() + } + } + private fun SavedStateHandle.registerSavedStateProvider() { setSavedStateProvider(KEY_SAVED_STATE) { val state = stateFlow.value diff --git a/financial-connections/src/main/java/com/stripe/android/financialconnections/repository/FinancialConnectionsConsumerSessionRepository.kt b/financial-connections/src/main/java/com/stripe/android/financialconnections/repository/FinancialConnectionsConsumerSessionRepository.kt index 0737d20d8cb..9fb625db051 100644 --- a/financial-connections/src/main/java/com/stripe/android/financialconnections/repository/FinancialConnectionsConsumerSessionRepository.kt +++ b/financial-connections/src/main/java/com/stripe/android/financialconnections/repository/FinancialConnectionsConsumerSessionRepository.kt @@ -34,7 +34,8 @@ internal interface FinancialConnectionsConsumerSessionRepository { suspend fun mobileLookupConsumerSession( email: String, - verificationToken: String + verificationToken: String, + appId: String ): ConsumerSessionLookup suspend fun signUp( @@ -247,10 +248,12 @@ private class FinancialConnectionsConsumerSessionRepositoryImpl( override suspend fun mobileLookupConsumerSession( email: String, - verificationToken: String + verificationToken: String, + appId: String ): ConsumerSessionLookup = consumersApiService.mobileLookupConsumerSession( email = email, verificationToken = verificationToken, + appId = appId, requestSurface = requestSurface, requestOptions = provideApiRequestOptions(useConsumerPublishableKey = false), ).also { diff --git a/payments-model/src/main/java/com/stripe/android/repository/ConsumersApiService.kt b/payments-model/src/main/java/com/stripe/android/repository/ConsumersApiService.kt index deff09004b6..0fbe9b6caa2 100644 --- a/payments-model/src/main/java/com/stripe/android/repository/ConsumersApiService.kt +++ b/payments-model/src/main/java/com/stripe/android/repository/ConsumersApiService.kt @@ -26,6 +26,7 @@ import com.stripe.android.model.parsers.ConsumerSessionLookupJsonParser import com.stripe.android.model.parsers.ConsumerSessionSignupJsonParser import com.stripe.android.model.parsers.SharePaymentDetailsJsonParser import java.util.Locale +import java.util.UUID @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP_PREFIX) interface ConsumersApiService { @@ -54,6 +55,7 @@ interface ConsumersApiService { email: String, requestSurface: String, verificationToken: String, + appId: String, requestOptions: ApiRequest.Options ): ConsumerSessionLookup @@ -190,6 +192,7 @@ class ConsumersApiServiceImpl( email: String, requestSurface: String, verificationToken: String, + appId: String, requestOptions: ApiRequest.Options ): ConsumerSessionLookup { return executeRequestWithModelJsonParser( @@ -201,7 +204,10 @@ class ConsumersApiServiceImpl( mapOf( "request_surface" to requestSurface, "email_address" to email.lowercase(), - "verification_token" to verificationToken + "android_verification_token" to verificationToken, + "session_id" to "12345", // TODO (carlosmuvi): remove this when we have a real session id + "email_source" to "user_action", // TODO (carlosmuvi): remove this when we have a real app id + "app_id" to appId ) ), responseJsonParser = ConsumerSessionLookupJsonParser()