diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e09f7b..3072412 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,3 +41,9 @@ - IdNot: logs supplémentaires des claims du token (`sub`, `entity_idn`, `profile_idn`) et contrôle explicite de `profile_idn`. - Effet: en cas d’absence de `profile_idn`, retour 400 (ValidationError) au lieu d’un 502. + +## v1.0.6 + +- IdNot: fallback quand `profile_idn` absent dans le token. + - Récupération des rattachements via `sub` puis sélection d’un rattachement d’étude (office) si présent. + - Objectif: permettre le login même si le JWT IdNot ne fournit pas `profile_idn`. diff --git a/package.json b/package.json index c893564..042bf23 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "lecoffre-back-mini", - "version": "1.0.5", + "version": "1.0.6", "description": "Mini serveur avec une route /api/ping", "main": "dist/server.js", "scripts": { diff --git a/src/controllers/idnot.controller.ts b/src/controllers/idnot.controller.ts index dd60253..07db594 100644 --- a/src/controllers/idnot.controller.ts +++ b/src/controllers/idnot.controller.ts @@ -109,14 +109,22 @@ export class IdNotController { profile_idn: payload?.profile_idn }); - // Validate essential claim - if (!payload?.profile_idn || typeof payload.profile_idn !== 'string') { - throw new ValidationError('Missing profile_idn in IdNot token'); + // 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; } - // Get user data - const userData = await IdNotService.getUserData(payload.profile_idn); - // Log d'analyse (non sensible) pour diagnostiquer les cas de rattachement Logger.info('IdNot userData summary', { profile_idn: payload.profile_idn,