-
-
Save skiph/4705f5d10e0634430a50244ee43afa0d to your computer and use it in GitHub Desktop.
API Key Proxy - approov proxy checking
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
// load and check approov token checking | |
const approov = require(`${__dirname}/approov`); | |
if (config.approov_header == null) { | |
throw new Error(`approov_header not found; please set in ${__dirname}/config.js`); | |
} | |
const approovHdr = config.approov_header; | |
// preprocess all proxy requests | |
app.use((req, res, next) => { | |
// check and delete approov token | |
//log_req(req); | |
var token = req.headers[approovHdr]; | |
delete req.headers[approovHdr]; | |
if (!approov.isValid(token)) { | |
console.log(chalk.red('Unauthorized: invalid Approov token')); | |
res.status(401).send('Unauthorized'); | |
return; | |
} | |
next(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment