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

CognitoUserSession is not valid because idToken is null. #3101

Closed
jbsolutions2008 opened this issue Dec 1, 2022 · 7 comments
Closed

CognitoUserSession is not valid because idToken is null. #3101

jbsolutions2008 opened this issue Dec 1, 2022 · 7 comments
Assignees
Labels
bug Something isn't working cognito Issues with the AWS Android SDK for Cognito pending-community-response Issue is pending response from the issue requestor

Comments

@jbsolutions2008
Copy link

Hi all, we are trying to configure the Amplify Authentication on Android 12, but when we try to sign in the result callback is called with a signInState equal to SignInState.DONE, but when we try to get the token (both sync or async),

an Exception raises: "CognitoUserSession is not valid because idToken is null. "

To Reproduce
A code sample or steps:

 #1 After  SignInState.DONE : 
 -------------------------
  fun finishSignIn() {
        launch(Dispatchers.IO) {
            AWSMobileClient.getInstance().getTokens(object : Callback<Tokens> {
                override fun onResult(result: Tokens?) {
                    result?.let {
                        Logger.d("token ${it.accessToken}")
                        val token = AWSMobileClient.getInstance().tokens.accessToken.tokenString
                        Logger.d("token $token")
                    }
                }
                override fun onError(e: java.lang.Exception?) {
                    e?.let {
                      Logger.d("token $e.toString()")
                    }
                }
            })
        }
    }
 
#2 Retrive token null in the result   
-------------------------------------
D/AWSMobileClient: _federatedSignIn: Putting provider and token in store
W/AWSMobileClient: Failed to federate tokens during sign-in
java.lang.Exception: Federation is not enabled, please check if you have CognitoIdentity configured.
at com.amazonaws.mobile.client.AWSMobileClient$11.run(AWSMobileClient.java:1901)
at com.amazonaws.mobile.client.internal.InternalCallback.await(InternalCallback.java:115)
at com.amazonaws.mobile.client.AWSMobileClient.federatedSignInWithoutAssigningState(AWSMobileClient.java:1854)
at com.amazonaws.mobile.client.AWSMobileClient$6$1.onSuccess(AWSMobileClient.java:1288)
at com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUser$6.onSuccess(CognitoUser.java:1102)
 at com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUser$29.run(CognitoUser.java:3155)  at com.amazonaws.mobileconnectors.cognitoidentityprovider.continuations.ChallengeContinuation.continueTask(ChallengeContinuation.java:202)
at com.amazonaws.mobile.client.AWSMobileClient$7.run(AWSMobileClient.java:1486)
at com.amazonaws.mobile.client.internal.InternalCallback$1.run(InternalCallback.java:101)
 at java.lang.Thread.run(Thread.java:1012)
 W/CognitoUserSession: CognitoUserSession is not valid because idToken is null.
 W/AWSMobileClient: signalTokensNotAvailable
 W/CognitoUserSession: CognitoUserSession is not valid because idToken is null.
 W/AWSMobileClient: signalTokensNotAvailable
 

Expected behavior
Android 12 OS Version only.

Screenshots
#issue

MotoG-Android12

Environment Information :

  • AWS Android SDK Version:
    implementation 'com.amplifyframework:core:1.37.7'
    implementation 'com.amplifyframework:aws-auth-cognito:1.37.7'

  • Device: Moto G

  • Android Version: Android 12

  • Specific to simulators: No

Additional context
In other Android os Versions. It working fine.

@sdhuka sdhuka added cognito Issues with the AWS Android SDK for Cognito pending-triage Issue is pending triage labels Dec 1, 2022
@banji180 banji180 removed the pending-triage Issue is pending triage label Dec 1, 2022
@mattcreaser
Copy link
Member

Hi @jbsolutions2008, thanks for your report. We are looking into this.

@tylerjroach
Copy link
Member

@jbsolutions2008
Does your awsconfiguration.json file have a block like this?

{ 
  "CredentialsProvider": {
    "CognitoIdentity": {
      "Default": {
        "PoolId": "POOL-ID-HERE",
        "Region": "REGION-ID-HERE"
      }
    }
  }
}

@mattcreaser mattcreaser added the pending-community-response Issue is pending response from the issue requestor label Dec 6, 2022
@jbsolutions2008
Copy link
Author

jbsolutions2008 commented Dec 7, 2022

@tylerjroach
Thank you for the update.
No, provided awsconfiguration.json is different from ours. We have shared our awsconfiguration.json file. Please review and update for the further process.

awsconfiguration.json

{
  "UserAgent": "aws-amplify-cli/2.0",
  "Version": "1.0",
  "auth": {
    "plugins": {
      "awsCognitoAuthPlugin": {
        "IdentityManager": {
          "Default": {
            
          }
        },
        "CognitoUserPool": {
          "Default": {
            "PoolId": "POOL-ID-HERE",
            "AppClientId": "AppClient-ID-HERE",
            "Region": "REGION-ID-HERE"
          }
        },
        "Auth": {
          "Default": {
            "authenticationFlowType": "CUSTOM_AUTH"
          }
        }
      }
    }
  }
}

@mattcreaser mattcreaser removed the pending-community-response Issue is pending response from the issue requestor label Dec 7, 2022
@eeatonaws eeatonaws added the bug Something isn't working label Jan 17, 2023
@sdhuka sdhuka assigned div5yesh and dengdan154 and unassigned tylerjroach and div5yesh Jan 19, 2023
@dengdan154
Copy link
Contributor

hi @jbsolutions2008, I am currently looking into your issue. Could you verify that you sent awsconfiguration.json? The file you sent seems to be amplifyconfiguration.json. Please let me know if my assumption is incorrect.

@dengdan154 dengdan154 added the pending-community-response Issue is pending response from the issue requestor label Jan 26, 2023
@Felixroldan
Copy link

Felixroldan commented Feb 19, 2023

Hello. I'm having this issue when try to verify if the user is signed in. I'm working in flutter. But it only happens the first time I enter after singout. It rise the exception then return true or false after a while. The exception take me to the login page again and the when try to login it works fine.. I'll put my code in a while...

@dengdan154 dengdan154 removed the pending-community-response Issue is pending response from the issue requestor label Mar 9, 2023
@dengdan154
Copy link
Contributor

Hi @Felixroldan, if you are still facing this issue, please paste your code here as well as the awsconfiguration.json and any reproduction steps and we can continue looking into this issue.

@dengdan154 dengdan154 added the pending-community-response Issue is pending response from the issue requestor label Apr 6, 2023
@takieddine12
Copy link

I guess upon registration is successful , you need to provide a CognitoUserSession so that we can get idToken , RefreshToken and so on ..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working cognito Issues with the AWS Android SDK for Cognito pending-community-response Issue is pending response from the issue requestor
Projects
None yet
Development

No branches or pull requests

10 participants