SwitchBotAPI icon indicating copy to clipboard operation
SwitchBotAPI copied to clipboard

Possibility to authenticate without calculating the sign every time?

Open taulfsime opened this issue 6 months ago • 1 comments

Current Situation

Hello, I'm writing Javascript code that will run on an esp32-based device. I don't have a lib to calculate the sign every time I want to send a request. Is it possible to calculate it once and reuse it for several requests?

Logs

If I use an already generated sign (together with the nonce, t, Authorization key), I get `statusCode: 401
{"message":"Unauthorized"}` on every request, if I edit the script to calculate the sign just before sending it, it works.

Configuration

`auth` - contains already generated sign, Authorization key, nonce, and t (same as when the sign is generated)

const options = {
  hostname: 'api.switch-bot.com',
  port: 443,
  path: `/v1.1/devices/`,
  method: 'GET',
  headers: {
    ...auth,
    'Content-Type': 'application/json',
    'Content-Length': 0,
  },
};

const req = https.request(options, res => {
  console.log(`statusCode: ${res.statusCode}`);
  res.on('data', d => {
      process.stdout.write(d);
  });
});

req.on('error', error => {
  console.error(error);
});

Environment

  • OS: MacOS
  • Software: Node
  • Node: v20.16.0
  • npm: 10.8.2

Additional Context

No response

taulfsime avatar Aug 25 '24 10:08 taulfsime