Client 3lept70k5j5va662em7v91p1tp is configured with secret but SECRET_HASH was not received这个问题是什么要怎么解决
时间: 2024-03-02 09:49:09 浏览: 21
这个问题是 AWS SDK 的一个警告,通常是在使用 Cognito User Pool 时出现的。这个警告是由于在使用 Cognito User Pool 的时候,应该同时提供 secret 和 secret hash,但是在这个情况下只提供了 secret。
要解决这个问题,你需要在使用 Cognito User Pool 的时候同时提供 secret 和 secret hash。可以在代码中使用以下方式来提供:
```
const cognito = new AWS.CognitoIdentityServiceProvider({
apiVersion: '2016-04-18',
region: 'REGION'
});
const params = {
ClientId: 'YOUR_APP_CLIENT_ID',
Username: 'YOUR_USERNAME',
Password: 'YOUR_PASSWORD',
SecretHash: 'YOUR_SECRET_HASH'
};
cognito.initiateAuth(params, (err, data) => {
if (err) console.log(err, err.stack);
else console.log(data);
});
```
其中,SecretHash 参数可以使用以下代码来计算:
```
const crypto = require('crypto');
function computeSecretHash(username, clientId, clientSecret) {
const message = username + clientId;
const hmac = crypto.createHmac('sha256', clientSecret);
hmac.update(message);
const hash = hmac.digest('base64');
return hash;
}
```
这样就可以解决这个问题了。