Skip to content

feat(authenticator): Add support for Email MFA #199

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

Merged
merged 11 commits into from
Oct 31, 2024
Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/*
* Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

package com.amplifyframework.ui.authenticator.ui

import com.amplifyframework.auth.AuthCodeDeliveryDetails
import com.amplifyframework.ui.authenticator.ScreenshotTestBase
import com.amplifyframework.ui.authenticator.SignInConfirmMfaState
import com.amplifyframework.ui.authenticator.enums.AuthenticatorInitialStep
import com.amplifyframework.ui.authenticator.enums.AuthenticatorStep
import com.amplifyframework.ui.authenticator.forms.FieldConfig
import com.amplifyframework.ui.authenticator.forms.FieldError
import com.amplifyframework.ui.authenticator.forms.FieldKey
import com.amplifyframework.ui.authenticator.mockFieldData
import com.amplifyframework.ui.authenticator.mockFieldState
import com.amplifyframework.ui.authenticator.mockForm
import org.junit.Test

class SignInConfirmMfa : ScreenshotTestBase() {

@Test
fun sign_in_confirm_email_mfa_default() {
screenshot {
SignInConfirmMfa(
mockSignInConfirmMfaState(
AuthCodeDeliveryDetails(
"[email protected]",
AuthCodeDeliveryDetails.DeliveryMedium.EMAIL
)
)
)
}
}

@Test
fun sign_in_confirm_email_mfa_incorrect_code() {
screenshot {
SignInConfirmMfa(
mockSignInConfirmMfaState(
AuthCodeDeliveryDetails(
"[email protected]",
AuthCodeDeliveryDetails.DeliveryMedium.EMAIL
),
"123456",
FieldError.ConfirmationCodeIncorrect
)
)
}
}

@Test
fun sign_in_confirm_sms_mfa_default() {
screenshot {
SignInConfirmMfa(
mockSignInConfirmMfaState(
AuthCodeDeliveryDetails(
"123-123-1234",
AuthCodeDeliveryDetails.DeliveryMedium.SMS
)
)
)
}
}

@Test
fun sign_in_confirm_sms_mfa_incorrect_code() {
screenshot {
SignInConfirmMfa(
mockSignInConfirmMfaState(
AuthCodeDeliveryDetails(
"123-123-1234",
AuthCodeDeliveryDetails.DeliveryMedium.SMS
),
"123456",
FieldError.ConfirmationCodeIncorrect
)
)
}
}

private fun mockSignInConfirmMfaState(
deliveryDetails: AuthCodeDeliveryDetails,
confirmationCode: String = "",
fieldError: FieldError? = null
) = object : SignInConfirmMfaState {
override val form = mockForm(
mockFieldData(
config = FieldConfig.Text(FieldKey.ConfirmationCode),
state = mockFieldState(content = confirmationCode, error = fieldError)
)
)
override val deliveryDetails: AuthCodeDeliveryDetails
get() = deliveryDetails

override fun moveTo(step: AuthenticatorInitialStep) {}
override suspend fun confirmSignIn() {
TODO("Not yet implemented")
}

override val step = AuthenticatorStep.SignInContinueWithEmailSetup
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

package com.amplifyframework.ui.authenticator.ui

import com.amplifyframework.ui.authenticator.ScreenshotTestBase
import com.amplifyframework.ui.authenticator.SignInContinueWithEmailSetupState
import com.amplifyframework.ui.authenticator.enums.AuthenticatorInitialStep
import com.amplifyframework.ui.authenticator.enums.AuthenticatorStep
import com.amplifyframework.ui.authenticator.forms.FieldConfig
import com.amplifyframework.ui.authenticator.forms.FieldKey
import com.amplifyframework.ui.authenticator.mockFieldData
import com.amplifyframework.ui.authenticator.mockFieldState
import com.amplifyframework.ui.authenticator.mockForm
import org.junit.Test

class SignInContinueWithEmailSetupScreenshots : ScreenshotTestBase() {

@Test
fun default_state() {
screenshot {
SignInContinueWithEmailSetup(mockSignInContinueWithEmailSetupState())
}
}

private fun mockSignInContinueWithEmailSetupState() = object : SignInContinueWithEmailSetupState {
override val form = mockForm(
mockFieldData(
config = FieldConfig.Text(FieldKey.Email),
state = mockFieldState(content = "[email protected]")
)
)
override fun moveTo(step: AuthenticatorInitialStep) {}
override suspend fun continueSignIn() {}
override val step = AuthenticatorStep.SignInContinueWithEmailSetup
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

package com.amplifyframework.ui.authenticator.ui

import com.amplifyframework.auth.MFAType
import com.amplifyframework.ui.authenticator.ScreenshotTestBase
import com.amplifyframework.ui.authenticator.SignInContinueWithMfaSetupSelectionState
import com.amplifyframework.ui.authenticator.enums.AuthenticatorInitialStep
import com.amplifyframework.ui.authenticator.enums.AuthenticatorStep
import com.amplifyframework.ui.authenticator.forms.FieldConfig
import com.amplifyframework.ui.authenticator.forms.FieldKey
import com.amplifyframework.ui.authenticator.mockFieldData
import com.amplifyframework.ui.authenticator.mockFieldState
import com.amplifyframework.ui.authenticator.mockForm
import org.junit.Test

class SignInContinueWithMfaSetupSelection : ScreenshotTestBase() {

@Test
fun default_state() {
screenshot {
SignInContinueWithMfaSetupSelection(mockSignInContinueWithMfaSetupSelectionState())
}
}

private fun mockSignInContinueWithMfaSetupSelectionState() = object : SignInContinueWithMfaSetupSelectionState {
override val form = mockForm(
mockFieldData(
config = FieldConfig.Text(FieldKey.MfaSelection),
state = mockFieldState(content = "EMAIL_OTP")
)
)
override val allowedMfaTypes: Set<MFAType>
get() = setOf(MFAType.TOTP, MFAType.SMS, MFAType.EMAIL)

override fun moveTo(step: AuthenticatorInitialStep) {}
override suspend fun continueSignIn() {}
override val step = AuthenticatorStep.SignInContinueWithEmailSetup
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading