river-of-ebooks/api/policies/keyAuth.js

15 lines
576 B
JavaScript
Raw Normal View History

module.exports = async function (req, res, next) {
const key = req.param('key') || req.headers['roe-key']
const secret = req.param('secret') || req.headers['roe-secret']
2019-03-05 20:39:07 +00:00
if (!key || !secret) return res.status(403).json({ error: 'Missing appid and secret.' })
const pk = await PublishKey.findOne({ appid: key, secret })
if (pk) {
if (pk.whitelisted) return next()
2019-03-05 20:39:07 +00:00
else res.status(403).json({ error: 'Your app has not been whitelisted yet. Please contact the site operator.' })
}
2019-03-05 20:39:07 +00:00
res.status(403).json({ error: 'Invalid publishing key/secret pair.' })
}