From 6ae0bbbea8767fe71000d66740c359afbfc9e6a1 Mon Sep 17 00:00:00 2001 From: Matt Creaser Date: Mon, 15 Apr 2024 11:58:57 -0300 Subject: [PATCH] Update to match enum changes in the schema --- .../auth/cognito/AuthConfiguration.kt | 10 +++---- .../auth/cognito/AuthConfigurationTest.kt | 6 ++--- core/api/core.api | 12 +++++++++ .../core/configuration/AmplifyOutputsData.kt | 26 ++++++++++++++++--- .../configuration/AmplifyOutputsDataTest.kt | 18 ++++++------- .../AmplifyOutputsDataBuilder.kt | 2 +- 6 files changed, 52 insertions(+), 22 deletions(-) diff --git a/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/AuthConfiguration.kt b/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/AuthConfiguration.kt index ebb6037f2..f82b8a4eb 100644 --- a/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/AuthConfiguration.kt +++ b/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/AuthConfiguration.kt @@ -189,14 +189,14 @@ data class AuthConfiguration internal constructor( } private fun AmplifyOutputsData.Auth.UsernameAttributes.toConfigType() = when (this) { - AmplifyOutputsData.Auth.UsernameAttributes.EMAIL -> UsernameAttribute.Email - AmplifyOutputsData.Auth.UsernameAttributes.PHONE -> UsernameAttribute.PhoneNumber - AmplifyOutputsData.Auth.UsernameAttributes.USERNAME -> UsernameAttribute.Username + AmplifyOutputsData.Auth.UsernameAttributes.Email -> UsernameAttribute.Email + AmplifyOutputsData.Auth.UsernameAttributes.PhoneNumber -> UsernameAttribute.PhoneNumber + AmplifyOutputsData.Auth.UsernameAttributes.Username -> UsernameAttribute.Username } private fun AmplifyOutputsData.Auth.UserVerificationTypes.toConfigType() = when (this) { - AmplifyOutputsData.Auth.UserVerificationTypes.EMAIL -> VerificationMechanism.Email - AmplifyOutputsData.Auth.UserVerificationTypes.PHONE -> VerificationMechanism.PhoneNumber + AmplifyOutputsData.Auth.UserVerificationTypes.Email -> VerificationMechanism.Email + AmplifyOutputsData.Auth.UserVerificationTypes.PhoneNumber -> VerificationMechanism.PhoneNumber } private fun AmplifyOutputsData.Auth.PasswordPolicy.toConfigType() = PasswordProtectionSettings( diff --git a/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/AuthConfigurationTest.kt b/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/AuthConfigurationTest.kt index 41c717474..b07fbc3c6 100644 --- a/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/AuthConfigurationTest.kt +++ b/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/AuthConfigurationTest.kt @@ -49,11 +49,11 @@ class AuthConfigurationTest { scopes += listOf("myScope", "myScope2") redirectSignInUri += "https://test.com/signin" redirectSignOutUri += "https://test.com/signout" - responseType = AmplifyOutputsData.Auth.Oauth.ResponseType.TOKEN + responseType = AmplifyOutputsData.Auth.Oauth.ResponseType.Token } standardRequiredAttributes += AuthUserAttributeKey.email() - usernameAttributes += AmplifyOutputsData.Auth.UsernameAttributes.EMAIL - userVerificationTypes += AmplifyOutputsData.Auth.UserVerificationTypes.EMAIL + usernameAttributes += AmplifyOutputsData.Auth.UsernameAttributes.Email + userVerificationTypes += AmplifyOutputsData.Auth.UserVerificationTypes.Email mfaConfiguration = AmplifyOutputsData.Auth.MfaConfiguration.REQUIRED mfaMethods += AmplifyOutputsData.Auth.MfaMethods.SMS } diff --git a/core/api/core.api b/core/api/core.api index 140cc4103..f76be1964 100644 --- a/core/api/core.api +++ b/core/api/core.api @@ -1379,6 +1379,18 @@ public final class com/amplifyframework/core/configuration/AmplifyOutputs$Compan public final fun fromString (Ljava/lang/String;)Lcom/amplifyframework/core/configuration/AmplifyOutputs; } +public final class com/amplifyframework/core/configuration/AmplifyOutputsData$Auth$Oauth$ResponseType$Companion { + public final fun serializer ()Lkotlinx/serialization/KSerializer; +} + +public final class com/amplifyframework/core/configuration/AmplifyOutputsData$Auth$UserVerificationTypes$Companion { + public final fun serializer ()Lkotlinx/serialization/KSerializer; +} + +public final class com/amplifyframework/core/configuration/AmplifyOutputsData$Auth$UsernameAttributes$Companion { + public final fun serializer ()Lkotlinx/serialization/KSerializer; +} + public final class com/amplifyframework/core/configuration/AmplifyOutputsKt { public static final synthetic fun AmplifyOutputs (I)Lcom/amplifyframework/core/configuration/AmplifyOutputs; public static final synthetic fun AmplifyOutputs (Ljava/lang/String;)Lcom/amplifyframework/core/configuration/AmplifyOutputs; diff --git a/core/src/main/java/com/amplifyframework/core/configuration/AmplifyOutputsData.kt b/core/src/main/java/com/amplifyframework/core/configuration/AmplifyOutputsData.kt index 36d3b496d..feed8f138 100644 --- a/core/src/main/java/com/amplifyframework/core/configuration/AmplifyOutputsData.kt +++ b/core/src/main/java/com/amplifyframework/core/configuration/AmplifyOutputsData.kt @@ -99,12 +99,13 @@ interface AmplifyOutputsData { } @InternalAmplifyApi + @Serializable enum class ResponseType { @SerialName("code") - CODE, + Code, @SerialName("token") - TOKEN + Token } } @@ -112,10 +113,27 @@ interface AmplifyOutputsData { enum class AuthenticationFlowType { USER_SRP_AUTH, CUSTOM_AUTH } @InternalAmplifyApi - enum class UsernameAttributes { USERNAME, EMAIL, PHONE } + @Serializable + enum class UsernameAttributes { + @SerialName("username") + Username, + + @SerialName("email") + Email, + + @SerialName("phone_number") + PhoneNumber + } @InternalAmplifyApi - enum class UserVerificationTypes { EMAIL, PHONE } + @Serializable + enum class UserVerificationTypes { + @SerialName("email") + Email, + + @SerialName("phone_number") + PhoneNumber + } @InternalAmplifyApi enum class MfaConfiguration { NONE, OPTIONAL, REQUIRED } diff --git a/core/src/test/java/com/amplifyframework/core/configuration/AmplifyOutputsDataTest.kt b/core/src/test/java/com/amplifyframework/core/configuration/AmplifyOutputsDataTest.kt index 8e415b6e4..85c7e8338 100644 --- a/core/src/test/java/com/amplifyframework/core/configuration/AmplifyOutputsDataTest.kt +++ b/core/src/test/java/com/amplifyframework/core/configuration/AmplifyOutputsDataTest.kt @@ -85,12 +85,12 @@ class AmplifyOutputsDataTest { AuthUserAttributeKey.gender().keyString ), Keys.usernameAttributes to listOf( - AmplifyOutputsData.Auth.UsernameAttributes.USERNAME.name, - AmplifyOutputsData.Auth.UsernameAttributes.EMAIL.name + AmplifyOutputsData.Auth.UsernameAttributes.Username.name, + AmplifyOutputsData.Auth.UsernameAttributes.Email.name ), Keys.userVerificationTypes to listOf( - AmplifyOutputsData.Auth.UserVerificationTypes.EMAIL.name, - AmplifyOutputsData.Auth.UserVerificationTypes.PHONE.name + AmplifyOutputsData.Auth.UserVerificationTypes.Email.name, + AmplifyOutputsData.Auth.UserVerificationTypes.PhoneNumber.name ), Keys.unauthenticatedIdentitiesEnabled to true, Keys.mfaConfiguration to AmplifyOutputsData.Auth.MfaConfiguration.OPTIONAL.name, @@ -126,19 +126,19 @@ class AmplifyOutputsDataTest { scopes shouldContainExactly listOf("scope1", "scope2") redirectSignInUri shouldContainExactly listOf("https://oauth.com/signin") redirectSignOutUri shouldContainExactly listOf("https://oauth.com/signout") - responseType shouldBe AmplifyOutputsData.Auth.Oauth.ResponseType.CODE + responseType shouldBe AmplifyOutputsData.Auth.Oauth.ResponseType.Code } standardRequiredAttributes shouldContainExactly listOf( AuthUserAttributeKey.email(), AuthUserAttributeKey.gender() ) usernameAttributes shouldContainExactly listOf( - AmplifyOutputsData.Auth.UsernameAttributes.USERNAME, - AmplifyOutputsData.Auth.UsernameAttributes.EMAIL + AmplifyOutputsData.Auth.UsernameAttributes.Username, + AmplifyOutputsData.Auth.UsernameAttributes.Email ) userVerificationTypes shouldContainExactly listOf( - AmplifyOutputsData.Auth.UserVerificationTypes.EMAIL, - AmplifyOutputsData.Auth.UserVerificationTypes.PHONE + AmplifyOutputsData.Auth.UserVerificationTypes.Email, + AmplifyOutputsData.Auth.UserVerificationTypes.PhoneNumber ) unauthenticatedIdentitiesEnabled.shouldBeTrue() mfaConfiguration shouldBe AmplifyOutputsData.Auth.MfaConfiguration.OPTIONAL diff --git a/testutils/src/main/java/com/amplifyframework/testutils/configuration/AmplifyOutputsDataBuilder.kt b/testutils/src/main/java/com/amplifyframework/testutils/configuration/AmplifyOutputsDataBuilder.kt index 8500824e1..eca613516 100644 --- a/testutils/src/main/java/com/amplifyframework/testutils/configuration/AmplifyOutputsDataBuilder.kt +++ b/testutils/src/main/java/com/amplifyframework/testutils/configuration/AmplifyOutputsDataBuilder.kt @@ -99,7 +99,7 @@ class OauthBuilder : AmplifyOutputsData.Auth.Oauth { override val redirectSignInUri: MutableList = mutableListOf() override val redirectSignOutUri: MutableList = mutableListOf() override var responseType: AmplifyOutputsData.Auth.Oauth.ResponseType = - AmplifyOutputsData.Auth.Oauth.ResponseType.CODE + AmplifyOutputsData.Auth.Oauth.ResponseType.Code } class GeoBuilder : AmplifyOutputsData.Geo {