diff --git a/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/AWSCognitoAuthPlugin.kt b/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/AWSCognitoAuthPlugin.kt index 625b64e662..d5bd72be14 100644 --- a/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/AWSCognitoAuthPlugin.kt +++ b/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/AWSCognitoAuthPlugin.kt @@ -33,7 +33,7 @@ import com.amplifyframework.auth.AuthUser import com.amplifyframework.auth.AuthUserAttribute import com.amplifyframework.auth.AuthUserAttributeKey import com.amplifyframework.auth.cognito.asf.UserContextDataProvider -import com.amplifyframework.auth.cognito.options.AWSCognitoAuthVerifyTOTPSetupOptions +import com.amplifyframework.auth.cognito.options.AWSAuthVerifyTOTPSetupOptions import com.amplifyframework.auth.cognito.options.FederateToIdentityPoolOptions import com.amplifyframework.auth.cognito.result.FederateToIdentityPoolResult import com.amplifyframework.auth.exceptions.ConfigurationException @@ -775,7 +775,7 @@ class AWSCognitoAuthPlugin : AuthPlugin() { queueChannel.trySend( pluginScope.launch(start = CoroutineStart.LAZY) { try { - val result = queueFacade.setupMFA() + val result = queueFacade.setUpTOTP() onSuccess.accept(result) } catch (e: Exception) { onError.accept(e.toAuthException()) @@ -785,7 +785,7 @@ class AWSCognitoAuthPlugin : AuthPlugin() { } override fun verifyTOTPSetup(code: String, onSuccess: Action, onError: Consumer) { - verifyTOTPSetup(code, AWSCognitoAuthVerifyTOTPSetupOptions.CognitoBuilder().build(), onSuccess, onError) + verifyTOTPSetup(code, AWSAuthVerifyTOTPSetupOptions.CognitoBuilder().build(), onSuccess, onError) } override fun verifyTOTPSetup( diff --git a/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/CognitoAuthExceptionConverter.kt b/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/CognitoAuthExceptionConverter.kt index ef6229ad7f..14c94d8415 100644 --- a/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/CognitoAuthExceptionConverter.kt +++ b/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/CognitoAuthExceptionConverter.kt @@ -91,7 +91,7 @@ internal class CognitoAuthExceptionConverter { is PasswordResetRequiredException -> com.amplifyframework.auth.cognito.exceptions.service.PasswordResetRequiredException(error) is EnableSoftwareTokenMfaException -> - com.amplifyframework.auth.cognito.exceptions.service.EnableSoftwareTokenMfaException(error) + com.amplifyframework.auth.cognito.exceptions.service.EnableSoftwareTokenMFAException(error) is UserLambdaValidationException -> com.amplifyframework.auth.cognito.exceptions.service.UserLambdaValidationException( error.message, diff --git a/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/KotlinAuthFacadeInternal.kt b/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/KotlinAuthFacadeInternal.kt index 96ce06d54a..e3b2e14d93 100644 --- a/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/KotlinAuthFacadeInternal.kt +++ b/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/KotlinAuthFacadeInternal.kt @@ -523,7 +523,7 @@ internal class KotlinAuthFacadeInternal(private val delegate: RealAWSCognitoAuth } } - suspend fun setupMFA(): TOTPSetupDetails { + suspend fun setUpTOTP(): TOTPSetupDetails { return suspendCoroutine { continuation -> delegate.setUpTOTP( { continuation.resume(it) }, diff --git a/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/RealAWSCognitoAuthPlugin.kt b/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/RealAWSCognitoAuthPlugin.kt index 67d99ec8d0..402e480483 100644 --- a/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/RealAWSCognitoAuthPlugin.kt +++ b/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/RealAWSCognitoAuthPlugin.kt @@ -80,7 +80,7 @@ import com.amplifyframework.auth.cognito.options.AWSCognitoAuthSignOutOptions import com.amplifyframework.auth.cognito.options.AWSCognitoAuthSignUpOptions import com.amplifyframework.auth.cognito.options.AWSCognitoAuthUpdateUserAttributeOptions import com.amplifyframework.auth.cognito.options.AWSCognitoAuthUpdateUserAttributesOptions -import com.amplifyframework.auth.cognito.options.AWSCognitoAuthVerifyTOTPSetupOptions +import com.amplifyframework.auth.cognito.options.AWSAuthVerifyTOTPSetupOptions import com.amplifyframework.auth.cognito.options.AWSCognitoAuthWebUISignInOptions import com.amplifyframework.auth.cognito.options.AuthFlowType import com.amplifyframework.auth.cognito.options.FederateToIdentityPoolOptions @@ -2167,7 +2167,7 @@ internal class RealAWSCognitoAuthPlugin( onSuccess: Action, onError: Consumer ) { - val cognitoOptions = options as? AWSCognitoAuthVerifyTOTPSetupOptions + val cognitoOptions = options as? AWSAuthVerifyTOTPSetupOptions verifyTotp(code, cognitoOptions?.friendlyDeviceName, onSuccess, onError) } diff --git a/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/exceptions/service/EnableSoftwareTokenMfaException.kt b/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/exceptions/service/EnableSoftwareTokenMFAException.kt similarity index 93% rename from aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/exceptions/service/EnableSoftwareTokenMfaException.kt rename to aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/exceptions/service/EnableSoftwareTokenMFAException.kt index 2cdd44c28a..4c290dc28f 100644 --- a/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/exceptions/service/EnableSoftwareTokenMfaException.kt +++ b/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/exceptions/service/EnableSoftwareTokenMFAException.kt @@ -20,7 +20,7 @@ import com.amplifyframework.auth.AuthException * Software Token MFA is not enabled for the user. * @param cause The underlying cause of this exception */ -open class EnableSoftwareTokenMfaException(cause: Throwable?) : +open class EnableSoftwareTokenMFAException(cause: Throwable?) : AuthException( "Software token TOTP multi-factor authentication (MFA) is not enabled for the user pool.", "Enable the software token MFA for the user.", diff --git a/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/options/AWSCognitoAuthVerifyTOTPSetupOptions.java b/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/options/AWSAuthVerifyTOTPSetupOptions.java similarity index 79% rename from aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/options/AWSCognitoAuthVerifyTOTPSetupOptions.java rename to aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/options/AWSAuthVerifyTOTPSetupOptions.java index f8794014d3..b92688e589 100644 --- a/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/options/AWSCognitoAuthVerifyTOTPSetupOptions.java +++ b/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/options/AWSAuthVerifyTOTPSetupOptions.java @@ -20,11 +20,11 @@ /** * Cognito extension of update verify totp setup options to add the platform specific fields. */ -public final class AWSCognitoAuthVerifyTOTPSetupOptions extends AuthVerifyTOTPSetupOptions { +public final class AWSAuthVerifyTOTPSetupOptions extends AuthVerifyTOTPSetupOptions { private String friendlyDeviceName; - private AWSCognitoAuthVerifyTOTPSetupOptions(String friendlyDeviceName) { + private AWSAuthVerifyTOTPSetupOptions(String friendlyDeviceName) { this.friendlyDeviceName = friendlyDeviceName; } @@ -42,16 +42,12 @@ public String getFriendlyDeviceName() { public static final class CognitoBuilder extends Builder { private String friendlyDeviceName; - private String getFriendlyDeviceName() { - return friendlyDeviceName; - } - /** * Friendly device name to be set in Cognito. * @param friendlyDeviceName String input for friendlyDeviceName * @return current CognitoBuilder instance * */ - public CognitoBuilder setFriendlyDeviceName(String friendlyDeviceName) { + public CognitoBuilder friendlyDeviceName(String friendlyDeviceName) { this.friendlyDeviceName = friendlyDeviceName; return this; } @@ -60,8 +56,8 @@ public CognitoBuilder setFriendlyDeviceName(String friendlyDeviceName) { * Construct and return the object with the values set in the builder. * @return a new instance of AWSCognitoAuthVerifyTOTPSetupOptions with the values specified in the builder. */ - public AWSCognitoAuthVerifyTOTPSetupOptions build() { - return new AWSCognitoAuthVerifyTOTPSetupOptions(getFriendlyDeviceName()); + public AWSAuthVerifyTOTPSetupOptions build() { + return new AWSAuthVerifyTOTPSetupOptions(friendlyDeviceName); } } } diff --git a/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/AWSCognitoAuthPluginTest.kt b/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/AWSCognitoAuthPluginTest.kt index a180bb6ef9..06a5976cd1 100644 --- a/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/AWSCognitoAuthPluginTest.kt +++ b/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/AWSCognitoAuthPluginTest.kt @@ -26,7 +26,7 @@ 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.options.AWSCognitoAuthVerifyTOTPSetupOptions +import com.amplifyframework.auth.cognito.options.AWSAuthVerifyTOTPSetupOptions import com.amplifyframework.auth.cognito.options.FederateToIdentityPoolOptions import com.amplifyframework.auth.cognito.result.FederateToIdentityPoolResult import com.amplifyframework.auth.options.AuthConfirmResetPasswordOptions @@ -703,7 +703,7 @@ class AWSCognitoAuthPluginTest { @Test fun verifyTOTPSetupWithOptions() { val code = "123456" - val options = AWSCognitoAuthVerifyTOTPSetupOptions.CognitoBuilder().setFriendlyDeviceName("DEVICE_NAME").build() + val options = AWSAuthVerifyTOTPSetupOptions.CognitoBuilder().friendlyDeviceName("DEVICE_NAME").build() val expectedOnSuccess = Action { } val expectedOnError = Consumer { } authPlugin.verifyTOTPSetup(code, options, expectedOnSuccess, expectedOnError) diff --git a/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/RealAWSCognitoAuthPluginTest.kt b/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/RealAWSCognitoAuthPluginTest.kt index e35e8708d9..65e5ee08a6 100644 --- a/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/RealAWSCognitoAuthPluginTest.kt +++ b/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/RealAWSCognitoAuthPluginTest.kt @@ -63,7 +63,7 @@ import com.amplifyframework.auth.cognito.options.AWSCognitoAuthResendUserAttribu import com.amplifyframework.auth.cognito.options.AWSCognitoAuthSignInOptions import com.amplifyframework.auth.cognito.options.AWSCognitoAuthUpdateUserAttributeOptions import com.amplifyframework.auth.cognito.options.AWSCognitoAuthUpdateUserAttributesOptions -import com.amplifyframework.auth.cognito.options.AWSCognitoAuthVerifyTOTPSetupOptions +import com.amplifyframework.auth.cognito.options.AWSAuthVerifyTOTPSetupOptions import com.amplifyframework.auth.cognito.options.AuthFlowType import com.amplifyframework.auth.cognito.usecases.ResetPasswordUseCase import com.amplifyframework.auth.exceptions.InvalidStateException @@ -1736,7 +1736,7 @@ class RealAWSCognitoAuthPluginTest { plugin.verifyTOTPSetup( code, - AWSCognitoAuthVerifyTOTPSetupOptions.CognitoBuilder().setFriendlyDeviceName(friendlyDeviceName).build(), + AWSAuthVerifyTOTPSetupOptions.CognitoBuilder().friendlyDeviceName(friendlyDeviceName).build(), onSuccess, onError ) @@ -1781,7 +1781,7 @@ class RealAWSCognitoAuthPluginTest { plugin.verifyTOTPSetup( code, - AWSCognitoAuthVerifyTOTPSetupOptions.CognitoBuilder().build(), + AWSAuthVerifyTOTPSetupOptions.CognitoBuilder().build(), onSuccess, onError ) diff --git a/core-kotlin/src/main/java/com/amplifyframework/kotlin/auth/Auth.kt b/core-kotlin/src/main/java/com/amplifyframework/kotlin/auth/Auth.kt index 60d31f8489..970f7dfa01 100644 --- a/core-kotlin/src/main/java/com/amplifyframework/kotlin/auth/Auth.kt +++ b/core-kotlin/src/main/java/com/amplifyframework/kotlin/auth/Auth.kt @@ -334,6 +334,7 @@ interface Auth { * Setup TOTP for the currently signed in user. * @return TOTP Setup details */ + @Throws(AuthException::class) suspend fun setUpTOTP(): TOTPSetupDetails /** @@ -341,6 +342,7 @@ interface Auth { * @param code TOTP code to verify TOTP setup * @param options additional options to verify totp setup */ + @Throws(AuthException::class) suspend fun verifyTOTPSetup( code: String, options: AuthVerifyTOTPSetupOptions = AuthVerifyTOTPSetupOptions.builder().build() diff --git a/core/src/main/java/com/amplifyframework/TOTPSetupDetails.kt b/core/src/main/java/com/amplifyframework/TOTPSetupDetails.kt index a9d77de1f1..2327964fe6 100644 --- a/core/src/main/java/com/amplifyframework/TOTPSetupDetails.kt +++ b/core/src/main/java/com/amplifyframework/TOTPSetupDetails.kt @@ -21,9 +21,9 @@ data class TOTPSetupDetails( val username: String ) { fun getSetupURI( - appName: String, + issuer: String, accountName: String = username ): Uri { - return Uri.parse("otpauth://totp/$appName:$accountName?secret=$sharedSecret&issuer=$appName") + return Uri.parse("otpauth://totp/$issuer:$accountName?secret=$sharedSecret&issuer=$issuer") } }