redbird
redbird copied to clipboard
Can we verify JWT
Hi,
In my case, I want to send a Bearer Token (JWT) with the request. Is there a way to validate that?
Tested and you could do this with customResolver. If token is valid return null and redbird will keep resolving to next registered route. else just point the user to server that handles unauthorized users.
For me i would do the validation inside service as usually you need some data from the jwt.
var http = require("http");
var proxy = require("redbird")({ port: 80 });
http
.createServer(function(req, res) {
res.write("You are not valid user");
res.end();
})
.listen(6666);
http
.createServer(function(req, res) {
res.write("Hello World!");
res.end();
})
.listen(8888);
var topPriority = function(host, url, req) {
if (req.headers["authorization"]) {
return null;
} else {
return "http://localhost:6666";
}
};
topPriority.priority = 200;
proxy.addResolver(topPriority);
proxy.register("localhost", "localhost:8888");