redbird icon indicating copy to clipboard operation
redbird copied to clipboard

Can we verify JWT

Open subhadippramanik opened this issue 6 years ago • 1 comments

Hi,

In my case, I want to send a Bearer Token (JWT) with the request. Is there a way to validate that?

subhadippramanik avatar Jul 28 '18 16:07 subhadippramanik

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");

TaDDu avatar Dec 14 '18 13:12 TaDDu