Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace /authorized call with /retrieve for auth sessions #10259

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import com.stripe.android.financialconnections.browser.BrowserManager
import com.stripe.android.financialconnections.di.APPLICATION_ID
import com.stripe.android.financialconnections.di.FinancialConnectionsSheetNativeComponent
import com.stripe.android.financialconnections.domain.CancelAuthorizationSession
import com.stripe.android.financialconnections.domain.CompleteAuthorizationSession
import com.stripe.android.financialconnections.domain.GetOrFetchSync
import com.stripe.android.financialconnections.domain.GetOrFetchSync.RefetchCondition.IfMissingActiveAuthSession
import com.stripe.android.financialconnections.domain.HandleError
Expand All @@ -52,7 +51,6 @@ import com.stripe.android.financialconnections.model.FinancialConnectionsSession
import com.stripe.android.financialconnections.model.FinancialConnectionsSessionManifest.Pane
import com.stripe.android.financialconnections.model.SynchronizeSessionResponse
import com.stripe.android.financialconnections.navigation.Destination
import com.stripe.android.financialconnections.navigation.Destination.AccountPicker
import com.stripe.android.financialconnections.navigation.NavigationManager
import com.stripe.android.financialconnections.navigation.PopUpToBehavior
import com.stripe.android.financialconnections.navigation.destination
Expand All @@ -75,7 +73,6 @@ import javax.inject.Named
import com.stripe.android.financialconnections.features.partnerauth.SharedPartnerAuthState.AuthenticationStatus as Status

internal class PartnerAuthViewModel @AssistedInject constructor(
private val completeAuthorizationSession: CompleteAuthorizationSession,
private val createAuthorizationSession: PostAuthorizationSession,
private val cancelAuthorizationSession: CancelAuthorizationSession,
private val retrieveAuthorizationSession: RetrieveAuthorizationSession,
Expand Down Expand Up @@ -427,23 +424,15 @@ internal class PartnerAuthViewModel @AssistedInject constructor(
status = "success"
)
)

