Skip to content

Instantly share code, notes, and snippets.

@michimau
Created June 1, 2022 19:41
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 michimau/710ce77403b8ff849701838b4fe3a818 to your computer and use it in GitHub Desktop.
Save michimau/710ce77403b8ff849701838b4fe3a818 to your computer and use it in GitHub Desktop.
nodejs example for openid integration
const express = require('express');
const { auth, requiresAuth } = require('express-openid-connect');
process.env.SECRET = 'verysecretcode'
process.env.BASE_URL = 'http://localhost:8080'
process.env.CLIENT_ID = 'client_id'
process.env.ISSUER_BASE_URL = 'https://login.eea.europa.eu/realms/login-eea'
const app = express();
app.use(
auth({
idpLogout: true,
authRequired: false,
})
);
app.get('/', (req, res) => {
res.send('<a href="/admin">Admin Section</a>');
});
app.get('/admin', requiresAuth(), (req, res) => {
res.send(`Hello ${req.oidc.user.given_name}, this is the admin section.`);
console.log (req.oidc.user);
});
app.set('trust proxy', true);
app.listen(8080, () => console.log('listening at http://localhost:8080'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment