Google sign-In "Wrong recipient, payload audience != requiredAudience"

Viewed 926

I'm trying to integrate Google Sign-In to my Node.js website following the guide at https://developers.google.com/identity/sign-in/web/backend-auth. I'm able to log in and authenticate with my back end server on localhost but not on my Heroku environment. It gives the error "Wrong recipient, payload audience != requiredAudience". Here is the backend authentication code.

const CLIENT_ID = process.env.CLIENT_ID;
const googleClient = new OAuth2Client(CLIENT_ID);
let token = req.body.token;
let user = {};

async function verify() {
    const ticket = await googleClient.verifyIdToken({
        idToken: token,
        audience: CLIENT_ID
    });
    const payload = ticket.getPayload();
    user.name = payload.name;
    user.email = payload.email;
    user.picture = payload.picture;
    user.id = payload.sub;
}
verify()
    .then(() => {
        res.cookie('session-token', token);
        res.send('success');
    })
    .catch(console.error);

CLIENT_ID has been added to Heroku's config vars. Both local host and my heroku url have been added to my google credentials page. enter image description here What would cause the authentication to work on localhost but not on Heroku?

0 Answers
Related