Created
June 1, 2022 19:41
-
-
Save michimau/710ce77403b8ff849701838b4fe3a818 to your computer and use it in GitHub Desktop.
nodejs example for openid integration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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