Node.js 节点无法获得响应
我使用的是LINE login模块,我可以访问oauth页面,但每当我单击Allow this app登录时,响应是Cannot/GET views/pages/callbackurl.ejs。这是我在本地运行的代码Node.js 节点无法获得响应,node.js,express,Node.js,Express,我使用的是LINE login模块,我可以访问oauth页面,但每当我单击Allow this app登录时,响应是Cannot/GET views/pages/callbackurl.ejs。这是我在本地运行的代码 "use strict"; const app = require('express')(); const line_login = require("line-login"); const login = new line_login({ channel_id:
"use strict";
const app = require('express')();
const line_login = require("line-login");
const login = new line_login({
channel_id: 15818,
channel_secret: "6bfb55e907",
callback_url: "http://localhost:5000/views/pages/callbackurl.ejs",
scope: "openid profile",
prompt: "consent",
bot_prompt: "normal"
});
app.listen(process.env.PORT || 5000, () => {
console.log(`server is listening to ${process.env.PORT || 5000}...`);
});
// Specify the path you want to start authorization.
app.use("/", login.auth());
// Specify the path you want to wait for the callback from LINE authorization endpoint.
app.use("http://localhost:5000/views/pages/callbackurl.ejs", login.callback((req, res, next, token_response) => {
// Success callback
res.json(token_response);
},(req, res, next, error) => {
// Failure callback
res.status(400).json(error);
}));
您正面临这个问题,因为您的回调url是
/views/pages/callbackurl.ejs
。只要身份验证成功,Line
就会重定向回LineOptions
中提到的callback\u url
,但在您的情况下,您尚未实现/views/pages/callbackurl.ejs
。它是/callbackurl
因此,您可以将callback\u url
更改为http://localhost:5000/callbackurl
在oauth成功后获得有效重定向
const app = require('express')();
const line_login = require("line-login");
const login = new line_login({
channel_id: 15818,
channel_secret: "6bfb55e907",
callback_url: "/callbackurl", // Update this url on Line developer portal
scope: "openid profile",
prompt: "consent",
bot_prompt: "normal"
});
app.listen(process.env.PORT || 5000, () => {
console.log(`server is listening to ${process.env.PORT || 5000}...`);
});
// Specify the path you want to start authorization.
app.use("/", login.auth());
// Specify the path you want to wait for the callback from LINE authorization endpoint.
app.use("/callbackurl", login.callback((req, res, next, token_response) => {
// Success callback
res.json(token_response);
},(req, res, next, error) => {
// Failure callback
res.status(400).json(error);
}));
请从此公开问题中删除
channel\u id
和channel\u secret
,如果它们有效。不,它们无效。我已经编辑过了,它不是真实的id和频道秘密谢谢你的回复,我仍然收到相同的错误。我应该使用app.get()吗?app.use
应该可以,但是你可以试试app.get
。您必须在代码和在线开发人员门户中更新callback\u url
。您能更新有问题的最新代码和您收到的错误吗?我们可以看到您错误地提到了callback\u url
和route.hi Mukesh。非常感谢。重定向工作,但我无法输出res.json,在回调url中,应用程序部署在Heroku中进行实时测试。