Skip to content

Commit

Permalink
PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
gpanshu committed Aug 26, 2023
1 parent 944a98c commit f5bd577
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -775,7 +775,7 @@ class AWSCognitoAuthPlugin : AuthPlugin<AWSCognitoAuthService>() {
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())
Expand All @@ -785,7 +785,7 @@ class AWSCognitoAuthPlugin : AuthPlugin<AWSCognitoAuthService>() {
}

override fun verifyTOTPSetup(code: String, onSuccess: Action, onError: Consumer<AuthException>) {
verifyTOTPSetup(code, AWSCognitoAuthVerifyTOTPSetupOptions.CognitoBuilder().build(), onSuccess, onError)
verifyTOTPSetup(code, AWSAuthVerifyTOTPSetupOptions.CognitoBuilder().build(), onSuccess, onError)
}

override fun verifyTOTPSetup(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -2167,7 +2167,7 @@ internal class RealAWSCognitoAuthPlugin(
onSuccess: Action,
onError: Consumer<AuthException>
) {
val cognitoOptions = options as? AWSCognitoAuthVerifyTOTPSetupOptions
val cognitoOptions = options as? AWSAuthVerifyTOTPSetupOptions
verifyTotp(code, cognitoOptions?.friendlyDeviceName, onSuccess, onError)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -42,16 +42,12 @@ public String getFriendlyDeviceName() {
public static final class CognitoBuilder extends Builder<CognitoBuilder> {
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;
}
Expand All @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<AuthException> { }
authPlugin.verifyTOTPSetup(code, options, expectedOnSuccess, expectedOnError)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1736,7 +1736,7 @@ class RealAWSCognitoAuthPluginTest {

plugin.verifyTOTPSetup(
code,
AWSCognitoAuthVerifyTOTPSetupOptions.CognitoBuilder().setFriendlyDeviceName(friendlyDeviceName).build(),
AWSAuthVerifyTOTPSetupOptions.CognitoBuilder().friendlyDeviceName(friendlyDeviceName).build(),
onSuccess,
onError
)
Expand Down Expand Up @@ -1781,7 +1781,7 @@ class RealAWSCognitoAuthPluginTest {

plugin.verifyTOTPSetup(
code,
AWSCognitoAuthVerifyTOTPSetupOptions.CognitoBuilder().build(),
AWSAuthVerifyTOTPSetupOptions.CognitoBuilder().build(),
onSuccess,
onError
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,13 +334,15 @@ interface Auth {
* Setup TOTP for the currently signed in user.
* @return TOTP Setup details
*/
@Throws(AuthException::class)
suspend fun setUpTOTP(): TOTPSetupDetails

/**
* Verify TOTP setup for the currently signed in user.
* @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()
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/com/amplifyframework/TOTPSetupDetails.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}

0 comments on commit f5bd577

Please sign in to comment.