Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(auth): Add Passwordless features to Amplify #2952

Merged
merged 10 commits into from
Nov 27, 2024
85 changes: 82 additions & 3 deletions aws-auth-cognito/api/aws-auth-cognito.api
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ public final class com/amplifyframework/auth/cognito/AWSCognitoAuthPlugin : com/
public static final field AWS_COGNITO_AUTH_LOG_NAMESPACE Ljava/lang/String;
public static final field Companion Lcom/amplifyframework/auth/cognito/AWSCognitoAuthPlugin$Companion;
public fun <init> ()V
public fun associateWebAuthnCredential (Landroid/app/Activity;Lcom/amplifyframework/auth/options/AuthAssociateWebAuthnCredentialsOptions;Lcom/amplifyframework/core/Action;Lcom/amplifyframework/core/Consumer;)V
public fun associateWebAuthnCredential (Landroid/app/Activity;Lcom/amplifyframework/core/Action;Lcom/amplifyframework/core/Consumer;)V
public fun autoSignIn (Lcom/amplifyframework/core/Consumer;Lcom/amplifyframework/core/Consumer;)V
public final fun clearFederationToIdentityPool (Lcom/amplifyframework/core/Action;Lcom/amplifyframework/core/Consumer;)V
public fun configure (Lorg/json/JSONObject;Landroid/content/Context;)V
public fun confirmResetPassword (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lcom/amplifyframework/auth/options/AuthConfirmResetPasswordOptions;Lcom/amplifyframework/core/Action;Lcom/amplifyframework/core/Consumer;)V
Expand All @@ -20,6 +23,8 @@ public final class com/amplifyframework/auth/cognito/AWSCognitoAuthPlugin : com/
public fun confirmSignUp (Ljava/lang/String;Ljava/lang/String;Lcom/amplifyframework/core/Consumer;Lcom/amplifyframework/core/Consumer;)V
public fun confirmUserAttribute (Lcom/amplifyframework/auth/AuthUserAttributeKey;Ljava/lang/String;Lcom/amplifyframework/core/Action;Lcom/amplifyframework/core/Consumer;)V
public fun deleteUser (Lcom/amplifyframework/core/Action;Lcom/amplifyframework/core/Consumer;)V
public fun deleteWebAuthnCredential (Ljava/lang/String;Lcom/amplifyframework/auth/options/AuthDeleteWebAuthnCredentialOptions;Lcom/amplifyframework/core/Action;Lcom/amplifyframework/core/Consumer;)V
public fun deleteWebAuthnCredential (Ljava/lang/String;Lcom/amplifyframework/core/Action;Lcom/amplifyframework/core/Consumer;)V
public final fun federateToIdentityPool (Ljava/lang/String;Lcom/amplifyframework/auth/AuthProvider;Lcom/amplifyframework/auth/cognito/options/FederateToIdentityPoolOptions;Lcom/amplifyframework/core/Consumer;Lcom/amplifyframework/core/Consumer;)V
public final fun federateToIdentityPool (Ljava/lang/String;Lcom/amplifyframework/auth/AuthProvider;Lcom/amplifyframework/core/Consumer;Lcom/amplifyframework/core/Consumer;)V
public fun fetchAuthSession (Lcom/amplifyframework/auth/options/AuthFetchSessionOptions;Lcom/amplifyframework/core/Consumer;Lcom/amplifyframework/core/Consumer;)V
Expand All @@ -36,6 +41,8 @@ public final class com/amplifyframework/auth/cognito/AWSCognitoAuthPlugin : com/
public fun getVersion ()Ljava/lang/String;
public fun handleWebUISignInResponse (Landroid/content/Intent;)V
public fun initialize (Landroid/content/Context;)V
public fun listWebAuthnCredentials (Lcom/amplifyframework/auth/options/AuthListWebAuthnCredentialsOptions;Lcom/amplifyframework/core/Consumer;Lcom/amplifyframework/core/Consumer;)V
public fun listWebAuthnCredentials (Lcom/amplifyframework/core/Consumer;Lcom/amplifyframework/core/Consumer;)V
public fun rememberDevice (Lcom/amplifyframework/core/Action;Lcom/amplifyframework/core/Consumer;)V
public fun resendSignUpCode (Ljava/lang/String;Lcom/amplifyframework/auth/options/AuthResendSignUpCodeOptions;Lcom/amplifyframework/core/Consumer;Lcom/amplifyframework/core/Consumer;)V
public fun resendSignUpCode (Ljava/lang/String;Lcom/amplifyframework/core/Consumer;Lcom/amplifyframework/core/Consumer;)V
Expand Down Expand Up @@ -238,7 +245,8 @@ public class com/amplifyframework/auth/cognito/exceptions/service/TooManyRequest
}

