Thursday 25 July 2019

Build a basic authentication for rest api in node.js

​​var auth = "116asd1f2341dfas2f" //this is executed always before somone calls a request app.use(function (req, res, next) { var header=req.headers['authorization']; // get the header if(header != auth) { res.status(401) // HTTP status 404: NotFound .send('401 Unauthorized'); return } next(); }); ​Hello, I am new in the language Node.js - so please have understanding.​Is this a good way to protect a RestApi?My RestApi is accessible via the internet.​If it's not a good method, do you have any tips on what I could use?​And why does this code not provide a sufficient security?

Submitted July 25, 2019 at 10:48AM by superfliege90

No comments:

Post a Comment