Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could not receive token from additionalInfo{} when calling signInWithWebUi method after migrated to amplify v2 #2581

Closed
1 task done
arvelalanaidn opened this issue Sep 6, 2023 · 8 comments
Labels
auth Related to the Auth category/plugins question General question

Comments

@arvelalanaidn
Copy link

arvelalanaidn commented Sep 6, 2023

Before opening, please confirm:

Language and Async Model

Kotlin

Amplify Categories

Authentication

Gradle script dependencies

// Put output below this line
  implementation("com.amplifyframework:core:2.13.0")
  implementation("com.amplifyframework:aws-auth-cognito:2.13.0")

Environment information

# Put output below this line
------------------------------------------------------------
Gradle 7.5.1
------------------------------------------------------------

Build time:   2022-08-05 21:17:56 UTC
Revision:     d1daa0cbf1a0103000b71484e1dbfe096e095918

Kotlin:       1.6.21
Groovy:       3.0.10
Ant:          Apache Ant(TM) version 1.10.11 compiled on July 10 2021
JVM:          11.0.20 (Amazon.com Inc. 11.0.20+8-LTS)
OS:           Mac OS X 13.0.1 aarch64

Please include any relevant guides or documentation you're referencing

https://docs.amplify.aws/lib/auth/signin_web_ui/q/platform/android/#configure-auth-category

Describe the bug

Hi,
After I migrated to amplify v2 from v1, I could not receive token from additionalInfo{} response when calling signInWithWebUi method, this is my response before and after migrating to v2.

My signInWithWebUi Implementation

Amplify.Auth.signInWithWebUI(
  activity,
  { result ->
    onSuccess.invoke(println(result.toString))
  },

  { ex ->
    onFailure.invoke(ex)
  },
)

amplify version 2.13.0 response:
signInStep=DONE, additionalInfo={}, codeDeliveryDetails=null

amplify version 1.37.3 response:
signInStep=DONE, additionalInfo={provider=cognito-idp.ap-southeast-1.amazonaws.com/ap-southeast-1_60Qu63nZM, token=eyJraWQiOiJ4R3lqTmdNK3JBZlRQc2VwczVhe....}, codeDeliveryDetails=null

Any instructions on how to get token from Amplify v2?

Reproduction steps (if applicable)

  1. Implement SignInWithWebUI
  2. Login into existing webview
  3. Print the result

Code Snippet

// Put your code below this line.

Amplify.Auth.signInWithWebUI(
  activity,
  { result ->
    onSuccess.invoke(println(result.toString))
  },

  { ex ->
    onFailure.invoke(ex)
  },
)

Log output

// Put your logs below this line
amplify version 2.13.0 response:
signInStep=DONE, additionalInfo={}, codeDeliveryDetails=null

amplify version 1.37.3 response:
signInStep=DONE, additionalInfo={provider=cognito-idp.ap-southeast-1.amazonaws.com/ap-southeast-1_60Qu63nZM, token=eyJraWQiOiJ4R3lqTmdNK3JBZlRQc2VwczVhe....}, codeDeliveryDetails=null

amplifyconfiguration.json

{
    "auth": {
        "plugins": {
            "awsCognitoAuthPlugin": {
                "IdentityManager": {
                    "Default": {}
                },
                "CredentialsProvider": {
                    "CognitoIdentity": {
                        "Default": {
                            "PoolId": "ap-southeast-1",
                            "Region": "ap-southeast-1"
                        }
                    }
                },
                "CognitoUserPool": {
                    "Default": {
                        "PoolId": "ap-southeast-1",
                        "AppClientId": "xxxxx",
                        "Region": "ap-southeast-1"
                    }
                },
                "Auth": {
                    "Default": {
                        "OAuth": {
                            "WebDomain": "account.satekxxx.com",
                            "AppClientId": "xxxxx",
                            "SignInRedirectURI": "idnapp://profile/me/",
                            "SignOutRedirectURI":  "idnapp://home/",
                            "Scopes": [
                                "phone",
                                "email",
                                "openid",
                                "profile",
                                "aws.cognito.signin.user.admin"
                            ]
                        }
                    }
                }
            }
        }
    }
}

GraphQL Schema

// Put your schema below this line

