awslabs / aws-jwt-verify

JS library for verifying JWTs signed by Amazon Cognito, and any OIDC-compatible IDP that signs JWTs with RS256, RS384, and RS512
Apache License 2.0
594 stars 43 forks source link

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

Closed anomaly44 closed 1 year ago

anomaly44 commented 1 year ago

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?

ottokruse commented 1 year ago

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)?

anomaly44 commented 1 year ago

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

ottokruse commented 1 year ago

You're running into this bug: https://github.com/TooTallNate/node-agent-base/issues/24

ottokruse commented 1 year ago

Updating agent-base should solve your problem.

ottokruse commented 1 year ago

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