requireNotNull(authSession)
postAuthSessionEvent(authSession.id, AuthSessionEvent.Success(Date()))
val nextPane = if (authSession.isOAuth) {
logger.debug("Web AuthFlow completed! waiting for oauth results")
val oAuthResults = pollAuthorizationSessionOAuthResults(authSession)
logger.debug("OAuth results received! completing session")
val updatedSession = completeAuthorizationSession(
authorizationSessionId = authSession.id,
publicToken = oAuthResults.publicToken
)
logger.debug("Session authorized!")
updatedSession.nextPane.destination(referrer = pane)
val isNetworkingRelink = pendingRepairRepository.get() != null

if (isNetworkingRelink) {
handleCompletionForNetworkingRelinkSession(authSession)
} else {
AccountPicker(referrer = pane)
handleCompletionForAuthSession(authSession)
}
FinancialConnections.emitEvent(Name.INSTITUTION_AUTHORIZED)
navigationManager.tryNavigateTo(nextPane)
}.onFailure {
eventTracker.logError(
extraMessage = "failed authorizing session",
Expand All @@ -455,6 +444,32 @@ internal class PartnerAuthViewModel @AssistedInject constructor(
}
}

private fun handleCompletionForNetworkingRelinkSession(
authSession: FinancialConnectionsAuthorizationSession,
) {
val nextPane = authSession.nextPane.destination(referrer = pane)
navigationManager.tryNavigateTo(nextPane)
}

private suspend fun handleCompletionForAuthSession(
authSession: FinancialConnectionsAuthorizationSession,
) {
if (authSession.isOAuth) {
logger.debug("Web AuthFlow completed! waiting for oauth results")
pollAuthorizationSessionOAuthResults(authSession)
logger.debug("OAuth results received! completing session")
}

val updatedSession = retrieveAuthorizationSession(
authorizationSessionId = authSession.id,
)
logger.debug("Session updated!")

FinancialConnections.emitEvent(Name.INSTITUTION_AUTHORIZED)
val nextPane = updatedSession.nextPane.destination(referrer = pane)
navigationManager.tryNavigateTo(nextPane)
}

// if clicked uri contains an eventName query param, track click event.
fun onClickableTextClick(uri: String) = viewModelScope.launch {
uriUtils.getQueryParameter(uri, "eventName")?.let { eventName ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,6 @@ internal interface FinancialConnectionsManifestRepository {
authSessionEvents: List<AuthSessionEvent>
): FinancialConnectionsAuthorizationSession

@Throws(
AuthenticationException::class,
InvalidRequestException::class,
APIConnectionException::class,
APIException::class
)
suspend fun completeAuthorizationSession(
clientSecret: String,
sessionId: String,
publicToken: String? = null
): FinancialConnectionsAuthorizationSession

@Throws(
AuthenticationException::class,
InvalidRequestException::class,
Expand Down Expand Up @@ -382,28 +370,6 @@ private class FinancialConnectionsManifestRepositoryImpl(
}
}

override suspend fun completeAuthorizationSession(
clientSecret: String,
sessionId: String,
publicToken: String?
): FinancialConnectionsAuthorizationSession {
val request = apiRequestFactory.createPost(
url = FinancialConnectionsRepositoryImpl.authorizeSessionUrl,
options = provideApiRequestOptions(useConsumerPublishableKey = true),
params = mapOf(
NetworkConstants.PARAMS_ID to sessionId,
NetworkConstants.PARAMS_CLIENT_SECRET to clientSecret,
"public_token" to publicToken
).filter { it.value != null }
)
return requestExecutor.execute(
request,
FinancialConnectionsAuthorizationSession.serializer()
).also {
updateCachedActiveAuthSession("completeAuthorizationSession", it)
}
}

override suspend fun postMarkLinkingMoreAccounts(
clientSecret: String
): FinancialConnectionsSessionManifest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,6 @@ internal class FinancialConnectionsRepositoryImpl @Inject constructor(
private const val authorizationSessionOAuthResultsUrl: String =
"${ApiRequest.API_HOST}/v1/connections/auth_sessions/oauth_results"

internal const val authorizeSessionUrl: String =
"${ApiRequest.API_HOST}/v1/connections/auth_sessions/authorized"

private const val paymentMethodsUrl: String =
"${ApiRequest.API_HOST}/v1/payment_methods"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ class PartnerAuthViewModelTest {
pendingRepairRepository: CoreAuthorizationPendingNetworkingRepairRepository = mock(),
): PartnerAuthViewModel {
return PartnerAuthViewModel(
completeAuthorizationSession = mock(),
createAuthorizationSession = createAuthorizationSession,
cancelAuthorizationSession = mock(),
retrieveAuthorizationSession = mock(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import com.stripe.android.financialconnections.CoroutineTestRule
import com.stripe.android.financialconnections.TestFinancialConnectionsAnalyticsTracker
import com.stripe.android.financialconnections.analytics.AuthSessionEvent
import com.stripe.android.financialconnections.domain.CancelAuthorizationSession
import com.stripe.android.financialconnections.domain.CompleteAuthorizationSession
import com.stripe.android.financialconnections.domain.GetOrFetchSync
import com.stripe.android.financialconnections.domain.NativeAuthFlowCoordinator
import com.stripe.android.financialconnections.domain.PollAuthorizationSessionOAuthResults
Expand Down Expand Up @@ -55,7 +54,6 @@ internal class SupportabilityViewModelTest {
private val retrieveAuthorizationSession = mock<RetrieveAuthorizationSession>()
private val eventTracker = TestFinancialConnectionsAnalyticsTracker()
private val pollAuthorizationSessionOAuthResults = mock<PollAuthorizationSessionOAuthResults>()
private val completeAuthorizationSession = mock<CompleteAuthorizationSession>()
private val cancelAuthorizationSession = mock<CancelAuthorizationSession>()
private val navigationManager = TestNavigationManager()
private val createAuthorizationSession = mock<PostAuthorizationSession>()
Expand Down Expand Up @@ -133,16 +131,15 @@ internal class SupportabilityViewModelTest {
)
whenever(pollAuthorizationSessionOAuthResults(activeAuthSession))
.thenReturn(mixedOAuthParams)
whenever(completeAuthorizationSession(any(), any()))
whenever(retrieveAuthorizationSession(any()))
.thenReturn(activeAuthSession)

// When
viewModel.onWebAuthFlowFinished(WebAuthFlowState.Success("stripe://success"))

// Then
verify(completeAuthorizationSession).invoke(
verify(retrieveAuthorizationSession).invoke(
authorizationSessionId = eq(activeAuthSession.id),
publicToken = eq(mixedOAuthParams.publicToken)
)
}

Expand Down Expand Up @@ -304,7 +301,6 @@ internal class SupportabilityViewModelTest {
): PartnerAuthViewModel {
return PartnerAuthViewModel(
navigationManager = TestNavigationManager(),
completeAuthorizationSession = completeAuthorizationSession,
createAuthorizationSession = createAuthorizationSession,
cancelAuthorizationSession = cancelAuthorizationSession,
retrieveAuthorizationSession = retrieveAuthorizationSession,
Expand Down
Loading