Mounting oidc-provider
The following snippets show how a Provider instance can be mounted to existing applications with a
path prefix /oidc.
to a fastify application
Section titled “to a fastify application”// assumes fastify ^4.0.0const fastify = new Fastify();await fastify.register(require("@fastify/middie"));// or// await app.register(require('@fastify/express'));fastify.use("/oidc", provider.callback());to a hapi application
Section titled “to a hapi application”// assumes @hapi/hapi ^21.0.0const callback = provider.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; },});to a nest application
Section titled “to a nest application”// assumes NestJS ^7.0.0import { Controller, All, Req, Res } from "@nestjs/common";import { Request, Response } from "express";const callback = provider.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); }}to an express application
Section titled “to an express application”// assumes express ^4.0.0 || ^5.0.0expressApp.use("/oidc", provider.callback());to a koa application
Section titled “to a koa application”// assumes koa ^2.0.0 || ^3.0.0// assumes koa-mount ^4.0.0import mount from "koa-mount";koaApp.use(mount("/oidc", provider));