Auth0 for node with passport but without express-openid-connect

I’m having problem getting auth0 to work with just passport. It works with express-openid-connect but for various reasons I dont want to use it. Dispite setting callback to localhost:3000/callback in app-setting in the auth0 dashboard I get a “Callback URL mismatch.”

I made this really simple code just to locate the problem:
const express = require(“express”);
const passport = require(“passport”);
const Auth0Strategy = require(“passport-auth0”);
const session = require(“express-session”);

// Konfigurera Passport att använda Auth0
const strategy = new Auth0Strategy(
{
domain: “.us.auth0.com",
clientID: "
”,
clientSecret:
“**********”,
callbackURL: “http://localhost:3000/callback”,
},
function (accessToken, refreshToken, extraParams, profile, done) {
// profile har all användarinformation från Auth0
return done(null, profile);
}
);

const app = express();

passport.use(strategy);

// Konfigurera sessionhantering
app.use(
session({
secret: “**********”,
resave: false,
saveUninitialized: true,
})
);

// Initiera Passport och återställ sessionen
app.use(passport.initialize());
app.use(passport.session());

// Lagra användarinformation i sessionen
passport.serializeUser((user, done) => {
done(null, user);
});

passport.deserializeUser((user, done) => {
done(null, user);
});

// Auth0 callback handler
app.get(
“/callback”,
(req, res, next) => {
console.log(“Callback hit”);
next();
},
passport.authenticate(“auth0”, { failureRedirect: “/login” }),
(req, res) => {
res.redirect(“/”);
}
);

app.get(
“/login”,
passport.authenticate(“auth0”, {
scope: “openid email profile”,
}),
function (req, res) {
res.redirect(“/”);
}
);

app.get(“/”, (req, res) => {
res.send(“Välkommen!”);
});

// Starta server
const port = process.env.PORT || 3000;
app.listen(port, () => {
console.log(Lyssnar på http://localhost:${port});
});

Add an http:// prefix to your callback and logout URLs and that should solve the problem. In other words, your callback URL should be http://localhost:3000/callback, not localhost:3000/callback.

Hi and thanx for your answer and time! Unfortunatly it didnt work. When I use the express-openid-connect modul on the same auth0-app it works, but when I transfer the same info to the passport solution (my code above) it doesnt work. I do however get another error now (see pic, its not a network error because It immidetly works when I try it with the e-o-c modul).

It looks like the authorize endpoint is not configured correctly. If you look closely at the address bar in your screenshot, you’ll see there’s no colon after https.

1 Like