Let's say I a web server with most of the endpoints publicly accessible. I want some of them to be accessible just by me (though it could be a group of people eventually).
I'm looking for the most bare-bone solution. I would not want to implement users accounts for example.
The webserver is implemented with express and nodejs. I run the server with nginx in case that helps, but if possible implemeting this at app level would be better.
Here's a small snippet you can use, pass in Basic Authorization header with PassKey in all private API requests
const express = require('express')
const app = express()
const tempauth = (req, res, next) => {
if(!req.headers.authorization || req.headers.authorization.split(" ")[1]!=="PassKey")
res.status(401).send("Unauthorized")
else
next()
}
app.get("/", tempauth, (req, res)=>{
res.send("Access granted")
})
app.listen(3000, ()=>{console.log("Server running on 3000")})