Dōrvis

Sign in

Examples by language

Every example runs the same flow. It redirects to Dorvis, exchanges the code and reads the personal code. Pick your language.

Default token endpoint authentication client_secret_post

Install

Shell
npm install express express-session passport passport-openidconnect dotenv

Code

JavaScriptapp.js
import 'dotenv/config';
import express from 'express';
import session from 'express-session';
import passport from 'passport';
import OpenIDConnectStrategy from 'passport-openidconnect';

const issuer = process.env.OIDC_ISSUER_URL; // https://dorvis.eu/oidc
const app = express();
app.use(session({ secret: process.env.SESSION_SECRET, resave: false, saveUninitialized: false }));
app.use(passport.initialize());
app.use(passport.session());

const strategy = new OpenIDConnectStrategy(
  {
    issuer,
    authorizationURL: `${issuer}/oauth2/auth`,
    tokenURL: `${issuer}/oauth2/token`,
    userInfoURL: `${issuer}/userinfo`,
    clientID: process.env.OIDC_CLIENT_ID,
    clientSecret: process.env.OIDC_CLIENT_SECRET,
    callbackURL: process.env.OIDC_REDIRECT_URL,
    scope: 'profile',
  },
  (iss, profile, cb) => cb(null, profile)
);
// pass ?acr=idp:smartid through to Dorvis to skip the method selection
strategy.authorizationParams = (options) => (options.acr ? { acr_values: options.acr } : {});
passport.use(strategy);
passport.serializeUser((user, done) => done(null, user));
passport.deserializeUser((user, done) => done(null, user));

app.get('/login', (req, res, next) =>
  passport.authenticate('openidconnect', { acr: req.query.acr })(req, res, next)
);
app.get('/callback', passport.authenticate('openidconnect', { failureRedirect: '/' }), (req, res) =>
  res.json(req.user._json) // given_name, family_name, person_code, auth_method
);

app.listen(3000);

Token endpoint authentication

Libraries differ in how they send the client secret. If the code exchange returns invalid_client, choose the method shown with the example in the integration advanced settings.

Full examples

Working demo apps in Node.js, Python and Go are in the Dorvis code repository. Write to us to request access.

Did not find the answer?

Write to us and a developer will reply.

Ask a question
Loading complete

We use cookies to make this website easier to use. Read our Privacy and Cookie Policy.