import { Body , Controller , Get , Post , Query , Redirect , Render , UsePipes , ValidationPipe , } from '@nestjs/common' ; import { ConfigService } from '@fc/config' ; import { ISessionService , Session } from '@fc/session' ; import { EidasClientConfig , EidasClientSession , EidasClientValidateEuropeanIdentity , ReponseHandlerDTO , } from './dto' ; import { EidasClientService } from './eidas-client.service' ; @ Controller ( 'eidas-client' ) export class EidasClientController { constructor ( private readonly config , private readonly eidasClient ) { } returns @ Get ( '/redirect-to-fr-node-connector' ) @ UsePipes ( new ValidationPipe ( { whitelist : true } ) ) @ Render ( 'redirect-to-fr-node-connector' ) async redirectToFrNode ( @ Query ( ) query , @ Session ( 'EidasClient' ) sessionEidas ) { const { eidasPartialRequest } = await sessionEidas . get ( ) ; const eidasRequest = this . eidasClient . completeEidasRequest ( eidasPartialRequest , query . country ) ; await sessionEidas . set ( 'eidasRequest' , eidasRequest ) ; const { token , lightRequest } = this . eidasClient . prepareLightRequest ( eidasRequest ) ; await this . eidasClient . writeLightRequestInCache ( eidasRequest . id , lightRequest ) ; const { connectorRequestCacheUrl } = this . config . get < EidasClientConfig > ( 'EidasClient' ) ; return { connectorRequestCacheUrl , token , } ; } param body returns @ Redirect ( ) @ Post ( '/response-handler' ) async responseHandler ( @ Body ( ) body , @ Session ( 'EidasClient' ) sessionEidas ) { const { token } = body ; const lightResponse = await this . eidasClient . readLightResponseFromCache ( token ) ; const eidasResponse = this . eidasClient . parseLightResponse ( lightResponse ) ; await sessionEidas . set ( 'eidasResponse' , eidasResponse ) ; const { redirectAfterResponseHandlingUrl } = this . config . get < EidasClientConfig > ( 'EidasClient' ) ; return { url : redirectAfterResponseHandlingUrl , statusCode : 302 } ; } }