如何使用 Express 服务器从 URL 获取 JWT 令牌?

How to get JWT token from URL using Express server?

假设 URL 就像 http://localhost:3000/auth?token=helloworld

如何使用 express 服务器从此 url 获取 jwt 令牌?我试过下面这段代码..没有输出。

var express = require('express');
var app = express();
var router = express.Router();

    router.use(function(req, res, next) {
    var token = req.query.token;
    console.log(token);
    try {
        var decoded = jwt.verify(token, 'thisismysecretstring');
        console.log(decoded);
        res.send(req.query.token);
    } catch (err) {
        console.log(err);
    }
});

app.use('/auth', router);

试试看

var express = require('express');
var validate = require('../../validate');
var service = require('./loginService');
var router = express.Router();

router.route('/authenticate').post(service.ldap, function(req, res, next) {
    var parameters = req.body;
    parameters.bluepages = req.bluepages;

    service.login(parameters).then(function(body) {
        res.status(200).json(body);
    }).fail(function(err) {
        res.status(err.status).json(err.data);
    });
});
module.exports = router;

URL格式应该是这样的:

http://localhost:3000/auth/?token=helloworld

现在,它正在运行。谢谢