Last active
July 29, 2019 09:02
-
-
Save maxmckenzie/a672341787d5decbff7f03b3758cc123 to your computer and use it in GitHub Desktop.
sha-1 authentication signature server using express.js #express
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
// 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