【问题标题】:Auth0 middleware in nodejs (express) gives Error: aggrinfo ENOTFOUNDnodejs(express)中的Auth0中间件给出错误:aggrinfo ENOTFOUND
【发布时间】:2017-11-10 07:37:12
【问题描述】:

我在我的 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。

【问题讨论】:

  • 不要写https://
  • 如果我删除它,验证将失败。
  • 你有回购吗?
  • 不公开。但是没有比问题中更相关的代码了。
  • 执行console.log(`https://${process.env.AUTH0_DOMAIN}/.well-known/jwks.json`) 并检查它是否未定义

标签: node.js linux express auth0


【解决方案1】:

你好像忘记在生产系统上设置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.

请在启动应用之前检查您的生产配置。

【讨论】:

    【解决方案2】:

    getaddrinfo ENOTFOUND

    这是当请求的服务器地址无法连接时出现的基本 Internet 传输协议错误。 可以是一个非常简单的错误,也可以是完全复杂的:

    • 主机系统上没有互联网连接
    • 主机系统没有发送请求的权限
    • 客户端系统没有接受请求的权限(例如,如果 vpc 的一部分被公共域阻止)

    错误:getaddrinfo ENOTFOUND undefined undefined:443

    • undefined undefined 表明系统尝试连接到的 url 未定义。

    我认为问题在于解析,因为显示的代码块正在注释掉您提供的 uri,请试试这个:

    const uri  = "https:\/\/"+${process.env.AUTH0_DOMAIN}+"/.well-known/jwks.json"
    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: uri
    }),
    
    // Validate the audience and the issuer.
    audience: process.env.AUTH0_AUDIENCE,
    issuer: `https://${process.env.AUTH0_DOMAIN}/`,
    algorithms: ['RS256']
    });
    

    在 jwt 选项中对颁发者进行类似的编辑

    【讨论】:

      【解决方案3】:

      确保 AUTH0_DOMAIN 环境变量没有 https:// 前缀。

      这引起了我的注意,但在 Auth0 文档中并不清楚。

      【讨论】:

      • 这也是我的情况!!!
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-05-24
      • 2016-04-20
      • 1970-01-01
      • 2012-05-26
      • 1970-01-01
      • 1970-01-01
      • 2018-02-18
      相关资源
      最近更新 更多