我在中间件中遇到身份验证用户令牌问题它表示将循环结构转换为JSON将循环结构转换为JSON
在stringify(/app/node_modules/express/lib/response.js),如果授权成功,我将其重定向到我的回调网址,我的回调网址是这样的。 "https://www.myapp.com/callback"
这是中间件的代码
callback(s, f){
router.get("/callback", (req, res, next) => {
const code = req.query.code;
const state = req.query.state;
const friendship_status_changed = req.query.friendship_status_changed;
if (!code){
debug("Authorization failed.");
return f(new Error("Authorization failed."));
}
if (req.session.line_login_state !== state){
debug("Authorization failed. State does not match.");
return f(new Error("Authorization failed. State does not match."));
}
debug("Authorization succeeded.");
this.issue_access_token(code).then((token_response) => {
if (this.verify_id_token && token_response.id_token){
let decoded_id_token;
try {
decoded_id_token = jwt.verify(
token_response.id_token,
this.channel_secret,
{
audience: this.channel_id,
issuer: "https://access.line.me",
algorithms: ["HS256"]
}
);
debug("id token verification succeeded.");
token_response.id_token = decoded_id_token;
console.log(token_response.id_token);
} catch(exception) {
debug("id token verification failed.");
if (f) return f(req, res, next, new Error("Verification of id token failed."));
throw new Error("Verification of id token failed.");
}
}
s(req, res, next, token_response);
}).catch((error) => {
debug(error);
if (f) return f(req, res, next, error);
throw error;
});
});
return router;
}
在我的server.js中,这是我使用app.use
调用它的方式app.use("/callback", login.callback((req, res, next, token_response) => {
// Success callback
res.json(token_response);
},(req, res, next, error) => {
// Failure callback
res.send(req);
//res.status(400).json(error);
}));
这些是我的依赖关系和devdepencies
"dependencies": {
"bluebird": "^3.5.1",
"body-parser": "^1.18.2",
"circular-json": "^0.5.1",
"debug": "^3.1.0",
"ejs": "^2.5.6",
"express": "^4.15.2",
"express-session": "^1.15.6",
"jsonwebtoken": "^8.1.1",
"line-login": "^1.0.8",
"node-fetch": "^1.7.3",
"nodemon": "^1.14.11",
"serve-static": "^1.13.1"
},
"devDependencies": {
"request": "^2.83.0",
"tape": "^4.7.0"
},