nicholastay / passport-discord

Passport strategy for authentication with Discord (discordapp.com)
ISC License
172 stars 55 forks source link

Prompt not working #33

Open tandpfun opened 3 years ago

tandpfun commented 3 years ago

The prompt strategy value no longer works.

Code:

passport.use(new Strategy({
    clientID: process.env.CLIENT_ID,
    clientSecret: process.env.CLIENT_SECRET,
    callbackURL: `${process.env.BASE_URL}/callback`,
    scope: ["identify", "guilds"],
    prompt: "none",
},
(accessToken, refreshToken, profile, done) => {\
    process.nextTick(() => done(null, profile));
}));

The prompt is nowhere to be found in the oauth URL.

FiredHydra commented 3 years ago

Works fine for me.

Server.js:

const express = require("express");
const session = require("express-session");
const passport = require("passport");
const Strategy = require("passport-discord").Strategy;

const app = express();

// These are... internal things related to passport. Honestly I have no clue either.
// Just leave 'em there.
passport.serializeUser((user, done) => {
  done(null, user);
});
passport.deserializeUser((obj, done) => {
  done(null, obj);
});

const scopes = ["identify", "email"];
const prompt = "none";

passport.use(
  new Strategy(
    {
      clientID: "",
      clientSecret: "",
      callbackURL: "http://localhost:5000/callback",
      scope: scopes,
      prompt: prompt,
    },
    function (accessToken, refreshToken, profile, done) {
      process.nextTick(function () {
        return done(null, profile);
      });
    }
  )
);

app.use(
  session({
    secret: "some super secret secret ooooooh scary",
    resave: false,
    saveUninitialized: false,
  })
);
app.use(passport.initialize());
app.use(passport.session());
app.get(
  "/",
  passport.authenticate("discord", { scope: scopes, prompt: prompt }),
  function (req, res) {}
);
app.get(
  "/callback",
  passport.authenticate("discord", { failureRedirect: "/" }),
  function (req, res) {
    res.redirect("/info");
  } // auth success
);
app.get("/logout", function (req, res) {
  req.logout();
  res.redirect("/");
});
app.get("/info", checkAuth, function (req, res) {
  //console.log(req.user)
  res.json(req.user);
});

function checkAuth(req, res, next) {
  if (req.isAuthenticated()) return next();
  res.send("not logged in :(");
}

app.listen(5000, function (err) {
  if (err) return console.log(err);
  console.log("Listening at http://localhost:5000/");
});

package.json:

{
  "name": "OAUTH2-test",
  "version": "1.0.0",
  "description": "",
  "main": "server.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "express": "^4.17.1",
    "express-session": "^1.17.1",
    "passport": "^0.4.1",
    "passport-discord": "^0.1.4"
  }
}
tandpfun commented 3 years ago

Looks like putting it into the strategy didn't work, and I had to put it into the passport.authenticate function as seen in your example above. Shouldn't it be working if I put it inside the strategy and not the authenticate though?

LingleDev commented 3 years ago

I get this issue also when I put it into my strategy, but it works when I put it in authenticate

tonestrike commented 3 years ago

@tandpfun and @FHGDev, the owner of this repo has stopped maintaining it. You can use my fork which offers the ability to use prompt on the strategy and several other bug fixes. You can find it here:

https://github.com/tonestrike/passport-discord