title: How to verify AWS Cognito Access Token on NodeJS
body: <p>I found an example on how to <a href="https://gist.github.com/rondomondo/b44660ec9acb0ae342733cada96b1518" rel="nofollow noreferrer">verify Cognito access tokens with Python</a>. How do I do the same with NodeJS? Is there no SDK function to do this? </p>
  
  <p>So far I have </p>
  
  <pre><code>authorizeCognitoJwt(token) {
      const COGNITO_POOL_ID = 'ap-southeast-1_xxx'
      const COGNITO_JWT_SET = {
      'keys': [
          {
          'alg': 'RS256',
          'e': 'AQAB',
          'kid': 'ChkV+...=',
          'kty': 'RSA',
          'n': 'tkjexS...johc5Q',
          'use': 'sig'
          },
          {
          'alg': 'RS256',
          'e': 'AQAB',
          'kid': 'Ve...Eb8dw6Y=',
          'kty': 'RSA',
          'n': 'hW19H...0c9Q',
          'use': 'sig'
          }
      ]
      }
      const decodedJwt = jwt.decode(token, {complete: true})
      console.log(decodedJwt)
  
      if (decodedJwt.payload.iss !== `https://cognito-idp.us-east-1.amazonaws.com/${COGNITO_POOL_ID}`) {
      return 'INVALID_ISSUER'
      }
  
      if (decodedJwt.payload.token_use !== 'access') {
      return 'INVALID_TOKEN_USE'
      }
  
      var jwtKey = COGNITO_JWT_SET.keys.find(k =&gt; k.kid === decodedJwt.header.kid)
      if (!jwtKey) {
      return 'INVALID_TOKEN_KID'
      }
  
      var verifiedKey = jwt.verify(token, /* how do I get the key? */)
  
      return 'VALID'
  }
  </code></pre>
  
  <p>But am stuck at how do I get keys from <code>COGNITO_JWT_SET</code></p>