title: Android Studio - Get Firebase token from GetIdToken
body: <p>I have done the following in Swift:</p>
  
  <pre><code>let currentUser = Auth.auth().currentUser
  currentUser?.getTokenForcingRefresh(true) {idToken, error in
     if let error = error {
       // Handle error
       print("error (below)")
       print(error)
       return;
     }
     print("idToken = " + idToken!) // token looks like this: kpJhbGRiOiJSUzI1NiIsIntpZCI9Ijg0MjIuYzc3NTWkOWZmTjI3OBQxZTkyNTpkNWZjZjUwNzg2YTFmNGIifQ.eyJpc3MiOiJodHRwczovL3NlY3Vy... (it's really long)
     //..do stuff with token
  }
  </code></pre>
  
  <p>I am now trying to do the equivalent for Android. The <a href="https://developers.google.com/android/reference/com/google/firebase/auth/GetTokenResult" rel="noreferrer">firebase documentation</a> touches on the topic but does not explain getting the token extensively.  I have tried the following:</p>
  
  <pre><code>Log.d(TAG, user.getIdToken(true));
  </code></pre>
  
  <p>However, this gives me the following error when I attempt to authenticate this alone on my backend server:</p>
  
  <blockquote>
    <p>Error: Decoding Firebase ID token failed. Make sure you passed the
    entire string JWT which represents an ID token. See
    <a href="https://firebase.google.com/docs/auth/admin/verify-id-tokens" rel="noreferrer">https://firebase.google.com/docs/auth/admin/verify-id-tokens</a> for
    details on how to retrieve an ID token.
        at FirebaseAuthError.Error (native)
        at FirebaseAuthError.FirebaseError [as constructor] (/user_code/node_modules/firebase-admin/lib/utils/error.js:25:28)
        at new FirebaseAuthError (/user_code/node_modules/firebase-admin/lib/utils/error.js:90:23)
        at FirebaseTokenGenerator.verifyIdToken (/user_code/node_modules/firebase-admin/lib/auth/token-generator.js:155:35)
        at Auth.verifyIdToken (/user_code/node_modules/firebase-admin/lib/auth/auth.js:104:37)
        at admin.database.ref.child.child.child.child.child.child.orderByChild.once.then.snapshot
    (/user_code/index.js:1430:22)
        at process._tickDomainCallback (internal/process/next_tick.js:135:7)</p>
  </blockquote>
  
  <p>I believe this is because there needs to be an onSuccessListener but am not sure, nor have had success implementing it as follows:</p>
  
  <pre><code>user.getIdToken(true).addOnSuccessListener(new OnSuccessListener&lt;UploadTask.TaskSnapshot&gt;() {
    @Override
    public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
      Log.d(TAG, "onSuccess: taskSnapshot = " + taskSnapshot);
    }
  });
  </code></pre>