Skip to content

Mounting oidc-provider

This content is for v8.x. Switch to the latest version for up-to-date documentation.

The following snippets show how a Provider instance can be mounted to existing applications with a path prefix /oidc.

Note: if you mount oidc-provider to a path it’s likely you will have to also update the interactions.url configuration to reflect the new path.

// assumes connect ^3.0.0
connectApp.use('/oidc', oidc.callback())
// assumes fastify ^4.0.0
const fastify = new Fastify()
await fastify.register(require('@fastify/middie'))
// or
// await app.register(require('@fastify/express'));
fastify.use('/oidc', oidc.callback())
// assumes @hapi/hapi ^21.0.0
const callback = oidc.callback()
hapiApp.route({
path: `/oidc/{any*}`,
method: '*',
config: { payload: { output: 'stream', parse: false } },
async handler({ raw: { req, res } }, h) {
req.originalUrl = req.url
req.url = req.url.replace('/oidc', '')
callback(req, res)
await once(res, 'finish')
req.url = req.url.replace('/', '/oidc')
delete req.originalUrl
return res.writableEnded ? h.abandon : h.continue
},
})
// assumes NestJS ^7.0.0
import { Controller, All, Req, Res } from '@nestjs/common'
import { Request, Response } from 'express'
const callback = oidc.callback()
@Controller('oidc')
export class OidcController {
@All('/*')
public mountedOidc(@Req() req: Request, @Res() res: Response): void {
req.url = req.originalUrl.replace('/oidc', '')
return callback(req, res)
}
}
// assumes express ^4.0.0
expressApp.use('/oidc', oidc.callback())
// assumes koa ^2.0.0
// assumes koa-mount ^4.0.0
import mount from 'koa-mount'
koaApp.use(mount('/oidc', oidc.app))

Note: when the issuer identifier does not include the path prefix you should take care of rewriting your ${root}/.well-known/openid-configuration to ${root}${prefix}/.well-known/openid-configuration so that your deployment remains conform to the Discovery 1.0 specification.