import { Body , Controller , Get , Post , Res , UsePipes , ValidationPipe , } from '@nestjs/common' ; import { ConfigService } from '@fc/config' ; import { IdentityProviderAdapterEnvService } from '@fc/identity-provider-adapter-env' ; import { LoggerLevelNames , LoggerService } from '@fc/logger' ; import { OidcClientConfig , OidcClientService , OidcClientSession , RedirectToIdp , } from '@fc/oidc-client' ; import { ISessionService , Session , SessionCsrfService , SessionInvalidCsrfSelectIdpException , } from '@fc/session' ; import { OidcClientRoutes } from '../enums' ; @ Controller ( OidcClientRoutes . BASE_ROUTE ) export class OidcClientController { constructor ( private readonly logger , private readonly oidcClient , private readonly config , private readonly csrfService , private readonly identityProvider ) { this . logger . setContext ( this . constructor . name ) ; } TODO see https @ Get ( OidcClientRoutes . WELL_KNOWN_KEYS ) async getWellKnownKeys ( ) { this . logger . trace ( { route : OidcClientRoutes . WELL_KNOWN_KEYS , method : 'GET' , name : 'OidcClientRoutes.WELL_KNOWN_KEYS' , } ) ; return this . oidcClient . utils . wellKnownKeys ( ) ; } todo @ Post ( OidcClientRoutes . REDIRECT_TO_IDP ) @ UsePipes ( new ValidationPipe ( { whitelist : true } ) ) async redirectToIdp ( @ Res ( ) res , @ Body ( ) body , todo author Hugues
     *  date ticket @ Session ( 'OidcClient' ) sessionOidc ) { const { acr : acr_values , scope } = this . config . get < OidcClientConfig > ( 'OidcClient' ) ; const { csrfToken } = body ; const IDP_ID = 'envIssuer' ; try { await this . csrfService . validate ( sessionOidc , csrfToken ) ; } catch ( error ) { this . logger . trace ( { error } , LoggerLevelNames . WARN ) ; throw new SessionInvalidCsrfSelectIdpException ( error ) ; } const { nonce , state } = await this . oidcClient . utils . buildAuthorizeParameters ( ) ; const authorizationUrl = await this . oidcClient . utils . getAuthorizeUrl ( { acr_values , nonce , idpId : IDP_ID , scope , state , } ) ; const { name : idpName } = await this . identityProvider . getById ( IDP_ID ) ; const session = { idpId : IDP_ID , idpName , idpNonce : nonce , idpState : state , } ; await sessionOidc . set ( session ) ; this . logger . trace ( { body , method : 'POST' , name : 'OidcClientRoutes.REDIRECT_TO_IDP' , redirect : authorizationUrl , res , route : OidcClientRoutes . REDIRECT_TO_IDP , session , } ) ; res . redirect ( authorizationUrl ) ; } }