Hello there! I'm trying to implement the OAuth Authentication, but I'm getting the "Invalid signature".
let query =
new URLSearchParams({
oauth_consumer_key: "xxx",
oauth_signature_method: 'HMAC-SHA1',
oauth_timestamp: Math.floor(Date.now() / 1000),
oauth_nonce: 'test',
oauth_version: '1.0',
oauth_callback: 'oob'
});
const method = 'GET';
const baseUrl = '
https://www.fatsecret.com/oauth/request_token';
const signatureBaseString = `${method}&${
encodeURIComponent(baseUrl)}&${
encodeURIComponent(query.toString())}`;
console.log('signature_base_string', signatureBaseString);
const secretKey = 'xxx';
const signingKey = `${secretKey}&`;
const oauth_signature = crypto.createHmac('sha1', signingKey).update(signatureBaseString).digest('base64');
let data = 'empty';
try {
const response =
await fetch(`${baseUrl}?${query.toString()}&oauth_signature=${oauth_signature}`, {
method: 'GET'
});
data =
await response.text();
}
catch (error) {
console.log('There was an error', error);
}