public class com/amplifyframework/auth/cognito/exceptions/service/UserCancelledException : com/amplifyframework/auth/exceptions/ServiceException {
public fun <init> (Ljava/lang/String;Ljava/lang/String;)V
public fun <init> (Ljava/lang/String;Ljava/lang/String;Ljava/lang/Throwable;)V
public synthetic fun <init> (Ljava/lang/String;Ljava/lang/String;Ljava/lang/Throwable;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
}

public class com/amplifyframework/auth/cognito/exceptions/service/UserLambdaValidationException : com/amplifyframework/auth/exceptions/ServiceException {
Expand All @@ -257,6 +265,21 @@ public class com/amplifyframework/auth/cognito/exceptions/service/UsernameExists
public fun <init> (Ljava/lang/Throwable;)V
}

public final class com/amplifyframework/auth/cognito/exceptions/service/WebAuthnNotEnabledException : com/amplifyframework/auth/exceptions/ServiceException {
}

public final class com/amplifyframework/auth/cognito/exceptions/webauthn/WebAuthnCredentialAlreadyExistsException : com/amplifyframework/auth/cognito/exceptions/webauthn/WebAuthnFailedException {
}

public class com/amplifyframework/auth/cognito/exceptions/webauthn/WebAuthnFailedException : com/amplifyframework/auth/AuthException {
}

public final class com/amplifyframework/auth/cognito/exceptions/webauthn/WebAuthnNotSupportedException : com/amplifyframework/auth/cognito/exceptions/webauthn/WebAuthnFailedException {
}

public final class com/amplifyframework/auth/cognito/exceptions/webauthn/WebAuthnRpMismatchException : com/amplifyframework/auth/cognito/exceptions/webauthn/WebAuthnFailedException {
}

public final class com/amplifyframework/auth/cognito/helpers/FlutterFactory {
public static final field INSTANCE Lcom/amplifyframework/auth/cognito/helpers/FlutterFactory;
public final fun createAWSCognitoAuthSession (ZLcom/amplifyframework/auth/result/AuthSessionResult;Lcom/amplifyframework/auth/result/AuthSessionResult;Lcom/amplifyframework/auth/result/AuthSessionResult;Lcom/amplifyframework/auth/result/AuthSessionResult;)Lcom/amplifyframework/auth/cognito/AWSCognitoAuthSession;
Expand Down Expand Up @@ -295,9 +318,11 @@ public final class com/amplifyframework/auth/cognito/options/AWSCognitoAuthConfi
public final fun component1 ()Ljava/util/Map;
public final fun component2 ()Ljava/util/List;
public final fun component3 ()Ljava/lang/String;
public final fun copy (Ljava/util/Map;Ljava/util/List;Ljava/lang/String;)Lcom/amplifyframework/auth/cognito/options/AWSCognitoAuthConfirmSignInOptions;
public static synthetic fun copy$default (Lcom/amplifyframework/auth/cognito/options/AWSCognitoAuthConfirmSignInOptions;Ljava/util/Map;Ljava/util/List;Ljava/lang/String;ILjava/lang/Object;)Lcom/amplifyframework/auth/cognito/options/AWSCognitoAuthConfirmSignInOptions;
public final fun component4 ()Ljava/lang/ref/WeakReference;
public final fun copy (Ljava/util/Map;Ljava/util/List;Ljava/lang/String;Ljava/lang/ref/WeakReference;)Lcom/amplifyframework/auth/cognito/options/AWSCognitoAuthConfirmSignInOptions;
public static synthetic fun copy$default (Lcom/amplifyframework/auth/cognito/options/AWSCognitoAuthConfirmSignInOptions;Ljava/util/Map;Ljava/util/List;Ljava/lang/String;Ljava/lang/ref/WeakReference;ILjava/lang/Object;)Lcom/amplifyframework/auth/cognito/options/AWSCognitoAuthConfirmSignInOptions;
public fun equals (Ljava/lang/Object;)Z
public final fun getCallingActivity ()Ljava/lang/ref/WeakReference;
public final fun getFriendlyDeviceName ()Ljava/lang/String;
public final fun getMetadata ()Ljava/util/Map;
public final fun getUserAttributes ()Ljava/util/List;
Expand All @@ -309,6 +334,7 @@ public final class com/amplifyframework/auth/cognito/options/AWSCognitoAuthConfi
public fun <init> ()V
public fun build ()Lcom/amplifyframework/auth/cognito/options/AWSCognitoAuthConfirmSignInOptions;
public synthetic fun build ()Lcom/amplifyframework/auth/options/AuthConfirmSignInOptions;
public final fun callingActivity (Landroid/app/Activity;)Lcom/amplifyframework/auth/cognito/options/AWSCognitoAuthConfirmSignInOptions$CognitoBuilder;
public final fun friendlyDeviceName (Ljava/lang/String;)Lcom/amplifyframework/auth/cognito/options/AWSCognitoAuthConfirmSignInOptions$CognitoBuilder;
public fun getThis ()Lcom/amplifyframework/auth/cognito/options/AWSCognitoAuthConfirmSignInOptions$CognitoBuilder;
public synthetic fun getThis ()Lcom/amplifyframework/auth/options/AuthConfirmSignInOptions$Builder;
Expand Down Expand Up @@ -347,6 +373,41 @@ public final class com/amplifyframework/auth/cognito/options/AWSCognitoAuthConfi
public final fun invoke (Lkotlin/jvm/functions/Function1;)Lcom/amplifyframework/auth/cognito/options/AWSCognitoAuthConfirmSignUpOptions;
}

public final class com/amplifyframework/auth/cognito/options/AWSCognitoAuthListWebAuthnCredentialsOptions : com/amplifyframework/auth/options/AuthListWebAuthnCredentialsOptions {
public static final field Companion Lcom/amplifyframework/auth/cognito/options/AWSCognitoAuthListWebAuthnCredentialsOptions$Companion;
public static final fun builder ()Lcom/amplifyframework/auth/cognito/options/AWSCognitoAuthListWebAuthnCredentialsOptions$Builder;
public final fun component1 ()Ljava/lang/String;
public final fun component2 ()Ljava/lang/Integer;
public final fun copy (Ljava/lang/String;Ljava/lang/Integer;)Lcom/amplifyframework/auth/cognito/options/AWSCognitoAuthListWebAuthnCredentialsOptions;
public static synthetic fun copy$default (Lcom/amplifyframework/auth/cognito/options/AWSCognitoAuthListWebAuthnCredentialsOptions;Ljava/lang/String;Ljava/lang/Integer;ILjava/lang/Object;)Lcom/amplifyframework/auth/cognito/options/AWSCognitoAuthListWebAuthnCredentialsOptions;
public static final fun defaults ()Lcom/amplifyframework/auth/cognito/options/AWSCognitoAuthListWebAuthnCredentialsOptions;
public fun equals (Ljava/lang/Object;)Z
public final fun getMaxResults ()Ljava/lang/Integer;
public final fun getNextToken ()Ljava/lang/String;
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
}

public final class com/amplifyframework/auth/cognito/options/AWSCognitoAuthListWebAuthnCredentialsOptions$Builder : com/amplifyframework/auth/options/AuthListWebAuthnCredentialsOptions$Builder {
public fun <init> ()V
public fun build ()Lcom/amplifyframework/auth/cognito/options/AWSCognitoAuthListWebAuthnCredentialsOptions;
public synthetic fun build ()Lcom/amplifyframework/auth/options/AuthListWebAuthnCredentialsOptions;
public final fun getMaxResults ()Ljava/lang/Integer;
public final fun getNextToken ()Ljava/lang/String;
public fun getThis ()Lcom/amplifyframework/auth/cognito/options/AWSCognitoAuthListWebAuthnCredentialsOptions$Builder;
public synthetic fun getThis ()Lcom/amplifyframework/auth/options/AuthListWebAuthnCredentialsOptions$Builder;
public final fun maxResults (Ljava/lang/Integer;)Lcom/amplifyframework/auth/cognito/options/AWSCognitoAuthListWebAuthnCredentialsOptions$Builder;
public final fun nextToken (Ljava/lang/String;)Lcom/amplifyframework/auth/cognito/options/AWSCognitoAuthListWebAuthnCredentialsOptions$Builder;
public final synthetic fun setMaxResults (Ljava/lang/Integer;)V
public final synthetic fun setNextToken (Ljava/lang/String;)V
}

public final class com/amplifyframework/auth/cognito/options/AWSCognitoAuthListWebAuthnCredentialsOptions$Companion {
public final fun builder ()Lcom/amplifyframework/auth/cognito/options/AWSCognitoAuthListWebAuthnCredentialsOptions$Builder;
public final fun defaults ()Lcom/amplifyframework/auth/cognito/options/AWSCognitoAuthListWebAuthnCredentialsOptions;
public final synthetic fun invoke (Lkotlin/jvm/functions/Function1;)Lcom/amplifyframework/auth/cognito/options/AWSCognitoAuthListWebAuthnCredentialsOptions;
}

public final class com/amplifyframework/auth/cognito/options/AWSCognitoAuthResendSignUpCodeOptions : com/amplifyframework/auth/options/AuthResendSignUpCodeOptions {
public static final field Companion Lcom/amplifyframework/auth/cognito/options/AWSCognitoAuthResendSignUpCodeOptions$Companion;
public static final fun builder ()Lcom/amplifyframework/auth/cognito/options/AWSCognitoAuthResendSignUpCodeOptions$CognitoBuilder;
Expand Down Expand Up @@ -429,7 +490,9 @@ public final class com/amplifyframework/auth/cognito/options/AWSCognitoAuthSignI
public static fun builder ()Lcom/amplifyframework/auth/cognito/options/AWSCognitoAuthSignInOptions$CognitoBuilder;
public fun equals (Ljava/lang/Object;)Z
public fun getAuthFlowType ()Lcom/amplifyframework/auth/cognito/options/AuthFlowType;
public fun getCallingActivity ()Ljava/lang/ref/WeakReference;
public fun getMetadata ()Ljava/util/Map;
public fun getPreferredFirstFactor ()Lcom/amplifyframework/auth/AuthFactorType;
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
}
Expand All @@ -439,9 +502,11 @@ public final class com/amplifyframework/auth/cognito/options/AWSCognitoAuthSignI
public fun authFlowType (Lcom/amplifyframework/auth/cognito/options/AuthFlowType;)Lcom/amplifyframework/auth/cognito/options/AWSCognitoAuthSignInOptions$CognitoBuilder;
public fun build ()Lcom/amplifyframework/auth/cognito/options/AWSCognitoAuthSignInOptions;
public synthetic fun build ()Lcom/amplifyframework/auth/options/AuthSignInOptions;
public fun callingActivity (Landroid/app/Activity;)Lcom/amplifyframework/auth/cognito/options/AWSCognitoAuthSignInOptions$CognitoBuilder;
public fun getThis ()Lcom/amplifyframework/auth/cognito/options/AWSCognitoAuthSignInOptions$CognitoBuilder;
public synthetic fun getThis ()Lcom/amplifyframework/auth/options/AuthSignInOptions$Builder;
public fun metadata (Ljava/util/Map;)Lcom/amplifyframework/auth/cognito/options/AWSCognitoAuthSignInOptions$CognitoBuilder;
public fun preferredFirstFactor (Lcom/amplifyframework/auth/AuthFactorType;)Lcom/amplifyframework/auth/cognito/options/AWSCognitoAuthSignInOptions$CognitoBuilder;
}

