Error when using adminRespondToAuthChallenge with Cognito (Express & Javascript)

0

Hi,

I'm trying to change a user password when they login for the first time and receive the challengeName: NEW_PASSWORD_REQUIRED and in the console their Confirmation Status is Force change password. I'm using the adminRespondToAuthChallenge function and I'm passing the parameters:

{
        ChallengeName: "NEW_PASSWORD_REQUIRED",
        ClientId: process.env.AWS_CLIENT_ID,
        UserPoolId: process.env.AWS_IDENTITY_POOL_ID,
        ChallengeResponses: {
          USERNAME: USER_ID_FOR_SRP,
          NEW_PASSWORD: proposedPassword,
        },
        Session: session,
      }

and my function looks like:

const response =
      await CognitoIdentityServiceProvider.adminRespondToAuthChallenge(parameters).promise();
    res.status(200).json({ status: "success", data: response });

When I post a request I get the error:

TypeError [ERR_INVALID_ARG_TYPE]: The "key" argument must be of type string or an instance of ArrayBuffer, Buffer, TypedArray, DataView, KeyObject, or CryptoKey. Received undefined
    at new NodeError (node:internal/errors:371:5)
    at prepareSecretKey (node:internal/crypto/keys:570:11)
    at new Hmac (node:internal/crypto/hash:132:9)
    at Object.createHmac (node:crypto:162:10)
    at Object.hmac (C:\Users\joshh\coding_bootcamp\projects\palace-drum-clinic-server\node_modules\aws-sdk\lib\util.js:436:30)
    at Object.getSigningKey (C:\Users\joshh\coding_bootcamp\projects\palace-drum-clinic-server\node_modules\aws-sdk\lib\signers\v4_credentials.js:62:8)
    at V4.signature (C:\Users\joshh\coding_bootcamp\projects\palace-drum-clinic-server\node_modules\aws-sdk\lib\signers\v4.js:98:36)
    at V4.authorization (C:\Users\joshh\coding_bootcamp\projects\palace-drum-clinic-server\node_modules\aws-sdk\lib\signers\v4.js:93:36)
    at V4.addAuthorization (C:\Users\joshh\coding_bootcamp\projects\palace-drum-clinic-server\node_modules\aws-sdk\lib\signers\v4.js:35:12)
    at C:\Users\joshh\coding_bootcamp\projects\palace-drum-clinic-server\node_modules\aws-sdk\lib\event_listeners.js:333:20 {
  code: 'ERR_INVALID_ARG_TYPE',
  retryDelay: 58.59727940103505

The user is able to login so I can get the session and USER_ID_FOR_SRP variables and my AWS variables are correct since I'm using them in other functions with no issues. I'm not sure what the "key" argument is or how to fix this

Thanks

1 個回答
0

It seems you have not setup your AWS Credentials properly on your machine or the code is not able to access them. key is the secretAccessKey associated to your credentials that are fetched from the credential provider chain from your machine (from the logs I am assuming that you are running this code from your local machine)

See: https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/loading-node-credentials-shared.html

AWS
專家
已回答 1 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南