From 9a1d9d04d6adb07a48a9f0164a1feef0c654c015 Mon Sep 17 00:00:00 2001 From: Matt Creaser Date: Tue, 11 Apr 2023 10:28:42 -0300 Subject: [PATCH 01/13] Add the authenticator component --- authenticator/.gitignore | 1 + authenticator/build.gradle | 33 ++ authenticator/consumer-rules.pro | 0 authenticator/gradle.properties | 20 + authenticator/proguard-rules.pro | 21 + authenticator/src/main/AndroidManifest.xml | 2 + .../AuthenticatorConfiguration.kt | 24 + .../authenticator/AuthenticatorScreenState.kt | 206 +++++++ .../ui/authenticator/AuthenticatorState.kt | 93 +++ .../authenticator/AuthenticatorViewModel.kt | 546 ++++++++++++++++++ .../authenticator/enums/AuthenticatorStep.kt | 97 ++++ .../ui/authenticator/forms/FieldConfig.kt | 156 +++++ .../ui/authenticator/forms/FieldError.kt | 91 +++ .../ui/authenticator/forms/FieldKey.kt | 60 ++ .../ui/authenticator/forms/FieldState.kt | 58 ++ .../ui/authenticator/forms/FieldValidator.kt | 145 +++++ .../ui/authenticator/forms/FormBuilder.kt | 344 +++++++++++ .../ui/authenticator/forms/FormState.kt | 139 +++++ .../locals/LocalStringResolver.kt | 21 + .../states/PasswordResetConfirmStateImpl.kt | 32 + .../states/PasswordResetStateImpl.kt | 30 + .../states/ScreenStateFactory.kt | 264 +++++++++ .../states/SignInConfirmCustomStateImpl.kt | 33 ++ .../states/SignInConfirmMfaStateImpl.kt | 32 + .../SignInConfirmNewPasswordStateImpl.kt | 30 + .../authenticator/states/SignInStateImpl.kt | 31 + .../states/SignUpConfirmStateImpl.kt | 34 ++ .../authenticator/states/SignUpStateImpl.kt | 30 + .../authenticator/states/SignedInStateImpl.kt | 29 + .../states/VerifyUserConfirmStateImpl.kt | 33 ++ .../states/VerifyUserStateImpl.kt | 31 + .../authenticator/strings/StringResolver.kt | 162 ++++++ .../ui/authenticator/ui/Authenticator.kt | 167 ++++++ .../ui/authenticator/ui/AuthenticatorError.kt | 53 ++ .../ui/authenticator/ui/AuthenticatorField.kt | 95 +++ .../ui/authenticator/ui/AuthenticatorForm.kt | 87 +++ .../authenticator/ui/AuthenticatorLoading.kt | 108 ++++ .../ui/authenticator/ui/AuthenticatorTitle.kt | 39 ++ .../ui/authenticator/ui/DateInputField.kt | 119 ++++ .../ui/authenticator/ui/DeliveryDetails.kt | 47 ++ .../ui/authenticator/ui/PasswordInputField.kt | 99 ++++ .../ui/authenticator/ui/PasswordReset.kt | 68 +++ .../authenticator/ui/PasswordResetConfirm.kt | 70 +++ .../ui/authenticator/ui/PhoneInputField.kt | 183 ++++++ .../ui/authenticator/ui/SignIn.kt | 76 +++ .../authenticator/ui/SignInConfirmCustom.kt | 74 +++ .../ui/authenticator/ui/SignInConfirmMfa.kt | 74 +++ .../ui/SignInConfirmNewPassword.kt | 97 ++++ .../ui/authenticator/ui/SignUp.kt | 67 +++ .../ui/authenticator/ui/SignUpConfirm.kt | 82 +++ .../ui/authenticator/ui/TextInputField.kt | 69 +++ .../ui/authenticator/ui/VerifyUser.kt | 114 ++++ .../ui/authenticator/ui/VerifyUserConfirm.kt | 87 +++ .../util/AnnotatedStringResource.kt | 102 ++++ .../ui/authenticator/util/AuthProvider.kt | 321 ++++++++++ .../util/AuthenticatorMessage.kt | 116 ++++ .../ui/authenticator/util/DialCodes.kt | 472 +++++++++++++++ .../ui/authenticator/util/Errors.kt | 32 + .../util/MissingConfigurationException.kt | 27 + .../drawable/ic_authenticator_invisible.xml | 25 + .../res/drawable/ic_authenticator_visible.xml | 25 + authenticator/src/main/res/values/buttons.xml | 27 + authenticator/src/main/res/values/errors.xml | 24 + authenticator/src/main/res/values/fields.xml | 65 +++ .../src/main/res/values/messages.xml | 20 + authenticator/src/main/res/values/strings.xml | 20 + authenticator/src/main/res/values/titles.xml | 25 + .../ui/authenticator/ui/SignInTest.kt | 45 ++ .../ui/authenticator/ui/SignUpTest.kt | 54 ++ build.gradle | 7 +- liveness/build.gradle | 4 +- samples/authenticator/.gitignore | 15 + samples/authenticator/.idea/.gitignore | 3 + samples/authenticator/.idea/.name | 1 + samples/authenticator/.idea/compiler.xml | 6 + .../.idea/deploymentTargetDropDown.xml | 17 + samples/authenticator/.idea/gradle.xml | 36 ++ .../inspectionProfiles/Project_Default.xml | 41 ++ .../authenticator/.idea/jarRepositories.xml | 35 ++ samples/authenticator/.idea/misc.xml | 10 + samples/authenticator/.idea/vcs.xml | 6 + samples/authenticator/README.md | 56 ++ samples/authenticator/app/.gitignore | 4 + samples/authenticator/app/build.gradle | 73 +++ .../app/src/main/AndroidManifest.xml | 25 + .../authenticator/AuthenticatorSampleApp.kt | 34 ++ .../ui/sample/authenticator/MainActivity.kt | 142 +++++ .../ui/sample/authenticator/ThemeSelector.kt | 66 +++ .../authenticator/theme/default/Color.kt | 26 + .../authenticator/theme/default/Theme.kt | 92 +++ .../authenticator/theme/default/Type.kt | 49 ++ .../drawable-v24/ic_launcher_foreground.xml | 45 ++ .../app/src/main/res/drawable/amplify.xml | 48 ++ .../res/drawable/ic_launcher_background.xml | 184 ++++++ .../res/mipmap-anydpi-v26/ic_launcher.xml | 19 + .../mipmap-anydpi-v26/ic_launcher_round.xml | 19 + .../res/mipmap-anydpi-v33/ic_launcher.xml | 20 + .../src/main/res/mipmap-hdpi/ic_launcher.webp | Bin 0 -> 1404 bytes .../res/mipmap-hdpi/ic_launcher_round.webp | Bin 0 -> 2898 bytes .../src/main/res/mipmap-mdpi/ic_launcher.webp | Bin 0 -> 982 bytes .../res/mipmap-mdpi/ic_launcher_round.webp | Bin 0 -> 1772 bytes .../main/res/mipmap-xhdpi/ic_launcher.webp | Bin 0 -> 1900 bytes .../res/mipmap-xhdpi/ic_launcher_round.webp | Bin 0 -> 3918 bytes .../main/res/mipmap-xxhdpi/ic_launcher.webp | Bin 0 -> 2884 bytes .../res/mipmap-xxhdpi/ic_launcher_round.webp | Bin 0 -> 5914 bytes .../main/res/mipmap-xxxhdpi/ic_launcher.webp | Bin 0 -> 3844 bytes .../res/mipmap-xxxhdpi/ic_launcher_round.webp | Bin 0 -> 7778 bytes .../app/src/main/res/values/strings.xml | 18 + .../app/src/main/res/values/themes.xml | 18 + samples/authenticator/build.gradle | 16 + samples/authenticator/gradle.properties | 38 ++ .../gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 59203 bytes .../gradle/wrapper/gradle-wrapper.properties | 21 + samples/authenticator/gradlew | 185 ++++++ samples/authenticator/gradlew.bat | 89 +++ samples/authenticator/settings.gradle | 20 + settings.gradle | 1 + 117 files changed, 7588 insertions(+), 4 deletions(-) create mode 100644 authenticator/.gitignore create mode 100644 authenticator/build.gradle create mode 100644 authenticator/consumer-rules.pro create mode 100644 authenticator/gradle.properties create mode 100644 authenticator/proguard-rules.pro create mode 100644 authenticator/src/main/AndroidManifest.xml create mode 100644 authenticator/src/main/java/com/amplifyframework/ui/authenticator/AuthenticatorConfiguration.kt create mode 100644 authenticator/src/main/java/com/amplifyframework/ui/authenticator/AuthenticatorScreenState.kt create mode 100644 authenticator/src/main/java/com/amplifyframework/ui/authenticator/AuthenticatorState.kt create mode 100644 authenticator/src/main/java/com/amplifyframework/ui/authenticator/AuthenticatorViewModel.kt create mode 100644 authenticator/src/main/java/com/amplifyframework/ui/authenticator/enums/AuthenticatorStep.kt create mode 100644 authenticator/src/main/java/com/amplifyframework/ui/authenticator/forms/FieldConfig.kt create mode 100644 authenticator/src/main/java/com/amplifyframework/ui/authenticator/forms/FieldError.kt create mode 100644 authenticator/src/main/java/com/amplifyframework/ui/authenticator/forms/FieldKey.kt create mode 100644 authenticator/src/main/java/com/amplifyframework/ui/authenticator/forms/FieldState.kt create mode 100644 authenticator/src/main/java/com/amplifyframework/ui/authenticator/forms/FieldValidator.kt create mode 100644 authenticator/src/main/java/com/amplifyframework/ui/authenticator/forms/FormBuilder.kt create mode 100644 authenticator/src/main/java/com/amplifyframework/ui/authenticator/forms/FormState.kt create mode 100644 authenticator/src/main/java/com/amplifyframework/ui/authenticator/locals/LocalStringResolver.kt create mode 100644 authenticator/src/main/java/com/amplifyframework/ui/authenticator/states/PasswordResetConfirmStateImpl.kt create mode 100644 authenticator/src/main/java/com/amplifyframework/ui/authenticator/states/PasswordResetStateImpl.kt create mode 100644 authenticator/src/main/java/com/amplifyframework/ui/authenticator/states/ScreenStateFactory.kt create mode 100644 authenticator/src/main/java/com/amplifyframework/ui/authenticator/states/SignInConfirmCustomStateImpl.kt create mode 100644 authenticator/src/main/java/com/amplifyframework/ui/authenticator/states/SignInConfirmMfaStateImpl.kt create mode 100644 authenticator/src/main/java/com/amplifyframework/ui/authenticator/states/SignInConfirmNewPasswordStateImpl.kt create mode 100644 authenticator/src/main/java/com/amplifyframework/ui/authenticator/states/SignInStateImpl.kt create mode 100644 authenticator/src/main/java/com/amplifyframework/ui/authenticator/states/SignUpConfirmStateImpl.kt create mode 100644 authenticator/src/main/java/com/amplifyframework/ui/authenticator/states/SignUpStateImpl.kt create mode 100644 authenticator/src/main/java/com/amplifyframework/ui/authenticator/states/SignedInStateImpl.kt create mode 100644 authenticator/src/main/java/com/amplifyframework/ui/authenticator/states/VerifyUserConfirmStateImpl.kt create mode 100644 authenticator/src/main/java/com/amplifyframework/ui/authenticator/states/VerifyUserStateImpl.kt create mode 100644 authenticator/src/main/java/com/amplifyframework/ui/authenticator/strings/StringResolver.kt create mode 100644 authenticator/src/main/java/com/amplifyframework/ui/authenticator/ui/Authenticator.kt create mode 100644 authenticator/src/main/java/com/amplifyframework/ui/authenticator/ui/AuthenticatorError.kt create mode 100644 authenticator/src/main/java/com/amplifyframework/ui/authenticator/ui/AuthenticatorField.kt create mode 100644 authenticator/src/main/java/com/amplifyframework/ui/authenticator/ui/AuthenticatorForm.kt create mode 100644 authenticator/src/main/java/com/amplifyframework/ui/authenticator/ui/AuthenticatorLoading.kt create mode 100644 authenticator/src/main/java/com/amplifyframework/ui/authenticator/ui/AuthenticatorTitle.kt create mode 100644 authenticator/src/main/java/com/amplifyframework/ui/authenticator/ui/DateInputField.kt create mode 100644 authenticator/src/main/java/com/amplifyframework/ui/authenticator/ui/DeliveryDetails.kt create mode 100644 authenticator/src/main/java/com/amplifyframework/ui/authenticator/ui/PasswordInputField.kt create mode 100644 authenticator/src/main/java/com/amplifyframework/ui/authenticator/ui/PasswordReset.kt create mode 100644 authenticator/src/main/java/com/amplifyframework/ui/authenticator/ui/PasswordResetConfirm.kt create mode 100644 authenticator/src/main/java/com/amplifyframework/ui/authenticator/ui/PhoneInputField.kt create mode 100644 authenticator/src/main/java/com/amplifyframework/ui/authenticator/ui/SignIn.kt create mode 100644 authenticator/src/main/java/com/amplifyframework/ui/authenticator/ui/SignInConfirmCustom.kt create mode 100644 authenticator/src/main/java/com/amplifyframework/ui/authenticator/ui/SignInConfirmMfa.kt create mode 100644 authenticator/src/main/java/com/amplifyframework/ui/authenticator/ui/SignInConfirmNewPassword.kt create mode 100644 authenticator/src/main/java/com/amplifyframework/ui/authenticator/ui/SignUp.kt create mode 100644 authenticator/src/main/java/com/amplifyframework/ui/authenticator/ui/SignUpConfirm.kt create mode 100644 authenticator/src/main/java/com/amplifyframework/ui/authenticator/ui/TextInputField.kt create mode 100644 authenticator/src/main/java/com/amplifyframework/ui/authenticator/ui/VerifyUser.kt create mode 100644 authenticator/src/main/java/com/amplifyframework/ui/authenticator/ui/VerifyUserConfirm.kt create mode 100644 authenticator/src/main/java/com/amplifyframework/ui/authenticator/util/AnnotatedStringResource.kt create mode 100644 authenticator/src/main/java/com/amplifyframework/ui/authenticator/util/AuthProvider.kt create mode 100644 authenticator/src/main/java/com/amplifyframework/ui/authenticator/util/AuthenticatorMessage.kt create mode 100644 authenticator/src/main/java/com/amplifyframework/ui/authenticator/util/DialCodes.kt create mode 100644 authenticator/src/main/java/com/amplifyframework/ui/authenticator/util/Errors.kt create mode 100644 authenticator/src/main/java/com/amplifyframework/ui/authenticator/util/MissingConfigurationException.kt create mode 100644 authenticator/src/main/res/drawable/ic_authenticator_invisible.xml create mode 100644 authenticator/src/main/res/drawable/ic_authenticator_visible.xml create mode 100644 authenticator/src/main/res/values/buttons.xml create mode 100644 authenticator/src/main/res/values/errors.xml create mode 100644 authenticator/src/main/res/values/fields.xml create mode 100644 authenticator/src/main/res/values/messages.xml create mode 100644 authenticator/src/main/res/values/strings.xml create mode 100644 authenticator/src/main/res/values/titles.xml create mode 100644 authenticator/src/test/java/com/amplifyframework/ui/authenticator/ui/SignInTest.kt create mode 100644 authenticator/src/test/java/com/amplifyframework/ui/authenticator/ui/SignUpTest.kt create mode 100644 samples/authenticator/.gitignore create mode 100644 samples/authenticator/.idea/.gitignore create mode 100644 samples/authenticator/.idea/.name create mode 100644 samples/authenticator/.idea/compiler.xml create mode 100644 samples/authenticator/.idea/deploymentTargetDropDown.xml create mode 100644 samples/authenticator/.idea/gradle.xml create mode 100644 samples/authenticator/.idea/inspectionProfiles/Project_Default.xml create mode 100644 samples/authenticator/.idea/jarRepositories.xml create mode 100644 samples/authenticator/.idea/misc.xml create mode 100644 samples/authenticator/.idea/vcs.xml create mode 100644 samples/authenticator/README.md create mode 100644 samples/authenticator/app/.gitignore create mode 100644 samples/authenticator/app/build.gradle create mode 100644 samples/authenticator/app/src/main/AndroidManifest.xml create mode 100644 samples/authenticator/app/src/main/java/com/amplifyframework/ui/sample/authenticator/AuthenticatorSampleApp.kt create mode 100644 samples/authenticator/app/src/main/java/com/amplifyframework/ui/sample/authenticator/MainActivity.kt create mode 100644 samples/authenticator/app/src/main/java/com/amplifyframework/ui/sample/authenticator/ThemeSelector.kt create mode 100644 samples/authenticator/app/src/main/java/com/amplifyframework/ui/sample/authenticator/theme/default/Color.kt create mode 100644 samples/authenticator/app/src/main/java/com/amplifyframework/ui/sample/authenticator/theme/default/Theme.kt create mode 100644 samples/authenticator/app/src/main/java/com/amplifyframework/ui/sample/authenticator/theme/default/Type.kt create mode 100644 samples/authenticator/app/src/main/res/drawable-v24/ic_launcher_foreground.xml create mode 100644 samples/authenticator/app/src/main/res/drawable/amplify.xml create mode 100644 samples/authenticator/app/src/main/res/drawable/ic_launcher_background.xml create mode 100644 samples/authenticator/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml create mode 100644 samples/authenticator/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml create mode 100644 samples/authenticator/app/src/main/res/mipmap-anydpi-v33/ic_launcher.xml create mode 100644 samples/authenticator/app/src/main/res/mipmap-hdpi/ic_launcher.webp create mode 100644 samples/authenticator/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp create mode 100644 samples/authenticator/app/src/main/res/mipmap-mdpi/ic_launcher.webp create mode 100644 samples/authenticator/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp create mode 100644 samples/authenticator/app/src/main/res/mipmap-xhdpi/ic_launcher.webp create mode 100644 samples/authenticator/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp create mode 100644 samples/authenticator/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp create mode 100644 samples/authenticator/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp create mode 100644 samples/authenticator/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp create mode 100644 samples/authenticator/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp create mode 100644 samples/authenticator/app/src/main/res/values/strings.xml create mode 100644 samples/authenticator/app/src/main/res/values/themes.xml create mode 100644 samples/authenticator/build.gradle create mode 100644 samples/authenticator/gradle.properties create mode 100644 samples/authenticator/gradle/wrapper/gradle-wrapper.jar create mode 100644 samples/authenticator/gradle/wrapper/gradle-wrapper.properties create mode 100755 samples/authenticator/gradlew create mode 100644 samples/authenticator/gradlew.bat create mode 100644 samples/authenticator/settings.gradle diff --git a/authenticator/.gitignore b/authenticator/.gitignore new file mode 100644 index 00000000..42afabfd --- /dev/null +++ b/authenticator/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/authenticator/build.gradle b/authenticator/build.gradle new file mode 100644 index 00000000..26397b64 --- /dev/null +++ b/authenticator/build.gradle @@ -0,0 +1,33 @@ +apply plugin: 'com.android.library' +apply plugin: 'kotlin-android' +apply from: rootProject.file("configuration/publishing.gradle") + +group = POM_GROUP + +android { + namespace 'com.amplifyframework.ui.authenticator' + defaultConfig { + testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' + } + + publishing { + singleVariant("release") { + withSourcesJar() + } + } +} + +dependencies { + api dependency.amplify.auth + + implementation dependency.androidx.material + implementation dependency.androidx.uiTooling + implementation dependency.androidx.lifecycle_ktx + implementation dependency.androidx.compose.viewmodel + + testImplementation dependency.test.androidx.espresso + testImplementation dependency.test.androidx.junit + testImplementation dependency.test.junit + testImplementation dependency.test.robolectric + testImplementation dependency.test.mockk +} diff --git a/authenticator/consumer-rules.pro b/authenticator/consumer-rules.pro new file mode 100644 index 00000000..e69de29b diff --git a/authenticator/gradle.properties b/authenticator/gradle.properties new file mode 100644 index 00000000..db9c84bd --- /dev/null +++ b/authenticator/gradle.properties @@ -0,0 +1,20 @@ +# +# Copyright 2023 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. +# + +POM_ARTIFACT_ID=authenticator +POM_NAME=Amplify UI Framework for Android - Authenticator +POM_DESCRIPTION=Amplify UI Framework for Android - Authenticator Plugin +POM_PACKAGING=aar +VERSION_NAME=1.0.0-dev-preview.0 diff --git a/authenticator/proguard-rules.pro b/authenticator/proguard-rules.pro new file mode 100644 index 00000000..481bb434 --- /dev/null +++ b/authenticator/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/authenticator/src/main/AndroidManifest.xml b/authenticator/src/main/AndroidManifest.xml new file mode 100644 index 00000000..8072ee00 --- /dev/null +++ b/authenticator/src/main/AndroidManifest.xml @@ -0,0 +1,2 @@ + + diff --git a/authenticator/src/main/java/com/amplifyframework/ui/authenticator/AuthenticatorConfiguration.kt b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/AuthenticatorConfiguration.kt new file mode 100644 index 00000000..0ce0bd5e --- /dev/null +++ b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/AuthenticatorConfiguration.kt @@ -0,0 +1,24 @@ +/* + * Copyright 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 + +import com.amplifyframework.ui.authenticator.enums.AuthenticatorInitialStep +import com.amplifyframework.ui.authenticator.forms.SignUpFormBuilder + +internal data class AuthenticatorConfiguration( + val initialStep: AuthenticatorInitialStep, + val signUpForm: SignUpFormBuilder.() -> Unit +) diff --git a/authenticator/src/main/java/com/amplifyframework/ui/authenticator/AuthenticatorScreenState.kt b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/AuthenticatorScreenState.kt new file mode 100644 index 00000000..e6ad99a1 --- /dev/null +++ b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/AuthenticatorScreenState.kt @@ -0,0 +1,206 @@ +/* + * Copyright 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 + +import androidx.compose.runtime.Immutable +import androidx.compose.runtime.Stable +import com.amplifyframework.auth.AuthCodeDeliveryDetails +import com.amplifyframework.auth.AuthException +import com.amplifyframework.auth.AuthUser +import com.amplifyframework.auth.AuthUserAttribute +import com.amplifyframework.auth.result.AuthSignOutResult +import com.amplifyframework.ui.authenticator.enums.AuthenticatorInitialStep +import com.amplifyframework.ui.authenticator.enums.AuthenticatorStep +import com.amplifyframework.ui.authenticator.forms.MutableFormState + +/** + * A Screen State is a state holder for the UI for a specific [AuthenticatorStep]. + */ +@Stable +interface AuthenticatorScreenState { + val step: AuthenticatorStep +} + +/** + * The Authenticator is loading the current state of the user's Auth session. + */ +@Immutable +object LoadingState : AuthenticatorScreenState { + override val step = AuthenticatorStep.Loading +} + +/** + * The Authenticator has encountered an unrecoverable error. + * @param error The error that occurred. + */ +@Immutable +data class ErrorState(val error: AuthException) : AuthenticatorScreenState { + override val step = AuthenticatorStep.Error +} + +/** + * The user has completed the sign in process. + */ +@Immutable +interface SignedInState : AuthenticatorScreenState { + /** + * The [AuthUser] instance for the signed in user. + */ + val user: AuthUser + + /** + * Sign out the current user. This does a local sign out and returns the [AuthSignOutResult] that + * may be inspected to determine if any parts of the sign out were unsuccessful. + */ + suspend fun signOut(): AuthSignOutResult +} + +/** + * An [AuthenticatorScreenState] for a part of UI that contains an input form. + */ +@Stable +interface FormHolderState : AuthenticatorScreenState { + val form: MutableFormState +} + +/** + * The user is on the Sign In step. They can enter their Sign In information to authenticate with Amplify. + */ +@Stable +interface SignInState : FormHolderState { + fun moveTo(step: AuthenticatorInitialStep) + suspend fun signIn() +} + +/** + * The user has completed the initial Sign In step, and needs to enter the confirmation code from an MFA + * message to complete the sign in process. + */ +@Stable +interface SignInConfirmMfaState : FormHolderState { + val deliveryDetails: AuthCodeDeliveryDetails? + fun moveTo(step: AuthenticatorInitialStep) + suspend fun confirmSignIn() +} + +/** + * The user has completed the initial Sign In step, and needs to enter the confirmation code from a custom + * challenge to complete the sign in process. + */ +@Stable +interface SignInConfirmCustomState : FormHolderState { + val additionalInfo: Map + val deliveryDetails: AuthCodeDeliveryDetails? + fun moveTo(step: AuthenticatorInitialStep) + suspend fun confirmSignIn() +} + +/** + * The user has completed the initial Sign In step, and is required to change their password in order to complete + * the sign in process. + */ +@Stable +interface SignInConfirmNewPasswordState : FormHolderState { + fun moveTo(step: AuthenticatorInitialStep) + suspend fun confirmSignIn() +} + +/** + * The user is on the Sign Up step, and can fill out the account creation form to Sign Up. + */ +@Stable +interface SignUpState : FormHolderState { + fun moveTo(step: AuthenticatorInitialStep) + suspend fun signUp() +} + +/** + * The user has signed up, but needs to enter a confirmation code sent to them. + */ +@Stable +interface SignUpConfirmState : FormHolderState { + val deliveryDetails: AuthCodeDeliveryDetails? + fun moveTo(step: AuthenticatorInitialStep) + suspend fun confirmSignUp() + suspend fun resendCode() +} + +/** + * The user is on the Password Reset step. They can enter their username to begin the password reset. + */ +@Stable +interface PasswordResetState : FormHolderState { + fun moveTo(step: AuthenticatorInitialStep) + suspend fun submitPasswordReset() +} + +/** + * The user has entered their username and been sent a confirmation code. The need to enter the code and their new + * password to complete the password reset. + */ +@Stable +interface PasswordResetConfirmState : FormHolderState { + val deliveryDetails: AuthCodeDeliveryDetails? + fun moveTo(step: AuthenticatorInitialStep) + suspend fun submitPasswordResetConfirm() +} + +/** + * The user has successfully signed in and their account is confirmed, however they do not have any means of account recovery (email, phone) that is confirmed. + */ +@Stable +interface VerifyUserState : FormHolderState { + /** + * The list of unverified attributes. + */ + val attributes: List + + /** + * Submit the selected attribute to initiate the attribute verification. + */ + suspend fun verifyUser() + + /** + * Skip verification and move to the Signed In state + */ + fun skip() +} + +/** + * The user has initiated verification of an account recovery mechanism (email, phone) and needs to provide a confirmation code. + */ +@Stable +interface VerifyUserConfirmState : FormHolderState { + /** + * The details of where the verification code was sent. + */ + val deliveryDetails: AuthCodeDeliveryDetails? + + /** + * Submit the entered confirmation code to confirm the verification. + */ + suspend fun confirmVerifyUser() + + /** + * Re-send the verification code. + */ + suspend fun resendCode() + + /** + * Skip verification and move to the Signed In state + */ + fun skip() +} diff --git a/authenticator/src/main/java/com/amplifyframework/ui/authenticator/AuthenticatorState.kt b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/AuthenticatorState.kt new file mode 100644 index 00000000..5d030020 --- /dev/null +++ b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/AuthenticatorState.kt @@ -0,0 +1,93 @@ +/* + * Copyright 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 + +import androidx.compose.runtime.Composable +import androidx.compose.runtime.Stable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue +import androidx.lifecycle.viewModelScope +import androidx.lifecycle.viewmodel.compose.viewModel +import com.amplifyframework.ui.authenticator.enums.AuthenticatorInitialStep +import com.amplifyframework.ui.authenticator.enums.AuthenticatorStep +import com.amplifyframework.ui.authenticator.forms.SignUpFormBuilder +import com.amplifyframework.ui.authenticator.util.AuthenticatorMessage +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.launch + +/** + * Create the [state holder](https://developer.android.com/jetpack/compose/state#managing-state) for the + * Authenticator composable. + * @param initialStep The [AuthenticatorInitialStep] that the user sees first when the Authenticator becomes visible. Default is [AuthenticatorStep.SignIn]. + * @param signUpForm The builder instance for configuring the sign up form content. A default sign up form will be inferred from your + * Amplify configuration, but this may be used to modify that form by changing the order of the fields, adding fields for custom or optional user attributes, + * or adding fully custom fields. Has an [SignUpFormBuilder] receiver. + */ +@Composable +fun rememberAuthenticatorState( + initialStep: AuthenticatorInitialStep = AuthenticatorStep.SignIn, + signUpForm: SignUpFormBuilder.() -> Unit = {} +): AuthenticatorState { + val viewModel = viewModel() + return remember { + val configuration = AuthenticatorConfiguration( + initialStep = initialStep, + signUpForm = signUpForm + ) + + viewModel.start(configuration) + AuthenticatorStateImpl(viewModel) + } +} + +/** + * The [state holder](https://developer.android.com/jetpack/compose/state#managing-state) instance for + * the Authenticator composable. + */ +@Stable +interface AuthenticatorState { + /** + * The state holder instance for the current content visible to the user. + */ + val screenState: AuthenticatorScreenState + + /** + * A flow of [AuthenticatorMessage] that may be presented to the user, such as messages indicating a + * password was successfully reset or certain error responses were received from the Auth backend. By + * default these messages will be shown in a Snackbar by the Authenticator, but this can be overridden + * by supplying an onDisplayMessage argument to the Authenticator composable. + */ + val messages: Flow +} + +internal class AuthenticatorStateImpl constructor( + private val viewModel: AuthenticatorViewModel +) : AuthenticatorState { + override var screenState by mutableStateOf(LoadingState) + + override val messages: Flow + get() = viewModel.events + + init { + viewModel.viewModelScope.launch { + viewModel.screenState.collect { + screenState = it + } + } + } +} diff --git a/authenticator/src/main/java/com/amplifyframework/ui/authenticator/AuthenticatorViewModel.kt b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/AuthenticatorViewModel.kt new file mode 100644 index 00000000..bf452fd3 --- /dev/null +++ b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/AuthenticatorViewModel.kt @@ -0,0 +1,546 @@ +/* + * Copyright 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 + +import android.app.Application +import androidx.lifecycle.AndroidViewModel +import androidx.lifecycle.viewModelScope +import com.amplifyframework.auth.AuthChannelEventName +import com.amplifyframework.auth.AuthException +import com.amplifyframework.auth.AuthUserAttribute +import com.amplifyframework.auth.AuthUserAttributeKey +import com.amplifyframework.auth.cognito.exceptions.service.CodeDeliveryFailureException +import com.amplifyframework.auth.cognito.exceptions.service.CodeExpiredException +import com.amplifyframework.auth.cognito.exceptions.service.CodeMismatchException +import com.amplifyframework.auth.cognito.exceptions.service.CodeValidationException +import com.amplifyframework.auth.cognito.exceptions.service.InvalidParameterException +import com.amplifyframework.auth.cognito.exceptions.service.InvalidPasswordException +import com.amplifyframework.auth.cognito.exceptions.service.PasswordResetRequiredException +import com.amplifyframework.auth.cognito.exceptions.service.UserNotConfirmedException +import com.amplifyframework.auth.cognito.exceptions.service.UserNotFoundException +import com.amplifyframework.auth.cognito.exceptions.service.UsernameExistsException +import com.amplifyframework.auth.exceptions.NotAuthorizedException +import com.amplifyframework.auth.options.AuthSignUpOptions +import com.amplifyframework.auth.result.AuthResetPasswordResult +import com.amplifyframework.auth.result.AuthSignInResult +import com.amplifyframework.auth.result.AuthSignUpResult +import com.amplifyframework.auth.result.step.AuthResetPasswordStep +import com.amplifyframework.auth.result.step.AuthSignInStep +import com.amplifyframework.auth.result.step.AuthSignUpStep +import com.amplifyframework.core.Amplify +import com.amplifyframework.ui.authenticator.amplify.AmplifyAuthConfiguration +import com.amplifyframework.ui.authenticator.amplify.toAttributeKey +import com.amplifyframework.ui.authenticator.amplify.toFieldKey +import com.amplifyframework.ui.authenticator.amplify.toVerifiedAttributeKey +import com.amplifyframework.ui.authenticator.enums.AuthenticatorInitialStep +import com.amplifyframework.ui.authenticator.enums.AuthenticatorStep +import com.amplifyframework.ui.authenticator.forms.FieldError +import com.amplifyframework.ui.authenticator.forms.FieldError.ConfirmationCodeIncorrect +import com.amplifyframework.ui.authenticator.forms.FieldError.FieldValueExists +import com.amplifyframework.ui.authenticator.forms.FieldError.NotFound +import com.amplifyframework.ui.authenticator.forms.FieldKey.ConfirmationCode +import com.amplifyframework.ui.authenticator.forms.FieldKey.Password +import com.amplifyframework.ui.authenticator.forms.FormState +import com.amplifyframework.ui.authenticator.forms.buildForm +import com.amplifyframework.ui.authenticator.forms.markSubmitting +import com.amplifyframework.ui.authenticator.forms.setFieldError +import com.amplifyframework.ui.authenticator.states.PasswordResetConfirmStateImpl +import com.amplifyframework.ui.authenticator.states.PasswordResetStateImpl +import com.amplifyframework.ui.authenticator.states.ScreenStateFactory +import com.amplifyframework.ui.authenticator.states.VerifyUserStateImpl +import com.amplifyframework.ui.authenticator.util.AmplifyResult +import com.amplifyframework.ui.authenticator.util.AuthProvider +import com.amplifyframework.ui.authenticator.util.AuthenticatorMessage +import com.amplifyframework.ui.authenticator.util.CannotSendCodeMessage +import com.amplifyframework.ui.authenticator.util.CodeSentMessage +import com.amplifyframework.ui.authenticator.util.ExpiredCodeMessage +import com.amplifyframework.ui.authenticator.util.InvalidLoginMessage +import com.amplifyframework.ui.authenticator.util.MissingConfigurationException +import com.amplifyframework.ui.authenticator.util.PasswordResetMessage +import com.amplifyframework.ui.authenticator.util.RealAuthProvider +import com.amplifyframework.ui.authenticator.util.UnableToResetPasswordMessage +import com.amplifyframework.ui.authenticator.util.UnknownErrorMessage +import com.amplifyframework.ui.authenticator.util.toFieldError +import kotlinx.coroutines.channels.BufferOverflow +import kotlinx.coroutines.flow.MutableSharedFlow +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.asSharedFlow +import kotlinx.coroutines.flow.asStateFlow +import kotlinx.coroutines.launch +import kotlinx.coroutines.withContext + +internal class AuthenticatorViewModel(application: Application) : AndroidViewModel(application) { + + companion object { + var authProvider: AuthProvider = RealAuthProvider() + } + + private val logger = Amplify.Logging.forNamespace("Authenticator") + + private lateinit var authConfiguration: AmplifyAuthConfiguration + private lateinit var stateFactory: ScreenStateFactory + lateinit var configuration: AuthenticatorConfiguration + private set + + private val _screenState = MutableStateFlow(LoadingState) + val screenState = _screenState.asStateFlow() + + private val currentState: AuthenticatorScreenState + get() = screenState.value + + // Gets the current state or null if the current state is not the parameter type + private inline fun getState(): T? = currentState as? T + + private val _events = MutableSharedFlow( + extraBufferCapacity = 1, + onBufferOverflow = BufferOverflow.DROP_OLDEST + ) + val events = _events.asSharedFlow() + + fun start(configuration: AuthenticatorConfiguration) { + if (::configuration.isInitialized) { + return + } + + this.configuration = configuration + + viewModelScope.launch { + val authConfig = authProvider.getConfiguration() + + if (authConfig == null) { + handleGeneralFailure(MissingConfigurationException()) + return@launch + } + + authConfiguration = authConfig + + stateFactory = ScreenStateFactory( + authConfiguration, + buildForm(configuration.signUpForm), + ::moveTo + ) + + // Fetch the current session to determine if the user is already authenticated + val result = authProvider.fetchAuthSession() + when { + result is AmplifyResult.Error -> handleGeneralFailure(result.error) + result is AmplifyResult.Success && result.data.isSignedIn -> handleSignedIn() + else -> moveTo(configuration.initialStep) + } + } + + // Respond to any events from Amplify Auth + viewModelScope.launch { + authProvider.authStatusEvents().collect { + when (it.name) { + AuthChannelEventName.SIGNED_IN.name -> handleSignedInEvent() + AuthChannelEventName.SIGNED_OUT.name -> handleSignedOut() + } + } + } + } + + fun moveTo(initialStep: AuthenticatorInitialStep) { + logger.debug("Moving to initial step: $initialStep") + val state = when (initialStep) { + AuthenticatorStep.SignUp -> stateFactory.newSignUpState(this::signUp) + AuthenticatorStep.PasswordReset -> stateFactory.newResetPasswordState(this::resetPassword) + else -> stateFactory.newSignInState(this::signIn) + } + moveTo(state) + } + + private fun moveTo(state: AuthenticatorScreenState) { + logger.debug("Moving to step: ${state.step}") + _screenState.value = state + } + + //region SignUp + + private suspend fun signUp(username: String, password: String, attributes: List) { + val state = getState() ?: return + viewModelScope.launch { + state.form.markSubmitting { + val options = AuthSignUpOptions.builder().userAttributes(attributes).build() + + when (val result = authProvider.signUp(username, password, options)) { + is AmplifyResult.Error -> handleSignUpFailure(result.error) + is AmplifyResult.Success -> handleSignUpSuccess(username, password, result.data) + } + } + }.join() + } + + private suspend fun confirmSignUp(username: String, password: String, code: String) { + val state = getState() ?: return + viewModelScope.launch { + state.form.markSubmitting { + when (val result = authProvider.confirmSignUp(username, code)) { + is AmplifyResult.Error -> handleSignUpConfirmFailure(result.error) + is AmplifyResult.Success -> handleSignUpSuccess(username, password, result.data) + } + } + }.join() + } + + private suspend fun resendSignUpCode(username: String) { + viewModelScope.launch { + logger.debug("Resending the SignUp code") + when (val result = authProvider.resendSignUpCode(username)) { + is AmplifyResult.Error -> handleSignUpFailure(result.error) + is AmplifyResult.Success -> sendMessage(CodeSentMessage) + } + }.join() + } + + private suspend fun handleSignUpFailure(error: AuthException) = handleAuthException(error) + private suspend fun handleSignUpConfirmFailure(error: AuthException) = handleAuthException(error) + + private suspend fun handleSignUpSuccess(username: String, password: String, result: AuthSignUpResult) { + when (result.nextStep.signUpStep) { + AuthSignUpStep.CONFIRM_SIGN_UP_STEP -> { + val newState = stateFactory.newSignUpConfirmState( + result.nextStep.codeDeliveryDetails, + onResendCode = { resendSignUpCode(username) }, + onSubmit = { confirmationCode -> confirmSignUp(username, password, confirmationCode) } + ) + moveTo(newState) + } + AuthSignUpStep.DONE -> handleSignedUp(username, password) + } + } + + private suspend fun handleSignedUp(username: String, password: String) { + when (val result = authProvider.signIn(username, password)) { + is AmplifyResult.Error -> { + moveTo(AuthenticatorStep.SignIn) + handleSignInFailure(username, password, result.error) + } + is AmplifyResult.Success -> handleSignInSuccess(username, password, result.data) + } + } + + //endregion + //region SignIn + + private suspend fun signIn(username: String, password: String) { + val state = getState() ?: return + viewModelScope.launch { + state.form.markSubmitting { + when (val result = authProvider.signIn(username, password)) { + is AmplifyResult.Error -> handleSignInFailure(username, password, result.error) + is AmplifyResult.Success -> handleSignInSuccess(username, password, result.data) + } + } + }.join() + } + + private suspend fun confirmSignIn(username: String, password: String, challengeResponse: String) { + val state = getState() ?: return + viewModelScope.launch { + state.form.markSubmitting { + when (val result = authProvider.confirmSignIn(challengeResponse)) { + is AmplifyResult.Error -> handleSignInFailure(username, password, result.error) + is AmplifyResult.Success -> handleSignInSuccess(username, password, result.data) + } + } + }.join() + } + + private suspend fun setNewSignInPassword(username: String, password: String) { + val state = getState() ?: return + viewModelScope.launch { + state.form.markSubmitting { + when (val result = authProvider.confirmSignIn(password)) { + // an error here is more similar to a sign up error + is AmplifyResult.Error -> handleSignUpFailure(result.error) + is AmplifyResult.Success -> handleSignInSuccess(username, password, result.data) + } + } + }.join() + } + + private suspend fun handleSignInFailure(username: String, password: String, error: AuthException) { + // UserNotConfirmed and PasswordResetRequired are special cases where we need + // to enter different flows + when (error) { + is UserNotConfirmedException -> handleUnconfirmedSignIn(username, password) + is PasswordResetRequiredException -> handleResetRequiredSignIn(username) + is NotAuthorizedException -> sendMessage(InvalidLoginMessage(error)) + else -> handleAuthException(error) + } + } + + private suspend fun handleUnconfirmedSignIn(username: String, password: String) { + when (val result = authProvider.resendSignUpCode(username)) { + is AmplifyResult.Error -> handleAuthException(result.error) + is AmplifyResult.Success -> { + val details = result.data + val newState = stateFactory.newSignUpConfirmState( + details, + onResendCode = { resendSignUpCode(username) }, + onSubmit = { confirmationCode -> confirmSignUp(username, password, confirmationCode) } + ) + moveTo(newState) + } + } + } + + private suspend fun handleResetRequiredSignIn(username: String) { + when (val result = authProvider.resetPassword(username)) { + is AmplifyResult.Error -> moveTo(AuthenticatorStep.PasswordReset) + is AmplifyResult.Success -> handleResetPasswordSuccess(username, result.data) + } + } + + private suspend fun handleSignInSuccess(username: String, password: String, result: AuthSignInResult) { + when (result.nextStep.signInStep) { + AuthSignInStep.DONE -> checkVerificationMechanisms() + AuthSignInStep.CONFIRM_SIGN_IN_WITH_SMS_MFA_CODE -> moveTo( + stateFactory.newSignInMfaState( + result.nextStep.codeDeliveryDetails + ) { confirmationCode -> confirmSignIn(username, password, confirmationCode) } + ) + AuthSignInStep.CONFIRM_SIGN_IN_WITH_CUSTOM_CHALLENGE -> moveTo( + stateFactory.newSignInConfirmCustomState( + result.nextStep.codeDeliveryDetails, + result.nextStep.additionalInfo ?: emptyMap() + ) { confirmationCode -> confirmSignIn(username, password, confirmationCode) } + ) + AuthSignInStep.CONFIRM_SIGN_IN_WITH_NEW_PASSWORD -> moveTo( + stateFactory.newSignInConfirmNewPasswordState { newPassword -> + setNewSignInPassword(username, newPassword) + } + ) + // This step isn't actually returned, it comes back as a PasswordResetRequiredException. + // Handling here for future correctness + AuthSignInStep.RESET_PASSWORD -> handleResetRequiredSignIn(username) + // This step isn't actually returned, it comes back as a UserNotConfirmedException. + // Handling here for future correctness + AuthSignInStep.CONFIRM_SIGN_UP -> handleUnconfirmedSignIn(username, password) + } + } + + private suspend fun checkVerificationMechanisms() { + val mechanisms = authConfiguration.verificationMechanisms + if (mechanisms.isEmpty()) { + handleSignedIn() + } else { + when (val result = authProvider.fetchUserAttributes()) { + is AmplifyResult.Error -> { + // We can't verify their attributes, simply skip it and continue + // the sign in + handleSignedIn() + } + is AmplifyResult.Success -> { + val hasVerified = mechanisms.any { mechanism -> + val key = mechanism.toVerifiedAttributeKey() + result.data.any { it.key == key && it.value.toBoolean() } + } + val verificationAttributeKeys = mechanisms.map { it.toAttributeKey() } + val verificationAttributes = result.data.filter { verificationAttributeKeys.contains(it.key) } + if (hasVerified) { + handleSignedIn() + } else { + val newState = stateFactory.newVerifyUserState( + attributes = verificationAttributes, + onSubmit = this::verifyUserAttribute, + onSkip = this::skipUserVerification + ) + moveTo(newState) + } + } + } + } + } + + //endregion + //region Password Reset + + private suspend fun resetPassword(username: String) { + val state = getState() ?: return + viewModelScope.launch { + logger.debug("Initiating reset password") + state.form.markSubmitting { + when (val result = authProvider.resetPassword(username)) { + is AmplifyResult.Error -> handleResetPasswordError(result.error) + is AmplifyResult.Success -> handleResetPasswordSuccess(username, result.data) + } + } + }.join() + } + + private suspend fun confirmResetPassword(username: String, password: String, code: String) { + val state = getState() ?: return + viewModelScope.launch { + logger.debug("Confirming password reset") + state.form.markSubmitting { + when (val result = authProvider.confirmResetPassword(username, password, code)) { + is AmplifyResult.Error -> handleResetPasswordError(result.error) + is AmplifyResult.Success -> handlePasswordResetComplete() + } + } + }.join() + } + + private suspend fun handleResetPasswordSuccess( + username: String, + result: AuthResetPasswordResult + ) { + when (result.nextStep.resetPasswordStep) { + AuthResetPasswordStep.DONE -> handlePasswordResetComplete() + AuthResetPasswordStep.CONFIRM_RESET_PASSWORD_WITH_CODE -> { + logger.debug("Password reset confirmation required") + val state = stateFactory.newResetPasswordConfirmState( + result.nextStep.codeDeliveryDetails + ) { newPassword, confirmationCode -> + confirmResetPassword( + username = username, + password = newPassword, + code = confirmationCode + ) + } + moveTo(state) + } + } + } + + private suspend fun handlePasswordResetComplete() { + logger.debug("Password reset complete") + sendMessage(PasswordResetMessage) + moveTo( + stateFactory.newSignInState(this::signIn) + ) + } + + private suspend fun handleResetPasswordError(error: AuthException) = handleAuthException(error) + +//endregion +//region Sign Out + + private suspend fun signOut() = withContext(viewModelScope.coroutineContext) { + logger.debug("Signing out the user") + authProvider.signOut() + } + +//endregion +// region Verify User + + private suspend fun verifyUserAttribute(key: AuthUserAttributeKey) { + val state = getState() ?: return + viewModelScope.launch { + state.form.markSubmitting { + when (val result = authProvider.resendUserAttributeConfirmationCode(key)) { + is AmplifyResult.Error -> handleAuthException(result.error) + is AmplifyResult.Success -> { + val newState = stateFactory.newVerifyUserConfirmState( + result.data, + onSubmit = { confirmUserAttribute(key, it) }, + onResendCode = { resendUserAttributeCode(key) }, + onSkip = { skipUserVerification() } + ) + moveTo(newState) + } + } + } + }.join() + } + + private fun skipUserVerification() { + viewModelScope.launch { + handleSignedIn() + } + } + + private suspend fun confirmUserAttribute(key: AuthUserAttributeKey, confirmationCode: String) { + val state = getState() ?: return + viewModelScope.launch { + state.form.markSubmitting { + when (val result = authProvider.confirmUserAttribute(key, confirmationCode)) { + is AmplifyResult.Error -> handleAuthException(result.error) + is AmplifyResult.Success -> handleSignedIn() + } + } + }.join() + } + + private suspend fun resendUserAttributeCode(key: AuthUserAttributeKey) { + viewModelScope.launch { + when (val result = authProvider.resendUserAttributeConfirmationCode(key)) { + is AmplifyResult.Error -> handleAuthException(result.error) + is AmplifyResult.Success -> sendMessage(CodeSentMessage) + } + }.join() + } + +//endregion + + private suspend fun handleAuthException(error: AuthException) { + val state = getState() ?: return + when (error) { + is InvalidParameterException -> { + // TODO : This happens if a field is invalid format e.g. phone number + // TODO : User's email is not verified... how to handle? + // This can also occur if no email/phone is set on a created user during + // sign in with a temp password, i.e. FORCE_CHANGE_PASSWORD state + sendMessage(UnknownErrorMessage(error)) + } + is UserNotFoundException -> state.form.setSignInMethodError(NotFound) + is UsernameExistsException -> state.form.setSignInMethodError(FieldValueExists) + is InvalidPasswordException -> state.form.setFieldError(Password, error.toFieldError()) + is NotAuthorizedException -> { + // FORCE_CHANGE_PASSWORD is not allowed to reset password + sendMessage(UnableToResetPasswordMessage(error)) + } + is CodeMismatchException -> state.form.setFieldError(ConfirmationCode, ConfirmationCodeIncorrect) + is CodeDeliveryFailureException -> sendMessage(CannotSendCodeMessage(error)) + is CodeExpiredException -> sendMessage(ExpiredCodeMessage(error)) + is CodeValidationException -> sendMessage(UnknownErrorMessage(error)) + else -> sendMessage(UnknownErrorMessage(error)) + } + } + + private suspend fun handleSignedIn() { + logger.debug("Log in successful, getting current user") + when (val result = authProvider.getCurrentUser()) { + is AmplifyResult.Error -> handleGeneralFailure(result.error) + is AmplifyResult.Success -> moveTo(stateFactory.newSignedInState(result.data, this::signOut)) + } + } + + // Amplify has told us the user signed in. + private suspend fun handleSignedInEvent() { + // TODO : move the user to signedInState *if* we are not in the process of signing in or verifying the user + } + + private fun handleSignedOut() { + logger.debug("User has been signed out") + moveTo(AuthenticatorStep.SignIn) + } + + private fun handleGeneralFailure(error: AuthException) { + moveTo(ErrorState(error)) + } + + private suspend fun sendMessage(event: AuthenticatorMessage) { + logger.debug("Sending message: $event") + _events.emit(event) + } + + private fun FormState.setSignInMethodError(error: FieldError) { + setFieldError(authConfiguration.signInMethod.toFieldKey(), error) + } +} diff --git a/authenticator/src/main/java/com/amplifyframework/ui/authenticator/enums/AuthenticatorStep.kt b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/enums/AuthenticatorStep.kt new file mode 100644 index 00000000..b3c05205 --- /dev/null +++ b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/enums/AuthenticatorStep.kt @@ -0,0 +1,97 @@ +/* + * Copyright 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.enums + +/** + * Denotes an [AuthenticatorStep] that can be an initial step in Authenticator + */ +abstract class AuthenticatorInitialStep internal constructor() : AuthenticatorStep() + +/** + * The [AuthenticatorStep] represents the user's current status in the authentication flow. + */ +abstract class AuthenticatorStep internal constructor() { + + /** + * The Authenticator is in a loading state. We are waiting to check + * the current authentication status. + */ + object Loading : AuthenticatorStep() + + /** + * The Authenticator has encountered an unrecoverable error. + */ + object Error : AuthenticatorStep() + + /** + * The user has successfully authenticated and is now signed in. + */ + object SignedIn : AuthenticatorStep() + + /** + * The user is on the Sign In step + */ + object SignIn : AuthenticatorInitialStep() + + /** + * The user has completed the initial Sign In step, and needs to enter the confirmation code from a custom + * challenge to complete the sign in process. + */ + object SignInConfirmCustomAuth : AuthenticatorStep() + + /** + * The user has completed the initial Sign In step, and needs to enter the confirmation code from an MFA + * message to complete the sign in process. + */ + object SignInConfirmMfa : AuthenticatorStep() + + /** + * The user has completed the initial Sign In step, and is required to change their password in order to complete + * the sign in process. + */ + object SignInConfirmNewPassword : AuthenticatorStep() + + /** + * The user is on the Sign Up step + */ + object SignUp : AuthenticatorInitialStep() + + /** + * The user has signed up, but needs to enter a confirmation code sent to them. + */ + object SignUpConfirm : AuthenticatorStep() + + /** + * The user is on the Password Reset step. They can enter their username to begin the password reset. + */ + object PasswordReset : AuthenticatorInitialStep() + + /** + * The user has entered their username and been sent a confirmation code. The need to enter the code and their new + * password to complete the password reset. + */ + object PasswordResetConfirm : AuthenticatorStep() + + /** + * The user has successfully signed in and their account is confirmed, however they do not have any means of account recovery (email, phone) that is confirmed. + */ + object VerifyUser : AuthenticatorStep() + + /** + * The user has initiated verification of an account recovery mechanism (email, phone) and needs to provide a confirmation code. + */ + object VerifyUserConfirm : AuthenticatorStep() +} diff --git a/authenticator/src/main/java/com/amplifyframework/ui/authenticator/forms/FieldConfig.kt b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/forms/FieldConfig.kt new file mode 100644 index 00000000..83cb6808 --- /dev/null +++ b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/forms/FieldConfig.kt @@ -0,0 +1,156 @@ +/* + * Copyright 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.forms + +import androidx.compose.runtime.Composable +import androidx.compose.runtime.Immutable +import androidx.compose.ui.text.input.KeyboardType +import java.util.* + +/** + * An [FieldConfig] specifies the metadata for an input field within the Authenticator composable. The + * various concrete types represent the different types of supported fields. + */ +@Immutable +abstract class FieldConfig private constructor() { + + /** + * The identifier key for this field. + */ + abstract val key: FieldKey + + /** + * Whether this field requires a non-blank value to submit the form. If [required] is + * true then the [validator] will be prepended with a validator that checks that the + * field content is non-blank. If false, the [label] will have the optional string marker appended. + */ + abstract val required: Boolean + + /** + * The [FieldValidator] instance for this field. If [required] is true + * this validator will be prepended with a check that the field content is non-blank. + */ + abstract val validator: FieldValidator + + /** + * The label for this field. This must be non-null for custom fields. Standard fields will instead + * read their label from resources. + */ + abstract val label: String? + + /** + * The hint for this field. This may be non-null for custom fields. Standard fields will instead + * read their hint from resources. + */ + abstract val hint: String? + + /** + * Configuration instance for a plain text input. + * @param key The identifier key for this field. + * @param required Whether this field requires a non-blank value to submit the form. + * @param validator The [FieldValidator] instance for this field. + * @param label The label for this field. This is null for standard fields. + * @param hint The hint for this field. This is null for standard fields. + * @param keyboardType The type of soft keyboard that is shown when the field is focused. + * @param maxLines The maximum number of lines the field will expand to show. + * @param maxLength The maximum number of characters that can be input into this field. + */ + @Immutable + data class Text internal constructor( + override val key: FieldKey, + override val required: Boolean = true, + override val validator: FieldValidator = FieldValidators.None, + override val label: String? = null, + override val hint: String? = null, + val keyboardType: KeyboardType = KeyboardType.Text, + val maxLines: Int = 1, + val maxLength: Int = 2048 + ) : FieldConfig() + + /** + * Configuration object for a password input + * @param key The identifier key for this field. + * @param required Whether this field requires a non-blank value to submit the form. + * @param validator The [FieldValidator] instance for this field. + * @param label The label for this field. This is null for standard fields. + * @param hint The hint for this field. This is null for standard fields. + * @param keyboardType The type of soft keyboard that is shown when the field is focused. + */ + @Immutable + data class Password internal constructor( + override val key: FieldKey, + override val required: Boolean = true, + override val validator: FieldValidator = FieldValidators.None, + override val label: String? = null, + override val hint: String? = null, + val keyboardType: KeyboardType = KeyboardType.Password + ) : FieldConfig() + + /** + * Configuration object for a date input + * @param key The identifier key for this field. + * @param required Whether this field requires a non-blank value to submit the form. + * @param validator The [FieldValidator] instance for this field. + * @param label The label for this field. This is null for standard fields. + * @param hint The hint for this field. This is null for standard fields. + */ + @Immutable + data class Date internal constructor( + override val key: FieldKey, + override val required: Boolean = true, + override val validator: FieldValidator = FieldValidators.date(), + override val label: String? = null, + override val hint: String? = null + ) : FieldConfig() + + /** + * Configuration object for a phone number input + * @param key The identifier key for this field. + * @param required Whether this field requires a non-blank value to submit the form. + * @param validator The [FieldValidator] instance for this field. + * @param label The label for this field. This is null for standard fields. + * @param hint The hint for this field. This is null for standard fields. + * @param defaultCountryCode The default country code that is pre-selected for this phone number. + */ + @Immutable + data class PhoneNumber internal constructor( + override val key: FieldKey, + override val required: Boolean = true, + override val validator: FieldValidator = FieldValidators.phoneNumber(), + override val label: String? = null, + override val hint: String? = null + ) : FieldConfig() + + /** + * Configuration object for a custom fields + * @param key The identifier key for this field. + * @param required Whether this field requires a non-blank value to submit the form. + * @param validator The [FieldValidator] instance for this field. + * @param label The label for this field. + * @param hint The hint for this field. + * @param content The composable content for this field. The content composable has a receiver of [FieldScope] + * that provides the state holder instance for the field. + */ + @Immutable + data class Custom internal constructor( + override val key: FieldKey, + override val required: Boolean = false, + override val validator: FieldValidator = FieldValidators.None, + override val label: String, + override val hint: String?, + val content: @Composable FieldScope.() -> Unit + ) : FieldConfig() +} diff --git a/authenticator/src/main/java/com/amplifyframework/ui/authenticator/forms/FieldError.kt b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/forms/FieldError.kt new file mode 100644 index 00000000..9c20228c --- /dev/null +++ b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/forms/FieldError.kt @@ -0,0 +1,91 @@ +/* + * Copyright 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.forms + +import androidx.compose.runtime.Immutable + +/** + * The various errors that can occur during password validation checks. + */ +interface PasswordError { + /** + * Password does not meet the minimum length threshold. + */ + class InvalidPasswordLength(val minimumLength: Int) : PasswordError + + /** + * Password requires at least one digit. + */ + object InvalidPasswordMissingNumber : PasswordError + + /** + * Password requires at least one special character. + */ + object InvalidPasswordMissingSpecial : PasswordError + + /** + * Password requires at least one upper + */ + object InvalidPasswordMissingUpper : PasswordError + object InvalidPasswordMissingLower : PasswordError +} + +abstract class FieldError private constructor() { + /** + * The submitted field value does not exist in the Auth backend. + */ + object NotFound : FieldError() + + /** + * A required field is missing a value. + */ + object MissingRequired : FieldError() + + /** + * The confirm password field value does not match the password field value. + */ + object PasswordsDoNotMatch : FieldError() + + /** + * The field value does not conform to the expected format. + */ + object InvalidFormat : FieldError() + + /** + * A field value conflicts with an existing user account, for example the user tried to sign up + * with a username that already exists. + */ + object FieldValueExists : FieldError() + + /** + * The user entered a confirmation code that is incorrect. + */ + object ConfirmationCodeIncorrect : FieldError() + + /** + * A custom validation error. + */ + class Custom(val message: String) : FieldError() + + /** + * A password failed to meet the configured criteria. + * @param errors The + */ + @Immutable + data class InvalidPassword internal constructor( + val errors: List + ) : FieldError() +} diff --git a/authenticator/src/main/java/com/amplifyframework/ui/authenticator/forms/FieldKey.kt b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/forms/FieldKey.kt new file mode 100644 index 00000000..e7e73a3b --- /dev/null +++ b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/forms/FieldKey.kt @@ -0,0 +1,60 @@ +/* + * Copyright 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.forms + +import com.amplifyframework.auth.AuthUserAttributeKey + +/** + * An [FieldKey] uniquely identifies a particular field in a form. + */ +abstract class FieldKey internal constructor() { + object Username : FieldKey() + object Password : FieldKey() + object ConfirmPassword : FieldKey() + object ConfirmationCode : FieldKey() + object VerificationAttribute : FieldKey() + + /** + * A [UserAttributeKey] is an [FieldKey] for a field that maps to an + * [AuthUserAttributeKey] in Amplify. + */ + abstract class UserAttributeKey internal constructor(val attributeKey: AuthUserAttributeKey) : + FieldKey() + + // Fields supported out-of-the-box + object Email : UserAttributeKey(AuthUserAttributeKey.email()) + object PhoneNumber : UserAttributeKey(AuthUserAttributeKey.phoneNumber()) + object Birthdate : UserAttributeKey(AuthUserAttributeKey.birthdate()) + object FamilyName : UserAttributeKey(AuthUserAttributeKey.familyName()) + object GivenName : UserAttributeKey(AuthUserAttributeKey.givenName()) + object MiddleName : UserAttributeKey(AuthUserAttributeKey.middleName()) + object Name : UserAttributeKey(AuthUserAttributeKey.name()) + object Nickname : UserAttributeKey(AuthUserAttributeKey.nickname()) + object PreferredUsername : UserAttributeKey(AuthUserAttributeKey.preferredUsername()) + object Profile : UserAttributeKey(AuthUserAttributeKey.profile()) + + /** + * The default website field. + */ + object Website : UserAttributeKey(AuthUserAttributeKey.website()) + + /** + * Key for a custom attribute. + * @param attribute The attribute name. This should match the name of a custom attribute configured in your + * Auth backend. + */ + data class Custom(val attribute: String) : UserAttributeKey(AuthUserAttributeKey.custom(attribute)) +} diff --git a/authenticator/src/main/java/com/amplifyframework/ui/authenticator/forms/FieldState.kt b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/forms/FieldState.kt new file mode 100644 index 00000000..822e6236 --- /dev/null +++ b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/forms/FieldState.kt @@ -0,0 +1,58 @@ +/* + * Copyright 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.forms + +import androidx.compose.runtime.Stable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.setValue + +/** + * The [state holder](https://developer.android.com/jetpack/compose/state#managing-state) for a single + * field within a form. + */ +@Stable +interface FieldState { + /** + * The content value of the field. + */ + val content: String + + /** + * The error, if any, associated with this field. Errors may represent client-side validation errors or certain + * classes of server-side error responses. + */ + val error: FieldError? +} + +/** + * The mutable [state holder](https://developer.android.com/jetpack/compose/state#managing-state) for a single + * field within a form. + */ +@Stable +interface MutableFieldState : FieldState { + /** + * The mutable content value of the field. + */ + override var content: String +} + +internal class FieldStateImpl constructor( + initialValue: String = "" +) : MutableFieldState { + override var content by mutableStateOf(initialValue) + override var error by mutableStateOf(null) +} diff --git a/authenticator/src/main/java/com/amplifyframework/ui/authenticator/forms/FieldValidator.kt b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/forms/FieldValidator.kt new file mode 100644 index 00000000..2fe52834 --- /dev/null +++ b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/forms/FieldValidator.kt @@ -0,0 +1,145 @@ +/* + * Copyright 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.forms + +import android.util.Patterns +import com.amplifyframework.ui.authenticator.amplify.PasswordCriteria +import com.amplifyframework.ui.authenticator.forms.FieldError.InvalidFormat +import com.amplifyframework.ui.authenticator.forms.FieldError.PasswordsDoNotMatch +import com.amplifyframework.ui.authenticator.forms.FieldKey.Password +import java.time.format.DateTimeFormatter +import java.time.format.DateTimeParseException +import java.util.regex.Pattern + +/** + * The receiver scope for a [FieldValidator]. Allows access to the content being validated and the other fields in the form. + */ +interface FieldValidatorScope { + val content: String + val formContent: Map +} + +/** + * A validation function for a field. + * @return A [FieldError] instance if the field content is invalid, or null otherwise. + */ +typealias FieldValidator = FieldValidatorScope.() -> FieldError? + +/** + * Concatenate two field validators together. This validator will run first, and the [other] validator will run + * if this validator passes. + * @param other A [FieldValidator] to run if this validator does not produce an error. + */ +internal operator fun FieldValidator.plus(other: FieldValidator): FieldValidator = { this@plus() ?: other() } + +/** + * Common [FieldValidator] implementations. + */ +internal object FieldValidators { + + private val usernamePattern = """[\p{L}\p{M}\p{S}\p{N}\p{P}]+""".toPattern() + private val confirmationCodePattern = """\d{6}""".toPattern() + private val specialRegex = """[\^\$\{}\*\.\[\]\{}\(\)\?\-"!@#%&/\\,><':;|_~`+=\s]+""".toRegex() + private val numbersRegex = "\\d+".toRegex() + private val upperRegex = "[A-Z]+".toRegex() + private val lowerRegex = "[a-z]+".toRegex() + private val dateFormat = DateTimeFormatter.ISO_LOCAL_DATE + + /** + * The empty [FieldValidator] instance. This never returns an error. + */ + val None: FieldValidator = { null } + + internal fun required( + error: FieldError = FieldError.MissingRequired + ): FieldValidator = { + if (content.isBlank()) error else null + } + + private fun matchingField( + other: FieldKey, + error: FieldError + ): FieldValidator = { + if (content != formContent[other]) error else null + } + + fun confirmPassword() = matchingField(Password, PasswordsDoNotMatch) + + private fun pattern( + pattern: Pattern, + error: FieldError = InvalidFormat + ): FieldValidator = { + if (content.isNotBlank() && !pattern.matcher(content).matches()) error else null + } + + fun username() = pattern(usernamePattern) + fun email() = pattern(Patterns.EMAIL_ADDRESS) + fun phoneNumber() = pattern(Patterns.PHONE) + fun webUrl() = pattern(Patterns.WEB_URL) + + fun date( + error: FieldError = InvalidFormat + ): FieldValidator = { + if (content.isNotBlank()) { + try { + dateFormat.parse(content) + null + } catch (e: DateTimeParseException) { + error + } + } else { + null + } + } + + internal fun confirmationCode() = pattern(confirmationCodePattern) + + internal fun password( + criteria: PasswordCriteria + ): FieldValidator = { + if (content.isNotBlank()) { + val potentialErrors = mutableListOf() + if (content.length < criteria.length) { + potentialErrors.add( + PasswordError.InvalidPasswordLength(criteria.length) + ) + } + + if (criteria.requiresSpecial && !specialRegex.containsMatchIn(content)) { + potentialErrors.add(PasswordError.InvalidPasswordMissingSpecial) + } + + if (criteria.requiresNumber && !numbersRegex.containsMatchIn(content)) { + potentialErrors.add(PasswordError.InvalidPasswordMissingNumber) + } + + if (criteria.requiresUpper && !upperRegex.containsMatchIn(content)) { + potentialErrors.add(PasswordError.InvalidPasswordMissingUpper) + } + if (criteria.requiresLower && !lowerRegex.containsMatchIn(content)) { + potentialErrors.add(PasswordError.InvalidPasswordMissingLower) + } + + if (potentialErrors.isNotEmpty()) { + FieldError.InvalidPassword(potentialErrors) + } else { + null + } + } else { + null + } + } +} diff --git a/authenticator/src/main/java/com/amplifyframework/ui/authenticator/forms/FormBuilder.kt b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/forms/FormBuilder.kt new file mode 100644 index 00000000..478caec0 --- /dev/null +++ b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/forms/FormBuilder.kt @@ -0,0 +1,344 @@ +/* + * Copyright 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.forms + +import androidx.compose.runtime.Composable +import androidx.compose.ui.text.input.KeyboardType +import com.amplifyframework.auth.AuthUserAttributeKey +import com.amplifyframework.ui.authenticator.amplify.SignInMethod +import com.amplifyframework.ui.authenticator.amplify.toFieldKey + +internal data class FormData(val fields: List) + +internal fun buildForm(func: FormBuilderImpl.() -> Unit): FormData { + return FormBuilderImpl().apply(func).build() +} + +/** + * Builder API for supplying custom form metadata for the signup form. + */ +interface SignUpFormBuilder { + /** + * Adds the standard username field. + */ + fun username() + fun password() + fun confirmPassword() + fun email(required: Boolean = false) + fun phoneNumber(required: Boolean = false) + fun birthdate(required: Boolean = false) + fun familyName(required: Boolean = false) + fun givenName(required: Boolean = false) + fun middleName(required: Boolean = false) + fun name(required: Boolean = false) + fun nickname(required: Boolean = false) + fun preferredUsername(required: Boolean = false) + fun profile(required: Boolean = false) + fun website(required: Boolean = false) + + fun text( + key: FieldKey, + label: String, + hint: String? = null, + required: Boolean = false, + validator: FieldValidator = FieldValidators.None, + keyboardType: KeyboardType = KeyboardType.Text, + maxLines: Int = 1, + maxLength: Int = 2048 + ) + + fun date( + key: FieldKey, + label: String, + hint: String? = null, + required: Boolean = false, + validator: FieldValidator = FieldValidators.date() + ) + + fun phone( + key: FieldKey, + label: String, + hint: String? = null, + required: Boolean = false, + validator: FieldValidator = FieldValidators.phoneNumber() + ) + + fun custom( + key: FieldKey, + label: String, + hint: String? = null, + required: Boolean = false, + validator: FieldValidator = FieldValidators.None, + content: @Composable FieldScope.() -> Unit + ) +} + +/** + * Receiver context for [SignUpFormBuilder.custom] field content. + */ +interface FieldScope { + /** + * The [FieldState] for the custom field. + */ + val fieldState: MutableFieldState + + /** + * The [FormState] for the entire form. + */ + val formState: FormState +} + +internal class FormBuilderImpl : SignUpFormBuilder { + // Note: Kotlin mutable map preserves entry order + private val fields = mutableMapOf() + + override fun username() { + this += FieldConfig.Text( + key = FieldKey.Username, + required = true, + validator = FieldValidators.username() + ) + } + + override fun password() = password(validator = FieldValidators.None) + + fun password(validator: FieldValidator) { + this += FieldConfig.Password( + key = FieldKey.Password, + validator = validator + ) + } + + override fun confirmPassword() { + this += FieldConfig.Password( + key = FieldKey.ConfirmPassword, + validator = FieldValidators.confirmPassword() + ) + } + + fun confirmationCode() { + this += FieldConfig.Text( + key = FieldKey.ConfirmationCode, + validator = FieldValidators.confirmationCode(), + keyboardType = KeyboardType.Number, + maxLength = 6 + ) + } + + override fun email(required: Boolean) { + this += FieldConfig.Text( + key = FieldKey.Email, + required = required, + validator = FieldValidators.email(), + keyboardType = KeyboardType.Email + ) + } + + override fun phoneNumber(required: Boolean) { + this += FieldConfig.PhoneNumber( + key = FieldKey.PhoneNumber, + required = required, + validator = FieldValidators.phoneNumber() + ) + } + + override fun birthdate(required: Boolean) { + this += FieldConfig.Date( + key = FieldKey.Birthdate, + required = required, + validator = FieldValidators.date() + ) + } + + override fun familyName(required: Boolean) { + this += FieldConfig.Text( + key = FieldKey.FamilyName, + required = required + ) + } + + override fun givenName(required: Boolean) { + this += FieldConfig.Text( + key = FieldKey.GivenName, + required = required + ) + } + + override fun middleName(required: Boolean) { + this += FieldConfig.Text( + key = FieldKey.MiddleName, + required = required + ) + } + + override fun name(required: Boolean) { + this += FieldConfig.Text( + key = FieldKey.Name, + required = required + ) + } + + override fun nickname(required: Boolean) { + this += FieldConfig.Text( + key = FieldKey.Nickname, + required = required + ) + } + + override fun preferredUsername(required: Boolean) { + this += FieldConfig.Text( + key = FieldKey.PreferredUsername, + required = required + ) + } + + override fun profile(required: Boolean) { + this += FieldConfig.Text( + key = FieldKey.Profile, + required = required + ) + } + + override fun website(required: Boolean) { + this += FieldConfig.Text( + key = FieldKey.Website, + required = required, + validator = FieldValidators.webUrl(), + keyboardType = KeyboardType.Uri + ) + } + + override fun text( + key: FieldKey, + label: String, + hint: String?, + required: Boolean, + validator: FieldValidator, + keyboardType: KeyboardType, + maxLines: Int, + maxLength: Int + ) { + this += FieldConfig.Text( + key = key, + label = label, + hint = hint, + required = required, + validator = validator, + keyboardType = keyboardType, + maxLines = maxLines, + maxLength = maxLength + ) + } + + override fun date( + key: FieldKey, + label: String, + hint: String?, + required: Boolean, + validator: FieldValidator + ) { + this += FieldConfig.Date( + key = key, + label = label, + hint = hint, + required = required, + validator = validator + ) + } + + override fun phone( + key: FieldKey, + label: String, + hint: String?, + required: Boolean, + validator: FieldValidator + ) { + this += FieldConfig.PhoneNumber( + key = key, + label = label, + hint = hint, + required = required, + validator = validator + ) + } + + override fun custom( + key: FieldKey, + label: String, + hint: String?, + required: Boolean, + validator: FieldValidator, + content: @Composable FieldScope.() -> Unit + ) { + this += FieldConfig.Custom( + key = key, + label = label, + hint = hint, + required = required, + validator = validator, + content = content + ) + } + + fun verificationAttribute() { + this += FieldConfig.Text( + key = FieldKey.VerificationAttribute + ) + } + + private operator fun plusAssign(config: FieldConfig) { + fields[config.key] = config + } + + fun replaceAndReorderFields(form: FormData) { + val map = form.fields.associateBy { it.key } + // Remove each existing instance of the field so that the form will be reordered as they are re-added + map.keys.forEach { fields.remove(it) } + fields.putAll(map) + } + + fun markRequiredFields( + signInMethod: SignInMethod, + requiredKeys: List + ) { + fields.replaceAll { fieldKey, config -> + if (fieldKey is FieldKey.UserAttributeKey && requiredKeys.contains(fieldKey.attributeKey)) { + config.required() + } else if (fieldKey == signInMethod.toFieldKey()) { + config.required() + } else { + config + } + } + } + + fun build() = FormData(fields = fields.values.toList()) +} + +internal fun FormData.toState(): FormStateImpl { + val state = FormStateImpl() + fields.forEach { state.add(it) } + return state +} + +private fun FieldConfig.required() = when (this) { + is FieldConfig.Text -> copy(required = true) + is FieldConfig.Password -> copy(required = true) + is FieldConfig.Date -> copy(required = true) + is FieldConfig.PhoneNumber -> copy(required = true) + is FieldConfig.Custom -> copy(required = true) + else -> this +} diff --git a/authenticator/src/main/java/com/amplifyframework/ui/authenticator/forms/FormState.kt b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/forms/FormState.kt new file mode 100644 index 00000000..ff3eb597 --- /dev/null +++ b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/forms/FormState.kt @@ -0,0 +1,139 @@ +/* + * Copyright 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.forms + +import androidx.compose.runtime.Stable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.setValue +import com.amplifyframework.auth.AuthUserAttribute + +/** + * The state holder class for an input form within the Authenticator. Holds a collection of fields as well as + * some state values relating to the entire form. + */ +@Stable +interface FormState { + val fields: Map + val submitting: Boolean + val fieldsHidden: Boolean +} + +@Stable +interface MutableFormState : FormState { + override val fields: Map + fun toggleHiddenFields() +} + +@Stable +interface FieldData { + val config: FieldConfig + val state: FieldState + val validator: FieldValidator +} + +@Stable +interface MutableFieldData : FieldData { + override val state: MutableFieldState +} + +internal class FormStateImpl : MutableFormState { + + // Backing property for the fields map + private val _fields = mutableMapOf() + override val fields = _fields + + override var submitting by mutableStateOf(false) + + override var fieldsHidden by mutableStateOf(true) + + private var onSubmit: suspend () -> Unit = {} + + fun add(config: FieldConfig) { + // Prepend the required validator for any fields that are required + var fieldValidator = config.validator + if (config.required) { + fieldValidator = FieldValidators.required() + fieldValidator + } + + fields[config.key] = FieldDataImpl( + config = config, + state = FieldStateImpl(), + validator = fieldValidator + ) + } + + fun validate(): Boolean { + val validationScope = FieldValidatorScopeImpl(fields.mapValues { it.value.state.content }) + _fields.values.forEach { field -> + validationScope.content = field.state.content + field.state.error = validationScope.run(field.validator) + } + return fields.values.all { it.state.error == null } + } + + fun getContent(key: FieldKey): String? { + return fields[key]?.state?.content + } + + override fun toggleHiddenFields() { + fieldsHidden = !fieldsHidden + } + + suspend fun submit() { + if (validate()) { + onSubmit() + } + } + + fun getUserAttributes() = fields.mapNotNull { (key, field) -> + if (key is FieldKey.UserAttributeKey) { + AuthUserAttribute(key.attributeKey, field.state.content.trim()) + } else { + null + } + } + + fun onSubmit(func: suspend () -> Unit) { + onSubmit = func + } +} + +internal class FieldDataImpl( + override val config: FieldConfig, + override val state: FieldStateImpl, + override val validator: FieldValidator +) : MutableFieldData + +internal fun FormState.setFieldError(fieldKey: FieldKey, error: FieldError) { + val impl = this as FormStateImpl + impl.fields[fieldKey]?.state?.error = error +} + +internal inline fun FormState.markSubmitting( + body: () -> Unit +) { + val form = this as FormStateImpl + form.submitting = true + body() + form.submitting = false +} + +internal class FieldValidatorScopeImpl( + override val formContent: Map +) : FieldValidatorScope { + override var content: String = "" +} diff --git a/authenticator/src/main/java/com/amplifyframework/ui/authenticator/locals/LocalStringResolver.kt b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/locals/LocalStringResolver.kt new file mode 100644 index 00000000..1f7c6d4a --- /dev/null +++ b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/locals/LocalStringResolver.kt @@ -0,0 +1,21 @@ +/* + * Copyright 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.locals + +import androidx.compose.runtime.staticCompositionLocalOf +import com.amplifyframework.ui.authenticator.strings.StringResolver + +internal val LocalStringResolver = staticCompositionLocalOf { StringResolver() } diff --git a/authenticator/src/main/java/com/amplifyframework/ui/authenticator/states/PasswordResetConfirmStateImpl.kt b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/states/PasswordResetConfirmStateImpl.kt new file mode 100644 index 00000000..4e7e9f7e --- /dev/null +++ b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/states/PasswordResetConfirmStateImpl.kt @@ -0,0 +1,32 @@ +/* + * Copyright 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.states + +import com.amplifyframework.auth.AuthCodeDeliveryDetails +import com.amplifyframework.ui.authenticator.PasswordResetConfirmState +import com.amplifyframework.ui.authenticator.enums.AuthenticatorInitialStep +import com.amplifyframework.ui.authenticator.enums.AuthenticatorStep +import com.amplifyframework.ui.authenticator.forms.FormStateImpl + +internal class PasswordResetConfirmStateImpl( + override val form: FormStateImpl, + override val deliveryDetails: AuthCodeDeliveryDetails?, + private val onMoveTo: (step: AuthenticatorInitialStep) -> Unit +) : PasswordResetConfirmState { + override val step: AuthenticatorStep = AuthenticatorStep.PasswordResetConfirm + override fun moveTo(step: AuthenticatorInitialStep) = onMoveTo(step) + override suspend fun submitPasswordResetConfirm() = form.submit() +} diff --git a/authenticator/src/main/java/com/amplifyframework/ui/authenticator/states/PasswordResetStateImpl.kt b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/states/PasswordResetStateImpl.kt new file mode 100644 index 00000000..0139fbf1 --- /dev/null +++ b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/states/PasswordResetStateImpl.kt @@ -0,0 +1,30 @@ +/* + * Copyright 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.states + +import com.amplifyframework.ui.authenticator.PasswordResetState +import com.amplifyframework.ui.authenticator.enums.AuthenticatorInitialStep +import com.amplifyframework.ui.authenticator.enums.AuthenticatorStep +import com.amplifyframework.ui.authenticator.forms.FormStateImpl + +internal class PasswordResetStateImpl( + override val form: FormStateImpl, + private val onMoveTo: (step: AuthenticatorInitialStep) -> Unit +) : PasswordResetState { + override val step = AuthenticatorStep.PasswordReset + override fun moveTo(step: AuthenticatorInitialStep) = onMoveTo(step) + override suspend fun submitPasswordReset() = form.submit() +} diff --git a/authenticator/src/main/java/com/amplifyframework/ui/authenticator/states/ScreenStateFactory.kt b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/states/ScreenStateFactory.kt new file mode 100644 index 00000000..00ad9a52 --- /dev/null +++ b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/states/ScreenStateFactory.kt @@ -0,0 +1,264 @@ +/* + * Copyright 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.states + +import com.amplifyframework.auth.AuthCodeDeliveryDetails +import com.amplifyframework.auth.AuthUser +import com.amplifyframework.auth.AuthUserAttribute +import com.amplifyframework.auth.AuthUserAttributeKey +import com.amplifyframework.auth.result.AuthSignOutResult +import com.amplifyframework.ui.authenticator.amplify.AmplifyAuthConfiguration +import com.amplifyframework.ui.authenticator.amplify.PasswordCriteria +import com.amplifyframework.ui.authenticator.amplify.SignInMethod +import com.amplifyframework.ui.authenticator.amplify.toFieldKey +import com.amplifyframework.ui.authenticator.enums.AuthenticatorInitialStep +import com.amplifyframework.ui.authenticator.forms.FieldKey +import com.amplifyframework.ui.authenticator.forms.FieldValidators +import com.amplifyframework.ui.authenticator.forms.FormBuilderImpl +import com.amplifyframework.ui.authenticator.forms.FormData +import com.amplifyframework.ui.authenticator.forms.FormStateImpl +import com.amplifyframework.ui.authenticator.forms.buildForm +import com.amplifyframework.ui.authenticator.forms.toState + +internal class ScreenStateFactory( + private val authConfiguration: AmplifyAuthConfiguration, + private val signUpForm: FormData, + private val onMoveTo: (step: AuthenticatorInitialStep) -> Unit +) { + + fun newSignedInState( + user: AuthUser, + onSignOut: suspend () -> AuthSignOutResult + ): SignedInStateImpl { + return SignedInStateImpl(user, onSignOut) + } + + fun newSignInState( + onSubmit: suspend (username: String, password: String) -> Unit + ): SignInStateImpl { + val form = buildForm { + signInMethod() + password() + }.toState() + + form.onSubmit { + val username = form.getSignInMethod()!! + val password = form.getTrimmed(FieldKey.Password)!! + onSubmit(username, password) + } + + return SignInStateImpl(form, onMoveTo) + } + + fun newSignInMfaState( + codeDeliveryDetails: AuthCodeDeliveryDetails?, + onSubmit: suspend (confirmationCode: String) -> Unit + ): SignInConfirmMfaStateImpl { + val form = buildForm { + confirmationCode() + }.toState() + + form.onSubmit { + val confirmationCode = form.getTrimmed(FieldKey.ConfirmationCode)!! + onSubmit(confirmationCode) + } + return SignInConfirmMfaStateImpl(codeDeliveryDetails, form, onMoveTo) + } + + fun newSignInConfirmCustomState( + codeDeliveryDetails: AuthCodeDeliveryDetails?, + additionalInfo: Map, + onSubmit: suspend (confirmationCode: String) -> Unit + ): SignInConfirmCustomStateImpl { + val form = buildForm { + confirmationCode() + }.toState() + + form.onSubmit { + val confirmationCode = form.getTrimmed(FieldKey.ConfirmationCode)!! + onSubmit(confirmationCode) + } + return SignInConfirmCustomStateImpl(form, codeDeliveryDetails, additionalInfo, onMoveTo) + } + + fun newSignInConfirmNewPasswordState( + onSubmit: suspend (password: String) -> Unit + ): SignInConfirmNewPasswordStateImpl { + val form = buildForm { + password(authConfiguration.passwordCriteria) + confirmPassword() + }.toState() + + form.onSubmit { + val password = form.getTrimmed(FieldKey.Password)!! + onSubmit(password) + } + return SignInConfirmNewPasswordStateImpl(form, onMoveTo) + } + + fun newSignUpState( + onSubmit: suspend (username: String, password: String, attributes: List) -> Unit + ): SignUpStateImpl { + val form = buildForm { + // First add all fields required by configuration in the standard order + signInMethod() + password(authConfiguration.passwordCriteria) + confirmPassword() + authConfiguration.signUpAttributes.forEach { attribute -> + when (attribute) { + AuthUserAttributeKey.birthdate() -> birthdate(required = true) + AuthUserAttributeKey.email() -> email(required = true) + AuthUserAttributeKey.familyName() -> familyName(required = true) + AuthUserAttributeKey.givenName() -> givenName(required = true) + AuthUserAttributeKey.middleName() -> middleName(required = true) + AuthUserAttributeKey.nickname() -> nickname(required = true) + AuthUserAttributeKey.phoneNumber() -> phoneNumber(required = true) + AuthUserAttributeKey.preferredUsername() -> preferredUsername(required = true) + AuthUserAttributeKey.profile() -> profile(required = true) + AuthUserAttributeKey.website() -> website(required = true) + AuthUserAttributeKey.name() -> name(required = true) + } + } + + // Next, replace and reorder the form according to the customer-supplied configuration + replaceAndReorderFields(signUpForm) + + // Lastly, re-mark any of the fields that are required to successfully sign up + markRequiredFields( + authConfiguration.signInMethod, + authConfiguration.signUpAttributes + ) + }.toState() + + form.onSubmit { + val username = form.getSignInMethod() + val password = form.getTrimmed(FieldKey.Password) + val attributes = form.getUserAttributes() + onSubmit(username!!, password!!, attributes) + } + return SignUpStateImpl(form, onMoveTo) + } + + fun newSignUpConfirmState( + deliveryDetails: AuthCodeDeliveryDetails?, + onResendCode: suspend () -> Unit, + onSubmit: suspend (confirmationCode: String) -> Unit + ): SignUpConfirmStateImpl { + val form = buildForm { + confirmationCode() + }.toState() + + form.onSubmit { + val code = form.getTrimmed(FieldKey.ConfirmationCode)!! + onSubmit(code) + } + return SignUpConfirmStateImpl( + deliveryDetails, + form, + onResendCode, + onMoveTo + ) + } + + fun newResetPasswordState( + onSubmit: suspend (username: String) -> Unit + ): PasswordResetStateImpl { + val form = buildForm { + signInMethod() + }.toState() + + form.onSubmit { + onSubmit(form.getSignInMethod()!!) + } + return PasswordResetStateImpl(form, onMoveTo) + } + + fun newResetPasswordConfirmState( + deliveryDetails: AuthCodeDeliveryDetails?, + onSubmit: suspend (newPassword: String, confirmationCode: String) -> Unit + ): PasswordResetConfirmStateImpl { + val form = buildForm { + confirmationCode() + password(authConfiguration.passwordCriteria) + confirmPassword() + }.toState() + + form.onSubmit { + val newPassword = form.getTrimmed(FieldKey.Password)!! + val confirmationCode = form.getTrimmed(FieldKey.ConfirmationCode)!! + onSubmit(newPassword, confirmationCode) + } + return PasswordResetConfirmStateImpl(form, deliveryDetails, onMoveTo) + } + + fun newVerifyUserState( + attributes: List, + onSubmit: suspend (attribute: AuthUserAttributeKey) -> Unit, + onSkip: () -> Unit + ): VerifyUserStateImpl { + val form = buildForm { + verificationAttribute() + }.toState() + + form.onSubmit { + val keyString = form.getTrimmed(FieldKey.VerificationAttribute)!! + val key = AuthUserAttributeKey.custom(keyString) + onSubmit(key) + } + + return VerifyUserStateImpl( + attributes = attributes, + form = form, + onSkip = onSkip + ) + } + + fun newVerifyUserConfirmState( + deliveryDetails: AuthCodeDeliveryDetails?, + onSubmit: suspend (confirmationCode: String) -> Unit, + onResendCode: suspend () -> Unit, + onSkip: () -> Unit + ): VerifyUserConfirmStateImpl { + val form = buildForm { + confirmationCode() + }.toState() + form.onSubmit { + val confirmationCode = form.getTrimmed(FieldKey.ConfirmationCode)!! + onSubmit(confirmationCode) + } + return VerifyUserConfirmStateImpl( + form = form, + deliveryDetails = deliveryDetails, + onResendCode = onResendCode, + onSkip = onSkip + ) + } + + private fun FormBuilderImpl.signInMethod() = + when (authConfiguration.signInMethod) { + SignInMethod.Username -> username() + SignInMethod.Email -> email(required = true) + SignInMethod.PhoneNumber -> phoneNumber(required = true) + } + + private fun FormStateImpl.getSignInMethod() = getTrimmed(authConfiguration.signInMethod.toFieldKey()) + + private fun FormBuilderImpl.password(criteria: PasswordCriteria) { + password(validator = FieldValidators.password(criteria)) + } + + private fun FormStateImpl.getTrimmed(key: FieldKey) = getContent(key)?.trim() +} diff --git a/authenticator/src/main/java/com/amplifyframework/ui/authenticator/states/SignInConfirmCustomStateImpl.kt b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/states/SignInConfirmCustomStateImpl.kt new file mode 100644 index 00000000..ed25514a --- /dev/null +++ b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/states/SignInConfirmCustomStateImpl.kt @@ -0,0 +1,33 @@ +/* + * Copyright 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.states + +import com.amplifyframework.auth.AuthCodeDeliveryDetails +import com.amplifyframework.ui.authenticator.SignInConfirmCustomState +import com.amplifyframework.ui.authenticator.enums.AuthenticatorInitialStep +import com.amplifyframework.ui.authenticator.enums.AuthenticatorStep +import com.amplifyframework.ui.authenticator.forms.FormStateImpl + +internal class SignInConfirmCustomStateImpl( + override val form: FormStateImpl, + override val deliveryDetails: AuthCodeDeliveryDetails?, + override val additionalInfo: Map, + private val onMoveTo: (step: AuthenticatorInitialStep) -> Unit +) : SignInConfirmCustomState { + override val step: AuthenticatorStep = AuthenticatorStep.SignInConfirmCustomAuth + override fun moveTo(step: AuthenticatorInitialStep) = onMoveTo(step) + override suspend fun confirmSignIn() = form.submit() +} diff --git a/authenticator/src/main/java/com/amplifyframework/ui/authenticator/states/SignInConfirmMfaStateImpl.kt b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/states/SignInConfirmMfaStateImpl.kt new file mode 100644 index 00000000..07149627 --- /dev/null +++ b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/states/SignInConfirmMfaStateImpl.kt @@ -0,0 +1,32 @@ +/* + * Copyright 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.states + +import com.amplifyframework.auth.AuthCodeDeliveryDetails +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.FormStateImpl + +internal class SignInConfirmMfaStateImpl( + override val deliveryDetails: AuthCodeDeliveryDetails?, + override val form: FormStateImpl, + private val onMoveTo: (step: AuthenticatorInitialStep) -> Unit +) : SignInConfirmMfaState { + override val step = AuthenticatorStep.SignInConfirmMfa + override fun moveTo(step: AuthenticatorInitialStep) = onMoveTo(step) + override suspend fun confirmSignIn() = form.submit() +} diff --git a/authenticator/src/main/java/com/amplifyframework/ui/authenticator/states/SignInConfirmNewPasswordStateImpl.kt b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/states/SignInConfirmNewPasswordStateImpl.kt new file mode 100644 index 00000000..743d2cb8 --- /dev/null +++ b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/states/SignInConfirmNewPasswordStateImpl.kt @@ -0,0 +1,30 @@ +/* + * Copyright 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.states + +import com.amplifyframework.ui.authenticator.SignInConfirmNewPasswordState +import com.amplifyframework.ui.authenticator.enums.AuthenticatorInitialStep +import com.amplifyframework.ui.authenticator.enums.AuthenticatorStep +import com.amplifyframework.ui.authenticator.forms.FormStateImpl + +internal class SignInConfirmNewPasswordStateImpl( + override val form: FormStateImpl, + private val onMoveTo: (step: AuthenticatorInitialStep) -> Unit +) : SignInConfirmNewPasswordState { + override val step: AuthenticatorStep = AuthenticatorStep.SignInConfirmNewPassword + override fun moveTo(step: AuthenticatorInitialStep) = onMoveTo(step) + override suspend fun confirmSignIn() = form.submit() +} diff --git a/authenticator/src/main/java/com/amplifyframework/ui/authenticator/states/SignInStateImpl.kt b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/states/SignInStateImpl.kt new file mode 100644 index 00000000..b3025b2b --- /dev/null +++ b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/states/SignInStateImpl.kt @@ -0,0 +1,31 @@ +/* + * Copyright 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.states + +import com.amplifyframework.ui.authenticator.SignInState +import com.amplifyframework.ui.authenticator.enums.AuthenticatorInitialStep +import com.amplifyframework.ui.authenticator.enums.AuthenticatorStep +import com.amplifyframework.ui.authenticator.forms.FormStateImpl + +internal class SignInStateImpl( + override val form: FormStateImpl, + private val onMoveTo: (step: AuthenticatorInitialStep) -> Unit +) : SignInState { + override val step = AuthenticatorStep.SignIn + override fun moveTo(step: AuthenticatorInitialStep) = onMoveTo(step) + + override suspend fun signIn() = form.submit() +} diff --git a/authenticator/src/main/java/com/amplifyframework/ui/authenticator/states/SignUpConfirmStateImpl.kt b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/states/SignUpConfirmStateImpl.kt new file mode 100644 index 00000000..c5bf62ad --- /dev/null +++ b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/states/SignUpConfirmStateImpl.kt @@ -0,0 +1,34 @@ +/* + * Copyright 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.states + +import com.amplifyframework.auth.AuthCodeDeliveryDetails +import com.amplifyframework.ui.authenticator.SignUpConfirmState +import com.amplifyframework.ui.authenticator.enums.AuthenticatorInitialStep +import com.amplifyframework.ui.authenticator.enums.AuthenticatorStep +import com.amplifyframework.ui.authenticator.forms.FormStateImpl + +internal data class SignUpConfirmStateImpl( + override val deliveryDetails: AuthCodeDeliveryDetails?, + override val form: FormStateImpl, + private val onResendCode: suspend () -> Unit, + private val onMoveTo: (step: AuthenticatorInitialStep) -> Unit +) : SignUpConfirmState { + override val step = AuthenticatorStep.SignUpConfirm + override fun moveTo(step: AuthenticatorInitialStep) = onMoveTo(step) + override suspend fun confirmSignUp() = form.submit() + override suspend fun resendCode() = onResendCode() +} diff --git a/authenticator/src/main/java/com/amplifyframework/ui/authenticator/states/SignUpStateImpl.kt b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/states/SignUpStateImpl.kt new file mode 100644 index 00000000..07fabd36 --- /dev/null +++ b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/states/SignUpStateImpl.kt @@ -0,0 +1,30 @@ +/* + * Copyright 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.states + +import com.amplifyframework.ui.authenticator.SignUpState +import com.amplifyframework.ui.authenticator.enums.AuthenticatorInitialStep +import com.amplifyframework.ui.authenticator.enums.AuthenticatorStep +import com.amplifyframework.ui.authenticator.forms.FormStateImpl + +internal data class SignUpStateImpl( + override val form: FormStateImpl, + private val onMoveTo: (step: AuthenticatorInitialStep) -> Unit +) : SignUpState { + override val step = AuthenticatorStep.SignUp + override fun moveTo(step: AuthenticatorInitialStep) = onMoveTo(step) + override suspend fun signUp() = form.submit() +} diff --git a/authenticator/src/main/java/com/amplifyframework/ui/authenticator/states/SignedInStateImpl.kt b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/states/SignedInStateImpl.kt new file mode 100644 index 00000000..9034d04e --- /dev/null +++ b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/states/SignedInStateImpl.kt @@ -0,0 +1,29 @@ +/* + * Copyright 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.states + +import com.amplifyframework.auth.AuthUser +import com.amplifyframework.auth.result.AuthSignOutResult +import com.amplifyframework.ui.authenticator.SignedInState +import com.amplifyframework.ui.authenticator.enums.AuthenticatorStep + +internal class SignedInStateImpl( + override val user: AuthUser, + private val onSignOut: suspend () -> AuthSignOutResult +) : SignedInState { + override val step = AuthenticatorStep.SignedIn + override suspend fun signOut() = onSignOut() +} diff --git a/authenticator/src/main/java/com/amplifyframework/ui/authenticator/states/VerifyUserConfirmStateImpl.kt b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/states/VerifyUserConfirmStateImpl.kt new file mode 100644 index 00000000..72d7e157 --- /dev/null +++ b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/states/VerifyUserConfirmStateImpl.kt @@ -0,0 +1,33 @@ +/* + * Copyright 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.states + +import com.amplifyframework.auth.AuthCodeDeliveryDetails +import com.amplifyframework.ui.authenticator.VerifyUserConfirmState +import com.amplifyframework.ui.authenticator.enums.AuthenticatorStep +import com.amplifyframework.ui.authenticator.forms.FormStateImpl + +internal class VerifyUserConfirmStateImpl( + override val form: FormStateImpl, + override val deliveryDetails: AuthCodeDeliveryDetails?, + private val onResendCode: suspend () -> Unit, + private val onSkip: () -> Unit +) : VerifyUserConfirmState { + override val step = AuthenticatorStep.VerifyUserConfirm + override suspend fun confirmVerifyUser() = form.submit() + override suspend fun resendCode() = onResendCode() + override fun skip() = onSkip() +} diff --git a/authenticator/src/main/java/com/amplifyframework/ui/authenticator/states/VerifyUserStateImpl.kt b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/states/VerifyUserStateImpl.kt new file mode 100644 index 00000000..4178030b --- /dev/null +++ b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/states/VerifyUserStateImpl.kt @@ -0,0 +1,31 @@ +/* + * Copyright 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.states + +import com.amplifyframework.auth.AuthUserAttribute +import com.amplifyframework.ui.authenticator.VerifyUserState +import com.amplifyframework.ui.authenticator.enums.AuthenticatorStep +import com.amplifyframework.ui.authenticator.forms.FormStateImpl + +internal class VerifyUserStateImpl( + override val attributes: List, + override val form: FormStateImpl, + private val onSkip: () -> Unit +) : VerifyUserState { + override val step = AuthenticatorStep.VerifyUser + override suspend fun verifyUser() = form.submit() + override fun skip() = onSkip() +} diff --git a/authenticator/src/main/java/com/amplifyframework/ui/authenticator/strings/StringResolver.kt b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/strings/StringResolver.kt new file mode 100644 index 00000000..ec6617a9 --- /dev/null +++ b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/strings/StringResolver.kt @@ -0,0 +1,162 @@ +/* + * Copyright 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.strings + +import androidx.compose.runtime.Composable +import androidx.compose.runtime.ReadOnlyComposable +import androidx.compose.ui.ExperimentalComposeUiApi +import androidx.compose.ui.res.pluralStringResource +import androidx.compose.ui.res.stringResource +import com.amplifyframework.auth.AuthException +import com.amplifyframework.ui.authenticator.R +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.forms.PasswordError +import com.amplifyframework.ui.authenticator.locals.LocalStringResolver + +internal open class StringResolver { + @Composable + @ReadOnlyComposable + open fun label(config: FieldConfig): String { + var label = title(config) + if (!config.required) { + label = stringResource(R.string.authenticator_field_optional, label) + } + return label + } + + @Composable + @ReadOnlyComposable + private fun title(config: FieldConfig): String { + return config.label ?: when (config.key) { + FieldKey.ConfirmPassword -> stringResource(R.string.authenticator_field_label_password_confirm) + FieldKey.ConfirmationCode -> stringResource(R.string.authenticator_field_label_confirmation_code) + FieldKey.Password -> stringResource(R.string.authenticator_field_label_password) + FieldKey.PhoneNumber -> stringResource(R.string.authenticator_field_label_phone_number) + FieldKey.Email -> stringResource(R.string.authenticator_field_label_email) + FieldKey.Username -> stringResource(R.string.authenticator_field_label_username) + FieldKey.Birthdate -> stringResource(R.string.authenticator_field_label_birthdate) + FieldKey.FamilyName -> stringResource(R.string.authenticator_field_label_family_name) + FieldKey.GivenName -> stringResource(R.string.authenticator_field_label_given_name) + FieldKey.MiddleName -> stringResource(R.string.authenticator_field_label_middle_name) + FieldKey.Name -> stringResource(R.string.authenticator_field_label_name) + FieldKey.Website -> stringResource(R.string.authenticator_field_label_website) + FieldKey.PhoneNumber -> stringResource(R.string.authenticator_field_label_phone_number) + FieldKey.Nickname -> stringResource(R.string.authenticator_field_label_nickname) + FieldKey.PreferredUsername -> stringResource(R.string.authenticator_field_label_preferred_username) + FieldKey.Profile -> stringResource(R.string.authenticator_field_label_profile) + FieldKey.VerificationAttribute -> stringResource(R.string.authenticator_field_label_verification_attribute) + else -> "" + } + } + + @Composable + @ReadOnlyComposable + open fun hint(config: FieldConfig): String? { + return config.hint ?: when { + config.key == FieldKey.ConfirmPassword -> stringResource(R.string.authenticator_field_hint_password_confirm) + config is FieldConfig.Date -> "yyyy-mm-dd" + else -> { + val label = label(config) + stringResource(R.string.authenticator_field_hint, label) + } + } + } + + @OptIn(ExperimentalComposeUiApi::class) + @Composable + @ReadOnlyComposable + open fun error(config: FieldConfig, error: FieldError): String { + return when (error) { + is FieldError.InvalidPassword -> { + var errorText = stringResource(R.string.authenticator_field_password_requirements) + error.errors.forEach { + errorText += "\n" + when (it) { + is PasswordError.InvalidPasswordLength -> + pluralStringResource( + id = R.plurals.authenticator_field_password_too_short, + count = it.minimumLength, + it.minimumLength + ) + PasswordError.InvalidPasswordMissingSpecial -> + stringResource(R.string.authenticator_field_password_missing_special) + PasswordError.InvalidPasswordMissingNumber -> + stringResource(R.string.authenticator_field_password_missing_number) + PasswordError.InvalidPasswordMissingUpper -> + stringResource(R.string.authenticator_field_password_missing_upper) + PasswordError.InvalidPasswordMissingLower -> + stringResource(R.string.authenticator_field_password_missing_lower) + else -> "" + } + } + errorText + } + FieldError.PasswordsDoNotMatch -> stringResource(R.string.authenticator_field_warn_unmatched_password_confirm) + FieldError.MissingRequired -> { + val label = title(config) + stringResource(R.string.authenticator_field_warn_empty, label) + } + FieldError.InvalidFormat -> { + val label = title(config) + stringResource(R.string.authenticator_field_warn_invalid_format, label) + } + FieldError.FieldValueExists -> { + val label = title(config) + stringResource(R.string.authenticator_field_warn_already_exists, label) + } + FieldError.ConfirmationCodeIncorrect -> { + stringResource(R.string.authenticator_field_warn_incorrect_code) + } + is FieldError.Custom -> error.message + FieldError.NotFound -> { + val label = title(config) + stringResource(R.string.authenticator_field_warn_not_found, label) + } + else -> "" + } + } + + @Composable + @ReadOnlyComposable + open fun error(error: AuthException): String { + return when (error) { + else -> stringResource(R.string.authenticator_error_unknown) + } + } + + companion object { + @Composable + @ReadOnlyComposable + fun label(config: FieldConfig) = + LocalStringResolver.current.label(config = config) + + @Composable + @ReadOnlyComposable + fun hint(config: FieldConfig) = + LocalStringResolver.current.hint(config = config) + + @Composable + @ReadOnlyComposable + fun error(config: FieldConfig, error: FieldError) = + LocalStringResolver.current.error(config = config, error = error) + + @Composable + @ReadOnlyComposable + fun error(error: AuthException) = + LocalStringResolver.current.error(error = error) + } +} diff --git a/authenticator/src/main/java/com/amplifyframework/ui/authenticator/ui/Authenticator.kt b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/ui/Authenticator.kt new file mode 100644 index 00000000..155605a1 --- /dev/null +++ b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/ui/Authenticator.kt @@ -0,0 +1,167 @@ +/* + * Copyright 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 androidx.compose.animation.AnimatedContent +import androidx.compose.animation.AnimatedContentScope +import androidx.compose.animation.ContentTransform +import androidx.compose.animation.ExperimentalAnimationApi +import androidx.compose.animation.core.tween +import androidx.compose.animation.fadeIn +import androidx.compose.animation.fadeOut +import androidx.compose.animation.scaleIn +import androidx.compose.animation.scaleOut +import androidx.compose.animation.with +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.rememberScrollState +import androidx.compose.foundation.verticalScroll +import androidx.compose.material3.SnackbarHost +import androidx.compose.material3.SnackbarHostState +import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.remember +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.LocalContext +import com.amplifyframework.ui.authenticator.AuthenticatorScreenState +import com.amplifyframework.ui.authenticator.AuthenticatorState +import com.amplifyframework.ui.authenticator.ErrorState +import com.amplifyframework.ui.authenticator.LoadingState +import com.amplifyframework.ui.authenticator.PasswordResetConfirmState +import com.amplifyframework.ui.authenticator.PasswordResetState +import com.amplifyframework.ui.authenticator.SignInConfirmCustomState +import com.amplifyframework.ui.authenticator.SignInConfirmMfaState +import com.amplifyframework.ui.authenticator.SignInConfirmNewPasswordState +import com.amplifyframework.ui.authenticator.SignInState +import com.amplifyframework.ui.authenticator.SignUpConfirmState +import com.amplifyframework.ui.authenticator.SignUpState +import com.amplifyframework.ui.authenticator.SignedInState +import com.amplifyframework.ui.authenticator.VerifyUserConfirmState +import com.amplifyframework.ui.authenticator.VerifyUserState +import com.amplifyframework.ui.authenticator.rememberAuthenticatorState +import com.amplifyframework.ui.authenticator.util.AuthenticatorMessage + +/** + * The Composable Authenticator UI. + * @param modifier The [Modifier] instance. + * @param state The state holder for the Authenticator. + * @param loadingContent The content to show for the [LoadingState]. + * @param signInContent The content to show for the [SignInState]. + * @param signInConfirmMfaContent The content to show for the [SignInConfirmMfaState]. + * @param signInConfirmCustomContent The content to show for the [SignInConfirmCustomState]. + * @param signInConfirmNewPasswordContent The content to show for the [SignInConfirmNewPasswordState]. + * @param signUpContent The content to show for the [SignUpState]. + * @param signUpConfirmContent The content to show for the [SignUpConfirmState]. + * @param passwordResetContent The content to show for the [PasswordResetState]. + * @param passwordResetConfirmContent The content to show for the [PasswordResetConfirmState]. + * @param verifyUserContent The content to show for the [VerifyUserState]. + * @param verifyUserConfirmContent The content to show for the [VerifyUserConfirmState]. + * @param errorContent The content to show for the [ErrorState]. + * @param headerContent The header content to show throughout the Authenticator UI. + * @param footerContent The footer content to show throughout the Authenticator UI. + * @param onDisplayMessage Override the default handling for displaying an [AuthenticatorMessage]. + * @param content The content shown when the Authenticator reaches the [SignedInState]. + */ +@OptIn(ExperimentalAnimationApi::class) +@Composable +fun Authenticator( + modifier: Modifier = Modifier, + state: AuthenticatorState = rememberAuthenticatorState(), + loadingContent: @Composable () -> Unit = { AuthenticatorLoading() }, + signInContent: @Composable (state: SignInState) -> Unit = { SignIn(it) }, + signInConfirmMfaContent: @Composable (state: SignInConfirmMfaState) -> Unit = { SignInConfirmMfa(it) }, + signInConfirmCustomContent: @Composable (state: SignInConfirmCustomState) -> Unit = { SignInConfirmCustom(it) }, + signInConfirmNewPasswordContent: @Composable (state: SignInConfirmNewPasswordState) -> Unit = { + SignInConfirmNewPassword(it) + }, + signUpContent: @Composable (state: SignUpState) -> Unit = { SignUp(it) }, + signUpConfirmContent: @Composable (state: SignUpConfirmState) -> Unit = { SignUpConfirm(it) }, + passwordResetContent: @Composable (state: PasswordResetState) -> Unit = { PasswordReset(it) }, + passwordResetConfirmContent: @Composable (state: PasswordResetConfirmState) -> Unit = { PasswordResetConfirm(it) }, + verifyUserContent: @Composable (state: VerifyUserState) -> Unit = { VerifyUser(it) }, + verifyUserConfirmContent: @Composable (state: VerifyUserConfirmState) -> Unit = { VerifyUserConfirm(it) }, + errorContent: @Composable (state: ErrorState) -> Unit = { AuthenticatorError(it) }, + headerContent: @Composable () -> Unit = {}, + footerContent: @Composable () -> Unit = {}, + onDisplayMessage: (suspend (AuthenticatorMessage) -> Unit)? = null, + content: @Composable (state: SignedInState) -> Unit +) { + val snackbarState = remember { SnackbarHostState() } + val context = LocalContext.current + + val screenState = state.screenState + + if (screenState is SignedInState) { + content(screenState) + } else { + Box(modifier = modifier) { + AnimatedContent( + targetState = screenState, + transitionSpec = { defaultTransition() } + ) { targetState -> + Column( + modifier = Modifier.verticalScroll(rememberScrollState()) + ) { + headerContent() + when (targetState) { + is LoadingState -> loadingContent() + is SignInState -> signInContent(targetState) + is SignInConfirmMfaState -> signInConfirmMfaContent(targetState) + is SignInConfirmCustomState -> signInConfirmCustomContent(targetState) + is SignInConfirmNewPasswordState -> signInConfirmNewPasswordContent( + targetState + ) + is SignUpState -> signUpContent(targetState) + is PasswordResetState -> passwordResetContent(targetState) + is PasswordResetConfirmState -> passwordResetConfirmContent(targetState) + is ErrorState -> errorContent(targetState) + is SignUpConfirmState -> signUpConfirmContent(targetState) + is VerifyUserState -> verifyUserContent(targetState) + is VerifyUserConfirmState -> verifyUserConfirmContent(targetState) + else -> Unit + } + footerContent() + } + } + SnackbarHost(hostState = snackbarState, modifier = Modifier.align(Alignment.BottomCenter)) + } + } + + LaunchedEffect(Unit) { + state.messages.collect { event -> + if (onDisplayMessage != null) { + onDisplayMessage(event) + } else { + snackbarState.showSnackbar(event.message(context)) + } + } + } +} + +@OptIn(ExperimentalAnimationApi::class) +internal fun AnimatedContentScope.defaultTransition(): ContentTransform { + // Show reverse transition when going back to signIn + if (targetState is SignInState && initialState != LoadingState) { + return fadeIn(animationSpec = tween(220, delayMillis = 90)) with + scaleOut(targetScale = 0.92f, animationSpec = tween(90)) + + fadeOut(animationSpec = tween(90)) + } + // Show forward transition for all others + return fadeIn(animationSpec = tween(220, delayMillis = 90)) + + scaleIn(initialScale = 0.92f, animationSpec = tween(220, delayMillis = 90)) with + fadeOut(animationSpec = tween(90)) +} diff --git a/authenticator/src/main/java/com/amplifyframework/ui/authenticator/ui/AuthenticatorError.kt b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/ui/AuthenticatorError.kt new file mode 100644 index 00000000..ef0e32f4 --- /dev/null +++ b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/ui/AuthenticatorError.kt @@ -0,0 +1,53 @@ +/* + * Copyright 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 androidx.compose.foundation.background +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.padding +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.unit.dp +import com.amplifyframework.ui.authenticator.ErrorState +import com.amplifyframework.ui.authenticator.strings.StringResolver + +/** + * The content displayed when Authenticator is in the ErrorState + */ +@Composable +fun AuthenticatorError( + state: ErrorState, + modifier: Modifier = Modifier +) { + Box( + modifier = modifier + .fillMaxWidth() + .padding(16.dp) + .background(MaterialTheme.colorScheme.errorContainer) + .padding(16.dp), + contentAlignment = Alignment.Center + ) { + val message = StringResolver.error(state.error) + Text( + text = message, + color = MaterialTheme.colorScheme.onErrorContainer + ) + } +} diff --git a/authenticator/src/main/java/com/amplifyframework/ui/authenticator/ui/AuthenticatorField.kt b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/ui/AuthenticatorField.kt new file mode 100644 index 00000000..c4dbb326 --- /dev/null +++ b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/ui/AuthenticatorField.kt @@ -0,0 +1,95 @@ +/* + * Copyright 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 androidx.compose.animation.AnimatedVisibility +import androidx.compose.animation.expandVertically +import androidx.compose.animation.fadeIn +import androidx.compose.animation.fadeOut +import androidx.compose.animation.shrinkVertically +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import com.amplifyframework.ui.authenticator.forms.FieldConfig +import com.amplifyframework.ui.authenticator.forms.FieldError +import com.amplifyframework.ui.authenticator.forms.FieldScope +import com.amplifyframework.ui.authenticator.forms.FormState +import com.amplifyframework.ui.authenticator.forms.MutableFieldState +import com.amplifyframework.ui.authenticator.forms.MutableFormState +import com.amplifyframework.ui.authenticator.strings.StringResolver + +@Composable +internal fun AuthenticatorField( + fieldConfig: FieldConfig, + fieldState: MutableFieldState, + formState: MutableFormState, + modifier: Modifier = Modifier +) { + when (fieldConfig) { + is FieldConfig.Text -> TextInputField( + modifier = modifier, + fieldConfig = fieldConfig, + fieldState = fieldState, + enabled = !formState.submitting + ) + is FieldConfig.Password -> PasswordInputField( + modifier = modifier, + fieldConfig = fieldConfig, + fieldState = fieldState, + enabled = !formState.submitting, + hidden = formState.fieldsHidden, + onClickHideShow = { formState.toggleHiddenFields() } + ) + is FieldConfig.Date -> DateInputField( + modifier = modifier, + fieldConfig = fieldConfig, + fieldState = fieldState, + enabled = !formState.submitting + ) + is FieldConfig.PhoneNumber -> PhoneInputField( + modifier = modifier, + fieldConfig = fieldConfig, + fieldState = fieldState, + enabled = !formState.submitting + ) + is FieldConfig.Custom -> { + val context = FieldScopeImpl(fieldState, formState) + fieldConfig.content(context) + } + } +} + +@Composable +internal fun AuthenticatorFieldError( + fieldConfig: FieldConfig, + error: FieldError?, + modifier: Modifier = Modifier +) { + AnimatedVisibility( + modifier = modifier, + visible = error != null, + enter = fadeIn() + expandVertically(), + exit = fadeOut() + shrinkVertically() + ) { + val text = error?.let { StringResolver.error(config = fieldConfig, error = it) } ?: "" + Text(text = text) + } +} + +private class FieldScopeImpl( + override val fieldState: MutableFieldState, + override val formState: FormState +) : FieldScope diff --git a/authenticator/src/main/java/com/amplifyframework/ui/authenticator/ui/AuthenticatorForm.kt b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/ui/AuthenticatorForm.kt new file mode 100644 index 00000000..e7c1a1db --- /dev/null +++ b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/ui/AuthenticatorForm.kt @@ -0,0 +1,87 @@ +/* + * Copyright 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 androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.size +import androidx.compose.material3.Button +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.unit.dp +import com.amplifyframework.ui.authenticator.R +import com.amplifyframework.ui.authenticator.forms.MutableFormState + +/** + * Displays the input fields for a [MutableFormState]. + * @param state The [MutableFormState] holding the form's state. + * @param modifier The Modifier for the composable. + */ +@Composable +internal fun AuthenticatorForm( + state: MutableFormState, + modifier: Modifier = Modifier +) { + Column( + modifier = modifier, + horizontalAlignment = Alignment.CenterHorizontally, + verticalArrangement = Arrangement.spacedBy(8.dp) + ) { + state.fields.values.forEach { field -> + AuthenticatorField( + modifier = Modifier.fillMaxWidth(), + fieldConfig = field.config, + fieldState = field.state, + formState = state + ) + } + Spacer(modifier = Modifier.size(16.dp)) + } +} + +/** + * The button displayed in Authenticator. + * @param onClick The click handler for the button + * @param loading True to show the [loadingIndicator] content, false to show the button label. + * @param modifier The [Modifier] for the composable. + * @param label The label for the button + * @param loadingIndicator The content to show when loading. + */ +@Composable +internal fun AuthenticatorButton( + onClick: () -> Unit, + loading: Boolean, + modifier: Modifier = Modifier, + label: String = stringResource(R.string.authenticator_button_submit), + loadingIndicator: @Composable () -> Unit = { LoadingIndicator() } +) { + Button( + modifier = modifier.fillMaxWidth(), + onClick = onClick, + enabled = !loading + ) { + if (loading) { + loadingIndicator() + } else { + Text(label) + } + } +} diff --git a/authenticator/src/main/java/com/amplifyframework/ui/authenticator/ui/AuthenticatorLoading.kt b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/ui/AuthenticatorLoading.kt new file mode 100644 index 00000000..a0966995 --- /dev/null +++ b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/ui/AuthenticatorLoading.kt @@ -0,0 +1,108 @@ +/* + * Copyright 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 androidx.compose.animation.core.RepeatMode +import androidx.compose.animation.core.StartOffset +import androidx.compose.animation.core.StartOffsetType +import androidx.compose.animation.core.animateFloat +import androidx.compose.animation.core.infiniteRepeatable +import androidx.compose.animation.core.rememberInfiniteTransition +import androidx.compose.animation.core.tween +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.aspectRatio +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.offset +import androidx.compose.foundation.layout.size +import androidx.compose.foundation.shape.CircleShape +import androidx.compose.material3.MaterialTheme +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.clip +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.unit.Dp +import androidx.compose.ui.unit.dp + +/** + * Content displayed when Authenticator is in the LoadingState. + */ +@Composable +fun AuthenticatorLoading(modifier: Modifier = Modifier) { + Box( + modifier = modifier + .fillMaxWidth() + .height(150.dp), + contentAlignment = Alignment.Center + ) { + LoadingIndicator() + } +} + +@Composable +private fun LoadingDot( + modifier: Modifier = Modifier, + color: Color +) { + Box( + modifier = modifier + .clip(shape = CircleShape) + .background(color = color) + ) +} + +@Composable +internal fun LoadingIndicator( + modifier: Modifier = Modifier, + color: Color = MaterialTheme.colorScheme.primary, + dotSize: Dp = 12.dp, + dotSpacing: Dp = 8.dp +) { + val magnitude = dotSize.value / 2 + Row( + modifier = modifier, + verticalAlignment = Alignment.CenterVertically, + horizontalArrangement = Arrangement.spacedBy(dotSpacing) + ) { + for (i in 0 until 3) { + val transition = rememberInfiniteTransition() + val offset by transition.animateFloat( + initialValue = magnitude, + targetValue = -magnitude, + animationSpec = infiniteRepeatable( + animation = tween(durationMillis = 450), + repeatMode = RepeatMode.Reverse, + initialStartOffset = StartOffset( + offsetMillis = i * 150, + StartOffsetType.FastForward + ) + ) + ) + LoadingDot( + color = color, + modifier = Modifier + .size(dotSize) + .aspectRatio(1f) + .offset(y = offset.dp) + ) + } + } +} diff --git a/authenticator/src/main/java/com/amplifyframework/ui/authenticator/ui/AuthenticatorTitle.kt b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/ui/AuthenticatorTitle.kt new file mode 100644 index 00000000..b43dfdce --- /dev/null +++ b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/ui/AuthenticatorTitle.kt @@ -0,0 +1,39 @@ +/* + * Copyright 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 androidx.compose.foundation.layout.padding +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.testTag +import androidx.compose.ui.unit.dp + +/** + * Composable for the title shown at the top of each state's content in Authenticator. + */ +@Composable +internal fun AuthenticatorTitle( + text: String, + modifier: Modifier = Modifier +) { + Text( + style = MaterialTheme.typography.titleLarge, + text = text, + modifier = modifier.padding(bottom = 16.dp).testTag("AuthenticatorTitle") + ) +} diff --git a/authenticator/src/main/java/com/amplifyframework/ui/authenticator/ui/DateInputField.kt b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/ui/DateInputField.kt new file mode 100644 index 00000000..0ddfb97f --- /dev/null +++ b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/ui/DateInputField.kt @@ -0,0 +1,119 @@ +/* + * Copyright 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 androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.text.KeyboardActions +import androidx.compose.foundation.text.KeyboardOptions +import androidx.compose.material3.ExperimentalMaterial3Api +import androidx.compose.material3.OutlinedTextField +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.focus.FocusDirection +import androidx.compose.ui.platform.LocalFocusManager +import androidx.compose.ui.text.AnnotatedString +import androidx.compose.ui.text.input.ImeAction +import androidx.compose.ui.text.input.KeyboardType +import androidx.compose.ui.text.input.OffsetMapping +import androidx.compose.ui.text.input.TransformedText +import androidx.compose.ui.text.input.VisualTransformation +import com.amplifyframework.ui.authenticator.forms.FieldConfig +import com.amplifyframework.ui.authenticator.forms.MutableFieldState +import com.amplifyframework.ui.authenticator.strings.StringResolver + +private val invalidDateChars = """[^\d-]+""".toRegex() + +private object DateVisualTransformation : VisualTransformation { + fun transform(original: String): String { + val trimmed: String = original.take(8) + if (trimmed.length < 4) return trimmed + if (trimmed.length == 4) return "$trimmed-" + val (year, monthAndOrDate) = trimmed.chunked(4) + if (trimmed.length == 5) return "$year-$monthAndOrDate" + if (trimmed.length == 6) return "$year-$monthAndOrDate-" + val (month, date) = monthAndOrDate.chunked(2) + return "$year-$month-$date" + } + + override fun filter(text: AnnotatedString): TransformedText { + return TransformedText( + AnnotatedString(transform(text.text)), + object : OffsetMapping { + override fun originalToTransformed(offset: Int): Int { + if (offset <= 3) return offset + if (offset <= 5) return offset + 1 + if (offset <= 7) return offset + 2 + return 10 + } + + override fun transformedToOriginal(offset: Int): Int { + if (offset <= 4) return offset + if (offset <= 7) return offset - 1 + if (offset <= 10) return offset - 2 + return 8 + } + } + ) + } +} + +@OptIn(ExperimentalMaterial3Api::class) +@Composable +internal fun DateInputField( + fieldConfig: FieldConfig.Date, + fieldState: MutableFieldState, + enabled: Boolean, + modifier: Modifier = Modifier +) { + val focusManager = LocalFocusManager.current + + val label = StringResolver.label(fieldConfig) + val hint = StringResolver.hint(fieldConfig) + OutlinedTextField( + modifier = modifier, + enabled = enabled, + value = fieldState.content.replace("-", ""), + onValueChange = { fieldState.content = filterDate(it) }, + label = { Text(label) }, + placeholder = hint?.let { { Text(it) } }, + visualTransformation = DateVisualTransformation, + singleLine = true, + isError = fieldState.error != null, + keyboardOptions = KeyboardOptions( + keyboardType = KeyboardType.Number, + imeAction = ImeAction.Next + ), + keyboardActions = KeyboardActions( + onNext = { focusManager.moveFocus(FocusDirection.Next) } + ), + supportingText = { + AuthenticatorFieldError( + modifier = Modifier.fillMaxWidth(), + fieldConfig = fieldConfig, + error = fieldState.error + ) + } + ) +} + +private fun filterDate(value: String): String { + val stripped = value.replace(invalidDateChars, "").take(8) + val year = stripped.take(4) + val month = stripped.drop(4).take(2) + val day = stripped.drop(6) + return "$year-$month-$day" +} diff --git a/authenticator/src/main/java/com/amplifyframework/ui/authenticator/ui/DeliveryDetails.kt b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/ui/DeliveryDetails.kt new file mode 100644 index 00000000..3d81564d --- /dev/null +++ b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/ui/DeliveryDetails.kt @@ -0,0 +1,47 @@ +/* + * Copyright 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 androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import com.amplifyframework.auth.AuthCodeDeliveryDetails +import com.amplifyframework.ui.authenticator.R +import com.amplifyframework.ui.authenticator.util.annotatedStringResource + +/** + * Displays a message outlining the information in an [AuthCodeDeliveryDetails]. + * @param details The [AuthCodeDeliveryDetails]. A generic message is shown if the details are null. + * @param modifier The composable Modifier + */ +@Composable +internal fun DeliveryDetails( + details: AuthCodeDeliveryDetails?, + modifier: Modifier = Modifier +) { + val content = when (details?.deliveryMedium) { + AuthCodeDeliveryDetails.DeliveryMedium.EMAIL -> annotatedStringResource( + R.string.authenticator_confirmation_code_sent, + details.destination + ) + AuthCodeDeliveryDetails.DeliveryMedium.SMS -> annotatedStringResource( + R.string.authenticator_confirmation_code_sent, + details.destination + ) + else -> annotatedStringResource(R.string.authenticator_confirmation_code_sent_unknown) + } + Text(modifier = modifier, text = content) +} diff --git a/authenticator/src/main/java/com/amplifyframework/ui/authenticator/ui/PasswordInputField.kt b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/ui/PasswordInputField.kt new file mode 100644 index 00000000..e4b46278 --- /dev/null +++ b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/ui/PasswordInputField.kt @@ -0,0 +1,99 @@ +/* + * Copyright 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 androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.text.KeyboardActions +import androidx.compose.foundation.text.KeyboardOptions +import androidx.compose.material3.ExperimentalMaterial3Api +import androidx.compose.material3.Icon +import androidx.compose.material3.IconButton +import androidx.compose.material3.OutlinedTextField +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.focus.FocusDirection +import androidx.compose.ui.platform.LocalFocusManager +import androidx.compose.ui.res.painterResource +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.text.input.ImeAction +import androidx.compose.ui.text.input.PasswordVisualTransformation +import androidx.compose.ui.text.input.VisualTransformation +import com.amplifyframework.ui.authenticator.R +import com.amplifyframework.ui.authenticator.forms.FieldConfig +import com.amplifyframework.ui.authenticator.forms.MutableFieldState +import com.amplifyframework.ui.authenticator.strings.StringResolver + +@OptIn(ExperimentalMaterial3Api::class) +@Composable +internal fun PasswordInputField( + fieldConfig: FieldConfig.Password, + fieldState: MutableFieldState, + enabled: Boolean, + hidden: Boolean, + onClickHideShow: () -> Unit, + modifier: Modifier = Modifier +) { + val focusManager = LocalFocusManager.current + + val label = StringResolver.label(fieldConfig) + val hint = StringResolver.hint(fieldConfig) + val transformation = if (hidden) PasswordVisualTransformation() else VisualTransformation.None + val trailingIcon = getTrailingIcon(hidden = hidden, onClick = onClickHideShow) + + OutlinedTextField( + modifier = modifier, + enabled = enabled, + value = fieldState.content, + onValueChange = { fieldState.content = it }, + label = { Text(label) }, + placeholder = hint?.let { { Text(it) } }, + visualTransformation = transformation, + singleLine = true, + keyboardOptions = KeyboardOptions( + keyboardType = fieldConfig.keyboardType, + imeAction = ImeAction.Next + ), + keyboardActions = KeyboardActions( + onNext = { focusManager.moveFocus(FocusDirection.Next) } + ), + trailingIcon = trailingIcon, + isError = fieldState.error != null, + supportingText = { + AuthenticatorFieldError( + modifier = Modifier.fillMaxWidth(), + fieldConfig = fieldConfig, + error = fieldState.error + ) + } + ) +} + +private fun getTrailingIcon(hidden: Boolean, onClick: () -> Unit): @Composable (() -> Unit) { + return { + val icon = when (hidden) { + true -> R.drawable.ic_authenticator_visible + false -> R.drawable.ic_authenticator_invisible + } + val contentDescription = when (hidden) { + true -> R.string.authenticator_field_a11y_password_hide + false -> R.string.authenticator_field_a11y_password_show + } + IconButton(onClick = onClick) { + Icon(painter = painterResource(icon), contentDescription = stringResource(contentDescription)) + } + } +} diff --git a/authenticator/src/main/java/com/amplifyframework/ui/authenticator/ui/PasswordReset.kt b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/ui/PasswordReset.kt new file mode 100644 index 00000000..73672073 --- /dev/null +++ b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/ui/PasswordReset.kt @@ -0,0 +1,68 @@ +/* + * Copyright 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 androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.padding +import androidx.compose.material3.Text +import androidx.compose.material3.TextButton +import androidx.compose.runtime.Composable +import androidx.compose.runtime.rememberCoroutineScope +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.unit.dp +import com.amplifyframework.ui.authenticator.PasswordResetState +import com.amplifyframework.ui.authenticator.R +import com.amplifyframework.ui.authenticator.enums.AuthenticatorStep +import kotlinx.coroutines.launch + +@Composable +fun PasswordReset( + state: PasswordResetState, + modifier: Modifier = Modifier, + headerContent: @Composable (PasswordResetState) -> Unit = { AuthenticatorTitle(stringResource(R.string.authenticator_title_password_reset)) }, + footerContent: @Composable (PasswordResetState) -> Unit = { PasswordResetFooter(it) } +) { + val scope = rememberCoroutineScope() + Column( + modifier = modifier + .fillMaxWidth() + .padding(horizontal = 16.dp) + ) { + headerContent(state) + AuthenticatorForm(state = state.form) + AuthenticatorButton( + onClick = { scope.launch { state.submitPasswordReset() } }, + loading = state.form.submitting + ) + footerContent(state) + } +} + +@Composable +fun PasswordResetFooter( + state: PasswordResetState, + modifier: Modifier = Modifier +) { + Box(modifier = modifier.fillMaxWidth(), contentAlignment = Alignment.Center) { + TextButton(onClick = { state.moveTo(AuthenticatorStep.SignIn) }) { + Text(stringResource(R.string.authenticator_button_back_to_signin)) + } + } +} diff --git a/authenticator/src/main/java/com/amplifyframework/ui/authenticator/ui/PasswordResetConfirm.kt b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/ui/PasswordResetConfirm.kt new file mode 100644 index 00000000..a6b96001 --- /dev/null +++ b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/ui/PasswordResetConfirm.kt @@ -0,0 +1,70 @@ +/* + * Copyright 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 androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.padding +import androidx.compose.material3.Text +import androidx.compose.material3.TextButton +import androidx.compose.runtime.Composable +import androidx.compose.runtime.rememberCoroutineScope +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.unit.dp +import com.amplifyframework.auth.AuthCodeDeliveryDetails +import com.amplifyframework.ui.authenticator.PasswordResetConfirmState +import com.amplifyframework.ui.authenticator.R +import com.amplifyframework.ui.authenticator.enums.AuthenticatorStep +import kotlinx.coroutines.launch + +@Composable +fun PasswordResetConfirm( + state: PasswordResetConfirmState, + modifier: Modifier = Modifier, + headerContent: @Composable (PasswordResetConfirmState) -> Unit = { AuthenticatorTitle(stringResource(R.string.authenticator_title_password_reset)) }, + footerContent: @Composable (PasswordResetConfirmState) -> Unit = { PasswordResetConfirmFooter(it) }, + deliveryNoticeContent: @Composable (details: AuthCodeDeliveryDetails?) -> Unit = { DeliveryDetails(it) } +) { + val scope = rememberCoroutineScope() + Column( + modifier = modifier + .fillMaxWidth() + .padding(horizontal = 16.dp) + ) { + headerContent(state) + deliveryNoticeContent(details = state.deliveryDetails) + AuthenticatorForm(state = state.form) + AuthenticatorButton( + onClick = { scope.launch { state.submitPasswordResetConfirm() } }, + loading = state.form.submitting + ) + footerContent(state) + } +} + +@Composable +fun PasswordResetConfirmFooter( + state: PasswordResetConfirmState, + modifier: Modifier = Modifier +) { + Column(modifier = modifier.fillMaxWidth(), horizontalAlignment = Alignment.CenterHorizontally) { + TextButton(onClick = { state.moveTo(AuthenticatorStep.SignIn) }) { + Text(stringResource(R.string.authenticator_button_back_to_signin)) + } + } +} diff --git a/authenticator/src/main/java/com/amplifyframework/ui/authenticator/ui/PhoneInputField.kt b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/ui/PhoneInputField.kt new file mode 100644 index 00000000..e9e3ff7d --- /dev/null +++ b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/ui/PhoneInputField.kt @@ -0,0 +1,183 @@ +/* + * Copyright 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 androidx.compose.foundation.background +import androidx.compose.foundation.clickable +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.width +import androidx.compose.foundation.lazy.LazyColumn +import androidx.compose.foundation.lazy.items +import androidx.compose.foundation.lazy.rememberLazyListState +import androidx.compose.foundation.text.KeyboardActions +import androidx.compose.foundation.text.KeyboardOptions +import androidx.compose.material3.Divider +import androidx.compose.material3.ExperimentalMaterial3Api +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.OutlinedTextField +import androidx.compose.material3.Surface +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.Stable +import androidx.compose.runtime.derivedStateOf +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.saveable.listSaver +import androidx.compose.runtime.saveable.rememberSaveable +import androidx.compose.runtime.setValue +import androidx.compose.ui.Modifier +import androidx.compose.ui.focus.FocusDirection +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.platform.LocalFocusManager +import androidx.compose.ui.text.input.ImeAction +import androidx.compose.ui.text.input.KeyboardType +import androidx.compose.ui.unit.dp +import androidx.compose.ui.window.Dialog +import com.amplifyframework.ui.authenticator.forms.FieldConfig +import com.amplifyframework.ui.authenticator.forms.MutableFieldState +import com.amplifyframework.ui.authenticator.strings.StringResolver +import com.amplifyframework.ui.authenticator.util.dialCodeFor +import com.amplifyframework.ui.authenticator.util.dialCodeList +import java.util.* + +@Stable +private class PhoneNumberFieldState( + initialDialCode: String, + initialNumber: String = "" +) { + var dialCode by mutableStateOf(initialDialCode) + var number by mutableStateOf(initialNumber) + var expanded by mutableStateOf(false) + val fieldValue by derivedStateOf { + if (number.isEmpty()) "" else dialCode + number + } +} + +@OptIn(ExperimentalMaterial3Api::class) +@Composable +internal fun PhoneInputField( + fieldConfig: FieldConfig.PhoneNumber, + fieldState: MutableFieldState, + enabled: Boolean, + modifier: Modifier = Modifier +) { + val focusManager = LocalFocusManager.current + + val label = StringResolver.label(fieldConfig) + val hint = StringResolver.hint(fieldConfig) + + val state = rememberSaveable( + saver = listSaver( + save = { listOf(it.dialCode, it.number) }, + restore = { PhoneNumberFieldState(it[0], it[1]) } + ) + ) { + val countryCode = Locale.getDefault().country + PhoneNumberFieldState(initialDialCode = dialCodeFor(countryCode)) + } + + OutlinedTextField( + modifier = modifier, + enabled = enabled, + value = state.number, + onValueChange = { state.number = it }, + label = { Text(label) }, + leadingIcon = { DialCodeSelector(state) }, + placeholder = hint?.let { { Text(it) } }, + isError = fieldState.error != null, + singleLine = true, + keyboardOptions = KeyboardOptions( + keyboardType = KeyboardType.Phone, + imeAction = ImeAction.Next + ), + keyboardActions = KeyboardActions( + onNext = { focusManager.moveFocus(FocusDirection.Next) } + ), + supportingText = { + AuthenticatorFieldError( + modifier = Modifier.fillMaxWidth(), + fieldConfig = fieldConfig, + error = fieldState.error + ) + } + ) + + LaunchedEffect(state.fieldValue) { + fieldState.content = state.fieldValue + } +} + +@Composable +private fun DialCodeSelector( + state: PhoneNumberFieldState +) { + Text( + modifier = Modifier + .clickable { state.expanded = true } + .padding(8.dp), + text = state.dialCode + ) + + if (state.expanded) { + Dialog( + onDismissRequest = { state.expanded = false } + ) { + val listState = rememberLazyListState( + initialFirstVisibleItemIndex = dialCodeList.indexOf(state.dialCode) + ) + Box( + modifier = Modifier + .padding(vertical = 24.dp) + .width(100.dp) + ) { + Surface { + LazyColumn( + state = listState + ) { + items(dialCodeList) { dialCode -> + val color = if (dialCode == state.dialCode) { + MaterialTheme.colorScheme.onSecondaryContainer + } else { + MaterialTheme.colorScheme.onSurface + } + val background = if (dialCode == state.dialCode) { + MaterialTheme.colorScheme.secondaryContainer + } else { + Color.Transparent + } + Text( + modifier = Modifier + .fillMaxWidth() + .background(background) + .clickable { + state.dialCode = dialCode + state.expanded = false + } + .padding(8.dp), + color = color, + text = dialCode + ) + Divider() + } + } + } + } + } + } +} diff --git a/authenticator/src/main/java/com/amplifyframework/ui/authenticator/ui/SignIn.kt b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/ui/SignIn.kt new file mode 100644 index 00000000..dbc24917 --- /dev/null +++ b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/ui/SignIn.kt @@ -0,0 +1,76 @@ +/* + * Copyright 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 androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.padding +import androidx.compose.material3.Text +import androidx.compose.material3.TextButton +import androidx.compose.runtime.Composable +import androidx.compose.runtime.rememberCoroutineScope +import androidx.compose.ui.Modifier +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.unit.dp +import com.amplifyframework.ui.authenticator.R +import com.amplifyframework.ui.authenticator.SignInState +import com.amplifyframework.ui.authenticator.enums.AuthenticatorStep +import kotlinx.coroutines.launch + +@Composable +fun SignIn( + state: SignInState, + modifier: Modifier = Modifier, + headerContent: @Composable (SignInState) -> Unit = { AuthenticatorTitle(stringResource(R.string.authenticator_title_signin)) }, + footerContent: @Composable (SignInState) -> Unit = { SignInFooter(it) } +) { + val scope = rememberCoroutineScope() + Column( + modifier = modifier.fillMaxWidth().padding(horizontal = 16.dp) + ) { + headerContent(state) + AuthenticatorForm(state = state.form) + AuthenticatorButton( + onClick = { scope.launch { state.signIn() } }, + loading = state.form.submitting, + label = stringResource(R.string.authenticator_button_signin) + ) + footerContent(state) + } +} + +@Composable +fun SignInFooter( + state: SignInState, + modifier: Modifier = Modifier, + hideSignUp: Boolean = false +) { + Row( + modifier = modifier.fillMaxWidth(), + horizontalArrangement = Arrangement.SpaceEvenly + ) { + TextButton(onClick = { state.moveTo(AuthenticatorStep.PasswordReset) }) { + Text(stringResource(R.string.authenticator_button_forgot_password)) + } + if (!hideSignUp) { + TextButton(onClick = { state.moveTo(AuthenticatorStep.SignUp) }) { + Text(stringResource(R.string.authenticator_button_signup)) + } + } + } +} diff --git a/authenticator/src/main/java/com/amplifyframework/ui/authenticator/ui/SignInConfirmCustom.kt b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/ui/SignInConfirmCustom.kt new file mode 100644 index 00000000..6dd02233 --- /dev/null +++ b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/ui/SignInConfirmCustom.kt @@ -0,0 +1,74 @@ +/* + * Copyright 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 androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.padding +import androidx.compose.material3.Text +import androidx.compose.material3.TextButton +import androidx.compose.runtime.Composable +import androidx.compose.runtime.rememberCoroutineScope +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.unit.dp +import com.amplifyframework.auth.AuthCodeDeliveryDetails +import com.amplifyframework.ui.authenticator.R +import com.amplifyframework.ui.authenticator.SignInConfirmCustomState +import com.amplifyframework.ui.authenticator.enums.AuthenticatorStep +import kotlinx.coroutines.launch + +@Composable +fun SignInConfirmCustom( + state: SignInConfirmCustomState, + modifier: Modifier = Modifier, + headerContent: @Composable (state: SignInConfirmCustomState) -> Unit = { AuthenticatorTitle(stringResource(R.string.authenticator_title_signin_confirm_mfa)) }, + footerContent: @Composable (state: SignInConfirmCustomState) -> Unit = { SignInConfirmCustomFooter(it) }, + deliveryDetailsContent: @Composable (details: AuthCodeDeliveryDetails?) -> Unit = { DeliveryDetails(it) } +) { + val scope = rememberCoroutineScope() + Column( + modifier = modifier + .fillMaxWidth() + .padding(horizontal = 16.dp) + ) { + headerContent(state) + deliveryDetailsContent(state.deliveryDetails) + AuthenticatorForm(state = state.form) + AuthenticatorButton( + onClick = { scope.launch { state.confirmSignIn() } }, + loading = state.form.submitting + ) + footerContent(state) + } +} + +@Composable +fun SignInConfirmCustomFooter( + state: SignInConfirmCustomState, + modifier: Modifier = Modifier +) { + Box( + modifier = modifier.fillMaxWidth(), + contentAlignment = Alignment.Center + ) { + TextButton(onClick = { state.moveTo(AuthenticatorStep.SignIn) }) { + Text(stringResource(R.string.authenticator_button_back_to_signin)) + } + } +} diff --git a/authenticator/src/main/java/com/amplifyframework/ui/authenticator/ui/SignInConfirmMfa.kt b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/ui/SignInConfirmMfa.kt new file mode 100644 index 00000000..39cde2c2 --- /dev/null +++ b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/ui/SignInConfirmMfa.kt @@ -0,0 +1,74 @@ +/* + * Copyright 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 androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.padding +import androidx.compose.material3.Text +import androidx.compose.material3.TextButton +import androidx.compose.runtime.Composable +import androidx.compose.runtime.rememberCoroutineScope +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.unit.dp +import com.amplifyframework.auth.AuthCodeDeliveryDetails +import com.amplifyframework.ui.authenticator.R +import com.amplifyframework.ui.authenticator.SignInConfirmMfaState +import com.amplifyframework.ui.authenticator.enums.AuthenticatorStep +import kotlinx.coroutines.launch + +@Composable +fun SignInConfirmMfa( + state: SignInConfirmMfaState, + modifier: Modifier = Modifier, + headerContent: @Composable (state: SignInConfirmMfaState) -> Unit = { AuthenticatorTitle(stringResource(R.string.authenticator_title_signin_confirm_mfa)) }, + footerContent: @Composable (state: SignInConfirmMfaState) -> Unit = { SignInConfirmMfaFooter(it) }, + deliveryNoticeContent: @Composable (details: AuthCodeDeliveryDetails?) -> Unit = { DeliveryDetails(details = it) } +) { + val scope = rememberCoroutineScope() + Column( + modifier = modifier + .fillMaxWidth() + .padding(horizontal = 16.dp) + ) { + headerContent(state) + deliveryNoticeContent(state.deliveryDetails) + AuthenticatorForm(state = state.form) + AuthenticatorButton( + onClick = { scope.launch { state.confirmSignIn() } }, + loading = state.form.submitting + ) + footerContent(state) + } +} + +@Composable +fun SignInConfirmMfaFooter( + state: SignInConfirmMfaState, + modifier: Modifier = Modifier +) { + Box( + modifier = modifier.fillMaxWidth(), + contentAlignment = Alignment.Center + ) { + TextButton(onClick = { state.moveTo(AuthenticatorStep.SignIn) }) { + Text(stringResource(R.string.authenticator_button_back_to_signin)) + } + } +} diff --git a/authenticator/src/main/java/com/amplifyframework/ui/authenticator/ui/SignInConfirmNewPassword.kt b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/ui/SignInConfirmNewPassword.kt new file mode 100644 index 00000000..b48c851a --- /dev/null +++ b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/ui/SignInConfirmNewPassword.kt @@ -0,0 +1,97 @@ +/* + * Copyright 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 androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.padding +import androidx.compose.material3.Text +import androidx.compose.material3.TextButton +import androidx.compose.runtime.Composable +import androidx.compose.runtime.CompositionLocalProvider +import androidx.compose.runtime.ReadOnlyComposable +import androidx.compose.runtime.rememberCoroutineScope +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.unit.dp +import com.amplifyframework.ui.authenticator.R +import com.amplifyframework.ui.authenticator.SignInConfirmNewPasswordState +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.locals.LocalStringResolver +import com.amplifyframework.ui.authenticator.strings.StringResolver +import kotlinx.coroutines.launch + +private object NewPasswordStringResolver : StringResolver() { + @Composable + @ReadOnlyComposable + override fun label(config: FieldConfig): String { + return when (config.key) { + is FieldKey.Password -> + stringResource(R.string.authenticator_field_label_new_password) + is FieldKey.ConfirmPassword -> + stringResource(R.string.authenticator_field_label_new_password_confirm) + else -> + super.label(config) + } + } +} + +@Composable +fun SignInConfirmNewPassword( + state: SignInConfirmNewPasswordState, + modifier: Modifier = Modifier, + headerContent: @Composable (state: SignInConfirmNewPasswordState) -> Unit = { + AuthenticatorTitle(stringResource(R.string.authenticator_title_signin_confirm_new_password)) + }, + footerContent: @Composable (state: SignInConfirmNewPasswordState) -> Unit = { SignInConfirmNewPasswordFooter(it) } +) { + val scope = rememberCoroutineScope() + Column( + modifier = modifier + .fillMaxWidth() + .padding(horizontal = 16.dp) + ) { + headerContent(state) + CompositionLocalProvider(LocalStringResolver provides NewPasswordStringResolver) { + AuthenticatorForm(state = state.form) + } + AuthenticatorButton( + onClick = { scope.launch { state.confirmSignIn() } }, + loading = state.form.submitting, + label = stringResource(R.string.authenticator_button_change_password) + ) + footerContent(state) + } +} + +@Composable +fun SignInConfirmNewPasswordFooter( + state: SignInConfirmNewPasswordState, + modifier: Modifier = Modifier +) { + Box( + modifier = modifier.fillMaxWidth(), + contentAlignment = Alignment.Center + ) { + TextButton(onClick = { state.moveTo(AuthenticatorStep.SignIn) }) { + Text(stringResource(R.string.authenticator_button_back_to_signin)) + } + } +} diff --git a/authenticator/src/main/java/com/amplifyframework/ui/authenticator/ui/SignUp.kt b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/ui/SignUp.kt new file mode 100644 index 00000000..c6d16fbc --- /dev/null +++ b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/ui/SignUp.kt @@ -0,0 +1,67 @@ +/* + * Copyright 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 androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.padding +import androidx.compose.material3.Text +import androidx.compose.material3.TextButton +import androidx.compose.runtime.Composable +import androidx.compose.runtime.rememberCoroutineScope +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.testTag +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.unit.dp +import com.amplifyframework.ui.authenticator.R +import com.amplifyframework.ui.authenticator.SignUpState +import com.amplifyframework.ui.authenticator.enums.AuthenticatorStep +import kotlinx.coroutines.launch + +@Composable +fun SignUp( + state: SignUpState, + modifier: Modifier = Modifier, + headerContent: @Composable (SignUpState) -> Unit = { AuthenticatorTitle(stringResource(R.string.authenticator_title_signup)) }, + footerContent: @Composable (SignUpState) -> Unit = { SignUpFooter(it) } +) { + val scope = rememberCoroutineScope() + Column(modifier = modifier.fillMaxWidth().padding(horizontal = 16.dp)) { + headerContent(state) + AuthenticatorForm(state = state.form) + AuthenticatorButton( + onClick = { scope.launch { state.signUp() } }, + loading = state.form.submitting, + label = stringResource(R.string.authenticator_button_signup), + modifier = Modifier.testTag("SignUpButton") + ) + footerContent(state) + } +} + +@Composable +fun SignUpFooter( + state: SignUpState, + modifier: Modifier = Modifier +) { + Box(modifier = modifier.fillMaxWidth(), contentAlignment = Alignment.Center) { + TextButton(onClick = { state.moveTo(AuthenticatorStep.SignIn) }) { + Text(stringResource(R.string.authenticator_button_back_to_signin)) + } + } +} diff --git a/authenticator/src/main/java/com/amplifyframework/ui/authenticator/ui/SignUpConfirm.kt b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/ui/SignUpConfirm.kt new file mode 100644 index 00000000..ce7ee29a --- /dev/null +++ b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/ui/SignUpConfirm.kt @@ -0,0 +1,82 @@ +/* + * Copyright 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 androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.padding +import androidx.compose.material3.Text +import androidx.compose.material3.TextButton +import androidx.compose.runtime.Composable +import androidx.compose.runtime.rememberCoroutineScope +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.unit.dp +import com.amplifyframework.auth.AuthCodeDeliveryDetails +import com.amplifyframework.ui.authenticator.R +import com.amplifyframework.ui.authenticator.SignUpConfirmState +import com.amplifyframework.ui.authenticator.enums.AuthenticatorStep +import kotlinx.coroutines.launch + +@Composable +fun SignUpConfirm( + state: SignUpConfirmState, + modifier: Modifier = Modifier, + headerContent: @Composable (SignUpConfirmState) -> Unit = { AuthenticatorTitle(stringResource(R.string.authenticator_title_signup_confirm)) }, + footerContent: @Composable (SignUpConfirmState) -> Unit = { SignUpConfirmFooter(it) }, + deliveryNoticeContent: @Composable (AuthCodeDeliveryDetails?) -> Unit = { DeliveryDetails(it) } +) { + val scope = rememberCoroutineScope() + Column(modifier = modifier.fillMaxWidth().padding(horizontal = 16.dp)) { + headerContent(state) + deliveryNoticeContent(state.deliveryDetails) + AuthenticatorForm(state = state.form) + AuthenticatorButton( + onClick = { scope.launch { state.confirmSignUp() } }, + loading = state.form.submitting + ) + footerContent(state) + } +} + +@Composable +fun SignUpConfirmFooter( + state: SignUpConfirmState, + modifier: Modifier = Modifier +) { + val scope = rememberCoroutineScope() + Column( + modifier = modifier.fillMaxWidth(), + horizontalAlignment = Alignment.CenterHorizontally + ) { + Row( + modifier = Modifier.fillMaxWidth(), + horizontalArrangement = Arrangement.SpaceEvenly, + verticalAlignment = Alignment.CenterVertically + ) { + Text(stringResource(R.string.authenticator_button_lost_code)) + TextButton(onClick = { scope.launch { state.resendCode() } }) { + Text(stringResource(R.string.authenticator_button_resend_code)) + } + } + TextButton(onClick = { state.moveTo(AuthenticatorStep.SignIn) }) { + Text(stringResource(R.string.authenticator_button_back_to_signin)) + } + } +} diff --git a/authenticator/src/main/java/com/amplifyframework/ui/authenticator/ui/TextInputField.kt b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/ui/TextInputField.kt new file mode 100644 index 00000000..01a677d9 --- /dev/null +++ b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/ui/TextInputField.kt @@ -0,0 +1,69 @@ +/* + * Copyright 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 androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.text.KeyboardActions +import androidx.compose.foundation.text.KeyboardOptions +import androidx.compose.material3.ExperimentalMaterial3Api +import androidx.compose.material3.OutlinedTextField +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.focus.FocusDirection +import androidx.compose.ui.platform.LocalFocusManager +import androidx.compose.ui.text.input.ImeAction +import com.amplifyframework.ui.authenticator.forms.FieldConfig +import com.amplifyframework.ui.authenticator.forms.MutableFieldState +import com.amplifyframework.ui.authenticator.strings.StringResolver + +@OptIn(ExperimentalMaterial3Api::class) +@Composable +internal fun TextInputField( + fieldConfig: FieldConfig.Text, + fieldState: MutableFieldState, + modifier: Modifier = Modifier, + enabled: Boolean = true +) { + val focusManager = LocalFocusManager.current + + val label = StringResolver.label(fieldConfig) + val hint = StringResolver.hint(fieldConfig) + OutlinedTextField( + modifier = modifier, + enabled = enabled, + value = fieldState.content, + onValueChange = { fieldState.content = it.take(fieldConfig.maxLength) }, + label = { Text(label) }, + placeholder = hint?.let { { Text(it) } }, + isError = fieldState.error != null, + maxLines = fieldConfig.maxLines, + keyboardOptions = KeyboardOptions( + keyboardType = fieldConfig.keyboardType, + imeAction = ImeAction.Next + ), + keyboardActions = KeyboardActions( + onNext = { focusManager.moveFocus(FocusDirection.Next) } + ), + supportingText = { + AuthenticatorFieldError( + modifier = Modifier.fillMaxWidth(), + fieldConfig = fieldConfig, + error = fieldState.error + ) + } + ) +} diff --git a/authenticator/src/main/java/com/amplifyframework/ui/authenticator/ui/VerifyUser.kt b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/ui/VerifyUser.kt new file mode 100644 index 00000000..3cf99f4d --- /dev/null +++ b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/ui/VerifyUser.kt @@ -0,0 +1,114 @@ +/* + * Copyright 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 androidx.compose.foundation.clickable +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.padding +import androidx.compose.material3.RadioButton +import androidx.compose.material3.Text +import androidx.compose.material3.TextButton +import androidx.compose.runtime.Composable +import androidx.compose.runtime.rememberCoroutineScope +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.unit.dp +import com.amplifyframework.auth.AuthUserAttribute +import com.amplifyframework.auth.AuthUserAttributeKey +import com.amplifyframework.ui.authenticator.R +import com.amplifyframework.ui.authenticator.VerifyUserState +import com.amplifyframework.ui.authenticator.forms.FieldKey +import com.amplifyframework.ui.authenticator.forms.FormState +import com.amplifyframework.ui.authenticator.forms.MutableFieldState +import kotlinx.coroutines.launch + +@Composable +fun VerifyUser( + state: VerifyUserState, + modifier: Modifier = Modifier, + headerContent: @Composable (VerifyUserState) -> Unit = { AuthenticatorTitle(stringResource(R.string.authenticator_title_verify_user)) }, + footerContent: @Composable (VerifyUserState) -> Unit = { VerifyUserFooter(it) } +) { + val scope = rememberCoroutineScope() + val fieldState = state.form.fields[FieldKey.VerificationAttribute]?.state!! + + Column( + modifier = modifier + .fillMaxWidth() + .padding(horizontal = 16.dp) + ) { + headerContent(state) + VerifyUserAttributeSelect( + attributes = state.attributes, + fieldState = fieldState, + formState = state.form, + modifier = Modifier.fillMaxWidth() + ) + AuthenticatorButton( + onClick = { scope.launch { state.verifyUser() } }, + loading = state.form.submitting + ) + footerContent(state) + } +} + +@Composable +internal fun VerifyUserAttributeSelect( + attributes: List, + fieldState: MutableFieldState, + formState: FormState, + modifier: Modifier = Modifier +) { + Column(modifier = modifier) { + attributes.forEach { attribute -> + Row( + modifier = Modifier.fillMaxWidth().clickable { fieldState.content = attribute.key.keyString }, + horizontalArrangement = Arrangement.spacedBy(8.dp), + verticalAlignment = Alignment.CenterVertically + ) { + RadioButton( + selected = attribute.key.keyString == fieldState.content, + onClick = { fieldState.content = attribute.key.keyString }, + enabled = !formState.submitting + ) + + val label = when (attribute.key) { + AuthUserAttributeKey.email() -> R.string.authenticator_field_label_email + else -> R.string.authenticator_field_label_phone_number + } + + Text(stringResource(label)) + } + } + } +} + +@Composable +fun VerifyUserFooter( + state: VerifyUserState, + modifier: Modifier = Modifier +) { + Box(modifier = modifier.fillMaxWidth(), contentAlignment = Alignment.Center) { + TextButton(onClick = { state.skip() }) { + Text(stringResource(R.string.authenticator_button_skip)) + } + } +} diff --git a/authenticator/src/main/java/com/amplifyframework/ui/authenticator/ui/VerifyUserConfirm.kt b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/ui/VerifyUserConfirm.kt new file mode 100644 index 00000000..925b1b84 --- /dev/null +++ b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/ui/VerifyUserConfirm.kt @@ -0,0 +1,87 @@ +/* + * Copyright 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 androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.padding +import androidx.compose.material3.Text +import androidx.compose.material3.TextButton +import androidx.compose.runtime.Composable +import androidx.compose.runtime.rememberCoroutineScope +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.unit.dp +import com.amplifyframework.auth.AuthCodeDeliveryDetails +import com.amplifyframework.ui.authenticator.R +import com.amplifyframework.ui.authenticator.VerifyUserConfirmState +import kotlinx.coroutines.launch + +@Composable +fun VerifyUserConfirm( + state: VerifyUserConfirmState, + modifier: Modifier = Modifier, + headerContent: @Composable (VerifyUserConfirmState) -> Unit = { AuthenticatorTitle(stringResource(R.string.authenticator_title_verify_user)) }, + footerContent: @Composable (VerifyUserConfirmState) -> Unit = { + VerifyUserConfirmFooter(it) + }, + deliveryNoticeContent: @Composable (AuthCodeDeliveryDetails?) -> Unit = { DeliveryDetails(it) } +) { + val scope = rememberCoroutineScope() + Column( + modifier = modifier + .fillMaxWidth() + .padding(horizontal = 16.dp) + ) { + headerContent(state) + deliveryNoticeContent(state.deliveryDetails) + AuthenticatorForm(state = state.form) + AuthenticatorButton( + onClick = { scope.launch { state.confirmVerifyUser() } }, + loading = state.form.submitting + ) + footerContent(state) + } +} + +@Composable +fun VerifyUserConfirmFooter( + state: VerifyUserConfirmState, + modifier: Modifier = Modifier +) { + val scope = rememberCoroutineScope() + Column( + modifier = modifier.fillMaxWidth(), + horizontalAlignment = Alignment.CenterHorizontally + ) { + Row( + modifier = Modifier.fillMaxWidth(), + horizontalArrangement = Arrangement.SpaceEvenly, + verticalAlignment = Alignment.CenterVertically + ) { + Text(stringResource(R.string.authenticator_button_lost_code)) + TextButton(onClick = { scope.launch { state.resendCode() } }) { + Text(stringResource(R.string.authenticator_button_resend_code)) + } + } + TextButton(onClick = { state.skip() }) { + Text(stringResource(R.string.authenticator_button_skip)) + } + } +} diff --git a/authenticator/src/main/java/com/amplifyframework/ui/authenticator/util/AnnotatedStringResource.kt b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/util/AnnotatedStringResource.kt new file mode 100644 index 00000000..d7113744 --- /dev/null +++ b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/util/AnnotatedStringResource.kt @@ -0,0 +1,102 @@ +/* + * Copyright 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.util + +import android.content.Context +import android.graphics.Typeface +import android.text.Spanned +import android.text.SpannedString +import android.text.style.StyleSpan +import android.text.style.UnderlineSpan +import androidx.annotation.StringRes +import androidx.compose.runtime.Composable +import androidx.compose.runtime.remember +import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.text.AnnotatedString +import androidx.compose.ui.text.SpanStyle +import androidx.compose.ui.text.buildAnnotatedString +import androidx.compose.ui.text.font.FontStyle +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.text.style.TextDecoration +import androidx.core.text.HtmlCompat +import androidx.core.text.HtmlCompat.FROM_HTML_MODE_COMPACT + +/** + * Reads an HTML string from resources and turns it into an [AnnotatedString] + */ +@Composable +internal fun annotatedStringResource( + @StringRes id: Int +): AnnotatedString { + val context = LocalContext.current + return remember(id) { + context.getText(id).toAnnotatedString() + } +} + +@Composable +internal fun annotatedStringResource( + @StringRes id: Int, + vararg formatArgs: Any +): AnnotatedString { + val context = LocalContext.current + return remember(id, formatArgs) { + context.getText(id, *formatArgs).toAnnotatedString() + } +} + +private fun Context.getText( + @StringRes id: Int, + vararg formatArgs: Any +): CharSequence { + val resource = SpannedString(getText(id)) + val html = HtmlCompat.toHtml(resource, HtmlCompat.TO_HTML_PARAGRAPH_LINES_CONSECUTIVE) + val string = String.format(html, *formatArgs) + return HtmlCompat.fromHtml(string, FROM_HTML_MODE_COMPACT) +} + +/** + * Converts certain style spans to their AnnotatedString equivalent + */ +private fun CharSequence.toAnnotatedString(): AnnotatedString { + return if (this is Spanned) { + val spanned = this + buildAnnotatedString { + append(spanned.toString()) + getSpans(0, spanned.length, Any::class.java).forEach { span -> + val start = getSpanStart(span) + val end = getSpanEnd(span) + when (span) { + is StyleSpan -> when (span.style) { + Typeface.BOLD -> addStyle(SpanStyle(fontWeight = FontWeight.Bold), start, end) + Typeface.ITALIC -> addStyle(SpanStyle(fontStyle = FontStyle.Italic), start, end) + Typeface.BOLD_ITALIC -> addStyle( + SpanStyle( + fontStyle = FontStyle.Italic, + fontWeight = FontWeight.Bold + ), + start, + end + ) + } + is UnderlineSpan -> addStyle(SpanStyle(textDecoration = TextDecoration.Underline), start, end) + } + } + } + } else { + AnnotatedString(this.toString()) + } +} diff --git a/authenticator/src/main/java/com/amplifyframework/ui/authenticator/util/AuthProvider.kt b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/util/AuthProvider.kt new file mode 100644 index 00000000..ac307349 --- /dev/null +++ b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/util/AuthProvider.kt @@ -0,0 +1,321 @@ +/* + * Copyright 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.util + +import com.amplifyframework.annotations.InternalAmplifyApi +import com.amplifyframework.auth.AuthChannelEventName +import com.amplifyframework.auth.AuthCodeDeliveryDetails +import com.amplifyframework.auth.AuthException +import com.amplifyframework.auth.AuthSession +import com.amplifyframework.auth.AuthUser +import com.amplifyframework.auth.AuthUserAttribute +import com.amplifyframework.auth.AuthUserAttributeKey +import com.amplifyframework.auth.cognito.AWSCognitoAuthPlugin +import com.amplifyframework.auth.options.AuthSignUpOptions +import com.amplifyframework.auth.result.AuthResetPasswordResult +import com.amplifyframework.auth.result.AuthSignInResult +import com.amplifyframework.auth.result.AuthSignOutResult +import com.amplifyframework.auth.result.AuthSignUpResult +import com.amplifyframework.core.Amplify +import com.amplifyframework.hub.HubChannel +import com.amplifyframework.hub.HubEvent +import com.amplifyframework.hub.HubEventFilter +import com.amplifyframework.ui.authenticator.BuildConfig +import com.amplifyframework.ui.authenticator.amplify.AmplifyAuthConfiguration +import com.amplifyframework.ui.authenticator.amplify.PasswordCriteria +import com.amplifyframework.ui.authenticator.amplify.SignInMethod +import com.amplifyframework.ui.authenticator.amplify.VerificationMechanism +import kotlinx.coroutines.channels.awaitClose +import kotlinx.coroutines.channels.trySendBlocking +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.callbackFlow +import org.json.JSONException +import kotlin.coroutines.resume +import kotlin.coroutines.suspendCoroutine + +/** + * An abstraction of the Amplify.Auth API that allows us to use coroutines with no exceptions + */ +internal interface AuthProvider { + suspend fun signIn( + username: String, + password: String + ): AmplifyResult + + suspend fun confirmSignIn( + challengeResponse: String + ): AmplifyResult + + suspend fun signUp( + username: String, + password: String, + options: AuthSignUpOptions + ): AmplifyResult + + suspend fun confirmSignUp( + username: String, + code: String + ): AmplifyResult + + suspend fun resendSignUpCode( + username: String + ): AmplifyResult + + suspend fun resetPassword( + username: String + ): AmplifyResult + + suspend fun confirmResetPassword( + username: String, + newPassword: String, + confirmationCode: String + ): AmplifyResult + + suspend fun signOut(): AuthSignOutResult + + suspend fun fetchAuthSession(): AmplifyResult + + suspend fun fetchUserAttributes(): AmplifyResult> + + suspend fun confirmUserAttribute( + key: AuthUserAttributeKey, + confirmationCode: String + ): AmplifyResult + + suspend fun resendUserAttributeConfirmationCode(key: AuthUserAttributeKey): AmplifyResult + + suspend fun getCurrentUser(): AmplifyResult + + fun authStatusEvents(): Flow> + + suspend fun getConfiguration(): AmplifyAuthConfiguration? +} + +/** + * The [AuthProvider] implementation that calls through to [Amplify.Auth] + */ +@OptIn(InternalAmplifyApi::class) +internal class RealAuthProvider : AuthProvider { + + init { + val cognitoPlugin = getCognitoPlugin() + // TODO After Amplify release cognitoPlugin?.addToUserAgent(AWSCognitoAuthMetadataType.Authenticator, BuildConfig.AUTHENTICATOR_VERSION) + } + + override suspend fun signIn(username: String, password: String) = suspendCoroutine { continuation -> + Amplify.Auth.signIn( + username, + password, + { continuation.resume(AmplifyResult.Success(it)) }, + { continuation.resume(AmplifyResult.Error(it)) } + ) + } + + override suspend fun confirmSignIn(challengeResponse: String) = suspendCoroutine { continuation -> + Amplify.Auth.confirmSignIn( + challengeResponse, + { continuation.resume(AmplifyResult.Success(it)) }, + { continuation.resume(AmplifyResult.Error(it)) } + ) + } + + override suspend fun signUp( + username: String, + password: String, + options: AuthSignUpOptions + ) = suspendCoroutine { continuation -> + Amplify.Auth.signUp( + username, + password, + options, + { continuation.resume(AmplifyResult.Success(it)) }, + { continuation.resume(AmplifyResult.Error(it)) } + ) + } + + override suspend fun confirmSignUp( + username: String, + code: String + ) = suspendCoroutine { continuation -> + Amplify.Auth.confirmSignUp( + username, + code, + { continuation.resume(AmplifyResult.Success(it)) }, + { continuation.resume(AmplifyResult.Error(it)) } + ) + } + + override suspend fun resendSignUpCode( + username: String + ) = suspendCoroutine { continuation -> + Amplify.Auth.resendSignUpCode( + username, + { continuation.resume(AmplifyResult.Success(it)) }, + { continuation.resume(AmplifyResult.Error(it)) } + ) + } + + override suspend fun resetPassword( + username: String + ) = suspendCoroutine { continuation -> + Amplify.Auth.resetPassword( + username, + { continuation.resume(AmplifyResult.Success(it)) }, + { continuation.resume(AmplifyResult.Error(it)) } + ) + } + + override suspend fun confirmResetPassword( + username: String, + newPassword: String, + confirmationCode: String + ) = suspendCoroutine { continuation -> + Amplify.Auth.confirmResetPassword( + username, + newPassword, + confirmationCode, + { continuation.resume(AmplifyResult.Success(Unit)) }, + { continuation.resume(AmplifyResult.Error(it)) } + ) + } + + override suspend fun signOut() = suspendCoroutine { continuation -> + Amplify.Auth.signOut { continuation.resume(it) } + } + + override suspend fun fetchAuthSession() = suspendCoroutine { continuation -> + Amplify.Auth.fetchAuthSession( + { continuation.resume(AmplifyResult.Success(it)) }, + { continuation.resume(AmplifyResult.Error(it)) } + ) + } + + override suspend fun fetchUserAttributes() = suspendCoroutine { continuation -> + Amplify.Auth.fetchUserAttributes( + { continuation.resume(AmplifyResult.Success(it)) }, + { continuation.resume(AmplifyResult.Error(it)) } + ) + } + + override suspend fun confirmUserAttribute( + key: AuthUserAttributeKey, + confirmationCode: String + ) = suspendCoroutine { continuation -> + Amplify.Auth.confirmUserAttribute( + key, + confirmationCode, + { continuation.resume(AmplifyResult.Success(Unit)) }, + { continuation.resume(AmplifyResult.Error(it)) } + ) + } + + override suspend fun resendUserAttributeConfirmationCode( + key: AuthUserAttributeKey + ) = suspendCoroutine { continuation -> + Amplify.Auth.resendUserAttributeConfirmationCode( + key, + { continuation.resume(AmplifyResult.Success(it)) }, + { continuation.resume(AmplifyResult.Error(it)) } + ) + } + + override suspend fun getCurrentUser() = suspendCoroutine { continuation -> + Amplify.Auth.getCurrentUser( + { continuation.resume(AmplifyResult.Success(it)) }, + { continuation.resume(AmplifyResult.Error(it)) } + ) + } + + override fun authStatusEvents(): Flow> = callbackFlow { + val filter = HubEventFilter { + it.name == AuthChannelEventName.SIGNED_OUT.name || it.name == AuthChannelEventName.SIGNED_IN.name + } + val token = Amplify.Hub.subscribe(HubChannel.AUTH, filter) { trySendBlocking(it) } + awaitClose { Amplify.Hub.unsubscribe(token) } + } + + @OptIn(InternalAmplifyApi::class) + override suspend fun getConfiguration(): AmplifyAuthConfiguration? { + val authConfigJSON = getCognitoPlugin()?.getPluginConfiguration() ?: return null + try { + val innerJSON = authConfigJSON + .getJSONObject("Auth") + .getJSONObject("Default") + val signUpAttributes = innerJSON.getJSONArray("signupAttributes") + val usernameAttributes = innerJSON.getJSONArray("usernameAttributes") + val passwordAttributes = innerJSON.getJSONObject("passwordProtectionSettings") + + val signInAttributeList = List(usernameAttributes.length()) { + usernameAttributes.getString(it) + } + val containsEmail = signInAttributeList.contains("EMAIL") + val containsPhoneNumber = signInAttributeList.contains("PHONE_NUMBER") + val signInMethod = when { + containsEmail -> SignInMethod.Email + containsPhoneNumber -> SignInMethod.PhoneNumber + else -> SignInMethod.Username + } + + val signUpAttributeList = List(signUpAttributes.length()) { + AuthUserAttributeKey.custom(signUpAttributes.getString(it).lowercase()) + } + + val passwordRequirementsJSON = passwordAttributes + .getJSONArray("passwordPolicyCharacters") + val passwordRequirements = List(passwordRequirementsJSON.length()) { + passwordRequirementsJSON.getString(it) + } + val passwordCriteria = PasswordCriteria( + length = passwordAttributes.getInt("passwordPolicyMinLength"), + requiresNumber = passwordRequirements.contains("REQUIRES_NUMBERS"), + requiresSpecial = passwordRequirements.contains("REQUIRES_SYMBOLS"), + requiresLower = passwordRequirements.contains("REQUIRES_LOWER"), + requiresUpper = passwordRequirements.contains("REQUIRES_UPPER") + ) + + val verificationMechanismsJson = innerJSON.getJSONArray("verificationMechanisms") + val verificationMechanisms = List(verificationMechanismsJson.length()) { + when (verificationMechanismsJson.getString(it)) { + "EMAIL" -> VerificationMechanism.Email + else -> VerificationMechanism.PhoneNumber + } + }.toSet() + + return AmplifyAuthConfiguration( + signInMethod, + signUpAttributeList, + passwordCriteria, + verificationMechanisms + ) + } catch (e: JSONException) { + return null + } + } + + private fun getCognitoPlugin(): AWSCognitoAuthPlugin? { + return try { + Amplify.Auth.getPlugin("awsCognitoAuthPlugin") + as AWSCognitoAuthPlugin + } catch (e: Throwable) { + null + } + } +} + +internal sealed interface AmplifyResult { + data class Success(val data: T) : AmplifyResult + data class Error(val error: AuthException) : AmplifyResult +} diff --git a/authenticator/src/main/java/com/amplifyframework/ui/authenticator/util/AuthenticatorMessage.kt b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/util/AuthenticatorMessage.kt new file mode 100644 index 00000000..8cd71c63 --- /dev/null +++ b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/util/AuthenticatorMessage.kt @@ -0,0 +1,116 @@ +/* + * Copyright 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.util + +import android.content.Context +import androidx.compose.runtime.Composable +import androidx.compose.ui.res.stringResource +import com.amplifyframework.auth.AuthException +import com.amplifyframework.ui.authenticator.R + +/** + * Messages that may be displayed in the Authenticator UI. + */ +interface AuthenticatorMessage { + /** + * Get the localized message content from a Composable function. + */ + @get:Composable + val message: String + + /** + * Get the localized message content using a [Context] instance. + */ + fun message(context: Context): String + + /** + * Indicates an informational update for the user, such as the successful completion of an async process. + */ + interface Information : AuthenticatorMessage + + /** + * Indicates an error occurred. You may inspect the [cause] for more information. + */ + interface Error : AuthenticatorMessage { + /** + * The [AuthException] that triggered this message. + */ + val cause: AuthException + } +} + +internal abstract class AuthenticatorMessageImpl( + private val resource: Int +) : AuthenticatorMessage { + + override val message: String + @Composable + get() = stringResource(resource) + + /** + * Get the message content using a [Context] instance. + */ + override fun message(context: Context) = context.getString(resource) +} + +/** + * The user's password has been successfully reset. + */ +internal object PasswordResetMessage : + AuthenticatorMessageImpl(R.string.authenticator_message_password_reset), + AuthenticatorMessage.Information + +/** + * A confirmation code was sent to the user. + */ +internal object CodeSentMessage : + AuthenticatorMessageImpl(R.string.authenticator_message_code_sent), + AuthenticatorMessage.Information + +/** + * The user cannot reset their password because their account is in an invalid state. + */ +internal class UnableToResetPasswordMessage( + override val cause: AuthException +) : AuthenticatorMessageImpl(R.string.authenticator_error_cannot_reset_password), AuthenticatorMessage.Error + +/** + * An unknown error occurred. + */ +internal class UnknownErrorMessage( + override val cause: AuthException +) : AuthenticatorMessageImpl(R.string.authenticator_error_unknown), AuthenticatorMessage.Error + +/** + * The username or password were incorrect. + */ +internal class InvalidLoginMessage( + override val cause: AuthException +) : AuthenticatorMessageImpl(R.string.authenticator_error_invalid_signin), AuthenticatorMessage.Error + +/** + * The server could not send a confirmation code to the user. + */ +internal class CannotSendCodeMessage( + override val cause: AuthException +) : AuthenticatorMessageImpl(R.string.authenticator_error_send_code), AuthenticatorMessage.Error + +/** + * The entered confirmation code has expired. + */ +internal class ExpiredCodeMessage( + override val cause: AuthException +) : AuthenticatorMessageImpl(R.string.authenticator_error_expired_code), AuthenticatorMessage.Error diff --git a/authenticator/src/main/java/com/amplifyframework/ui/authenticator/util/DialCodes.kt b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/util/DialCodes.kt new file mode 100644 index 00000000..3011857b --- /dev/null +++ b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/util/DialCodes.kt @@ -0,0 +1,472 @@ +/* + * Copyright 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.util + +internal fun dialCodeFor(countryCode: String) = when (countryCode) { + "AF" -> "+93" + "AX" -> "+358" + "AL" -> "+355" + "DZ" -> "+213" + "AS" -> "+1" + "AD" -> "+376" + "AO" -> "+244" + "AI" -> "+1" + "AQ" -> "+672" + "AG" -> "+1" + "AR" -> "+54" + "AM" -> "+374" + "AW" -> "+297" + "AU" -> "+61" + "AT" -> "+43" + "AZ" -> "+994" + "BS" -> "+1" + "BH" -> "+973" + "BD" -> "+880" + "BB" -> "+1" + "BY" -> "+375" + "BE" -> "+32" + "BZ" -> "+501" + "BJ" -> "+229" + "BM" -> "+1" + "BT" -> "+975" + "BO" -> "+591" + "BA" -> "+387" + "BW" -> "+267" + "BR" -> "+55" + "IO" -> "+246" + "BN" -> "+673" + "BG" -> "+359" + "BF" -> "+226" + "BI" -> "+257" + "KH" -> "+855" + "CM" -> "+237" + "CA" -> "+1" + "CV" -> "+238" + "KY" -> "+345" + "CF" -> "+236" + "TD" -> "+235" + "CL" -> "+56" + "CN" -> "+86" + "CX" -> "+61" + "CC" -> "+61" + "CO" -> "+57" + "KM" -> "+269" + "CG" -> "+242" + "CD" -> "+243" + "CK" -> "+682" + "CR" -> "+506" + "CI" -> "+225" + "HR" -> "+385" + "CU" -> "+53" + "CY" -> "+357" + "CZ" -> "+420" + "DK" -> "+45" + "DJ" -> "+253" + "DM" -> "+1" + "DO" -> "+1" + "EC" -> "+593" + "EG" -> "+20" + "SV" -> "+503" + "GQ" -> "+240" + "ER" -> "+291" + "EE" -> "+372" + "ET" -> "+251" + "FK" -> "+500" + "FO" -> "+298" + "FJ" -> "+679" + "FI" -> "+358" + "FR" -> "+33" + "GF" -> "+594" + "PF" -> "+689" + "GA" -> "+241" + "GM" -> "+220" + "GE" -> "+995" + "DE" -> "+49" + "GH" -> "+233" + "GI" -> "+350" + "GR" -> "+30" + "GL" -> "+299" + "GD" -> "+1" + "GP" -> "+590" + "GU" -> "+1" + "GT" -> "+502" + "GG" -> "+44" + "GN" -> "+224" + "GW" -> "+245" + "GY" -> "+595" + "HT" -> "+509" + "VA" -> "+379" + "HN" -> "+504" + "HK" -> "+852" + "HU" -> "+36" + "IS" -> "+354" + "IN" -> "+91" + "ID" -> "+62" + "IR" -> "+98" + "IQ" -> "+964" + "IE" -> "+353" + "IM" -> "+44" + "IL" -> "+972" + "IT" -> "+39" + "JM" -> "+1" + "JP" -> "+81" + "JE" -> "+44" + "JO" -> "+962" + "KZ" -> "+77" + "KE" -> "+254" + "KI" -> "+686" + "KP" -> "+850" + "KR" -> "+82" + "KW" -> "+965" + "KG" -> "+996" + "LA" -> "+856" + "LV" -> "+371" + "LB" -> "+961" + "LS" -> "+266" + "LR" -> "+231" + "LY" -> "+218" + "LI" -> "+423" + "LT" -> "+370" + "LU" -> "+352" + "MO" -> "+853" + "MK" -> "+389" + "MG" -> "+261" + "MW" -> "+265" + "MY" -> "+60" + "MV" -> "+960" + "ML" -> "+223" + "MT" -> "+356" + "MH" -> "+692" + "MQ" -> "+596" + "MR" -> "+222" + "MU" -> "+230" + "YT" -> "+262" + "MX" -> "+52" + "FM" -> "+691" + "MD" -> "+373" + "MC" -> "+377" + "MN" -> "+976" + "ME" -> "+382" + "MS" -> "+1" + "MA" -> "+212" + "MZ" -> "+258" + "MM" -> "+95" + "NA" -> "+264" + "NR" -> "+674" + "NP" -> "+977" + "NL" -> "+31" + "AN" -> "+599" + "NC" -> "+687" + "NZ" -> "+64" + "NI" -> "+505" + "NE" -> "+227" + "NG" -> "+234" + "NU" -> "+683" + "NF" -> "+672" + "MP" -> "+1" + "NO" -> "+47" + "OM" -> "+968" + "PK" -> "+92" + "PW" -> "+680" + "PS" -> "+970" + "PA" -> "+507" + "PG" -> "+675" + "PY" -> "+595" + "PE" -> "+51" + "PH" -> "+63" + "PN" -> "+872" + "PL" -> "+48" + "PT" -> "+351" + "PR" -> "+1" + "QA" -> "+974" + "RO" -> "+40" + "RU" -> "+7" + "RW" -> "+250" + "RE" -> "+262" + "BL" -> "+590" + "SH" -> "+290" + "KN" -> "+1" + "LC" -> "+1" + "MF" -> "+590" + "PM" -> "+508" + "VC" -> "+1" + "WS" -> "+685" + "SM" -> "+378" + "ST" -> "+239" + "SA" -> "+966" + "SN" -> "+221" + "RS" -> "+381" + "SC" -> "+248" + "SL" -> "+232" + "SG" -> "+65" + "SK" -> "+421" + "SI" -> "+386" + "SB" -> "+677" + "SO" -> "+252" + "ZA" -> "+27" + "SS" -> "+211" + "GS" -> "+500" + "ES" -> "+34" + "LK" -> "+94" + "SD" -> "+249" + "SR" -> "+597" + "SJ" -> "+47" + "SZ" -> "+268" + "SE" -> "+46" + "CH" -> "+41" + "SY" -> "+963" + "TW" -> "+886" + "TJ" -> "+992" + "TZ" -> "+255" + "TH" -> "+66" + "TL" -> "+670" + "TG" -> "+228" + "TK" -> "+690" + "TO" -> "+676" + "TT" -> "+1" + "TN" -> "+216" + "TR" -> "+90" + "TM" -> "+993" + "TC" -> "+1" + "TV" -> "+688" + "UG" -> "+256" + "UA" -> "+380" + "AE" -> "+971" + "GB" -> "+44" + "US" -> "+1" + "UY" -> "+598" + "UZ" -> "+998" + "VU" -> "+678" + "VE" -> "+58" + "VN" -> "+84" + "VG" -> "+1" + "VI" -> "+1" + "WF" -> "+681" + "YE" -> "+967" + "ZM" -> "+260" + "ZW" -> "+263" + else -> "+1" +} + +internal val dialCodeList = listOf( + "+1", + "+7", + "+20", + "+27", + "+30", + "+31", + "+32", + "+33", + "+34", + "+36", + "+39", + "+40", + "+41", + "+43", + "+44", + "+45", + "+46", + "+47", + "+48", + "+49", + "+51", + "+52", + "+53", + "+54", + "+55", + "+56", + "+57", + "+58", + "+60", + "+61", + "+62", + "+63", + "+64", + "+65", + "+66", + "+77", + "+81", + "+82", + "+84", + "+86", + "+90", + "+91", + "+92", + "+93", + "+94", + "+95", + "+98", + "+211", + "+212", + "+213", + "+216", + "+218", + "+220", + "+221", + "+222", + "+223", + "+224", + "+225", + "+226", + "+227", + "+228", + "+229", + "+230", + "+231", + "+232", + "+233", + "+234", + "+235", + "+236", + "+237", + "+238", + "+239", + "+240", + "+241", + "+242", + "+243", + "+244", + "+245", + "+246", + "+248", + "+249", + "+250", + "+251", + "+252", + "+253", + "+254", + "+255", + "+256", + "+257", + "+258", + "+260", + "+261", + "+262", + "+263", + "+264", + "+265", + "+266", + "+267", + "+268", + "+269", + "+290", + "+291", + "+297", + "+298", + "+299", + "+345", + "+350", + "+351", + "+352", + "+353", + "+354", + "+355", + "+356", + "+357", + "+358", + "+359", + "+370", + "+371", + "+372", + "+373", + "+374", + "+375", + "+376", + "+377", + "+378", + "+379", + "+380", + "+381", + "+382", + "+385", + "+386", + "+387", + "+389", + "+420", + "+421", + "+423", + "+500", + "+501", + "+502", + "+503", + "+504", + "+505", + "+506", + "+507", + "+508", + "+509", + "+590", + "+591", + "+593", + "+594", + "+595", + "+596", + "+597", + "+598", + "+599", + "+670", + "+672", + "+673", + "+674", + "+675", + "+676", + "+677", + "+678", + "+679", + "+680", + "+681", + "+682", + "+683", + "+685", + "+686", + "+687", + "+688", + "+689", + "+690", + "+691", + "+692", + "+850", + "+852", + "+853", + "+855", + "+856", + "+872", + "+880", + "+886", + "+960", + "+961", + "+962", + "+963", + "+964", + "+965", + "+966", + "+967", + "+968", + "+970", + "+971", + "+972", + "+973", + "+974", + "+975", + "+976", + "+977", + "+992", + "+993", + "+994", + "+995", + "+996", + "+998" +) diff --git a/authenticator/src/main/java/com/amplifyframework/ui/authenticator/util/Errors.kt b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/util/Errors.kt new file mode 100644 index 00000000..51713dfb --- /dev/null +++ b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/util/Errors.kt @@ -0,0 +1,32 @@ +/* + * Copyright 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.util + +import com.amplifyframework.auth.cognito.exceptions.service.InvalidPasswordException +import com.amplifyframework.ui.authenticator.forms.FieldError + +// This SHOULD be caught by the field validator, but it's possible that the local configuration is +// different from the server configuration. In such cases this exception will be returned. +// We cannot extract the specific problem from the exception, so just show the message returned +// or an InvalidFormat if none +internal fun InvalidPasswordException.toFieldError(): FieldError { + val cause = this.cause + return if (cause is aws.sdk.kotlin.services.cognitoidentityprovider.model.InvalidPasswordException && cause.localizedMessage != null) { + FieldError.Custom(cause.localizedMessage!!) + } else { + FieldError.InvalidFormat + } +} diff --git a/authenticator/src/main/java/com/amplifyframework/ui/authenticator/util/MissingConfigurationException.kt b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/util/MissingConfigurationException.kt new file mode 100644 index 00000000..34dc6cb6 --- /dev/null +++ b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/util/MissingConfigurationException.kt @@ -0,0 +1,27 @@ +/* + * Copyright 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.util + +import com.amplifyframework.auth.AuthException + +/** + * Exception that is passed to the errorContent if the application does not have the auth plugin + * configured when attempting to use Authenticator + */ +class MissingConfigurationException : AuthException( + "Missing auth configuration", + "Make sure the Auth plugin is added and Amplify.configure is called. See https://docs.amplify.aws/lib/auth/getting-started/q/platform/android/ for details" +) diff --git a/authenticator/src/main/res/drawable/ic_authenticator_invisible.xml b/authenticator/src/main/res/drawable/ic_authenticator_invisible.xml new file mode 100644 index 00000000..ee822a9a --- /dev/null +++ b/authenticator/src/main/res/drawable/ic_authenticator_invisible.xml @@ -0,0 +1,25 @@ + + + + + diff --git a/authenticator/src/main/res/drawable/ic_authenticator_visible.xml b/authenticator/src/main/res/drawable/ic_authenticator_visible.xml new file mode 100644 index 00000000..c6b6926d --- /dev/null +++ b/authenticator/src/main/res/drawable/ic_authenticator_visible.xml @@ -0,0 +1,25 @@ + + + + + diff --git a/authenticator/src/main/res/values/buttons.xml b/authenticator/src/main/res/values/buttons.xml new file mode 100644 index 00000000..88d9ebf2 --- /dev/null +++ b/authenticator/src/main/res/values/buttons.xml @@ -0,0 +1,27 @@ + + + + + Submit + Sign In + Change Password + Create Account + Forgot Password? + Back to Sign In + Lost your code? + Send Code + Skip + diff --git a/authenticator/src/main/res/values/errors.xml b/authenticator/src/main/res/values/errors.xml new file mode 100644 index 00000000..ddebc5ec --- /dev/null +++ b/authenticator/src/main/res/values/errors.xml @@ -0,0 +1,24 @@ + + + + + Username or Password is incorrect + + User password cannot be reset in the current state + Could not send confirmation code + Code has expired + Sorry, something went wrong + diff --git a/authenticator/src/main/res/values/fields.xml b/authenticator/src/main/res/values/fields.xml new file mode 100644 index 00000000..95d0bde7 --- /dev/null +++ b/authenticator/src/main/res/values/fields.xml @@ -0,0 +1,65 @@ + + + + + Enter your %s + %s (optional) + %s not found + %s field must not be blank + Invalid %s format + %s already exists + + + Username + Password + Confirm Password + New Password + Confirm New Password + Confirmation Code + Phone Number + Email + Birthdate + Family Name + Middle Name + Given Name + Name + Nickname + Preferred Username + Profile + Website + Verification Attribute + + + Show password + Hide password + Password must include: + * at least one special character + * at least one number + * at least one uppercase letter + * at least one lowercase letter + + + + * at least %d characters + + + + Re-enter your password + Passwords do not match + + + Confirmation code is incorrect + diff --git a/authenticator/src/main/res/values/messages.xml b/authenticator/src/main/res/values/messages.xml new file mode 100644 index 00000000..628c974a --- /dev/null +++ b/authenticator/src/main/res/values/messages.xml @@ -0,0 +1,20 @@ + + + + Account created + Password has been reset + Confirmation code sent + diff --git a/authenticator/src/main/res/values/strings.xml b/authenticator/src/main/res/values/strings.xml new file mode 100644 index 00000000..0dbfc3d9 --- /dev/null +++ b/authenticator/src/main/res/values/strings.xml @@ -0,0 +1,20 @@ + + + + + A confirmation code has been sent to %s. + A confirmation code has been sent. + diff --git a/authenticator/src/main/res/values/titles.xml b/authenticator/src/main/res/values/titles.xml new file mode 100644 index 00000000..a608bc7b --- /dev/null +++ b/authenticator/src/main/res/values/titles.xml @@ -0,0 +1,25 @@ + + + + + Sign In + Enter your sign in code + Change your password to sign in + Create Account + Reset Password + Enter your confirmation code + Account recovery requires verified contact information + diff --git a/authenticator/src/test/java/com/amplifyframework/ui/authenticator/ui/SignInTest.kt b/authenticator/src/test/java/com/amplifyframework/ui/authenticator/ui/SignInTest.kt new file mode 100644 index 00000000..2f51c99b --- /dev/null +++ b/authenticator/src/test/java/com/amplifyframework/ui/authenticator/ui/SignInTest.kt @@ -0,0 +1,45 @@ +/* + * Copyright 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 androidx.compose.ui.test.hasTestTag +import androidx.compose.ui.test.hasText +import com.amplifyframework.ui.authenticator.SignInState +import com.amplifyframework.ui.authenticator.forms.buildForm +import com.amplifyframework.ui.authenticator.forms.toState +import com.amplifyframework.ui.authenticator.states.SignInStateImpl +import com.amplifyframework.ui.testing.ComposeTest +import org.junit.Test + +class SignInTest : ComposeTest() { + + @Test + fun `title is Sign In`() { + composeTestRule.setContent { + SignIn(state = mockSignInState()) + } + composeTestRule.onNode(hasTestTag("AuthenticatorTitle") and hasText("Sign In")).assertExists() + } + + private fun mockSignInState(): SignInState { + val form = buildForm { + username() + password() + }.toState() + + return SignInStateImpl(form, {}) + } +} diff --git a/authenticator/src/test/java/com/amplifyframework/ui/authenticator/ui/SignUpTest.kt b/authenticator/src/test/java/com/amplifyframework/ui/authenticator/ui/SignUpTest.kt new file mode 100644 index 00000000..5ce97fd6 --- /dev/null +++ b/authenticator/src/test/java/com/amplifyframework/ui/authenticator/ui/SignUpTest.kt @@ -0,0 +1,54 @@ +/* + * Copyright 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 androidx.compose.ui.test.hasTestTag +import androidx.compose.ui.test.hasText +import com.amplifyframework.ui.authenticator.SignUpState +import com.amplifyframework.ui.authenticator.forms.buildForm +import com.amplifyframework.ui.authenticator.forms.toState +import com.amplifyframework.ui.authenticator.states.SignUpStateImpl +import com.amplifyframework.ui.testing.ComposeTest +import org.junit.Test + +class SignUpTest : ComposeTest() { + + @Test + fun `title is Create Account`() { + composeTestRule.setContent { + SignUp(state = mockSignUpState()) + } + composeTestRule.onNode(hasTestTag("AuthenticatorTitle") and hasText("Create Account")).assertExists() + } + + @Test + fun `button is Create Account`() { + composeTestRule.setContent { + SignUp(state = mockSignUpState()) + } + composeTestRule.onNode(hasTestTag("SignUpButton") and hasText("Create Account")).assertExists() + } + + private fun mockSignUpState(): SignUpState { + val form = buildForm { + username() + password() + confirmPassword() + email(required = true) + }.toState() + return SignUpStateImpl(form, {}) + } +} diff --git a/build.gradle b/build.gradle index 202a574a..f22d1fd3 100755 --- a/build.gradle +++ b/build.gradle @@ -69,7 +69,8 @@ ext { cameraXVersion = '1.2.0' dependency = [ amplify: [ - auth: "com.amplifyframework:aws-api:$amplifyVersion", + api: "com.amplifyframework:aws-api:$amplifyVersion", + auth: "com.amplifyframework:aws-auth-cognito:$amplifyVersion", predictions: "com.amplifyframework:aws-predictions:$amplifyVersion", ], androidx: [ @@ -82,6 +83,9 @@ ext { material: 'androidx.compose.material3:material3:1.0.1', uiTooling: 'androidx.compose.ui:ui-tooling:1.3.2', lifecycle_ktx: 'androidx.lifecycle:lifecycle-runtime-ktx:2.4.0', + compose: [ + viewmodel: "androidx.lifecycle:lifecycle-viewmodel-compose:2.4.0" + ] ], kotlin: [ stdlib: 'org.jetbrains.kotlin:kotlin-stdlib:1.8.10', @@ -178,7 +182,6 @@ private void configureAndroidLibrary(Project project) { } buildFeatures { - mlModelBinding true compose true } diff --git a/liveness/build.gradle b/liveness/build.gradle index 5b7b5193..1d551ee1 100644 --- a/liveness/build.gradle +++ b/liveness/build.gradle @@ -45,7 +45,7 @@ android { dependencies { - api dependency.amplify.auth + api dependency.amplify.api api dependency.amplify.predictions implementation dependency.androidx.camera.core @@ -66,4 +66,4 @@ dependencies { testImplementation dependency.test.junit testImplementation dependency.test.robolectric testImplementation dependency.test.mockk -} \ No newline at end of file +} diff --git a/samples/authenticator/.gitignore b/samples/authenticator/.gitignore new file mode 100644 index 00000000..aa724b77 --- /dev/null +++ b/samples/authenticator/.gitignore @@ -0,0 +1,15 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild +.cxx +local.properties diff --git a/samples/authenticator/.idea/.gitignore b/samples/authenticator/.idea/.gitignore new file mode 100644 index 00000000..26d33521 --- /dev/null +++ b/samples/authenticator/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/samples/authenticator/.idea/.name b/samples/authenticator/.idea/.name new file mode 100644 index 00000000..f684978a --- /dev/null +++ b/samples/authenticator/.idea/.name @@ -0,0 +1 @@ +Authenticator Sample \ No newline at end of file diff --git a/samples/authenticator/.idea/compiler.xml b/samples/authenticator/.idea/compiler.xml new file mode 100644 index 00000000..fb7f4a8a --- /dev/null +++ b/samples/authenticator/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/samples/authenticator/.idea/deploymentTargetDropDown.xml b/samples/authenticator/.idea/deploymentTargetDropDown.xml new file mode 100644 index 00000000..989da50d --- /dev/null +++ b/samples/authenticator/.idea/deploymentTargetDropDown.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/samples/authenticator/.idea/gradle.xml b/samples/authenticator/.idea/gradle.xml new file mode 100644 index 00000000..bf0f3a92 --- /dev/null +++ b/samples/authenticator/.idea/gradle.xml @@ -0,0 +1,36 @@ + + + + + + + \ No newline at end of file diff --git a/samples/authenticator/.idea/inspectionProfiles/Project_Default.xml b/samples/authenticator/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 00000000..44ca2d9b --- /dev/null +++ b/samples/authenticator/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,41 @@ + + + + \ No newline at end of file diff --git a/samples/authenticator/.idea/jarRepositories.xml b/samples/authenticator/.idea/jarRepositories.xml new file mode 100644 index 00000000..95fdb42e --- /dev/null +++ b/samples/authenticator/.idea/jarRepositories.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/samples/authenticator/.idea/misc.xml b/samples/authenticator/.idea/misc.xml new file mode 100644 index 00000000..54d5acd7 --- /dev/null +++ b/samples/authenticator/.idea/misc.xml @@ -0,0 +1,10 @@ + + + + + + + + + \ No newline at end of file diff --git a/samples/authenticator/.idea/vcs.xml b/samples/authenticator/.idea/vcs.xml new file mode 100644 index 00000000..b2bdec2d --- /dev/null +++ b/samples/authenticator/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/samples/authenticator/README.md b/samples/authenticator/README.md new file mode 100644 index 00000000..55233068 --- /dev/null +++ b/samples/authenticator/README.md @@ -0,0 +1,56 @@ +# Amplify Authenticator for Android + +![](images/signin.png) +![](images/signup.png) +![](images/resetpassword.png) + +## Overview + +Authenticator is a _connected UI component_ in Amplify UI - that is, it is a UI implementation that is built on +functionality from the Amplify library. Authenticator uses the Amplify Auth category to implement a UI flow for +application sign up, sign in, and reset password. + +## Running the Sample App + +To run the sample application you will need: + +- [Android Studio](https://developer.android.com/studio) Electric Eel or higher +- [Amplify CLI](https://docs.amplify.aws/cli/) + +### Setup your backend + +1. Follow the [project setup](https://docs.amplify.aws/lib/project-setup/prereq/q/platform/android/) steps on the + Amplify Android documentation if you have not previously set up an AWS profile. +2. Create an Amplify project using + the [amplify init](https://docs.amplify.aws/lib/project-setup/create-application/q/platform/android/#3-provision-the-backend-with-amplify-cli) + command. +3. Configure your authentication backend using + the [amplify add auth](https://docs.amplify.aws/lib/auth/getting-started/q/platform/android/#configure-auth-category) + command. You do not need to follow the subsequent sections starting with `Install Amplify Libraries` as this is + already done in the sample application. Remember to do an `amplify push` to deploy your backend. + +### Run the application + +1. Open the root folder in Android Studio to load the project into the IDE. +2. If you do not have an existing emulator setup, create + an [Android Virtual Device](https://developer.android.com/studio/run/managing-avds) that will run the app. +3. Click the run button to build and run the application. + +![](images/run.png) + +### Modify your backend + +You can try using different auth configurations to see how Authenticator responds. Some configurations need to be set +when the cognito user pool is created, while others can be modified in an existing pool. + +#### Modify an existing user pool + +You can modify the existing backend using the `amplify update auth` CLI command (recommended), or you can use +the [AWS Cognito Console](https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-console.html) +to modify the user pool settings, followed by running `amplify pull` to update the local configuration. + +#### Create a new user pool + +You can run `amplify remove auth` followed by `amplify add auth` to create and start using a new user pool. Note this +will delete any existing users you have created, but it will allow changing some configurations such as the username +attribute. Remember to do an `amplify push` to deploy your changes. diff --git a/samples/authenticator/app/.gitignore b/samples/authenticator/app/.gitignore new file mode 100644 index 00000000..7915f57c --- /dev/null +++ b/samples/authenticator/app/.gitignore @@ -0,0 +1,4 @@ +/build +/buildNative +**/awsconfiguration.json +**/amplifyconfiguration.json \ No newline at end of file diff --git a/samples/authenticator/app/build.gradle b/samples/authenticator/app/build.gradle new file mode 100644 index 00000000..2a067257 --- /dev/null +++ b/samples/authenticator/app/build.gradle @@ -0,0 +1,73 @@ +plugins { + id 'com.android.application' + id 'org.jetbrains.kotlin.android' + id 'org.jetbrains.kotlin.plugin.serialization' +} + +android { + namespace 'com.amplifyframework.ui.sample.authenticator' + compileSdk 33 + + defaultConfig { + applicationId "com.amplifyframework.ui.sample.authenticator" + minSdk 24 + targetSdk 33 + versionCode 1 + versionName "1" + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + kotlinOptions { + jvmTarget = '1.8' + } + buildFeatures { + compose true + } + composeOptions { + kotlinCompilerExtensionVersion '1.4.3' + } + packagingOptions { + resources { + excludes += '/META-INF/{AL2.0,LGPL2.1}' + } + } +} + +dependencies { + // Use this to pull in local module of Amplify UI + // Must also uncomment authenticator sample project settings.gradle includeBuild + implementation 'com.amplifyframework.ui:authenticator' + + // or + + // Use this to use published version of Amplify UI + //implementation "com.amplifyframework.ui:authenticator$authenticatorVersion" + + implementation "com.amplifyframework:core-kotlin:$amplifyVersion" + implementation "com.amplifyframework:aws-auth-cognito:$amplifyVersion" + + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4' + implementation "com.google.accompanist:accompanist-permissions:0.28.0" + implementation 'org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.3' + implementation 'androidx.core:core-ktx:1.9.0' + implementation 'androidx.navigation:navigation-compose:2.5.3' + implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.5.1' + implementation 'androidx.activity:activity-compose:1.6.1' + implementation "androidx.compose.ui:ui:$compose_version" + implementation "androidx.compose.ui:ui-tooling-preview:$compose_version" + implementation 'androidx.compose.material3:material3:1.0.1' + implementation 'androidx.appcompat:appcompat:1.6.1' + debugImplementation "androidx.compose.ui:ui-tooling:$compose_version" + debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_version" +} diff --git a/samples/authenticator/app/src/main/AndroidManifest.xml b/samples/authenticator/app/src/main/AndroidManifest.xml new file mode 100644 index 00000000..60340bb7 --- /dev/null +++ b/samples/authenticator/app/src/main/AndroidManifest.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + diff --git a/samples/authenticator/app/src/main/java/com/amplifyframework/ui/sample/authenticator/AuthenticatorSampleApp.kt b/samples/authenticator/app/src/main/java/com/amplifyframework/ui/sample/authenticator/AuthenticatorSampleApp.kt new file mode 100644 index 00000000..537cbad5 --- /dev/null +++ b/samples/authenticator/app/src/main/java/com/amplifyframework/ui/sample/authenticator/AuthenticatorSampleApp.kt @@ -0,0 +1,34 @@ +/* + * Copyright 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.sample.authenticator + +import android.app.Application +import android.util.Log +import com.amplifyframework.AmplifyException +import com.amplifyframework.auth.cognito.AWSCognitoAuthPlugin +import com.amplifyframework.core.Amplify + +class AuthenticatorSampleApp : Application() { + override fun onCreate() { + super.onCreate() + try { + Amplify.addPlugin(AWSCognitoAuthPlugin()) + Amplify.configure(applicationContext) + } catch (e: AmplifyException) { + Log.e("AuthenticatorSampleApp", "Cannot instantiate Amplify. Please see the getting started guide at https://docs.amplify.aws/lib/auth/getting-started/q/platform/android/ for details.", e) + } + } +} diff --git a/samples/authenticator/app/src/main/java/com/amplifyframework/ui/sample/authenticator/MainActivity.kt b/samples/authenticator/app/src/main/java/com/amplifyframework/ui/sample/authenticator/MainActivity.kt new file mode 100644 index 00000000..fc561c95 --- /dev/null +++ b/samples/authenticator/app/src/main/java/com/amplifyframework/ui/sample/authenticator/MainActivity.kt @@ -0,0 +1,142 @@ +/* + * Copyright 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.sample.authenticator + +import android.app.Activity +import android.content.Context +import android.content.ContextWrapper +import android.os.Bundle +import androidx.activity.ComponentActivity +import androidx.activity.compose.setContent +import androidx.compose.foundation.isSystemInDarkTheme +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.fillMaxHeight +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.padding +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.filled.Menu +import androidx.compose.material3.Button +import androidx.compose.material3.DrawerState +import androidx.compose.material3.DrawerValue +import androidx.compose.material3.ExperimentalMaterial3Api +import androidx.compose.material3.Icon +import androidx.compose.material3.IconButton +import androidx.compose.material3.ModalNavigationDrawer +import androidx.compose.material3.Scaffold +import androidx.compose.material3.Surface +import androidx.compose.material3.Text +import androidx.compose.material3.TopAppBar +import androidx.compose.material3.rememberDrawerState +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.rememberCoroutineScope +import androidx.compose.runtime.setValue +import androidx.compose.ui.Modifier +import androidx.compose.ui.unit.dp +import com.amplifyframework.ui.authenticator.AuthenticatorState +import com.amplifyframework.ui.authenticator.SignedInState +import com.amplifyframework.ui.authenticator.rememberAuthenticatorState +import com.amplifyframework.ui.authenticator.ui.Authenticator +import kotlinx.coroutines.launch + +class MainActivity : ComponentActivity() { + @OptIn(ExperimentalMaterial3Api::class) + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContent { + val inDarkMode = isSystemInDarkTheme() + var currentTheme by remember { mutableStateOf(SupportedTheme.Default) } + var darkMode by remember { mutableStateOf(inDarkMode) } + val drawerState = rememberDrawerState(initialValue = DrawerValue.Closed) + + val authenticatorState = rememberAuthenticatorState() + + ApplyTheme(theme = currentTheme, darkMode = darkMode) { + ModalNavigationDrawer( + drawerState = drawerState, + drawerContent = { + Surface(modifier = Modifier.fillMaxHeight()) { + Column(modifier = Modifier.padding(horizontal = 16.dp)) { + ThemeSelector( + modifier = Modifier.padding(16.dp), + currentTheme = currentTheme, + darkMode = darkMode, + onChangeCurrentTheme = { currentTheme = it }, + onChangeDarkMode = { darkMode = it } + ) + } + } + } + ) { + SampleAppContent(drawerState, authenticatorState) + } + } + } + } +} + +@OptIn(ExperimentalMaterial3Api::class) +@Composable +fun SampleAppContent( + drawerState: DrawerState, + authenticatorState: AuthenticatorState +) { + val scope = rememberCoroutineScope() + Scaffold( + topBar = { + TopAppBar( + title = { Text("Authenticator Sample App") }, + navigationIcon = { + IconButton(onClick = { + scope.launch { drawerState.open() } + }) { + Icon(imageVector = Icons.Default.Menu, contentDescription = "Open Menu") + } + } + ) + } + ) { padding -> + Column( + modifier = Modifier + .fillMaxSize() + .padding(padding), + verticalArrangement = Arrangement.Center + ) { + Authenticator( + modifier = Modifier.fillMaxWidth(), + state = authenticatorState + ) { state -> + SignedInContent(state) + } + } + } +} + +@Suppress("DeferredResultUnused") +@Composable +fun SignedInContent(state: SignedInState) { + val scope = rememberCoroutineScope() + Column { + Text("You've signed in as ${state.user.username}!") + Button(onClick = { scope.launch { state.signOut() } }) { + Text("Sign Out") + } + } +} diff --git a/samples/authenticator/app/src/main/java/com/amplifyframework/ui/sample/authenticator/ThemeSelector.kt b/samples/authenticator/app/src/main/java/com/amplifyframework/ui/sample/authenticator/ThemeSelector.kt new file mode 100644 index 00000000..1ee09578 --- /dev/null +++ b/samples/authenticator/app/src/main/java/com/amplifyframework/ui/sample/authenticator/ThemeSelector.kt @@ -0,0 +1,66 @@ +/* + * Copyright 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.sample.authenticator + +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.padding +import androidx.compose.material3.ExperimentalMaterial3Api +import androidx.compose.material3.RadioButton +import androidx.compose.material3.Switch +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.unit.dp +import com.amplifyframework.ui.sample.authenticator.theme.amplify.AmplifyTheme +import com.amplifyframework.ui.sample.authenticator.theme.default.AppTheme + +enum class SupportedTheme { + Default, + Amplify +} + +@OptIn(ExperimentalMaterial3Api::class) +@Composable +fun ThemeSelector( + modifier: Modifier = Modifier, + currentTheme: SupportedTheme, + darkMode: Boolean, + onChangeCurrentTheme: (SupportedTheme) -> Unit, + onChangeDarkMode: (Boolean) -> Unit +) { + Column(modifier = modifier) { + SupportedTheme.values().forEach { theme -> + Row(verticalAlignment = Alignment.CenterVertically) { + RadioButton(selected = theme == currentTheme, onClick = { onChangeCurrentTheme(theme) }) + Text(modifier = Modifier.padding(start = 8.dp), text = theme.name) + } + } + Row(verticalAlignment = Alignment.CenterVertically) { + Switch(checked = darkMode, onCheckedChange = { onChangeDarkMode(!darkMode) }) + Text(modifier = Modifier.padding(start = 8.dp), text = "Dark Mode") + } + } +} + +@Composable +fun ApplyTheme(theme: SupportedTheme, darkMode: Boolean, content: @Composable () -> Unit) { + when (theme) { + SupportedTheme.Default -> AppTheme(darkTheme = darkMode, content = content) + SupportedTheme.Amplify -> AmplifyTheme(useDarkTheme = darkMode, content = content) + } +} diff --git a/samples/authenticator/app/src/main/java/com/amplifyframework/ui/sample/authenticator/theme/default/Color.kt b/samples/authenticator/app/src/main/java/com/amplifyframework/ui/sample/authenticator/theme/default/Color.kt new file mode 100644 index 00000000..99012530 --- /dev/null +++ b/samples/authenticator/app/src/main/java/com/amplifyframework/ui/sample/authenticator/theme/default/Color.kt @@ -0,0 +1,26 @@ +/* + * Copyright 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.sample.authenticator.theme.default + +import androidx.compose.ui.graphics.Color + +val Purple80 = Color(0xFFD0BCFF) +val PurpleGrey80 = Color(0xFFCCC2DC) +val Pink80 = Color(0xFFEFB8C8) + +val Purple40 = Color(0xFF6650a4) +val PurpleGrey40 = Color(0xFF625b71) +val Pink40 = Color(0xFF7D5260) diff --git a/samples/authenticator/app/src/main/java/com/amplifyframework/ui/sample/authenticator/theme/default/Theme.kt b/samples/authenticator/app/src/main/java/com/amplifyframework/ui/sample/authenticator/theme/default/Theme.kt new file mode 100644 index 00000000..bb852ef3 --- /dev/null +++ b/samples/authenticator/app/src/main/java/com/amplifyframework/ui/sample/authenticator/theme/default/Theme.kt @@ -0,0 +1,92 @@ +/* + * Copyright 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.sample.authenticator.theme.default + +import android.app.Activity +import android.os.Build +import androidx.compose.foundation.isSystemInDarkTheme +import androidx.compose.material3.ColorScheme +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.darkColorScheme +import androidx.compose.material3.dynamicDarkColorScheme +import androidx.compose.material3.dynamicLightColorScheme +import androidx.compose.material3.lightColorScheme +import androidx.compose.runtime.Composable +import androidx.compose.runtime.ReadOnlyComposable +import androidx.compose.runtime.SideEffect +import androidx.compose.ui.graphics.toArgb +import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.platform.LocalView +import androidx.core.view.ViewCompat + +private val DarkColorScheme = darkColorScheme( + primary = Purple80, + secondary = PurpleGrey80, + tertiary = Pink80 +) + +private val LightColorScheme = lightColorScheme( + primary = Purple40, + secondary = PurpleGrey40, + tertiary = Pink40 + + /* Other default colors to override + background = Color(0xFFFFFBFE), + surface = Color(0xFFFFFBFE), + onPrimary = Color.White, + onSecondary = Color.White, + onTertiary = Color.White, + onBackground = Color(0xFF1C1B1F), + onSurface = Color(0xFF1C1B1F), + */ +) + +@Composable +fun AppTheme( + darkTheme: Boolean = isSystemInDarkTheme(), + // Dynamic color is available on Android 12+ + dynamicColor: Boolean = true, + content: @Composable () -> Unit +) { + val colorScheme = when { + dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> { + val context = LocalContext.current + if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context) + } + darkTheme -> DarkColorScheme + else -> LightColorScheme + } + val view = LocalView.current + if (!view.isInEditMode) { + SideEffect { + (view.context as Activity).window.statusBarColor = colorScheme.primary.toArgb() + ViewCompat.getWindowInsetsController(view)?.isAppearanceLightStatusBars = darkTheme + } + } + + MaterialTheme( + colorScheme = colorScheme, + typography = Typography, + content = content + ) +} + +object AppTheme { + val colorScheme: ColorScheme + @Composable + @ReadOnlyComposable + get() = MaterialTheme.colorScheme +} diff --git a/samples/authenticator/app/src/main/java/com/amplifyframework/ui/sample/authenticator/theme/default/Type.kt b/samples/authenticator/app/src/main/java/com/amplifyframework/ui/sample/authenticator/theme/default/Type.kt new file mode 100644 index 00000000..93cb653c --- /dev/null +++ b/samples/authenticator/app/src/main/java/com/amplifyframework/ui/sample/authenticator/theme/default/Type.kt @@ -0,0 +1,49 @@ +/* + * Copyright 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.sample.authenticator.theme.default + +import androidx.compose.material3.Typography +import androidx.compose.ui.text.TextStyle +import androidx.compose.ui.text.font.FontFamily +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.unit.sp + +// Set of Material typography styles to start with +val Typography = Typography( + bodyLarge = TextStyle( + fontFamily = FontFamily.Default, + fontWeight = FontWeight.Normal, + fontSize = 16.sp, + lineHeight = 24.sp, + letterSpacing = 0.5.sp + ) + /* Other default text styles to override + titleLarge = TextStyle( + fontFamily = FontFamily.Default, + fontWeight = FontWeight.Normal, + fontSize = 22.sp, + lineHeight = 28.sp, + letterSpacing = 0.sp + ), + labelSmall = TextStyle( + fontFamily = FontFamily.Default, + fontWeight = FontWeight.Medium, + fontSize = 11.sp, + lineHeight = 16.sp, + letterSpacing = 0.5.sp + ) + */ +) diff --git a/samples/authenticator/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/samples/authenticator/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 00000000..09a6caee --- /dev/null +++ b/samples/authenticator/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + diff --git a/samples/authenticator/app/src/main/res/drawable/amplify.xml b/samples/authenticator/app/src/main/res/drawable/amplify.xml new file mode 100644 index 00000000..3a412887 --- /dev/null +++ b/samples/authenticator/app/src/main/res/drawable/amplify.xml @@ -0,0 +1,48 @@ + + + + + + + + + + + + + diff --git a/samples/authenticator/app/src/main/res/drawable/ic_launcher_background.xml b/samples/authenticator/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 00000000..49796b7e --- /dev/null +++ b/samples/authenticator/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,184 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/samples/authenticator/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml b/samples/authenticator/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml new file mode 100644 index 00000000..268471d5 --- /dev/null +++ b/samples/authenticator/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml @@ -0,0 +1,19 @@ + + + + + + diff --git a/samples/authenticator/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml b/samples/authenticator/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml new file mode 100644 index 00000000..268471d5 --- /dev/null +++ b/samples/authenticator/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml @@ -0,0 +1,19 @@ + + + + + + diff --git a/samples/authenticator/app/src/main/res/mipmap-anydpi-v33/ic_launcher.xml b/samples/authenticator/app/src/main/res/mipmap-anydpi-v33/ic_launcher.xml new file mode 100644 index 00000000..28952e8b --- /dev/null +++ b/samples/authenticator/app/src/main/res/mipmap-anydpi-v33/ic_launcher.xml @@ -0,0 +1,20 @@ + + + + + + + diff --git a/samples/authenticator/app/src/main/res/mipmap-hdpi/ic_launcher.webp b/samples/authenticator/app/src/main/res/mipmap-hdpi/ic_launcher.webp new file mode 100644 index 0000000000000000000000000000000000000000..c209e78ecd372343283f4157dcfd918ec5165bb3 GIT binary patch literal 1404 zcmV-?1%vuhNk&F=1pok7MM6+kP&il$0000G0000-002h-06|PpNX!5L00Dqw+t%{r zzW2vH!KF=w&cMnnN@{whkTw+#mAh0SV?YL=)3MimFYCWp#fpdtz~8$hD5VPuQgtcN zXl<@<#Cme5f5yr2h%@8TWh?)bSK`O z^Z@d={gn7J{iyxL_y_%J|L>ep{dUxUP8a{byupH&!UNR*OutO~0{*T4q5R6@ApLF! z5{w?Z150gC7#>(VHFJZ-^6O@PYp{t!jH(_Z*nzTK4 zkc{fLE4Q3|mA2`CWQ3{8;gxGizgM!zccbdQoOLZc8hThi-IhN90RFT|zlxh3Ty&VG z?Fe{#9RrRnxzsu|Lg2ddugg7k%>0JeD+{XZ7>Z~{=|M+sh1MF7~ zz>To~`~LVQe1nNoR-gEzkpe{Ak^7{{ZBk2i_<+`Bq<^GB!RYG+z)h;Y3+<{zlMUYd zrd*W4w&jZ0%kBuDZ1EW&KLpyR7r2=}fF2%0VwHM4pUs}ZI2egi#DRMYZPek*^H9YK zay4Iy3WXFG(F14xYsoDA|KXgGc5%2DhmQ1gFCkrgHBm!lXG8I5h*uf{rn48Z!_@ z4Bk6TJAB2CKYqPjiX&mWoW>OPFGd$wqroa($ne7EUK;#3VYkXaew%Kh^3OrMhtjYN?XEoY`tRPQsAkH-DSL^QqyN0>^ zmC>{#F14jz4GeW{pJoRpLFa_*GI{?T93^rX7SPQgT@LbLqpNA}<@2wH;q493)G=1Y z#-sCiRNX~qf3KgiFzB3I>4Z%AfS(3$`-aMIBU+6?gbgDb!)L~A)je+;fR0jWLL-Fu z4)P{c7{B4Hp91&%??2$v9iRSFnuckHUm}or9seH6 z>%NbT+5*@L5(I9j@06@(!{ZI?U0=pKn8uwIg&L{JV14+8s2hnvbRrU|hZCd}IJu7*;;ECgO%8_*W Kmw_-CKmY()leWbG literal 0 HcmV?d00001 diff --git a/samples/authenticator/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp b/samples/authenticator/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp new file mode 100644 index 0000000000000000000000000000000000000000..b2dfe3d1ba5cf3ee31b3ecc1ced89044a1f3b7a9 GIT binary patch literal 2898 zcmV-Y3$650Nk&FW3jhFDMM6+kP&il$0000G0000-002h-06|PpNWB9900E$G+qN-D z+81ABX7q?;bwx%xBg?kcwr$(C-Tex-ZCkHUw(Y9#+`E5-zuONG5fgw~E2WDng@Bc@ z24xy+R1n%~6xI#u9vJ8zREI)sb<&Il(016}Z~V1n^PU3-_H17A*Bf^o)&{_uBv}Py zulRfeE8g(g6HFhk_?o_;0@tz?1I+l+Y#Q*;RVC?(ud`_cU-~n|AX-b`JHrOIqn(-t&rOg-o`#C zh0LPxmbOAEb;zHTu!R3LDh1QO zZTf-|l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uG-+Axf*AZ-P1 z0ZZ*fx+ck4{XtFsbcc%GRStht@q!m*ImssGwuK+P@%gEK!f5dHymg<9nSCXsB6 zQ*{<`%^bxB($Z@5286^-A(tR;r+p7B%^%$N5h%lb*Vlz-?DL9x;!j<5>~kmXP$E}m zQV|7uv4SwFs0jUervsxVUm>&9Y3DBIzc1XW|CUZrUdb<&{@D5yuLe%Xniw^x&{A2s z0q1+owDSfc3Gs?ht;3jw49c#mmrViUfX-yvc_B*wY|Lo7; zGh!t2R#BHx{1wFXReX*~`NS-LpSX z#TV*miO^~B9PF%O0huw!1Zv>^d0G3$^8dsC6VI!$oKDKiXdJt{mGkyA`+Gwd4D-^1qtNTUK)`N*=NTG-6}=5k6suNfdLt*dt8D| z%H#$k)z#ZRcf|zDWB|pn<3+7Nz>?WW9WdkO5(a^m+D4WRJ9{wc>Y}IN)2Kbgn;_O? zGqdr&9~|$Y0tP=N(k7^Eu;iO*w+f%W`20BNo)=Xa@M_)+o$4LXJyiw{F?a633SC{B zl~9FH%?^Rm*LVz`lkULs)%idDX^O)SxQol(3jDRyBVR!7d`;ar+D7do)jQ}m`g$TevUD5@?*P8)voa?kEe@_hl{_h8j&5eB-5FrYW&*FHVt$ z$kRF9Nstj%KRzpjdd_9wO=4zO8ritN*NPk_9avYrsF(!4))tm{Ga#OY z(r{0buexOzu7+rw8E08Gxd`LTOID{*AC1m*6Nw@osfB%0oBF5sf<~wH1kL;sd zo)k6^VyRFU`)dt*iX^9&QtWbo6yE8XXH?`ztvpiOLgI3R+=MOBQ9=rMVgi<*CU%+d1PQQ0a1U=&b0vkF207%xU0ssI2 literal 0 HcmV?d00001 diff --git a/samples/authenticator/app/src/main/res/mipmap-mdpi/ic_launcher.webp b/samples/authenticator/app/src/main/res/mipmap-mdpi/ic_launcher.webp new file mode 100644 index 0000000000000000000000000000000000000000..4f0f1d64e58ba64d180ce43ee13bf9a17835fbca GIT binary patch literal 982 zcmV;{11bDcNk&G_0{{S5MM6+kP&il$0000G0000l001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7+c2kck>`^q1^^gR0QB7Y?KUD{vz-uVX~;V-rW)PDcI)$_UjgVV?S?=oLR zf4}zz{#*R_{LkiJ#0RdQLNC^2Vp%JPEUvG9ra2BVZ92(p9h7Ka@!yf9(lj#}>+|u* z;^_?KWdzkM`6gqPo9;;r6&JEa)}R3X{(CWv?NvgLeOTq$cZXqf7|sPImi-7cS8DCN zGf;DVt3Am`>hH3{4-WzH43Ftx)SofNe^-#|0HdCo<+8Qs!}TZP{HH8~z5n`ExcHuT zDL1m&|DVpIy=xsLO>8k92HcmfSKhflQ0H~9=^-{#!I1g(;+44xw~=* zxvNz35vfsQE)@)Zsp*6_GjYD};Squ83<_?^SbALb{a`j<0Gn%6JY!zhp=Fg}Ga2|8 z52e1WU%^L1}15Ex0fF$e@eCT(()_P zvV?CA%#Sy08_U6VPt4EtmVQraWJX` zh=N|WQ>LgrvF~R&qOfB$!%D3cGv?;Xh_z$z7k&s4N)$WYf*k=|*jCEkO19{h_(%W4 zPuOqbCw`SeAX*R}UUsbVsgtuG?xs(#Ikx9`JZoQFz0n*7ZG@Fv@kZk`gzO$HoA9kN z8U5{-yY zvV{`&WKU2$mZeoBmiJrEdzUZAv1sRxpePdg1)F*X^Y)zp^Y*R;;z~vOv-z&)&G)JQ{m!C9cmziu1^nHA z`#`0c>@PnQ9CJKgC5NjJD8HM3|KC(g5nnCq$n0Gsu_DXk36@ql%npEye|?%RmG)

FJ$wK}0tWNB{uH;AM~i literal 0 HcmV?d00001 diff --git a/samples/authenticator/app/src/main/res/mipmap-xhdpi/ic_launcher.webp b/samples/authenticator/app/src/main/res/mipmap-xhdpi/ic_launcher.webp new file mode 100644 index 0000000000000000000000000000000000000000..948a3070fe34c611c42c0d3ad3013a0dce358be0 GIT binary patch literal 1900 zcmV-y2b1_xNk&Fw2LJ$9MM6+kP&il$0000G0001A003VA06|PpNH75a00DqwTbm-~ zullQTcXxO9ki!OCRx^i?oR|n!<8G0=kI^!JSjFi-LL*`V;ET0H2IXfU0*i>o6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xa(#^VU5}@FNqpc$?#SbVsX!~RH*5p0p@w z;~v{QMX0^bFT1!cXGM8K9FP+=9~-d~#TK#ZE{4umGT=;dfvWi?rYj;^l_Zxywze`W z^Cr{55U@*BalS}K%Czii_80e0#0#Zkhlij4-~I@}`-JFJ7$5{>LnoJSs??J8kWVl6|8A}RCGAu9^rAsfCE=2}tHwl93t0C?#+jMpvr7O3`2=tr{Hg$=HlnjVG^ewm|Js0J*kfPa6*GhtB>`fN!m#9J(sU!?(OSfzY*zS(FJ<-Vb zfAIg+`U)YaXv#sY(c--|X zEB+TVyZ%Ie4L$gi#Fc++`h6%vzsS$pjz9aLt+ZL(g;n$Dzy5=m=_TV(3H8^C{r0xd zp#a%}ht55dOq?yhwYPrtp-m1xXp;4X;)NhxxUpgP%XTLmO zcjaFva^}dP3$&sfFTIR_jC=2pHh9kpI@2(6V*GQo7Ws)`j)hd+tr@P~gR*2gO@+1? zG<`_tB+LJuF|SZ9tIec;h%}}6WClT`L>HSW?E{Hp1h^+mlbf_$9zA>!ug>NALJsO{ mU%z=YwVD?}XMya)Bp;vlyE5&E_6!fzx9pwrdz474!~g(M6R?N? literal 0 HcmV?d00001 diff --git a/samples/authenticator/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp b/samples/authenticator/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp new file mode 100644 index 0000000000000000000000000000000000000000..1b9a6956b3acdc11f40ce2bb3f6efbd845cc243f GIT binary patch literal 3918 zcmV-U53%r4Nk&FS4*&pHMM6+kP&il$0000G0001A003VA06|PpNSy@$00HoY|G(*G z+qV7x14$dSO^Re!iqt-AAIE9iwr$(CZQJL$blA4B`>;C3fBY6Q8_YSjb2%a=fc}4E zrSzssacq<^nmW|Rs93PJni30R<8w<(bK_$LO4L?!_OxLl$}K$MUEllnMK|rg=f3;y z*?;3j|Nh>)p0JQ3A~rf(MibH2r+)3cyV1qF&;8m{w-S*y+0mM){KTK^M5}ksc`qX3 zy>rf^b>~l>SSHds8(I@h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46)c5&}B)Tts49oU92>3xBLLy}FMUW=84DQbVq^;7_e7|(Sdz|&J z73N+M`rc2rt*oSWu#7S{*s~nH6HRHJS1SmzeXk|;CA)FI4bat3<%}nkB%;;?=F>B7ms9QSxv#@+69;@>QaR?REYX4&)=itG>rM{<{A79Rmk)`5ON#GL`*KX%}Ihk3w(RtM-WLt z?f&FLF}4N^yE!(pZ&Yj&Bc`~K0@4_}*0Om?wN|}4WJ>WL;G^H2*QpgEkGA~OET-Km zkwz|5{6dnz1U<2Pe9DNL>3g5FEIvp1jzP&2K#z~j%g6!7B;^zF+o95?fV{3mnB8*RMhCDNp>Am-3e@jNfMj?jHV$MWjk!DDKP zkAz$Y?Sr)!GUOX}qTQ5aMh|wq1uq}~joWyKl=b_LboM#wi{CMuz5x6BKlA-qy++cM01D3b7`uD z#l6M4pI;JCypO8JZ6?U&wNxR!{4oB_ zlV!x9+-&Qy6{%MQ{~yoZGkKiTSC`YS_j22~G;xUV855g2&C(zm^V!(wpcm@zn{%!g z4}JGo(sGZ1O~to-}le

UmY2RIYtNPVDpE$%vda+HD#3m z&VuXJ{BK&Qe+rBa7eq}Q(bq|tn(RrJAk|ztj2(i{d>nmQnM?;HF2k&9sA6up5tmjl z7lySlzMbifH17-m-Lwa_F&e7nOH?ESi3#ckR3tsM+jsck3`oG!uMS}|eAwVXv>}qxwq?QY%QJ0}r@^;fhuUA9W z*BVl>TGo&N004@xSiwDUXUvp51sVmqO3m)=B55aPwf@0=e}cN+$-BdKxY`YrT_4)0 z_d10#i44Q*rFr8MC>*)v$EJvz``(pb{e&*6k+b zsMz%($|1+8hn8c2?P(l@;Rb&CsZeYoCI3?2!LqjbwPXW3z4G$Qfj=cT5Yb%vY0(AX oeb?AaKtwrnc|$|zzw9vfvn^aJJ!zd)XFXqqy0000001=f@-~a#s literal 0 HcmV?d00001 diff --git a/samples/authenticator/app/src/main/res/values/strings.xml b/samples/authenticator/app/src/main/res/values/strings.xml new file mode 100644 index 00000000..d55ea0e1 --- /dev/null +++ b/samples/authenticator/app/src/main/res/values/strings.xml @@ -0,0 +1,18 @@ + + + + Amplify Authenticator + diff --git a/samples/authenticator/app/src/main/res/values/themes.xml b/samples/authenticator/app/src/main/res/values/themes.xml new file mode 100644 index 00000000..59bceba1 --- /dev/null +++ b/samples/authenticator/app/src/main/res/values/themes.xml @@ -0,0 +1,18 @@ + + + +