import { Injectable } from '@nestjs/common' ; import { RequiredExcept } from '@fc/common' ; import { CoreService } from '@fc/core' ; import { CryptographyFcpService } from '@fc/cryptography-fcp' ; import { FeatureHandler } from '@fc/feature-handler' ; import { LoggerService } from '@fc/logger' ; import { IOidcIdentity } from '@fc/oidc' ; import { OidcClientSession } from '@fc/oidc-client' ; import { RnippPivotIdentity , RnippReceivedValidEvent , RnippRequestedEvent , RnippService , } from '@fc/rnipp' ; import { ServiceProviderAdapterMongoService } from '@fc/service-provider-adapter-mongo' ; import { TrackingService } from '@fc/tracking' ; import { IVerifyFeatureHandler , IVerifyFeatureHandlerHandleArgument , } from '../../interfaces' ; @ Injectable ( ) @ FeatureHandler ( 'core-fcp-default-verify' ) export class CoreFcpDefaultVerifyHandler implements IVerifyFeatureHandler { constructor ( private readonly logger , private readonly core , private readonly tracking , private readonly rnipp , private readonly serviceProvider , private readonly cryptographyFcp ) { this . logger . setContext ( this . constructor . name ) ; } param req async handle ( { sessionOidc , trackingContext , } ) { this . logger . debug ( 'getConsent service: ##### core-fcp-default-verify' ) ; const { idpAcr , idpId , idpIdentity , spAcr , spId } = await sessionOidc . get ( ) ; todo see https this . core . checkIfAcrIsValid ( idpAcr , spAcr ) ; const rnippIdentity = await this . rnippCheck ( idpIdentity as IOidcIdentity , trackingContext ) ; const { entityId } = await this . serviceProvider . getById ( spId ) ; const hashSp = this . cryptographyFcp . computeIdentityHash ( rnippIdentity ) ; await this . core . checkIfAccountIsBlocked ( hashSp ) ; const subSp = this . cryptographyFcp . computeSubV1 ( entityId , hashSp ) ; const idpIdentityHash = this . cryptographyFcp . computeIdentityHash ( idpIdentity as IOidcIdentity ) ; const subIdp = this . cryptographyFcp . computeSubV1 ( spId , idpIdentityHash ) ; const accountId = await this . core . computeInteraction ( { entityId , hashSp , spId , subSp , } , { idpId , subIdp , } ) ; /**
         * Prepare identity that will be retrieved by `oidc-provider`
         * and sent to the SP
         *
         * We need to replace IdP's sub, by our own sub
         */ const spIdentity = { ... idpIdentity , sub : subSp } ; const idpIdentityCleaned = { sub : idpIdentity . sub } ; const session = { amr : [ 'fc' ] , idpIdentity : idpIdentityCleaned , spIdentity , accountId , } ; this . logger . trace ( { session } ) ; await sessionOidc . set ( session ) ; } param idpIdentity param req private async rnippCheck ( idpIdentity , trackingContext ) { this . tracking . track ( RnippRequestedEvent , trackingContext ) ; const rnippIdentity = await this . rnipp . check ( idpIdentity ) ; this . tracking . track ( RnippReceivedValidEvent , trackingContext ) ; this . logger . trace ( { rnippIdentity } ) ; return rnippIdentity ; } }