gpt4 book ai didi

node.js - 类型不可分配给 express-jwt 中的类型 'GetVerificationKey'。(使用 auth0)

转载 作者:行者123 更新时间:2023-12-05 08:24:44 27 4
gpt4 key购买 nike

我正在根据 here 构建一个 auth0 实现使用 express-jwt 和 jwks-rsa 的组合。
但是,发生如下错误,tsc 无法正常完成。

Error:(102, 5) TS2322: Type 'SecretCallbackLong | GetVerificationKey' is not assignable to type 'Secret | GetVerificationKey'.
Type 'SecretCallbackLong' is not assignable to type 'Secret | GetVerificationKey'.
Type 'SecretCallbackLong' is not assignable to type 'GetVerificationKey'.

我的代码很糟糕。

import {expressjwt} from "express-jwt";
import * as jwksRsa from "jwks-rsa";


const checkJwt = expressjwt({
secret: jwksRsa.expressJwtSecret({ //<--The error occurred in here.
cache: true,
rateLimit: true,
jwksRequestsPerMinute: 5,
jwksUri: `**************************`
}),

audience: '*****************',
issuer: '*******************',
algorithms: [ 'RS256' ],
});

expressjwt选项设置中的secret值出现类型错误。
上面的代码几乎是here的副本.
所以,我想不出解决这个问题的办法。这是第一次使用auth0。
谁能解决这个问题?

typescript :4.7.4
express :4.18.1
jwks-rsa: 2.1.4
express jwt:7.7.5

最佳答案

您可以显式键入 secret 参数,如下所示:https://github.com/auth0/express-jwt/issues/288

import jwksRsa from 'jwks-rsa';
import { expressjwt, GetVerificationKey } from 'express-jwt';


const checkJwt = expressjwt({
secret: jwksRsa.expressJwtSecret({ //<--The error occurred in here.
cache: true,
rateLimit: true,
jwksRequestsPerMinute: 5,
jwksUri: `**************************`
}) as GetVerificationKey,

audience: '*****************',
issuer: '*******************',
algorithms: [ 'RS256' ],
});

关于node.js - 类型不可分配给 express-jwt 中的类型 'GetVerificationKey'。(使用 auth0),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73202006/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com