John Wick
John Wick

Reputation: 509

Node Cannot GET response

I'm using LINE login module, I am able to access the oauth page but whenever I click Allow this app to login the response is Cannot/GET views/pages/callbackurl.ejs. This is the code that I run locally

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

Upvotes: 0

Views: 78

Answers (1)

Mukesh Sharma
Mukesh Sharma

Reputation: 9022

You are facing the issue, because your callback url is /views/pages/callbackurl.ejs. Whenever authentication is successful, Line redirects back to callback_url mentioned in LineOptions, but in your case, you have not implemented /views/pages/callbackurl.ejs. It is /callbackurl.

So, you can change callback_url to http://localhost:5000/callbackurl to get valid redirection after successful 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);
}));

Upvotes: 1

Related Questions