awslabs/aws-jwt-verify

[BUG TypeError [ERR_INVALID_ARG_TYPE]: The "listener" argument must be of type function. Received an instance of Object

Closed this issue · 5 comments

Describe the bug
I get this error by basically using the example from the doc:

TypeError [ERR_INVALID_ARG_TYPE]: The "listener" argument must be of type function. Received an instance of Object
    at checkListener (node:events:266:3)
    at ClientRequest.once (node:events:647:3)
    at new ClientRequest (node:_http_client:245:10)
    at Object.request (node:https:360:10)
    at Object.<anonymous> (/Users/rob/dev/charlin-api/node_modules/agent-base/patch-core.js:25:22)
    at /Users/rob/dev/charlin-api/node_modules/socks-proxy-agent/node_modules/agent-base/patch-core.js:23:20
    at /Users/rob/dev/charlin-api/node_modules/aws-jwt-verify/dist/cjs/https-node.js:24:41
    at new Promise (<anonymous>)
    at fetchJson (/Users/rob/dev/charlin-api/node_modules/aws-jwt-verify/dist/cjs/https-node.js:23:12)
    at SimpleJsonFetcher.fetch (/Users/rob/dev/charlin-api/node_modules/aws-jwt-verify/dist/cjs/https.js:48:42)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async SimpleJwksCache.getJwks (/Users/rob/dev/charlin-api/node_modules/aws-jwt-verify/dist/cjs/jwk.js:169:20)
    at async SimpleJwksCache.getJwk (/Users/rob/dev/charlin-api/node_modules/aws-jwt-verify/dist/cjs/jwk.js:206:22)
    at async verifyDecomposedJwt (/Users/rob/dev/charlin-api/node_modules/aws-jwt-verify/dist/cjs/jwt-rsa.js:52:17)
    at async CognitoJwtVerifier.verify (/Users/rob/dev/charlin-api/node_modules/aws-jwt-verify/dist/cjs/cognito-verifier.js:122:9) {
  code: 'ERR_INVALID_ARG_TYPE'
}

Versions
Which version of aws-jwt-verify are you using? using 4.0 and also tried downgrading to 3.4

If Node.js, which version of Node.js are you using? (Should be at least 14) node 18
If using TypeScript, which version of TypeScript are you using? (Should be at least 4) 4.0.3

To Reproduce

const verifier = CognitoJwtVerifier.create({
  userPoolId: process.env.AWS_COGNITO_USER_POOL_ID,
  tokenUse: 'access',
  clientId: cognitoClientId,
});

const verifiedPayload = await verifier.verify(activeToken);

Any ideas what might be causing this?

I see socks-proxy-agent in your stack trace?

Try without proxy?

Which version of socks-proxy-agent are you using? And which of agent-base (the one under node_modules/socks-proxy-agent/node_modules/agent-base)?

Hmmm they are dependencies of other libraries, not really using a proxy.
agent-base in the folder you mentioned is "version": "4.2.1",
for socks-proxy-agent I find multiple versions in yarn lock 4.0.1 6.0.0 and 7.0.0

You're running into this bug: TooTallNate/node-agent-base#24

Updating agent-base should solve your problem.

Closing for now as I believe this is not an issue in our library. Let us know if you can't resolve it by fixing your dependencies