博士后;无效算法“;RS256加密JWT toaken出错

博士后;无效算法“;RS256加密JWT toaken出错,jwt,Jwt,我正在节点项目中使用JWT验证和PostGraphile 4.6.0。以下是代码片段的示例: createServer( postgraphile(env.DATABASE_URL, "public", { jwtVerifyAlgorithms: ["RS256"], jwtSecret: "./publickey.pem", jwtPgTypeIdentifier: "public.jwt_token", rejectUnauthorized: false, graphi

我正在节点项目中使用JWT验证和PostGraphile 4.6.0。以下是代码片段的示例:

createServer(
postgraphile(env.DATABASE_URL, "public", {
  jwtVerifyAlgorithms: ["RS256"],
  jwtSecret: "./publickey.pem",
  jwtPgTypeIdentifier: "public.jwt_token",
  rejectUnauthorized: false,
  graphiql: true,
  enhanceGraphiql: true,
  graphqlRoute: env.POSTGRAPHILE_ROUTE + "/graphql",
  graphiqlRoute: env.POSTGRAPHILE_ROUTE + "/graphiql",
})).listen(port, () => {
console.log("Listening at port:" + port);});
但当我使用Postman发送RS256加密JWT令牌时,得到错误:

{
"errors": [
    {
        "message": "invalid algorithm"
    }
]
}

我在Postgres中创建了一个函数来返回JWT令牌,它总是返回HS256加密的JWT令牌。我在Postman中使用PostGraphile返回的HS256加密JWT令牌,JWT令牌经过验证,GrqphQL查询返回良好

“jwtVerifyAlgorithms”选项似乎不起作用

对于RS256加密的JWT令牌,有没有办法使其工作?

将jwtPublicKey设置为提供秘密的正确设置。现在您正在使用带有字符串
“/publickey.pem”
jwtSecret
,该字符串不会加载文件,而是使用文件路径作为密码。 请确保自己使用以下方式加载文件:

...
jwtPublicKey: fs.readFileSync("./secretkey.pem", "ascii")
...
可通过PG设置选择 最坏情况下,您还可以提供一个自定义
pgSettings
函数,该函数使用
jsonwebtoken
npm库,自己验证令牌并将其写入设置