Additional information and screenshots

No response

@mattcreaser mattcreaser added auth Related to the Auth category/plugins pending-triage Issue is pending triage question General question and removed pending-triage Issue is pending triage labels Sep 6, 2023
@mattcreaser
Copy link
Member

Hi @arvelalanaidn we'll take a look and get back to you soon.

@mattcreaser
Copy link
Member

@arvelalanaidn This is the intended behaviour in V2. Please see this document for information about how to access the user's token. The code you want will look something like:

// Using coroutines
val session = Amplify.Auth.fetchAuthSession() as AWSCognitoAuthSession
val token = session.accessToken

Please let us know if you have any other questions.

@arvelalanaidn
Copy link
Author

@mattcreaser Hi, I have used that code for accessToken, but my idToken is still null after I log out and log in again then fetchAuthSession using this code

       Amplify.Auth.fetchAuthSession(
        {
          val session = it as AWSCognitoAuthSession
          when (session.identityIdResult.type) {
            AuthSessionResult.Type.SUCCESS ->
              session.userPoolTokensResult.value?.let { awsUserPoolTokens -> println(awsUserPoolTokens.idToken)}
          }
        })

Any instructions on how to properly log out and get an IdToken after logging out and logging in again? Because my IdToken is always null after trying to log out then immediately log in using this code.

    Amplify.Auth.signOut { signOutResult ->
      when (signOutResult) {
        is AWSCognitoAuthSignOutResult.CompleteSignOut -> {
          // Call sign In function and fetchAuthSession
          toSignIn()
        }

@tylerjroach
Copy link
Member

@arvelalanaidn

Just to confirm, your PoolId under the Default block of CognitoUserPool is something like "PoolId": "ap-southeast-1_xxxx" right?

I created a clean signInWithWebUi sample app and am receiving a value for idToken in the AWSCognitoUserPoolTokens type.

@arvelalanaidn
Copy link
Author

@tylerjroach yes

                "CognitoUserPool": {
                    "Default": {
                        "PoolId": "ap-southeast-1",
                        "AppClientId": "xxxxx",
                        "Region": "ap-southeast-1"
                    }
                },

did you try logging in immediately after logging out?
I get a completeResult after logout, but when I try to log in again, my idToken is null
This is my code for logout and login

SignOut

    Amplify.Auth.signOut { signOutResult ->
      when (signOutResult) {
        is AWSCognitoAuthSignOutResult.CompleteSignOut -> {
          // Call sign In function and fetchAuthSession
          toSignIn()
        }

SignIn

    Amplify.Auth.signInWithWebUI(
      activity,
      { result ->
        onSuccess.invoke(
          fetchAuthSession()
        )
      },

Fetch

       Amplify.Auth.fetchAuthSession(
        {
          val session = it as AWSCognitoAuthSession
          when (session.identityIdResult.type) {
            AuthSessionResult.Type.SUCCESS ->
              session.userPoolTokensResult.value?.let { awsUserPoolTokens -> println(awsUserPoolTokens.idToken)}
          }
        })

@tylerjroach
Copy link
Member

Hi @arvelalanaidn

I see that you said yes, but in the latest post, your PoolId still just shows the region. A PoolId contains more than just a region.

I understand that you may have just removed the additional characters to obfuscate the PoolId, but just to make sure it is understood, your user pool config should look more like this.

"CognitoUserPool": {
  "Default": {
    "PoolId": "ap-southeast-1_xxxxxxxxx",
    "AppClientId": "xxxxx",
    "Region": "ap-southeast-1"
  }
}

@mattcreaser mattcreaser added pending-community-response Issue is pending response from the issue requestor closing soon This issue will be closed in 7 days unless further comments are made. labels Feb 13, 2024
@mattcreaser
Copy link
Member

Hey there! We haven't heard back on this so we'll close this issue. Please feel free to open a new issue if needed.

@github-actions github-actions bot removed pending-community-response Issue is pending response from the issue requestor closing soon This issue will be closed in 7 days unless further comments are made. labels Feb 28, 2024
Copy link
Contributor

This issue is now closed. Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auth Related to the Auth category/plugins question General question
Projects
None yet
Development

No branches or pull requests

3 participants