title: Login with Cognito credentials in Node.js and calling the API gateway
body: <p>So I've been at this for quite some time, and I'm still feeling like I'm just running circles around myself :)</p>
  
  <p>I have an API gateway on AWS that uses a user pool as its authorizer.
  I know AWS-Amplify, since I use it for my React frontend part, but I can't seem to find an elegant way to login with Cognito credentials in node.js.</p>
  
  <p>I tried using <a href="https://www.npmjs.com/package/amazon-cognito-identity-js-node" rel="nofollow noreferrer">this library</a> which is a fork of the somewhat deprecated amazon-cognito-identity-js, AWS-Amplify's precursor.</p>
  
  <p>It allows me to use the <code>.authenticateUser</code> method and returns three tokens:</p>
  
  <ul>
  <li><p>Cognito id token</p></li>
  <li><p>Cognito refresh token</p></li>
  <li><p>Cognito access token</p></li>
  </ul>
  
  <p>Next I tried to use axios (doesn't really matter I guess), to make a simple <code>GET</code> request with the Authorization header set to the <code>idToken</code> I got before.</p>
  
  <p>This token works while testing the authorizer on the API Gateway console, but it doesn't work from node...</p>
  
  <p>The error returned is: </p>
  
  <blockquote>
    <p>Authorization header requires \'Credential\' parameter. Authorization header requires \'Signature\' parameter. Authorization header requires \'SignedHeaders\' parameter. Authorization header requires existence of either a \'X-Amz-Date\' or a \'Date\' header.</p>
  </blockquote>
  
  <p>So I tried signing the request with aws4 which also didn't help, it returned an error which said their signature doesn't match mine and to check my secretAccessKey...</p>
  
  <p>Is it really this complicated? I just wanted to write a simple PoC app that tests my lambda API, this all seems like too much work for something so simple...</p>