Skip to content
This repository has been archived by the owner on Oct 4, 2024. It is now read-only.

decode-verify-jwt.ts does not compile #178

Open
rajinder-yadav opened this issue Sep 24, 2021 · 1 comment
Open

decode-verify-jwt.ts does not compile #178

rajinder-yadav opened this issue Sep 24, 2021 · 1 comment

Comments

@rajinder-yadav
Copy link

Does the ts code actually work? I tired to fix it but no luck.

$ ts-node decode-verify-jwt.ts

/home/WD4TB/websites/hdt/research/aws-cognito-validate-jwt/node_modules/ts-node/src/index.ts:692
    return new TSError(diagnosticText, diagnosticCodes);
           ^
TSError: ⨯ Unable to compile TypeScript:
aws.ts:93:19 - error TS2352: Conversion of type 'SigningKeyCallback' to type 'Claim' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
  Type 'SigningKeyCallback' is missing the following properties from type 'Claim': token_use, auth_time, iss, exp, and 2 more.

93     const claim = await verifyPromised(token, key.pem) as Claim;
                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
aws.ts:93:47 - error TS2554: Expected 1 arguments, but got 2.

93     const claim = await verifyPromised(token, key.pem) as Claim;
                                                 ~~~~~~~

    at createTSError (/home/WD4TB/websites/hdt/research/aws-cognito-validate-jwt/node_modules/ts-node/src/index.ts:692:12)
    at reportTSError (/home/WD4TB/websites/hdt/research/aws-cognito-validate-jwt/node_modules/ts-node/src/index.ts:696:19)
    at getOutput (/home/WD4TB/websites/hdt/research/aws-cognito-validate-jwt/node_modules/ts-node/src/index.ts:883:36)
    at Object.compile (/home/WD4TB/websites/hdt/research/aws-cognito-validate-jwt/node_modules/ts-node/src/index.ts:1185:30)
    at Module.m._compile (/home/WD4TB/websites/hdt/research/aws-cognito-validate-jwt/node_modules/ts-node/src/index.ts:1309:30)
    at Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
    at Object.require.extensions.<computed> [as .ts] (/home/WD4TB/websites/hdt/research/aws-cognito-validate-jwt/node_modules/ts-node/src/index.ts:1313:12)
    at Module.load (internal/modules/cjs/loader.js:937:32)
    at Function.Module._load (internal/modules/cjs/loader.js:778:12)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12) {
  diagnosticText: "\x1B[96maws.ts\x1B[0m:\x1B[93m93\x1B[0m:\x1B[93m19\x1B[0m - \x1B[91merror\x1B[0m\x1B[90m TS2352: \x1B[0mConversion of type 'SigningKeyCallback' to type 'Claim' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.\n" +
    "  Type 'SigningKeyCallback' is missing the following properties from type 'Claim': token_use, auth_time, iss, exp, and 2 more.\n" +
    '\n' +
    '\x1B[7m93\x1B[0m     const claim = await verifyPromised(token, key.pem) as Claim;\n' +
    '\x1B[7m  \x1B[0m \x1B[91m                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\x1B[0m\n' +
    '\x1B[96maws.ts\x1B[0m:\x1B[93m93\x1B[0m:\x1B[93m47\x1B[0m - \x1B[91merror\x1B[0m\x1B[90m TS2554: \x1B[0mExpected 1 arguments, but got 2.\n' +
    '\n' +
    '\x1B[7m93\x1B[0m     const claim = await verifyPromised(token, key.pem) as Claim;\n' +
    '\x1B[7m  \x1B[0m \x1B[91m                                              ~~~~~~~\x1B[0m\n',
  diagnosticCodes: [ 2352, 2554 ]
}
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
/home/WD4TB/websites/hdt/research/aws-cognito-validate-jwt/node_modules/ts-node/src/index.ts:692
    return new TSError(diagnosticText, diagnosticCodes);
           ^
TSError: ⨯ Unable to compile TypeScript:
aws.ts:93:19 - error TS2352: Conversion of type 'SigningKeyCallback' to type 'Claim' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
  Type 'SigningKeyCallback' is missing the following properties from type 'Claim': token_use, auth_time, iss, exp, and 2 more.

93     const claim = await verifyPromised(token, key.pem) as Claim;
                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
aws.ts:93:47 - error TS2554: Expected 1 arguments, but got 2.

93     const claim = await verifyPromised(token, key.pem) as Claim;
                                                 ~~~~~~~

    at createTSError (/home/WD4TB/websites/hdt/research/aws-cognito-validate-jwt/node_modules/ts-node/src/index.ts:692:12)
    at reportTSError (/home/WD4TB/websites/hdt/research/aws-cognito-validate-jwt/node_modules/ts-node/src/index.ts:696:19)
    at getOutput (/home/WD4TB/websites/hdt/research/aws-cognito-validate-jwt/node_modules/ts-node/src/index.ts:883:36)
    at Object.compile (/home/WD4TB/websites/hdt/research/aws-cognito-validate-jwt/node_modules/ts-node/src/index.ts:1185:30)
    at Module.m._compile (/home/WD4TB/websites/hdt/research/aws-cognito-validate-jwt/node_modules/ts-node/src/index.ts:1309:30)
    at Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
    at Object.require.extensions.<computed> [as .ts] (/home/WD4TB/websites/hdt/research/aws-cognito-validate-jwt/node_modules/ts-node/src/index.ts:1313:12)
    at Module.load (internal/modules/cjs/loader.js:937:32)
    at Function.Module._load (internal/modules/cjs/loader.js:778:12)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12) {
  diagnosticText: "\x1B[96maws.ts\x1B[0m:\x1B[93m93\x1B[0m:\x1B[93m19\x1B[0m - \x1B[91merror\x1B[0m\x1B[90m TS2352: \x1B[0mConversion of type 'SigningKeyCallback' to type 'Claim' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.\n" +
    "  Type 'SigningKeyCallback' is missing the following properties from type 'Claim': token_use, auth_time, iss, exp, and 2 more.\n" +
    '\n' +
    '\x1B[7m93\x1B[0m     const claim = await verifyPromised(token, key.pem) as Claim;\n' +
    '\x1B[7m  \x1B[0m \x1B[91m                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\x1B[0m\n' +
    '\x1B[96maws.ts\x1B[0m:\x1B[93m93\x1B[0m:\x1B[93m47\x1B[0m - \x1B[91merror\x1B[0m\x1B[90m TS2554: \x1B[0mExpected 1 arguments, but got 2.\n' +
    '\n' +
    '\x1B[7m93\x1B[0m     const claim = await verifyPromised(token, key.pem) as Claim;\n' +
    '\x1B[7m  \x1B[0m \x1B[91m                                              ~~~~~~~\x1B[0m\n',
  diagnosticCodes: [ 2352, 2554 ]
}
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
@rajinder-yadav rajinder-yadav changed the title decode-verify-jwt.ts don't compile decode-verify-jwt.ts does not compile Sep 24, 2021
@Khrisseh1995
Copy link

Khrisseh1995 commented Jan 24, 2022

I didn't dig into this issue too deeply, but I just converted it using a standard Promise.

const verifyPromised = promisify(jsonwebtoken.verify.bind(jsonwebtoken));

becomes

export const verifyJWT = (token: string, publicKey: string) => new Promise((res, rej) =>  {
  jsonwebtoken.verify(token, publicKey, (err, decoded) => {
    if(err) rej(err)

    res(decoded)
  })
})

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants