Skip to main content

createOIDCInteractionController

Package: @nauth-toolkit/oidc-provider/nestjs Type: Controller factory

Builds the NestJS controller that bridges the OpenID Connect provider and nauth-toolkit's login. OIDCProviderModule.forRoot() calls this for you; call it directly only when registering the controller in your own module.

import { createOIDCInteractionController, DEFAULT_INTERACTION_PATH } from '@nauth-toolkit/oidc-provider/nestjs';
function createOIDCInteractionController(path?: string): Type<unknown>

Parameters

  • path - Path relative to any global prefix. Default DEFAULT_INTERACTION_PATH, which is 'oidc/interaction'

Routes​

RouteMethodBridge methodReturns
:uidGETgetState()InteractionStateDTO
:uid/abortPOSTabort()InteractionRedirectDTO
:uid/confirmPOSTcompleteConsent()InteractionRedirectDTO
:uid/loginPOSTcompleteLogin()InteractionRedirectDTO

Request body for :uid/confirm (OIDCConsentBody):

PropertyTypeRequiredDescription
approvebooleanNoAnything but an explicit false is an approval
scopesstring[]NoA narrowed set of scopes to grant
{ "approve": true, "scopes": ["openid", "email"] }

The guard arrangement​

The controller applies @UseGuards(AuthGuard) at the class level and @Public() on every route. Both halves are load-bearing:

  • AuthGuard is not a global guard in this toolkit. Without it CURRENT_USER is never populated, and the session gate reports no_session for everyone, forever.
  • @Public() then makes the guard optional — it attaches a user when a valid session is present and never rejects — which is required, because an anonymous caller is exactly the case that has to work in order to send someone to the login page.

Reproduce both if you write your own controller.

Example​

src/oidc/my-oidc.module.ts
import { Module } from '@nestjs/common';
import { createOIDCInteractionController } from '@nauth-toolkit/oidc-provider/nestjs';

@Module({
controllers: [createOIDCInteractionController('identity/interaction')],
})
export class MyOIDCModule {}

Registering it yourself means turning the module's own registration off:

OIDCProviderModule.forRoot({ ...oidcConfig, interaction: { enabled: false } });

What's Next​