作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在根据 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/
我正在根据 here 构建一个 auth0 实现使用 express-jwt 和 jwks-rsa 的组合。 但是,发生如下错误,tsc 无法正常完成。 Error:(102, 5) TS2322:
我是一名优秀的程序员,十分优秀!