import { Injectable } from '@nestjs/common' ; import { CoreService } from '@fc/core' ; import { CryptographyEidasService } from '@fc/cryptography-eidas' ; import { FeatureHandler } from '@fc/feature-handler' ; import { LoggerService } from '@fc/logger' ; import { IOidcIdentity } from '@fc/oidc' ; import { ServiceProviderAdapterMongoService } from '@fc/service-provider-adapter-mongo' ; import { IVerifyFeatureHandler , IVerifyFeatureHandlerHandleArgument , } from '../../interfaces' ; @ Injectable ( ) @ FeatureHandler ( 'core-fcp-eidas-verify' ) export class CoreFcpEidasVerifyHandler implements IVerifyFeatureHandler { constructor ( private readonly logger , private readonly core , private readonly serviceProvider , private readonly cryptographyEidas ) { this . logger . setContext ( this . constructor . name ) ; } async handle ( { sessionOidc , } ) { this . logger . debug ( 'getConsent service: ##### core-fcp-eidas-verify ' ) ; const { idpId , idpIdentity , idpAcr , spId , spAcr } = await sessionOidc . get ( ) ; const { entityId } = await this . serviceProvider . getById ( spId ) ; this . core . checkIfAcrIsValid ( idpAcr , spAcr ) ; const hashSp = this . cryptographyEidas . computeIdentityHash ( idpIdentity as IOidcIdentity ) ; const subSp = this . cryptographyEidas . computeSubV1 ( entityId , hashSp ) ; const subIdp = this . cryptographyEidas . computeSubV1 ( spId , hashSp ) ; const accountId = await this . core . computeInteraction ( { spId , entityId , subSp , hashSp , } , { 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 spIdentityCleaned = { ... idpIdentity , sub : subSp } ; const idpIdentityCleaned = { sub : idpIdentity . sub } ; await sessionOidc . set ( { amr : [ 'eidas' ] , idpIdentity : idpIdentityCleaned , spIdentity : spIdentityCleaned , accountId , } ) ; } }