NestJS

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
+import { ConfigService } from "@nestjs/config";

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

    // Requires ConfigModule.forRoot() somewhere in your imports (typically AppModule).
    const configService = app.get(ConfigService);

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


    await app.listen(parseInt(configService.get("PORT") ?? "3000"));
}

bootstrap();

And this is how your controlled would look:

This is the only “integration” code you need:

Last updated

Was this helpful?