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

Module is not exporting typescript types #40

Closed planktoon1 closed 2 years ago

planktoon1 commented 2 years ago

The module is built with typescript but is not exporting any types which makes it hard to work within a typescript project.

Specifically, I want to use the verifier inside a class where I initialize it in the constructor of the class and assign it to a private member. But I'm missing the CognitoJwtVerifierSingleUserPool type to be able to do it.

class AuthMiddleware {
private verifier: CognitoJwtVerifierSingleUserPool<{
    userPoolId: string;
    tokenUse: "access";
    clientId: string;
}>;

... 

this.verifier = CognitoJwtVerifier.create({
  userPoolId: "<user_pool_id>",
  tokenUse: "access",
  clientId: "<client_id>",
});
...
ottokruse commented 2 years ago

HI @planktoon1, Makes sense, think we should add some export statements to make that easier. In the meantime here is a workaround:

import { CognitoJwtVerifier } from "aws-jwt-verify";

class Test {
  verifier: CognitoJwtVerifier<
    {
        // add only properties here, that you're not passing in the actual `create` call, e.g.
        // clientId: string
        // properties that you add here, will become mandatory on individual `verify` calls (i.e. make the 2nd paramater mandatory)
    },
    {
      issuer: string;
      audience: null;
      userPoolId: string;
    }, // just satisfy the type, for assignment below you don't have to spell out everything
    false // false for single user pool, true for multi user pool
  >;
  constructor() {
    this.verifier = CognitoJwtVerifier.create({
      userPoolId: "<user_pool_id>",
      tokenUse: "access",
      clientId: "<client_id>",
    });
  }
  public async test() {
    await this.verifier.verify("ey......");
  }
}
ottokruse commented 2 years ago

Solved by #42