modif
This commit is contained in:
parent
63cec006bc
commit
8f1bd9e962
1 changed files with 8 additions and 34 deletions
|
|
@ -61,48 +61,22 @@ const getUserProfile = async (req, res) => {
|
||||||
return res.status(401).json({ error: "Aucun accessToken en session." });
|
return res.status(401).json({ error: "Aucun accessToken en session." });
|
||||||
}
|
}
|
||||||
|
|
||||||
const url =
|
const { data } = await axios.get("https://api.linkedin.com/v2/userinfo", {
|
||||||
"https://api.linkedin.com/v2/me" +
|
|
||||||
"?projection=(id,localizedFirstName,localizedLastName,profilePicture(displayImage~:playableStreams))";
|
|
||||||
|
|
||||||
const { data } = await axios.get(url, {
|
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${token}`,
|
Authorization: `Bearer ${token}`,
|
||||||
"X-Restli-Protocol-Version": "2.0.0", // souvent requis par les endpoints v2
|
|
||||||
Accept: "application/json",
|
Accept: "application/json",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
return res.json(data);
|
return res.json(data);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const status = error.response?.status ?? 500;
|
console.error(
|
||||||
const payload = error.response?.data ?? { message: error.message };
|
"LinkedIn OIDC error:",
|
||||||
|
error.response?.data || error.message
|
||||||
// Log côté serveur pour diagnostiquer vite
|
);
|
||||||
console.error("LinkedIn API error:", status, payload);
|
return res
|
||||||
|
.status(500)
|
||||||
if (status === 401) {
|
.json({ error: "Erreur lors de la récupération du profil." });
|
||||||
return res.status(401).json({
|
|
||||||
error: "Token invalide ou expiré.",
|
|
||||||
hint: "Renouvelle le token OAuth (nouvelle auth) et réessaie.",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
if (status === 403) {
|
|
||||||
return res.status(403).json({
|
|
||||||
error: "Permissions insuffisantes.",
|
|
||||||
hint: "Ajoute le scope 'r_liteprofile' (et 'r_emailaddress' si besoin) et assure que ton app y est autorisée.",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
if (status === 429) {
|
|
||||||
return res.status(429).json({
|
|
||||||
error: "Trop de requêtes (rate limit).",
|
|
||||||
hint: "Ajoute du retry/backoff.",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return res.status(500).json({
|
|
||||||
error: "Erreur lors de la récupération du profil.",
|
|
||||||
details: payload,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue