Firebase token error, "The custom token corresponds to a different audience."
<p>I'm trying to generate JWT token for Firebase using Ruby on the server. Before 3.0 we used <a href="https://github.com/firebase/firebase-token-generator-ruby">token generator</a> but it stopped working after the upgrade. The token I get with code below gives an error:</p>

<blockquote>
  <p>The custom token corresponds to a different audience.</p>
</blockquote>

<p>and I can't find anywhere what it means.</p>

<pre><code>private_key = OpenSSL::PKey::RSA.new &lt;&lt;-PEM
-----BEGIN PRIVATE KEY-----
..redacted..
-----END PRIVATE KEY-----
PEM

service_account_email = 'redacted@redacted.iam.gserviceaccount.com'
now_seconds = Time.now.to_i

payload = {
  iss: service_account_email,
  sub: service_account_email,
  aud: 'https://identitytoolkit.googleapis.com/google.identity.identitytoolkit.v1.IdentityToolkit',
  iat: now_seconds,
  exp: now_seconds + (60 * 60),
  uid: self.id.to_s,
  debug: true,
  claims: {
    userId: self.id,
    slug: self.slug,
    username: self.username,
    avatar: self.profile.avatar.url,
    group: self.group,
    debug: true
  }
}

JWT.encode payload, private_key, 'RS256'
</code></pre>

<p>Thanks</p>