Skip to content

Instantly share code, notes, and snippets.

@letsautomatenet
Last active June 4, 2024 19:53
Show Gist options
  • Save letsautomatenet/2601c1ed1bfc686a5c2db90db9cd66b6 to your computer and use it in GitHub Desktop.
Save letsautomatenet/2601c1ed1bfc686a5c2db90db9cd66b6 to your computer and use it in GitHub Desktop.
Node-Red SwitchBot Authentication Example
// Add module called 'crypto'
const token = msg.token;
const secret = msg.secret;
const t = Date.now();
const nonce = msg.payload;
const data = token + t + nonce;
const signTerm = crypto.createHmac('sha256', secret)
.update(Buffer.from(data, 'utf-8'))
.digest();
const sign = signTerm.toString("base64");
msg = { "headers": { "Authorization": token, "t": t, "sign": sign, "nonce": nonce } }
return msg;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment