I’m trying to set up Google OAuth in my mobile app and having issues with server-side token validation. The frontend part works perfectly fine.
Frontend code:
const userAccount = await authService.authenticate();
const credentials = await userAccount.authData;
const idToken = credentials.accessToken;
Backend validation code:
const serviceConfig = require('./google-config.json');
const { OAuth2Client } = require('google-auth-library');
const authClient = new OAuth2Client(serviceConfig.web.client_id);
const verificationResult = await authClient.verifyIdToken({
idToken: receivedToken,
audience: serviceConfig.web.client_id
});
const userInfo = verificationResult.getPayload();
I keep getting the error message “Wrong recipient, payload audience != requiredAudience” when trying to validate the token on my Node.js backend. I’m using the same configuration file on both client and server sides.
I also created new credentials through Google Cloud Platform console but still getting the same error. What’s the correct way to find the right client_id for token verification?