title: JWT validation failed: Could not find matching key in public key set for kid
body: <p>I'm generating a JWT using <code>google-auth-library-nodejs</code> by providing the credentials through env variables, similar to the sample code from <a href="https://github.com/googleapis/google-auth-library-nodejs" rel="nofollow noreferrer">here</a>.</p>
  <pre><code>const credentials = JSON.parse(JSON.stringify(env.service_account.credentials));
  const client = auth.fromJSON(credentials);
  const url = 'my_url';
  const token = await client.fetchIdToken(url);
  </code></pre>
  <p>When using that token later on for authentication, the request fails because of the following error:</p>
  <blockquote>
  <p>JWT validation failed: Could not find matching key in public key set for kid=7da7843e8637d669bc2a12622cede2a8814d11b1</p>
  </blockquote>
  <p><a href="https://jwt.io/#debugger-io" rel="nofollow noreferrer">https://jwt.io/#debugger-io</a> confirms that the kid of the generated JWT is indeed <code>7da7843e8637d669bc2a12622cede2a8814d11b1</code>, however, the private key id in the json is <code>6bd5b5d36f9a4225bd814ff3d6909d95e23e0793</code>.</p>
  <p>Here's the json</p>
  <pre><code>'{
    &quot;type&quot;: &quot;service_account&quot;,
    &quot;project_id&quot;: &quot;project_id&quot;,
    &quot;private_key_id&quot;: &quot;6bd5b5d36f9a4225bd814ff3d6909d95e23e0793&quot;,
    &quot;private_key&quot;: &quot;-----BEGIN PRIVATE KEY-----\nXXXXXXXXXXX\n-----END PRIVATE KEY-----\n&quot;,
    &quot;client_email&quot;: &quot;my_service_account@project_id.iam.gserviceaccount.com&quot;,
    &quot;client_id&quot;: &quot;REDACTED&quot;,
    &quot;auth_uri&quot;: &quot;https://accounts.google.com/o/oauth2/auth&quot;,
    &quot;token_uri&quot;: &quot;https://oauth2.googleapis.com/token&quot;,
    &quot;auth_provider_x509_cert_url&quot;: &quot;https://www.googleapis.com/oauth2/v1/certs&quot;,
    &quot;client_x509_cert_url&quot;: &quot;https://www.googleapis.com/robot/v1/metadata/x509/my_service_account%40project_id.iam.gserviceaccount.com&quot;
  }
  </code></pre>
  <p>Should the kid match the privat_key_id?</p>