Hello,
I am unable to get the Auth0 Basic Config to work on GitHub Pages.
I tried watching the “Add Node.js User Authentication in 10 Minutes!” tutorial on YouTube, and also tried to follow the App Integration documentation, but had no luck.
This is what I was able to accomplish:
const express = require(‘express’);
const app = express();
require('dotenv').config();
// Express JS middleware implementing sign on for Express web apps using OpenID Connect
const { auth, requiresAuth } = require('express-openid-connect');
// With this basic config, our app requires authentication for all routes and stores the user's identity in an encrypted and signed cookie
app.use(
auth({
authRequired: false,
auth0Logout: true,
issuerBaseURL: process.env.ISSUER_BASE_URL,
baseURL: process.env.BASE_URL,
clientID: process.env.CLIENT_ID,
secret: process.env.SECRET,
idpLogout: true,
})
);
app.get('/', (req, res) => {
res.send(req.oidc.isAuthenticated() ? 'Logged in' : 'Logged out');
});
const port = process.env.PORT || 3000;
app.listen(port, () => {
console.log(`listening on port ${port}`);
});
app.get('/profile', requiresAuth(), (req, res) => {
res.send(JSON.stringify(req.oidc.user));
});
While I was able to get this working on http://localhost:3000, I was unsure how to plug my GitHub pages URL into either the baseURL or Allowed Logout or Callback URLs.
On my local machine, when I run app.js and search /login I get re-directed to log into Auth0. However, when I attempt to replace my BASE_URL with my GitHub Pages domain I do not get the same result. Instead, I get a 404 because there is no /login page on my domain.
Why does this work on localhost:3000 but not a GitHub page? Is there any example of what to plug into the following areas as I believe they are the source of my issue?
- ISSUER_BASE_URL (I believe this wouldn’t change, this should be like “https://dev-…us.auth0.com”
- BASE_URL (I am not sure what this should be when I want to push my ignored .env and full application to GitHub Pages)
- Application Callback URLs
- Application Login URLs
- Application Logout URLs
Any help would be greatly appreciated.