Skip to content

Commit 9736901

Browse files
authored
feat(authenticator): Authenticator Connected Component (#10)
1 parent a48bbc8 commit 9736901

File tree

116 files changed

+7541
-5
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

116 files changed

+7541
-5
lines changed

authenticator/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

authenticator/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
## [Release 1.0.0-dev-preview.0](https://github.com/aws-amplify/amplify-ui-android/releases/tag/release_authenticator_v1.0.0-dev-preview.0)
2+
3+
### Features
4+
- **authenticator:** Initial Authenticator Dev Preview Release ([#10](https://github.com/aws-amplify/amplify-ui-android/issues/10))

authenticator/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Authenticator
2+
3+
Amplify Authenticator provides a complete drop-in implementation of an authentication flow for your application using [Amplify Authentication](https://docs.amplify.aws/lib/auth/getting-started/q/platform/android/).

authenticator/build.gradle

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
apply plugin: 'com.android.library'
2+
apply plugin: 'kotlin-android'
3+
apply from: rootProject.file("configuration/publishing.gradle")
4+
5+
group = POM_GROUP
6+
7+
android {
8+
namespace 'com.amplifyframework.ui.authenticator'
9+
defaultConfig {
10+
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
11+
}
12+
13+
publishing {
14+
singleVariant("release") {
15+
withSourcesJar()
16+
}
17+
}
18+
}
19+
20+
dependencies {
21+
api dependency.amplify.auth
22+
23+
implementation dependency.androidx.material
24+
implementation dependency.androidx.uiTooling
25+
implementation dependency.androidx.lifecycle_ktx
26+
implementation dependency.androidx.compose.viewmodel
27+
28+
testImplementation dependency.test.androidx.espresso
29+
testImplementation dependency.test.androidx.junit
30+
testImplementation dependency.test.junit
31+
testImplementation dependency.test.robolectric
32+
testImplementation dependency.test.mockk
33+
}

authenticator/consumer-rules.pro

Whitespace-only changes.

authenticator/gradle.properties

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#
2+
# Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License").
5+
# You may not use this file except in compliance with the License.
6+
# A copy of the License is located at
7+
#
8+
# http://aws.amazon.com/apache2.0
9+
#
10+
# or in the "license" file accompanying this file. This file is distributed
11+
# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
# express or implied. See the License for the specific language governing
13+
# permissions and limitations under the License.
14+
#
15+
16+
POM_ARTIFACT_ID=authenticator
17+
POM_NAME=Amplify UI Framework for Android - Authenticator
18+
POM_DESCRIPTION=Amplify UI Framework for Android - Authenticator Plugin
19+
POM_PACKAGING=aar
20+
VERSION_NAME=1.0.0-dev-preview.0

authenticator/proguard-rules.pro

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
~ Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the "License").
6+
~ You may not use this file except in compliance with the License.
7+
~ A copy of the License is located at
8+
~
9+
~ http://aws.amazon.com/apache2.0
10+
~
11+
~ or in the "license" file accompanying this file. This file is distributed
12+
~ on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13+
~ express or implied. See the License for the specific language governing
14+
~ permissions and limitations under the License.
15+
-->
16+
17+
<manifest />
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
package com.amplifyframework.ui.authenticator
17+
18+
import com.amplifyframework.ui.authenticator.enums.AuthenticatorInitialStep
19+
import com.amplifyframework.ui.authenticator.forms.SignUpFormBuilder
20+
21+
internal data class AuthenticatorConfiguration(
22+
val initialStep: AuthenticatorInitialStep,
23+
val signUpForm: SignUpFormBuilder.() -> Unit
24+
)
Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
/*
2+
* Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
package com.amplifyframework.ui.authenticator
17+
18+
import androidx.compose.runtime.Immutable
19+
import androidx.compose.runtime.Stable
20+
import com.amplifyframework.auth.AuthCodeDeliveryDetails
21+
import com.amplifyframework.auth.AuthException
22+
import com.amplifyframework.auth.AuthUser
23+
import com.amplifyframework.auth.AuthUserAttribute
24+
import com.amplifyframework.auth.result.AuthSignOutResult
25+
import com.amplifyframework.ui.authenticator.enums.AuthenticatorInitialStep
26+
import com.amplifyframework.ui.authenticator.enums.AuthenticatorStep
27+
import com.amplifyframework.ui.authenticator.forms.MutableFormState
28+
29+
/**
30+
* A Screen State is a state holder for the UI for a specific [AuthenticatorStep].
31+
*/
32+
@Stable
33+
interface AuthenticatorScreenState {
34+
val step: AuthenticatorStep
35+
}
36+
37+
/**
38+
* The Authenticator is loading the current state of the user's Auth session.
39+
*/
40+
@Immutable
41+
object LoadingState : AuthenticatorScreenState {
42+
override val step = AuthenticatorStep.Loading
43+
}
44+
45+
/**
46+
* The Authenticator has encountered an unrecoverable error.
47+
* @param error The error that occurred.
48+
*/
49+
@Immutable
50+
data class ErrorState(val error: AuthException) : AuthenticatorScreenState {
51+
override val step = AuthenticatorStep.Error
52+
}
53+
54+
/**
55+
* The user has completed the sign in process.
56+
*/
57+
@Immutable
58+
interface SignedInState : AuthenticatorScreenState {
59+
/**
60+
* The [AuthUser] instance for the signed in user.
61+
*/
62+
val user: AuthUser
63+
64+
/**
65+
* Sign out the current user. This does a local sign out and returns the [AuthSignOutResult] that
66+
* may be inspected to determine if any parts of the sign out were unsuccessful.
67+
*/
68+
suspend fun signOut(): AuthSignOutResult
69+
}
70+
71+
/**
72+
* An [AuthenticatorScreenState] for a part of UI that contains an input form.
73+
*/
74+
@Stable
75+
interface FormHolderState : AuthenticatorScreenState {
76+
val form: MutableFormState
77+
}
78+
79+
/**
80+
* The user is on the Sign In step. They can enter their Sign In information to authenticate with Amplify.
81+
*/
82+
@Stable
83+
interface SignInState : FormHolderState {
84+
fun moveTo(step: AuthenticatorInitialStep)
85+
suspend fun signIn()
86+
}
87+
88+
/**
89+
* The user has completed the initial Sign In step, and needs to enter the confirmation code from an MFA
90+
* message to complete the sign in process.
91+
*/
92+
@Stable
93+
interface SignInConfirmMfaState : FormHolderState {
94+
val deliveryDetails: AuthCodeDeliveryDetails?
95+
fun moveTo(step: AuthenticatorInitialStep)
96+
suspend fun confirmSignIn()
97+
}
98+
99+
/**
100+
* The user has completed the initial Sign In step, and needs to enter the confirmation code from a custom
101+
* challenge to complete the sign in process.
102+
*/
103+
@Stable
104+
interface SignInConfirmCustomState : FormHolderState {
105+
val additionalInfo: Map<String, String>
106+
val deliveryDetails: AuthCodeDeliveryDetails?
107+
fun moveTo(step: AuthenticatorInitialStep)
108+
suspend fun confirmSignIn()
109+
}
110+
111+
/**
112+
* The user has completed the initial Sign In step, and is required to change their password in order to complete
113+
* the sign in process.
114+
*/
115+
@Stable
116+
interface SignInConfirmNewPasswordState : FormHolderState {
117+
fun moveTo(step: AuthenticatorInitialStep)
118+
suspend fun confirmSignIn()
119+
}
120+
121+
/**
122+
* The user is on the Sign Up step, and can fill out the account creation form to Sign Up.
123+
*/
124+
@Stable
125+
interface SignUpState : FormHolderState {
126+
fun moveTo(step: AuthenticatorInitialStep)
127+
suspend fun signUp()
128+
}
129+
130+
/**
131+
* The user has signed up, but needs to enter a confirmation code sent to them.
132+
*/
133+
@Stable
134+
interface SignUpConfirmState : FormHolderState {
135+
val deliveryDetails: AuthCodeDeliveryDetails?
136+
fun moveTo(step: AuthenticatorInitialStep)
137+
suspend fun confirmSignUp()
138+
suspend fun resendCode()
139+
}
140+
141+
/**
142+
* The user is on the Password Reset step. They can enter their username to begin the password reset.
143+
*/
144+
@Stable
145+
interface PasswordResetState : FormHolderState {
146+
fun moveTo(step: AuthenticatorInitialStep)
147+
suspend fun submitPasswordReset()
148+
}
149+
150+
/**
151+
* The user has entered their username and been sent a confirmation code. The need to enter the code and their new
152+
* password to complete the password reset.
153+
*/
154+
@Stable
155+
interface PasswordResetConfirmState : FormHolderState {
156+
val deliveryDetails: AuthCodeDeliveryDetails?
157+
fun moveTo(step: AuthenticatorInitialStep)
158+
suspend fun submitPasswordResetConfirm()
159+
}
160+
161+
/**
162+
* 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.
163+
*/
164+
@Stable
165+
interface VerifyUserState : FormHolderState {
166+
/**
167+
* The list of unverified attributes.
168+
*/
169+
val attributes: List<AuthUserAttribute>
170+
171+
/**
172+
* Submit the selected attribute to initiate the attribute verification.
173+
*/
174+
suspend fun verifyUser()
175+
176+
/**
177+
* Skip verification and move to the Signed In state
178+
*/
179+
fun skip()
180+
}
181+
182+
/**
183+
* The user has initiated verification of an account recovery mechanism (email, phone) and needs to provide a confirmation code.
184+
*/
185+
@Stable
186+
interface VerifyUserConfirmState : FormHolderState {
187+
/**
188+
* The details of where the verification code was sent.
189+
*/
190+
val deliveryDetails: AuthCodeDeliveryDetails?
191+
192+
/**
193+
* Submit the entered confirmation code to confirm the verification.
194+
*/
195+
suspend fun confirmVerifyUser()
196+
197+
/**
198+
* Re-send the verification code.
199+
*/
200+
suspend fun resendCode()
201+
202+
/**
203+
* Skip verification and move to the Signed In state
204+
*/
205+
fun skip()
206+
}

0 commit comments

Comments
 (0)