public final class com/amplifyframework/auth/cognito/options/AWSCognitoAuthSignOutOptions : com/amplifyframework/auth/options/AuthSignOutOptions {
Expand Down Expand Up @@ -586,6 +651,7 @@ public final class com/amplifyframework/auth/cognito/options/AuthFlowType : java
public static final field CUSTOM_AUTH Lcom/amplifyframework/auth/cognito/options/AuthFlowType;
public static final field CUSTOM_AUTH_WITHOUT_SRP Lcom/amplifyframework/auth/cognito/options/AuthFlowType;
public static final field CUSTOM_AUTH_WITH_SRP Lcom/amplifyframework/auth/cognito/options/AuthFlowType;
public static final field USER_AUTH Lcom/amplifyframework/auth/cognito/options/AuthFlowType;
public static final field USER_PASSWORD_AUTH Lcom/amplifyframework/auth/cognito/options/AuthFlowType;
public static final field USER_SRP_AUTH Lcom/amplifyframework/auth/cognito/options/AuthFlowType;
public static fun valueOf (Ljava/lang/String;)Lcom/amplifyframework/auth/cognito/options/AuthFlowType;
Expand Down Expand Up @@ -615,6 +681,19 @@ public final class com/amplifyframework/auth/cognito/options/FederateToIdentityP
public final fun invoke (Lkotlin/jvm/functions/Function1;)Lcom/amplifyframework/auth/cognito/options/FederateToIdentityPoolOptions;
}

