Hi,
I’m using Node and trying to use oidc.ensureAuthentication to protect some of my routes. I am currently testing it on a page called alarms with a file called “alarms.html” in the directory. I am able to login using the oidc-middleware package however afterwards I am unable to use oidc.ensureAuthentication. My URL is a localhost port.
My server.js
const express = require('express');
const app = express();
const session = require('express-session');
const { ExpressOIDC } = require('@okta/oidc-middleware');
const port = 8080;
// Setting up the public directory
app.use(express.static(__dirname));
app.listen(port, () => console.log(`listening on port ${port}!`));
// session support is required to use ExpressOIDC
app.use(session({
secret: 'this should be secure',
resave: true,
saveUninitialized: false
}));
const oidc = new ExpressOIDC({
issuer: <URL>/oauth2/default',
client_id: '.....',
client_secret: '.....',
redirect_uri: '<URL>/authorization-code/callback',
scope: 'openid profile',
appBaseUrl: '<URL>'
});
// ExpressOIDC attaches handlers for the /login and /authorization-code/callback routes
app.use(oidc.router);
app.get('/alarms', oidc.ensureAuthenticated(), (req, res) => {
console.log('Authenticated');
res.render('alarms');
});