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

CognitoJwtVerifier verify function error: Expected 4 arguments, but got 1 #26

Closed shelou closed 2 years ago

shelou commented 2 years ago

What are the steps to reproduce this issue?

  1. npm i aws-jwt-verify
  2. import {CognitoJwtVerifier} from "aws-jwt-verify";
  3. const verifier = CognitoJwtVerifier.create({ userPoolId: userPoolId, tokenUse: "id", clientId: clientId, });
  4. const payload = await verifier.verify(token)

What happens? verify function gives an error: TS2554: Expected 4 arguments, but got 1

What versions of software are you using? "typescript": "^3.9.10", "ts-node": "^8.10.2", "aws-jwt-verify": "1.0.3", and also tried version 1.0.2

ottokruse commented 2 years ago

Mmm, afraid you'll need at least TypeScript 4 :|

Work around is to run in JS (not in TS) or change the import to a require but you'll loose type checking then:

// NOT: import { CognitoJwtVerifier } from "aws-jwt-verify";
const { CognitoJwtVerifier } = require("aws-jwt-verify"); // Works, but you loose type checking
ottokruse commented 2 years ago

Or upgrade to TypeScript 4 of course for a proper solution

ottokruse commented 2 years ago

For consideration, it might be possible to support TypeScript 3 also, using this: https://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html#version-selection-with-typesversions

We'll have to decide if the effort is worth the value.

shelou commented 2 years ago

@ottokruse thank you so much! Upgrading typescript did the job

MudabbarHussain commented 1 year ago

hello, I am using the CognitoJwtVerifier.create but got an error CognitoJwtVerifier.create is not a function. kindly guide me. code: const verifier = CognitoJwtVerifier.create({ userPoolId: process.env.AWS_COGNITO_USERPOOL, tokenUse: "access", clientId: process.env.AWS_COGNITO_CLIENT_ID, });

ottokruse commented 1 year ago

Please create a separate issue and provide us a complete example with which to reproduce (i.e. one that at least also shows how you import the library)