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." });
|
||||
}
|
||||
|
||||
const url =
|
||||
"https://api.linkedin.com/v2/me" +
|
||||
"?projection=(id,localizedFirstName,localizedLastName,profilePicture(displayImage~:playableStreams))";
|
||||
|
||||
const { data } = await axios.get(url, {
|
||||
const { data } = await axios.get("https://api.linkedin.com/v2/userinfo", {
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
"X-Restli-Protocol-Version": "2.0.0", // souvent requis par les endpoints v2
|
||||
Accept: "application/json",
|
||||
},
|
||||
});
|
||||
|
||||
return res.json(data);
|
||||
} catch (error) {
|
||||
const status = error.response?.status ?? 500;
|
||||
const payload = error.response?.data ?? { message: error.message };
|
||||
|
||||
// Log côté serveur pour diagnostiquer vite
|
||||
console.error("LinkedIn API error:", status, payload);
|
||||
|
||||
if (status === 401) {
|
||||
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,
|
||||
});
|
||||
console.error(
|
||||
"LinkedIn OIDC error:",
|
||||
error.response?.data || error.message
|
||||
);
|
||||
return res
|
||||
.status(500)
|
||||
.json({ error: "Erreur lors de la récupération du profil." });
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue