Skip to content

Instantly share code, notes, and snippets.

@maxmckenzie
Last active July 29, 2019 09:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maxmckenzie/a672341787d5decbff7f03b3758cc123 to your computer and use it in GitHub Desktop.
Save maxmckenzie/a672341787d5decbff7f03b3758cc123 to your computer and use it in GitHub Desktop.
sha-1 authentication signature server using express.js #express
// https://url/?timestamp=&UID=&secretKey=
const express = require('express');
const crypto = require('crypto');
const app = express()
const signature = (timestamp, uid, secretKey) => {
const buf = Buffer.from(secretKey, 'base64');
const baseString = timestamp + "_" + uid
const binaryBaseString = baseString.toString('binary')
const sig = crypto.createHmac('sha1', buf).update(binaryBaseString).digest()
console.log(sig.toString('base64'))
return sig.toString('base64')
}
app.get('/:request?', (req, res) => {
const timestamp = req.query.timestamp
const uid = req.query.UID
const secretKey = req.query.secretKey
res.send(signature(timestamp, uid, secretKey))
})
app.get('/', function (req, res) {})
const port = process.env.PORT || 3000
app.listen(port, function() {
console.log('running on http://localhost:' + port)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment