Use this express middleware to retrieve information about the user, when an OAuth2 access token is given.
The userinfo would typically adhere to OIDC's userinfo.
(Note: You need promises and ES6 support for const
keyword; if this is an
issue, it should be easy enough to downgrade; pull requests welcome.)
Assuming an existing expressjs application, install this middleware
npm install express-userinfo isomorphic-fetch
, then configure and use it in a route, e.g.
const expressUserinfo = require('express-userinfo')
const getUserinfo = expressUserinfo({
site: 'http://my-oidc-provider.com'
})
app.get('/something-with-userinfo', getUserinfo, (req, res, next) => {
res.send(`sub=${ req.userinfo.sub }, token=${ req.access_token }`)
})