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

Can you not just return the instance without knowing what "Generic" properties are defined???? #137

Closed markbenedict closed 10 months ago

markbenedict commented 10 months ago

Question The create function should just return the instance of the object, who cares about shape used to define it.

Instead of:

container .bind<CognitoJwtVerifierSingleUserPool<{ userPoolId: string; tokenUse: 'id' | 'access' }>>(IocSymbols.Authorizer) .toConstantValue(CognitoJwtVerifier.create({ userPoolId: APP_ENV.userPoolId, tokenUse: 'id' }));

Use: @inject(IocSymbols.Authorizer) private readonly _authorizer: CognitoJwtVerifierSingleUserPool<{ userPoolId: string; tokenUse: 'id' | 'access' }>,

public handler(....) { this._authorizer.verify(authToken); <----- this throws an error because it can't interpret the values }

Intended:

container .bind(IocSymbols.Authorizer) .toConstantValue(CognitoJwtVerifier.create({ userPoolId: APP_ENV.userPoolId, tokenUse: 'id' }));

Use: @inject(IocSymbols.Authorizer) private readonly _authorizer: CognitoJwtVerifier>,

public handler(....) { this._authorizer.verify(authToken); <---- inject the instance and properties are set }