title: Firebase IdToken generated using FirebaseAuth.currentUser.getIdToken() on flutter gives error "failed to verify token signature" on Go backend
body: <p>I am working on a flutter app where after sign-in, I have to validate a user's <code>idToken</code> on a custom backend (written in Go) using the Firebase admin SDK: <code>firebase.google.com/go</code>.</p>
  <p>I am using the following snippet to sign-in the user via GoogleSignIn and retrieve the Firebase idToken on the client side:</p>
  <pre><code>final FirebaseAuth _auth = FirebaseAuth.instance;
  final GoogleSignIn googleSignIn = GoogleSignIn();
  
  Future&lt;String&gt; signInWithGoogle() async {
    await Firebase.initializeApp();
   
    final GoogleSignInAccount googleSignInAccount = await googleSignIn.signIn();
    
    final GoogleSignInAuthentication googleSignInAuthentication =
        await googleSignInAccount.authentication;
  
    final AuthCredential credential = GoogleAuthProvider.credential(
      accessToken: googleSignInAuthentication.accessToken,
      idToken: googleSignInAuthentication.idToken,
    );  
  
    final UserCredential authResult = await _auth.signInWithCredential(credential);
  
    final User user = authResult.user;
  
    String FirebaseIdToken = await _auth.currentUser.getIdToken();
    print(&quot;FirebaseIdToken: &quot; + FirebaseIdToken);
    
    if (user != null) {
      /* code to validate user and return it */
    }  return null;
  }
  </code></pre>
  <p>I copy the token corresponding to the <code>FirebaseIdToken</code> variable and send it to the backend using Postman with a <code>Authentication: Bearer &lt;token&gt;</code> request header.</p>
  <p>At the backend, there is the following:</p>
  <pre><code>  /* am.cli here is basically the auth.Client in firebase admin SDK and clientToken is the token received from flutter app. */
    idToken, err := am.cli.VerifyIDToken(context.Background(), clientToken) 
    log.Println(&quot;ERROR:&quot;, err)
  </code></pre>
  <p>I get the following error printed:</p>
  <pre><code>  ERROR: failed to verify token signature
  </code></pre>
  <p>Based on the documentation for both client &amp; backend, I believe that I'm using the correct methods to retrieve and to verify the token.</p>
  <p>I have tried to retrieve the idToken with the following code as well:</p>
  <pre><code>  IdTokenResult idTokRes = await _auth.currentUser.getIdTokenResult(true);
    print(&quot;idTokRes: &quot; + idTokRes.token);
  </code></pre>
  <p>But this fails the same way. (And <code>idTokRes.token</code> and the <code>FirebaseIdToken</code> from the previous method are not same.)</p>
  <p>I have also tried to verify the token manually on <a href="https://jwt.io/" rel="nofollow noreferrer">https://jwt.io/</a> with the public certificate and the private key which fails as well.</p>
  <p>Any help would be appreciated!</p>