import { Injectable } from '@nestjs/common' ; import { ModuleRef } from '@nestjs/core' ; import { CoreMissingAuthenticationEmailException } from '@fc/core' ; import { FeatureHandler , IFeatureHandler } from '@fc/feature-handler' ; import { IdentityProviderAdapterMongoService } from '@fc/identity-provider-adapter-mongo' ; import { LoggerLevelNames , LoggerService } from '@fc/logger' ; import { OidcSession } from '@fc/oidc' ; import { OidcClientSession } from '@fc/oidc-client' ; import { ScopesService } from '@fc/scopes' ; import { ServiceProviderAdapterMongoService } from '@fc/service-provider-adapter-mongo' ; import { ISessionService } from '@fc/session' ; import { ProcessCore } from '../enums' ; import { CoreFcpSendEmailHandler } from '../handlers' ; import { IVerifyFeatureHandler } from '../interfaces' ; @ Injectable ( ) export class CoreFcpService { constructor ( private readonly logger , private readonly identityProvider , public readonly moduleRef , private readonly scopes , private readonly serviceProvider ) { this . logger . setContext ( this . constructor . name ) ; } param { ISessionService < OidcClientSession > } sessionOidc returns { Promise < void > } async verify ( sessionOidc , trackingContext ) { this . logger . debug ( 'CoreFcpService.verify' ) ; const { idpId } = await sessionOidc . get ( ) ; const verifyHandler = await this . getFeature < IVerifyFeatureHandler > ( idpId , ProcessCore . CORE_VERIFY ) ; this . logger . trace ( { idpId , trackingContext } ) ; return await verifyHandler . handle ( { sessionOidc , trackingContext } ) ; } async getFeature < T extends IFeatureHandler > ( idpId , process ) { this . logger . debug ( `getFeature ${ process } for provider: ${ idpId }` ) ; const idp = await this . identityProvider . getById ( idpId ) ; const idClass = idp . featureHandlers [ process ] ; this . logger . trace ( { idp , idClass } ) ; return FeatureHandler . get < T > ( idClass , this ) ; } param { ISessionService < OidcClientSession > } sessionOidc returns { Promise < void > } async sendAuthenticationMail ( session ) { this . logger . debug ( 'CoreFcpService.sendAuthenticationMail()' ) ; const { idpId } = session ; const idp = await this . identityProvider . getById ( idpId ) ; let handler ; try { const { authenticationEmail } = idp . featureHandlers ; handler = await FeatureHandler . get < CoreFcpSendEmailHandler > ( authenticationEmail , this ) ; } catch ( error ) { this . logger . trace ( { error } , LoggerLevelNames . WARN ) ; throw new CoreMissingAuthenticationEmailException ( ) ; } this . logger . trace ( { idpId , idp } ) ; await handler . handle ( session ) ; } async isConsentRequired ( spId ) { const { type , identityConsent } = await this . serviceProvider . getById ( spId ) ; const consentRequired = this . serviceProvider . consentRequired ( type , identityConsent ) ; this . logger . trace ( { consentRequired } ) ; return consentRequired ; } todo async getClaimsLabelsForInteraction ( interaction ) { const scopes = this . getScopesForInteraction ( interaction ) ; const claims = await this . scopes . mapScopesToLabel ( scopes ) ; this . logger . trace ( { interaction , claims } ) ; return claims ; } todo async getClaimsForInteraction ( interaction ) { const scopes = this . getScopesForInteraction ( interaction ) ; const claims = await this . scopes . getClaimsFromScopes ( scopes ) ; this . logger . trace ( { interaction , claims } ) ; return claims ; } todo getScopesForInteraction ( interaction ) { const { params : { scope } , } = interaction ; const scopes = scope . split ( ' ' ) ; this . logger . trace ( { interaction , scopes } ) ; return scopes ; } }