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", "name": "lecoffre-back-mini",
"version": "1.0.8", "version": "1.0.9",
"description": "Mini serveur avec une route /api/ping", "description": "Mini serveur avec une route /api/ping",
"main": "dist/server.js", "main": "dist/server.js",
"scripts": { "scripts": {

View File

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

View File

@ -159,20 +159,20 @@ export class IdNotService {
} }
static async getUserData(profileIdn: string) { 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) { if (!IDNOT_API_KEY || !IDNOT_ANNUARY_BASE_URL) {
throw new Error('Missing IDnot API key or base URL'); throw new Error('Missing IDnot API key or annuary base URL');
} }
// Essayer plusieurs variantes d'endpoints selon la documentation API Annuaire V2 // Essayer plusieurs variantes d'endpoints selon la documentation API Annuaire V2
const endpoints = [ const endpoints = [
// Format correct selon doc: /api/pp/v2/personnes/{id}/rattachements // 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 // 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) // 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({ const searchParams = new URLSearchParams({