From 6bc8d52affe96b0f8bdfb6b940b199edaeeea050 Mon Sep 17 00:00:00 2001 From: Anshul Gupta Date: Wed, 6 Dec 2023 14:38:47 -0600 Subject: [PATCH] Addressing PR comments: --- .../auth/cognito/RealAWSCognitoAuthPlugin.kt | 14 +++++++------- .../auth/cognito/helpers/AuthHelper.kt | 6 +++--- 2 files changed, 10 insertions(+), 10 deletions(-) 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 7a59ddf665..09fa969bc8 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 @@ -164,13 +164,6 @@ import com.amplifyframework.statemachine.codegen.states.SetupTOTPState import com.amplifyframework.statemachine.codegen.states.SignInChallengeState import com.amplifyframework.statemachine.codegen.states.SignInState import com.amplifyframework.statemachine.codegen.states.SignOutState -import java.io.IOException -import java.util.concurrent.CountDownLatch -import java.util.concurrent.TimeUnit -import java.util.concurrent.atomic.AtomicReference -import kotlin.coroutines.resume -import kotlin.coroutines.resumeWithException -import kotlin.coroutines.suspendCoroutine import kotlinx.coroutines.DelicateCoroutinesApi import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.async @@ -184,6 +177,13 @@ import okhttp3.OkHttpClient import okhttp3.Request import okhttp3.RequestBody.Companion.toRequestBody import okhttp3.Response +import java.io.IOException +import java.util.concurrent.CountDownLatch +import java.util.concurrent.TimeUnit +import java.util.concurrent.atomic.AtomicReference +import kotlin.coroutines.resume +import kotlin.coroutines.resumeWithException +import kotlin.coroutines.suspendCoroutine internal class RealAWSCognitoAuthPlugin( private val configuration: AuthConfiguration, diff --git a/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/helpers/AuthHelper.kt b/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/helpers/AuthHelper.kt index 09964c88bd..a480ab212f 100644 --- a/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/helpers/AuthHelper.kt +++ b/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/helpers/AuthHelper.kt @@ -17,9 +17,9 @@ package com.amplifyframework.auth.cognito.helpers import com.amplifyframework.auth.cognito.exceptions.service.InvalidParameterException import com.amplifyframework.auth.exceptions.UnknownException +import org.json.JSONObject import javax.crypto.Mac import javax.crypto.spec.SecretKeySpec -import org.json.JSONObject internal open class AuthHelper { @@ -75,9 +75,9 @@ internal open class AuthHelper { * @return the username from the magic link. * */ fun getUsernameFromMagicLink(magicLinkCode: String): String? { - val header = magicLinkCode.split(".")[0] - val jsonString = android.util.Base64.decode(header, android.util.Base64.NO_WRAP) return try { + val header = magicLinkCode.split(".")[0] + val jsonString = android.util.Base64.decode(header, android.util.Base64.NO_WRAP) JSONObject(jsonString.toString(Charsets.UTF_8)).getString(USERNAME_KEY) } catch (e: Exception) { null