Last active
June 4, 2024 19:53
-
-
Save letsautomatenet/2601c1ed1bfc686a5c2db90db9cd66b6 to your computer and use it in GitHub Desktop.
Node-Red SwitchBot Authentication Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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