diff --git a/src/domain/user.ts b/src/domain/user.ts index 5b01f65..0554720 100644 --- a/src/domain/user.ts +++ b/src/domain/user.ts @@ -24,7 +24,8 @@ export namespace User { POLE_EMPLOI_BRSA = 'POLE_EMPLOI_BRSA', POLE_EMPLOI_AIJ = 'POLE_EMPLOI_AIJ', FRANCE_TRAVAIL = 'FRANCE_TRAVAIL', - CONSEIL_DEPT = 'CONSEIL_DEPT' + CONSEIL_DEPT = 'CONSEIL_DEPT', + AVENIR_PRO = 'AVENIR_PRO' } } diff --git a/src/idp/avenirpro-conseiller/avenirpro-conseiller.controller.ts b/src/idp/avenirpro-conseiller/avenirpro-conseiller.controller.ts new file mode 100644 index 0000000..c1f2858 --- /dev/null +++ b/src/idp/avenirpro-conseiller/avenirpro-conseiller.controller.ts @@ -0,0 +1,64 @@ +import { + Controller, + Get, + HttpStatus, + Logger, + Param, + Redirect, + Req, + Res +} from '@nestjs/common' +import { Request, Response } from 'express' +import { isFailure } from '../../utils/result/result' +import { redirectFailure } from '../../utils/result/result.handler' +import { AvenirProConseillerService } from './avenirpro-conseiller.service' +import { User } from '../../domain/user' + +@Controller() +export class AvenirProConseillerController { + private readonly logger: Logger + + constructor( + private readonly avenirProConseillerService: AvenirProConseillerService + ) { + this.logger = new Logger('AvenirProConseiller') + } + + @Get('avenirpro-conseiller/connect/:interactionId') + @Redirect('blank', HttpStatus.TEMPORARY_REDIRECT) + async connect( + @Res({ passthrough: true }) response: Response, + @Param('interactionId') interactionId: string + ): Promise<{ url: string } | void> { + const authorizationUrlResult = + this.avenirProConseillerService.getAuthorizationUrl(interactionId) + if (isFailure(authorizationUrlResult)) + return redirectFailure( + response, + authorizationUrlResult, + User.Type.CONSEILLER, + User.Structure.AVENIR_PRO + ) + return { + url: authorizationUrlResult.data + } + } + + @Get('auth/realms/pass-emploi/broker/avenirpro-conseiller/endpoint') + async callback( + @Req() request: Request, + @Res({ passthrough: true }) response: Response + ): Promise { + const result = await this.avenirProConseillerService.callback( + request, + response + ) + if (isFailure(result)) + return redirectFailure( + response, + result, + User.Type.CONSEILLER, + User.Structure.AVENIR_PRO + ) + } +} diff --git a/src/idp/avenirpro-conseiller/avenirpro-conseiller.module.ts b/src/idp/avenirpro-conseiller/avenirpro-conseiller.module.ts new file mode 100644 index 0000000..8674b9d --- /dev/null +++ b/src/idp/avenirpro-conseiller/avenirpro-conseiller.module.ts @@ -0,0 +1,16 @@ +import { Module } from '@nestjs/common' + +import { ConfigModule } from '@nestjs/config' +import { APIModule } from '../../api/api.module' +import { OidcModule } from '../../oidc-provider/oidc.module' +import { TokenModule } from '../../token/token.module' +import { AvenirProConseillerController } from './avenirpro-conseiller.controller' +import { AvenirProConseillerService } from './avenirpro-conseiller.service' + +@Module({ + imports: [ConfigModule, OidcModule, TokenModule, APIModule], + providers: [AvenirProConseillerService], + exports: [], + controllers: [AvenirProConseillerController] +}) +export class AvenirProConseillerModule {} diff --git a/src/idp/avenirpro-conseiller/avenirpro-conseiller.service.ts b/src/idp/avenirpro-conseiller/avenirpro-conseiller.service.ts new file mode 100644 index 0000000..ea81988 --- /dev/null +++ b/src/idp/avenirpro-conseiller/avenirpro-conseiller.service.ts @@ -0,0 +1,27 @@ +import { Injectable } from '@nestjs/common' +import { ConfigService } from '@nestjs/config' +import { PassEmploiAPIClient } from '../../api/pass-emploi-api.client' +import { User } from '../../domain/user' +import { OidcService } from '../../oidc-provider/oidc.service' +import { TokenService } from '../../token/token.service' +import { IdpService } from '../service/idp.service' + +@Injectable() +export class AvenirProConseillerService extends IdpService { + constructor( + configService: ConfigService, + oidcService: OidcService, + tokenService: TokenService, + passemploiapi: PassEmploiAPIClient + ) { + super( + 'AvenirProConseillerService', + User.Type.CONSEILLER, + User.Structure.AVENIR_PRO, + configService, + oidcService, + tokenService, + passemploiapi + ) + } +} diff --git a/src/idp/service/helpers.ts b/src/idp/service/helpers.ts index 6bda10b..bbc51b1 100644 --- a/src/idp/service/helpers.ts +++ b/src/idp/service/helpers.ts @@ -49,6 +49,7 @@ function getIdpConfigIdentifier( case User.Structure.POLE_EMPLOI_BRSA: case User.Structure.POLE_EMPLOI_AIJ: case User.Structure.CONSEIL_DEPT: + case User.Structure.AVENIR_PRO: return IdpConfigIdentifier.FT_BENEFICIAIRE } case User.Type.CONSEILLER: @@ -61,6 +62,7 @@ function getIdpConfigIdentifier( case User.Structure.POLE_EMPLOI_CEJ: case User.Structure.POLE_EMPLOI_BRSA: case User.Structure.POLE_EMPLOI_AIJ: + case User.Structure.AVENIR_PRO: return IdpConfigIdentifier.FT_CONSEILLER } } diff --git a/src/oidc-provider/oidc.service.ts b/src/oidc-provider/oidc.service.ts index 0ed6dca..a597e4e 100644 --- a/src/oidc-provider/oidc.service.ts +++ b/src/oidc-provider/oidc.service.ts @@ -369,6 +369,8 @@ export class OidcService { return `/francetravail-conseiller/connect/${interaction.uid}?type=aij` case 'conseildepartemental-conseiller': return `/conseildepartemental-conseiller/connect/${interaction.uid}` + case 'avenirpro-conseiller': + return `/avenirpro-conseiller/connect/${interaction.uid}` default: return `/choice/${interaction.uid}` }