import { ValidatorOptions } from 'class-validator' ; import { Body , Controller , Get , Next , Post , Query , Req , Res , UsePipes , ValidationPipe , } from '@nestjs/common' ; import { validateDto } from '@fc/common' ; import { CoreRoutes } from '@fc/core' ; import { LoggerLevelNames , LoggerService } from '@fc/logger' ; import { OidcProviderAuthorizeParamsException , OidcProviderService , } from '@fc/oidc-provider' ; import { OidcProviderRoutes } from '@fc/oidc-provider/enums' ; import { SessionService } from '@fc/session' ; import { AuthorizeParamsDto , ErrorParamsDto } from '../dto' ; import { CoreFcpFailedAbortSessionException } from '../exceptions' ; const validatorOptions = { forbidNonWhitelisted : true , forbidUnknownValues : true , whitelist : true , } ; @ Controller ( ) export class OidcProviderController { constructor ( private readonly logger , private readonly oidcProvider , private readonly sessionService ) { this . logger . setContext ( this . constructor . name ) ; } see https TODO see https @ Get ( OidcProviderRoutes . AUTHORIZATION ) async getAuthorize ( @ Req ( ) req , @ Res ( ) res , @ Next ( ) next , @ Query ( ) query ) { this . logger . trace ( { method : 'GET' , name : 'OidcProviderRoutes.AUTHORIZATION' , query , route : OidcProviderRoutes . AUTHORIZATION , } ) ; this . sessionService . reset ( req , res ) ; const errors = await validateDto ( query , AuthorizeParamsDto , validatorOptions ) ; if ( errors . length ) { this . logger . trace ( { errors } , LoggerLevelNames . WARN ) ; throw new OidcProviderAuthorizeParamsException ( ) ; } return next ( ) ; } see https TODO see https @ Post ( OidcProviderRoutes . AUTHORIZATION ) async postAuthorize ( @ Req ( ) req , @ Res ( ) res , @ Next ( ) next , @ Body ( ) body ) { this . logger . trace ( { body , method : 'POST' , name : 'OidcProviderRoutes.AUTHORIZATION' , route : OidcProviderRoutes . AUTHORIZATION , } ) ; this . sessionService . reset ( req , res ) ; const errors = await validateDto ( body , AuthorizeParamsDto , validatorOptions ) ; if ( errors . length ) { this . logger . trace ( { errors } , LoggerLevelNames . WARN ) ; throw new OidcProviderAuthorizeParamsException ( ) ; } return next ( ) ; } @ Get ( CoreRoutes . REDIRECT_TO_SP_WITH_ERROR ) @ UsePipes ( new ValidationPipe ( { whitelist : true } ) ) async redirectToSpWithError ( @ Query ( ) { error , error_description : errorDescription } , @ Req ( ) req , @ Res ( ) res ) { try { await this . oidcProvider . abortInteraction ( req , res , error , errorDescription ) ; } catch ( error ) { throw new CoreFcpFailedAbortSessionException ( error ) ; } } }