import express from 'express' import {Issuer, generators} from 'openid-client' import bodyParser from 'body-parser' async function run() { const app = express(); app.use(bodyParser.urlencoded()); app.use(bodyParser.json()) const issuer = await Issuer.discover('https://gateway-gab7y.codemowers.ee/'); console.log('Discovered issuer %s %O', issuer.issuer, issuer.metadata); const client = new issuer.Client({ client_id: 'foo', redirect_uris: ['https://client-gab7y.codemowers.ee/cb'], response_types: ['id_token'], // id_token_signed_response_alg (default "RS256") }) const nonce = generators.nonce(); app.get('/', async function (req, res) { let url = client.authorizationUrl({ redirect_uri: 'https://client-gab7y.codemowers.ee/cb', scope: 'openid', response_mode: 'form_post', nonce, }); res.redirect(url); }); app.post('/cb', async function (req, res) { const params = client.callbackParams(req); const tokenSet = await client.callback('https://client-gab7y.codemowers.ee/ok', params, {nonce}); console.log('received and validated tokens %j', tokenSet); console.log('validated ID Token claims %j', tokenSet.claims()); res.send(tokenSet.claims()); }); app.listen(3000); } run().catch(console.dir);