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