public final class com/amplifyframework/auth/cognito/result/AWSCognitoAuthListWebAuthnCredentialsResult : com/amplifyframework/auth/result/AuthListWebAuthnCredentialsResult {
public fun <init> (Ljava/util/List;Ljava/lang/String;)V
public final fun component1 ()Ljava/util/List;
public final fun component2 ()Ljava/lang/String;
public final fun copy (Ljava/util/List;Ljava/lang/String;)Lcom/amplifyframework/auth/cognito/result/AWSCognitoAuthListWebAuthnCredentialsResult;
public static synthetic fun copy$default (Lcom/amplifyframework/auth/cognito/result/AWSCognitoAuthListWebAuthnCredentialsResult;Ljava/util/List;Ljava/lang/String;ILjava/lang/Object;)Lcom/amplifyframework/auth/cognito/result/AWSCognitoAuthListWebAuthnCredentialsResult;
public fun equals (Ljava/lang/Object;)Z
public fun getCredentials ()Ljava/util/List;
public final fun getNextToken ()Ljava/lang/String;
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
}

public abstract class com/amplifyframework/auth/cognito/result/AWSCognitoAuthSignOutResult : com/amplifyframework/auth/result/AuthSignOutResult {
public abstract fun getSignedOutLocally ()Z
}
Expand Down
5 changes: 5 additions & 0 deletions aws-auth-cognito/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ group = properties["POM_GROUP"].toString()

