Nest.js

If you prefer a more "Nestish" experience, there's a comunity wrapper around oidc-spa/server:

https://github.com/mwolf1989/nestjs-spa-oidc

This is how your Nest API would typically look like.

src/main.ts
import { NestFactory } from "@nestjs/core";
import { AppModule } from "./app.module";
import { bootstrapAuth } from "./auth"; // See below

async function bootstrap() {
    bootstrapAuth({
        implementation: "real", // or "mock", see: https://docs.oidc-spa.dev/v/v8/integration-guides/backend-token-validation/mock-modes
        issuerUri: process.env.OIDC_ISSUER_URI!,
        expectedAudience: process.env.OIDC_AUDIENCE
    });

    const app = await NestFactory.create(AppModule, /* Any adapter */);

    await app.listen(parseInt(process.env.PORT ?? "3000"));
}

bootstrap();

And this is how your controlled would look:

This is the only “integration” code you need:

Last updated

Was this helpful?