Skip to content

Instantly share code, notes, and snippets.

@jake-walker
Created July 31, 2018 12:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jake-walker/3de9e13b8f8517f6bf4c3f3a74861edc to your computer and use it in GitHub Desktop.
Save jake-walker/3de9e13b8f8517f6bf4c3f3a74861edc to your computer and use it in GitHub Desktop.
Auth0 Authentication Problem
[2018-07-31T11:58:46.083Z] DEBUG: app/1 on app: ***.***.***.*** ==[GET]==> /auth/callback?code=****************&state=************************
[2018-07-31T11:58:46.084Z] DEBUG: app/1 on app: Processing callback...
[2018-07-31T11:58:46.130Z] DEBUG: app/1 on app: ***.***.***.*** ==[GET]==> /auth/fail
[2018-07-31T11:58:46.131Z] WARN: app/1 on app: Problem authenticating user. (error=[])
"use strict";
const express = require("express");
const passport = require("passport");
const config = require("../config");
const router = express.Router();
router.get("/", passport.authenticate("auth0", {
clientID: config.auth0.clientID,
domain: config.auth0.domain,
redirectUri: config.auth0.callbackURL,
audience: `https://${config.auth0.domain}/userinfo`,
responseType: "code",
scope: "openid email profile",
}), (req, res) => {
req.app.locals.log.debug("Successful login");
res.redirect("/");
});
router.get("/logout", (req, res) => {
req.logout();
req.app.locals.log.debug("Successful logout");
res.redirect("/");
});
router.get("/callback", (req, res, next) => {
req.app.locals.log.debug("Processing callback...");
next();
}, passport.authenticate("auth0", {
failureRedirect: "/auth/fail",
failureFlash: true,
}), (req, res) => {
req.app.locals.log.debug("Called back from Auth0");
res.redirect(req.session.returnTo || "/");
});
router.get("/fail", (req, res) => {
req.app.locals.log.warn({error: req.flash("error")}, "Problem authenticating user.");
res.render("message", {
title: "Login Failure",
message: "There was a problem logging you in. Perhaps the authorization code expired or something else. You could try again or contact support if the problem persists.",
buttonText: "Try again",
buttonHref: "/auth",
});
});
module.exports = router;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment