节点无法获得响应

时间:2018-01-26 15:51:32

标签: node.js express

我使用LINE登录模块,我可以访问oauth页面,但每当我点击允许此应用程序登录时,响应就是Can not / GET views / pages / callbackurl.ejs。这是我在本地运行的代码

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

1 个答案:

答案 0 :(得分:1)

您遇到了问题,因为您的回调网址为/views/pages/callbackurl.ejs。只要身份验证成功,Line会重定向回callback_url中提及的LineOptions,但在您的情况下,您尚未实施/views/pages/callbackurl.ejs。它是/callbackurl

因此,您可以将callback_url更改为http://localhost:5000/callbackurl,以便在成功完成后获得有效的重定向。

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