Handle null or blank auth urls for Duo 2FA (#1044)

This commit is contained in:
Caleb Derosier
2024-02-21 11:00:38 -07:00
committed by Álison Fernandes
parent 8eafb8e180
commit 2e2b80470c
4 changed files with 47 additions and 8 deletions

View File

@@ -32,14 +32,13 @@ val GetTokenResponseJson.TwoFactorRequired?.preferredAuthMethod: TwoFactorAuthMe
/**
* If it exists, return the value of the Duo auth url.
*/
val GetTokenResponseJson.TwoFactorRequired?.twoFactorDuoAuthUrl: String
val GetTokenResponseJson.TwoFactorRequired?.twoFactorDuoAuthUrl: String?
get() = this
?.authMethodsData
?.duo
?.get("AuthUrl")
?.jsonPrimitive
?.contentOrNull
.orEmpty()
/**
* If it exists, return the value to display for the email used with two-factor authentication.

View File

@@ -160,10 +160,19 @@ class TwoFactorLoginViewModel @Inject constructor(
*/
private fun handleContinueButtonClick() {
if (state.authMethod.isDuo) {
val authUrl = authRepository.twoFactorResponse.twoFactorDuoAuthUrl
// The url should not be empty unless the environment is somehow not supported.
sendEvent(
event = TwoFactorLoginEvent.NavigateToDuo(
uri = Uri.parse(authRepository.twoFactorResponse.twoFactorDuoAuthUrl),
),
event = authUrl
?.let {
TwoFactorLoginEvent.NavigateToDuo(
uri = Uri.parse(it),
)
}
?: TwoFactorLoginEvent.ShowToast(
// TODO BIT-1927 Update to use string resource
message = "Duo not yet supported".asText(),
),
)
} else {
initiateLogin()