Last active
February 27, 2025 18:39
-
-
Save bricss/1c7d2963672933f1a1e4a7ae80e80d7c to your computer and use it in GitHub Desktop.
Insomnia π HMAC-SHA256 signature π generator
This file contains hidden or 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
| const crypto = require('crypto-js'); | |
| const appId = insomnia.collectionVariables.get('appId'); | |
| const method = insomnia.request.method; | |
| const payload = insomnia.request.payload || ''; | |
| const sharedKey = insomnia.collectionVariables.get('sharedKey'); | |
| const timestamp = Math.round(Date.now() / 1000); | |
| const url = insomnia.environment.replaceIn( | |
| insomnia.request.url.toString().replace(/\_\./gi, '') | |
| ); | |
| console.log(appId, sharedKey, timestamp, url); | |
| const msg = `${appId}${timestamp}${method}${url}${payload}`; | |
| const hmac = crypto.HmacSHA256(msg, sharedKey); | |
| const sig = crypto.enc.Base64.stringify(hmac); | |
| console.log(hmac, sig); | |
| insomnia.request.addHeader({ key: 'X-K1-ApplicationId', value: appId }); | |
| insomnia.request.addHeader({ key: 'X-K1-Hmac', value: sig }); | |
| insomnia.request.addHeader({ key: 'X-K1-Timestamp', value: timestamp }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment