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
All checks were successful
build-and-push-ext / build_push (push) Successful in 23s
This commit is contained in:
parent
0c74cccc04
commit
c4d8676b55
@ -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": {
|
||||||
|
@ -109,21 +109,16 @@ 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') {
|
const rattachementsJson = await IdNotService.getUserRattachements(payload.sub);
|
||||||
userData = await IdNotService.getUserData(payload.profile_idn);
|
const results: any[] = Array.isArray(rattachementsJson?.result) ? rattachementsJson.result : [];
|
||||||
} else {
|
// pick first office rattachement with a defined entite
|
||||||
Logger.info('IdNot fallback via rattachements using sub');
|
const candidate = results.find((r: any) => r?.entite?.typeEntite?.name === 'office') || results[0];
|
||||||
const rattachementsJson = await IdNotService.getUserRattachements(payload.sub);
|
if (!candidate) {
|
||||||
const results: any[] = Array.isArray(rattachementsJson?.result) ? rattachementsJson.result : [];
|
throw new ForbiddenError('User not attached to an office');
|
||||||
// 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;
|
|
||||||
}
|
}
|
||||||
|
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', {
|
||||||
|
@ -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({
|
||||||
|
Loading…
x
Reference in New Issue
Block a user