ci: docker_tag=ext - Fix: use sub instead of profile_idn and correct URL base v1.0.9
All checks were successful
build-and-push-ext / build_push (push) Successful in 23s

This commit is contained in:
dev4 2025-09-19 12:20:52 +00:00
parent 0c74cccc04
commit c4d8676b55
3 changed files with 34 additions and 39 deletions

View File

@ -1,6 +1,6 @@
{
"name": "lecoffre-back-mini",
"version": "1.0.8",
"version": "1.0.9",
"description": "Mini serveur avec une route /api/ping",
"main": "dist/server.js",
"scripts": {

View File

@ -109,21 +109,16 @@ export class IdNotController {
profile_idn: payload?.profile_idn
});
// Try standard flow with profile_idn; otherwise fallback via rattachements using sub
let userData: any;
if (payload?.profile_idn && typeof payload.profile_idn === 'string') {
userData = await IdNotService.getUserData(payload.profile_idn);
} else {
Logger.info('IdNot fallback via rattachements using sub');
const rattachementsJson = await IdNotService.getUserRattachements(payload.sub);
const results: any[] = Array.isArray(rattachementsJson?.result) ? rattachementsJson.result : [];
// pick first office rattachement with a defined entite
const candidate = results.find((r: any) => r?.entite?.typeEntite?.name === 'office') || results[0];
if (!candidate) {
throw new ForbiddenError('User not attached to an office');
}
userData = candidate;
// Always use sub for rattachements API as it's more reliable than profile_idn
Logger.info('IdNot using rattachements API with sub', { sub: payload.sub });
const rattachementsJson = await IdNotService.getUserRattachements(payload.sub);
const results: any[] = Array.isArray(rattachementsJson?.result) ? rattachementsJson.result : [];
// pick first office rattachement with a defined entite
const candidate = results.find((r: any) => r?.entite?.typeEntite?.name === 'office') || results[0];
if (!candidate) {
throw new ForbiddenError('User not attached to an office');
}
const userData = candidate;
// Log d'analyse (non sensible) pour diagnostiquer les cas de rattachement
Logger.info('IdNot userData summary', {

View File

@ -159,20 +159,20 @@ export class IdNotService {
}
static async getUserData(profileIdn: string) {
const { IDNOT_API_KEY, IDNOT_API_BASE_URL } = process.env;
const { IDNOT_API_KEY, IDNOT_ANNUARY_BASE_URL } = process.env;
if (!IDNOT_API_KEY || !IDNOT_API_BASE_URL) {
throw new Error('Missing IDnot API key or base URL');
if (!IDNOT_API_KEY || !IDNOT_ANNUARY_BASE_URL) {
throw new Error('Missing IDnot API key or annuary base URL');
}
// Essayer plusieurs variantes d'endpoints selon la documentation API Annuaire V2
const endpoints = [
// Format correct selon doc: /api/pp/v2/personnes/{id}/rattachements
`${IDNOT_API_BASE_URL}/api/pp/v2/personnes/${profileIdn}/rattachements`,
`${IDNOT_ANNUARY_BASE_URL}/api/pp/v2/personnes/${profileIdn}/rattachements`,
// Variante sans /annuaire dans l'URL de base
`${IDNOT_API_BASE_URL.replace('/annuaire', '')}/api/pp/v2/personnes/${profileIdn}/rattachements`,
`${IDNOT_ANNUARY_BASE_URL.replace('/annuaire', '')}/api/pp/v2/personnes/${profileIdn}/rattachements`,
// Ancien format (fallback)
`${IDNOT_API_BASE_URL}/api/pp/v2/rattachements/${profileIdn}`
`${IDNOT_ANNUARY_BASE_URL}/api/pp/v2/rattachements/${profileIdn}`
];
const searchParams = new URLSearchParams({