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
606 stars 42 forks source link

TypeScript error "verifier.verify()" is expecting 4 parameters #39

Closed DennisMC closed 2 years ago

DennisMC commented 2 years ago

I am getting a typescript error trying to verify a JWT using the provided example for cognito. here is my code:

       const verifier = CognitoJwtVerifier.create({
            userPoolId: "<user_pool_id>",
            tokenUse: "access",
            clientId: "<client_id>",
        });

        try {
            const payload = await verifier.verify(token);
            console.log("Token is valid. Payload:", payload);
        } catch {
            console.log("Token not valid!");
        }

The "verifier.verify(token)" is expecting 4 parameters but I am only providing it 1 as the example states, I am not sure how to proceed

ottokruse commented 2 years ago

Hi @DennisMC . Are you on TypeScript 4 or higher? This might be a duplicate of #26

DennisMC commented 2 years ago

I am using Typescript Version 4.5.4

DennisMC commented 2 years ago

Okay, so i realized my local Typescript was 4.5.4 but my Node.Js typescript version was not, I have now upgraded, however now i get a Syntax error: SyntaxError: Unexpected token '.'

I have had this error before but is was due to a typo, it seems not to be the case this time

DennisMC commented 2 years ago

This is where the syntax error originates: https://github.com/awslabs/aws-jwt-verify/blob/67a660278706d02746e30c1f469e87052e2b7262/src/jwt-rsa.ts#L708

ottokruse commented 2 years ago

That might be because of the optional chaining (?), which is supported only by NodeJS v14.0.0 and up. What's your NodeJS version?

DennisMC commented 2 years ago

It definitely is that then, my NodeJS version is 12

ottokruse commented 2 years ago

Okay then, hope you can go to Node14, it is the minimum version we support (also for other reasons, see also #23 )