Auth0 middleware in nodejs (express) gives error: aggrinfo ENOTFOUND

I use middleware in my express API to test for 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);

It works on my local dev machine, but when I run it during production, I get:

Error: getaddrinfo ENOTFOUND undefined undefined:443
    at errnoException (dns.js:28:10)
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:76:26)

I am running ubuntu 12 in production and mac on dev.

+5
source share
3 answers

It seems that you forgot to set the environment variable AUTH0_DOMAINin the production system.

Your code is correct according to the example from github ,

but this example has a section on how to run this code with a lot of settings for environment variables.

DEBUG=express,jwks JWKS_HOST=https://my-authz-server AUDIENCE=urn:my-resource-server ISSUER=https://my-authz-server/ node server.js.

, .

+3

getaddrinfo ENOTFOUND

-, , , , . , - :

  • -
  • -
  • (, pf 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

Make sure that the variable AUTH0_DOMAIN env does not have the https: // prefix.

This caught me and was not clear from the Auth0 docs.

0
source

Source: https://habr.com/ru/post/1678795/


All Articles