Wrong public key type error when calling verifyIdToken in google-auth-library for Node.js

61 Views Asked by At

I am using google-auth-library to verify sign in with google credentials server side that I get from users who sign in with google on my site in line with the method described here.

However, calling this function gives me the error:

8875 |   }
8876 | }), require_verify = __commonJS({
8877 |   "node_modules/browserify-sign/browser/verify.js"(exports, module) {
8878 |     var Buffer2 = require_safe_buffer().Buffer, BN = require_bn3(), EC = require_elliptic().ec, parseKeys = require_parse_asn1(), curves = require_curves2();
8879 | 
8880 |     function verify(sig, hash, key, signType, tag) {
                                         ^
error: wrong public key type
      at verify (node:crypto:8880:38)

My code:

import { OAuth2Client } from "google-auth-library";

const client = new OAuth2Client({
  clientId: process.env.GOOGLE_CLIENT_ID,
  clientSecret: process.env.GOOGLE_CLIENT_SECRET,
});

export const verifyGoogleCredential = async (credential: string) => {
  try {
    const ticket = await client.verifyIdToken({
      idToken: credential,
      audience: process.env.GOOGLE_CLIENT_ID,
    });
    const payload = ticket.getPayload();
    return payload;
  } catch (err) {
    console.log(err);
  }
};

Is this not getting the public key or something and therefore failing? Any help would be appreciated. Thanks!

0

There are 0 best solutions below