import { Body , Controller , Get , Next , Post , Render , Req , Res , UsePipes , ValidationPipe , } from '@nestjs/common' ; import { LoggerLevelNames , LoggerService } from '@fc/logger' ; import { OidcClientSession } from '@fc/oidc-client' ; import { OidcProviderService } from '@fc/oidc-provider' ; import { ISessionService , Session , SessionService } from '@fc/session' ; import { AppSession , SignInDTO } from '../dto' ; import { MockIdentityProviderRoutes } from '../enums' ; import { MockIdentityProviderService } from '../services' ; @ Controller ( ) export class MockIdentityProviderController { constructor ( private readonly logger , private readonly oidcProvider , private readonly mockIdentityProviderService , private readonly sessionService ) { this . logger . setContext ( this . constructor . name ) ; } @ Get ( MockIdentityProviderRoutes . INDEX ) async index ( ) { const response = { status : 'ok' } ; this . logger . trace ( { route : MockIdentityProviderRoutes . INDEX , method : 'GET' , name : 'MockIdentityProviderRoutes.INDEX' , response , } ) ; return response ; } @ Get ( MockIdentityProviderRoutes . INTERACTION ) @ UsePipes ( new ValidationPipe ( { whitelist : true } ) ) @ Render ( 'interaction' ) async getInteraction ( @ Req ( ) req , @ Res ( ) res , todo author Hugues
     *  date ticket @ Session ( 'OidcClient' ) sessionOidc , @ Session ( 'App' ) appSession ) { const { uid , params } = await this . oidcProvider . getInteraction ( req , res ) ; const spName = await sessionOidc . get ( 'spName' ) ; const finalSpId = await appSession . get ( 'finalSpId' ) ; const response = { uid , params , spName , finalSpId , } ; this . logger . trace ( { route : MockIdentityProviderRoutes . INTERACTION , method : 'GET' , name : 'MockIdentityProviderRoutes.INTERACTION' , response , } ) ; return response ; } @ Post ( MockIdentityProviderRoutes . INTERACTION_LOGIN ) async getLogin ( @ Next ( ) next , @ Req ( ) req , @ Body ( ) body , todo author Hugues
     *  date ticket @ Session ( 'OidcClient' ) sessionOidc ) { const { login , acr } = body ; const spIdentity = await this . mockIdentityProviderService . getIdentity ( login ) ; if ( ! spIdentity ) { this . logger . trace ( { spIdentity } , LoggerLevelNames . WARN ) ; throw new Error ( 'Identity not found in database' ) ; } const spAcr = acr ; /**
         * We need to set an alias with the sub since later (findAccount) we do not have access
         * to the sessionId, nor the interactionId.
         */ await this . sessionService . setAlias ( spIdentity . sub , req . sessionId ) ; sessionOidc . set ( { spAcr , spIdentity , } ) ; this . logger . trace ( { route : MockIdentityProviderRoutes . INTERACTION_LOGIN , method : 'POST' , name : 'MockIdentityProviderRoutes.INTERACTION_LOGIN' , spIdentity , } ) ; return next ( ) ; } }