where can I find the secret key for the JWT from cognito

后端 未结 4 1768
天涯浪人
天涯浪人 2021-02-13 20:21

I am trying out the log in function for the Cognito User Pool for my Web App. I was able to obtain the Token but I am not sure where to find the secret to decode it. I\'ve rea

4条回答
  •  执念已碎
    2021-02-13 21:07

    Just want to summarize this topic with the snippet of code:

    const jwkToPem = require('jwk-to-pem');
    const requestify = require('requestify');
    
    /**
     * Get cognito's secret key
     * @param {String} region
     * @param {String} userPoolId
     * @returns {Promise}
     */
    function getPem(region, userPoolId) {
      const jwkUrl = `https://cognito-idp.${region}.amazonaws.com/${userPoolId}/.well-known/jwks.json`;
    
      return requestify.request(jwkUrl, { method: 'get', dataType: 'json'})
        .then(res => res.getBody()['keys'].shift())
        .then(jwk => jwkToPem(jwk))
      ;
    }
    

提交回复
热议问题