android {
namespace = "com.amplifyframework.auth.cognito"
defaultConfig {
consumerProguardFiles += file("consumer-rules.pro")
}
}

dependencies {
Expand All @@ -37,6 +40,7 @@ dependencies {
implementation(libs.androidx.appcompat)
implementation(libs.androidx.security)
implementation(libs.androidx.browser)
implementation(libs.androidx.credentials)

implementation(libs.aws.http)
implementation(libs.aws.cognitoidentity)
Expand All @@ -61,6 +65,7 @@ dependencies {
testImplementation(libs.test.kotlin.reflection)
testImplementation(libs.test.kotest.assertions)
testImplementation(libs.test.kotest.assertions.json)
testImplementation(libs.test.turbine)

androidTestImplementation(libs.gson)
//noinspection GradleDependency
Expand Down
5 changes: 5 additions & 0 deletions aws-auth-cognito/consumer-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# CredentialManager rules
-if class androidx.credentials.CredentialManager
-keep class androidx.credentials.playservices.** {
*;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package com.amplifyframework.auth.cognito
import android.content.Context
import androidx.test.core.app.ApplicationProvider
import com.amplifyframework.api.aws.AWSApiPlugin
import com.amplifyframework.api.graphql.GraphQLOperation
import com.amplifyframework.api.graphql.SimpleGraphQLRequest
import com.amplifyframework.auth.AuthUserAttribute
import com.amplifyframework.auth.AuthUserAttributeKey
Expand Down Expand Up @@ -51,6 +52,7 @@ class AWSCognitoAuthPluginEmailMFATests {
private var authPlugin = AWSCognitoAuthPlugin()
private var apiPlugin = AWSApiPlugin()
private lateinit var synchronousAuth: SynchronousAuth
private var subscription: GraphQLOperation<MfaInfo>? = null
private var mfaCode = ""
private var latch: CountDownLatch? = null

Expand All @@ -64,8 +66,8 @@ class AWSCognitoAuthPluginEmailMFATests {
apiPlugin.configure(config, context)
synchronousAuth = SynchronousAuth.delegatingTo(authPlugin)

apiPlugin.subscribe(
SimpleGraphQLRequest<MfaInfo>(
subscription = apiPlugin.subscribe(
SimpleGraphQLRequest(
Assets.readAsString("create-mfa-subscription.graphql"),
MfaInfo::class.java,
null
Expand All @@ -83,6 +85,7 @@ class AWSCognitoAuthPluginEmailMFATests {

@After
fun tearDown() {
subscription?.cancel()
mfaCode = ""
synchronousAuth.deleteUser()
}
Expand Down
Loading