Skip to content

Instantly share code, notes, and snippets.

@leon-do
Created March 9, 2020 20:47
Show Gist options
  • Save leon-do/8346a93eacf74e71c179ba59c4e99dee to your computer and use it in GitHub Desktop.
Save leon-do/8346a93eacf74e71c179ba59c4e99dee to your computer and use it in GitHub Desktop.
Okta + Express
const express = require('express');
const session = require('express-session');
const { ExpressOIDC } = require('@okta/oidc-middleware');
const app = express();
// session support is required to use ExpressOIDC
app.use(session({
secret: 'this should be secure',
resave: true,
saveUninitialized: false
}));
const oidc = new ExpressOIDC({
issuer: 'https://dev-652439.okta.com/oauth2/default',
client_id: '0oa36633u9VQFFvz34x1',
client_secret: 'Q3xX8Jdf5EpbCRSpOqpE-vNvWjpmWAuF1sYa70Wo', // https://developer.okta.com/docs/guides/find-your-app-credentials/overview/
appBaseUrl: 'http://localhost:8080',
scope: 'openid profile'
});
// ExpressOIDC will attach handlers for /authorization-code/callback routes
app.use(oidc.router);
app.get('/', oidc.ensureAuthenticated(), (req, res) => {
res.send(JSON.stringify(req.userContext.userinfo));
});
oidc.on('ready', () => {
app.listen(8080, () => console.log('app started 8080'));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment