Skip to content

Commit

Permalink
feat: ouvrir avenir pro
Browse files Browse the repository at this point in the history
  • Loading branch information
Mzem committed Dec 3, 2024
1 parent 07a6f4a commit d903fad
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/domain/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
}

Expand Down
64 changes: 64 additions & 0 deletions src/idp/avenirpro-conseiller/avenirpro-conseiller.controller.ts
Original file line number Diff line number Diff line change
@@ -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<void> {
const result = await this.avenirProConseillerService.callback(
request,
response
)
if (isFailure(result))
return redirectFailure(
response,
result,
User.Type.CONSEILLER,
User.Structure.AVENIR_PRO
)
}
}
16 changes: 16 additions & 0 deletions src/idp/avenirpro-conseiller/avenirpro-conseiller.module.ts
Original file line number Diff line number Diff line change
@@ -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 {}
27 changes: 27 additions & 0 deletions src/idp/avenirpro-conseiller/avenirpro-conseiller.service.ts
Original file line number Diff line number Diff line change
@@ -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
)
}
}
2 changes: 2 additions & 0 deletions src/idp/service/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/oidc-provider/oidc.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
}
Expand Down

0 comments on commit d903fad

Please sign in to comment.