首页 > 解决方案 > 错误:无效的令牌签名:token_here

问题描述

错误:无效的令牌签名:token_here at OAuth2Client.verifySignedJwtWithCertsAsync (E:\Node\node_modules\google-auth-library\build\src\auth\oauth2client.js:562:19) 在 processTicksAndRejections (internal/process/task_queues.js: 94:5) 在异步验证时 OAuth2Client.verifyIdTokenAsync (E:\Node\node_modules\google-auth-library\build\src\auth\oauth2client.js:392:23) 6:20)

const verified = await crypto.verify(cert, signed, signature);
  if (!verified) {
    throw new Error('Invalid token signature: ' + jwt);
}

在 google-auth-library node js 中获取这些行的错误

令牌是在颤振上使用 googleAuthentication 获得的。

这是Node的代码片段

const { OAuth2Client } = require('google-auth-library');
const client = new OAuth2Client(CLIENT_ID);
async function verify() {
  const ticket = await client.verifyIdToken({
    idToken: token,
    audience: CLIENT_ID,
  });
  const payload = ticket.getPayload();
  const userid = payload['sub'];
  console.log(payload);
  console.log(userid);
}

我在 Flutter 应用程序中获得的令牌 -

final GoogleSignInAuthentication googleAuth =
await currentUser.authentication;
googleAuth.idToken;
googleAuth.accessToken;

标签: node.jsfluttergoogle-signin

解决方案


就我而言,这是一个空白空间,我正在接收Bearier TOKEN_HERE,Bearier 和 TOKEN_HERE 之间有一个空间,删除该空间对我有用。

在此处输入图像描述


推荐阅读