Skip to content

Commit

Permalink
fix(e2ei): force login to idp to update certificate (WPB-6877) (#2742)
Browse files Browse the repository at this point in the history
  • Loading branch information
mchenani committed Feb 27, 2024
1 parent fadfac3 commit 30b8039
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
31 changes: 17 additions & 14 deletions app/src/main/kotlin/com/wire/android/feature/e2ei/OAuthUseCase.kt
Expand Up @@ -69,22 +69,25 @@ class OAuthUseCase(

fun launch(
activityResultRegistry: ActivityResultRegistry,
resultHandler: (OAuthResult) -> Unit
forceLoginFlow: Boolean,
resultHandler: (OAuthResult) -> Unit,
) {
authState.performActionWithFreshTokens(authorizationService) { _, idToken, exception ->
if (exception != null) {
appLogger.e(
message = "OAuthTokenRefreshManager: Error refreshing tokens, continue with login!",
throwable = exception
)
launchLoginFlow(activityResultRegistry, resultHandler)
} else {
resultHandler(
OAuthResult.Success(
idToken.toString(),
authState.jsonSerializeString()
if (forceLoginFlow) {
launchLoginFlow(activityResultRegistry, resultHandler)
} else {
authState.performActionWithFreshTokens(authorizationService) { _, idToken, exception ->
if (exception != null) {
appLogger.e(
message = "OAuthTokenRefreshManager: Error refreshing tokens, continue with login!", throwable = exception
)
)
launchLoginFlow(activityResultRegistry, resultHandler)
} else {
resultHandler(
OAuthResult.Success(
idToken.toString(), authState.jsonSerializeString()
)
)
}
}
}
}
Expand Down
Expand Up @@ -43,7 +43,7 @@ fun GetE2EICertificateUI(
LaunchedEffect(Unit) {
viewModel.requestOAuthFlow.onEach {
OAuthUseCase(context, it.target, it.oAuthClaims, it.oAuthState).launch(
context.getActivity()!!.activityResultRegistry
context.getActivity()!!.activityResultRegistry, forceLoginFlow = true
) { result -> viewModel.handleOAuthResult(result, it) }
}.launchIn(coroutineScope)
}
Expand Down

0 comments on commit 30b8039

Please sign in to comment.