我在我的 express API 中使用中间件来验证 auth0
const checkJwt = jwt({
// Dynamically provide a signing key based on the kid in the header and the singing keys provided by the JWKS endpoint.
secret: jwksRsa.expressJwtSecret({
cache: true,
rateLimit: true,
jwksRequestsPerMinute: 5,
jwksUri: `https://${process.env.AUTH0_DOMAIN}/.well-known/jwks.json`
}),
// Validate the audience and the issuer.
audience: process.env.AUTH0_AUDIENCE,
issuer: `https://${process.env.AUTH0_DOMAIN}/`,
algorithms: ['RS256']
});
...
server.use('/api', checkJwt, routes);
它可以在我的本地开发机器上运行,但是当我在生产环境中运行它时,我得到:
Error: getaddrinfo ENOTFOUND undefined undefined:443
at errnoException (dns.js:28:10)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:76:26)
我在生产环境中运行 ubuntu 12,在开发环境中运行 mac。
最佳答案
您似乎忘记了在生产系统上设置 AUTH0_DOMAIN
环境变量。
根据 github 中的示例,您的代码是正确的,
但是在这个例子中有一段如何运行这段代码并设置了很多环境变量。
DEBUG=express,jwks JWKS_HOST=https://my-authz-server AUDIENCE=urn:my-resource-server ISSUER=https://my-authz-server/node server.js
.
请在启动应用程序之前检查您的生产配置。
关于node.js - nodejs (express) 中的 Auth0 中间件给出错误 : aggrinfo ENOTFOUND,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44438240/