amplify-android: CodeValidationException when calling signInWithWebUI

Before opening, please confirm:

Language and Async Model

Kotlin

Amplify Categories

Authentication

Gradle script dependencies

implementation 'com.amplifyframework:aws-api:2.1.0'
implementation 'com.amplifyframework:aws-auth-cognito:2.1.0'
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5'

Environment information

------------------------------------------------------------
Gradle 7.4
------------------------------------------------------------

Build time:   2022-02-08 09:58:38 UTC
Revision:     f0d9291c04b90b59445041eaa75b2ee744162586

Kotlin:       1.5.31
Groovy:       3.0.9
Ant:          Apache Ant(TM) version 1.10.11 compiled on July 10 2021
JVM:          18 (Homebrew 18+0)
OS:           Mac OS X 13.1 aarch64


Please include any relevant guides or documentation you’re referencing

https://docs.amplify.aws/lib/auth/signin/q/platform/android/

Describe the bug

I am trying to upgrade my project from amplify 1 to amplify 2. The project is already live running on version 1, so my config files should be correct, at least for version 1. After upgrading to version 2, I am not able to sign in anymore with web UI, when the function is called, the browser tab opens and immediately closes again with a CodeValidationException:

I also tried starting a fresh new project from scratch, following the documentation, but with the same result. I am not using amplify (or the cli), but a Cognito User Pool without an Identity Pool.

Reproduction steps (if applicable)

No response

Code Snippet

override fun onCreate(savedInstanceState: Bundle?) {
  binding.fab.setOnClickListener {view ->
      Amplify.Auth.signInWithWebUI(
          this,
          { Log.i("MyAmplifyApp", "Signin OK = $it") },
          { Log.e("MyAmplifyApp", "Signin failed", it) }
        )
    }

    try {
        Amplify.addPlugin(AndroidLoggingPlugin(LogLevel.VERBOSE))
        Amplify.addPlugin(AWSCognitoAuthPlugin())
        Amplify.configure(applicationContext)
        Log.i("MyAmplifyApp", "Initialized Amplify")
    } catch (error: AmplifyException) {
        Log.e("MyAmplifyApp", "Could not initialize Amplify", error)
    }
}

Log output

// Put your logs below this line
CodeValidationException{message=invalid_request, cause=null, recoverySuggestion=Sorry, we don't have a suggested fix for this error yet.}
at com.amplifyframework.auth.cognito.HostedUIClient.fetchToken(HostedUIClient.kt:106)
at com.amplifyframework.auth.cognito.actions.HostedUICognitoActions$fetchHostedUISignInToken$$inlined$invoke$1.execute(Action.kt:73)
at com.amplifyframework.statemachine.ConcurrentEffectExecutor$execute$1$1.invokeSuspend(ConcurrentEffectExecutor.kt:26)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:570)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:749)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:677)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:664)

amplifyconfiguration.json

{
  "auth": {
    "plugins": {
      "awsCognitoAuthPlugin": {
        "IdentityManager": {
          "Default": {}
        },
        "CognitoUserPool": {
          "Default": {
            "PoolId": "$poolId",
            "AppClientId": "$appClient",
            "Region": "$region"
          }
        },
        "Auth": {
          "Default": {
            "authenticationFlowType": "USER_SRP_AUTH",
            "OAuth": {
              "WebDomain": "auth.XYZ.com",
              "AppClientId": "$appClient",
              "SignInRedirectURI": "myApp://",
              "SignOutRedirectURI": "myApp://",
              "Scopes": [
                "email",
                "openid",
                "profile",
                "aws.cognito.signin.user.admin"
              ]
            }
          }
        }
      }
    }
  }
}

awsconfiguration.json

{
  "IdentityManager": {
    "Default": {}
  },
  "CognitoUserPool": {
    "Default": {
      "AppClientId": "$appClient",
      "PoolId": "$poolId",
      "Region": "$region"
    }
  }
}

GraphQL Schema

// Put your schema below this line


Additional information and screenshots

No response

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 15 (9 by maintainers)

Most upvoted comments

PR has been merged and should make it in the next Amplify release. You will be able to match the error by checking for:

CodeValidationException(
  message = "invalid_request: User already exists with provider user id."
)