L3.2 : fait remonter statut et corps de la réponse STS dans les erreurs d'auth
authenticate() ré-enveloppait l'erreur axios en "Authentication failed:
Request failed with status code 400" et jetait le corps de la réponse du
STS, qui contenait le diagnostic exact ({"error":"invalid_request",
"error_description":"Tenant not found"} sur le profil AD).
Réutilise _enrichHttpError (L1.1) dans authenticate() et
refreshOAuthToken(), avec payload volontairement omis : il contient les
credentials (password grant) ou le refresh_token ; l'helper n'inclut
jamais les headers. Le chemin "token trop vieux -> password grant" de
refreshOAuthToken() sort du try : un échec d'authenticate() y était
rattrapé pour... rappeler authenticate() à l'identique ; il propage
désormais son erreur enrichie directement.
Mesure (via le protocole) : switch_wms_profile("AD") puis
count_wms_entities("Products") ->
Count failed for Products: Authentication failed: POST
https://10.255.255.2/EasySTS/OAuth/Token failed (HTTP 400): Request
failed with status code 400
Response body: {"error":"invalid_request","error_description":"Tenant
not found"}
Aucun credential ni header dans la réponse (vérifié : pas de
password/Basic/Bearer/payload).
ROADMAP : L3.2 retirée, point ouvert "profil AD" mis à jour.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
+17
-10
@@ -77,8 +77,12 @@ class APIService {
|
||||
console.error(`[API] Authentication successful. Token expires in ~${this.tokenMaxAge}s`);
|
||||
return this.token;
|
||||
} catch (error) {
|
||||
console.error('[API] Authentication failed:', error.message);
|
||||
throw new Error(`Authentication failed: ${error.message}`);
|
||||
// Statut + corps de la réponse STS dans le message : c'est là que vit le
|
||||
// diagnostic ("Tenant not found", ...). Payload volontairement omis — il
|
||||
// contient les credentials ; _enrichHttpError n'inclut jamais les headers.
|
||||
const enriched = this._enrichHttpError(error, 'POST', profile.tokenUrl, undefined);
|
||||
console.error('[API] Authentication failed:', enriched.message);
|
||||
throw new Error(`Authentication failed: ${enriched.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,17 +92,17 @@ class APIService {
|
||||
async refreshOAuthToken() {
|
||||
const tokenAge = this.getTokenAge();
|
||||
|
||||
try {
|
||||
// If token is too old (>= maxAge), use password grant
|
||||
if (tokenAge >= this.tokenMaxAge) {
|
||||
console.error('[API] Token too old, re-authenticating with password...');
|
||||
return await this.authenticate();
|
||||
}
|
||||
// If token is too old (>= maxAge), use password grant
|
||||
if (tokenAge >= this.tokenMaxAge) {
|
||||
console.error('[API] Token too old, re-authenticating with password...');
|
||||
return await this.authenticate();
|
||||
}
|
||||
|
||||
const profile = profileManager.getCurrent();
|
||||
try {
|
||||
// Otherwise use refresh_token grant
|
||||
console.error('[API] Refreshing token with refresh_token grant...');
|
||||
|
||||
const profile = profileManager.getCurrent();
|
||||
const response = await this.httpClient.post(
|
||||
profile.tokenUrl,
|
||||
new URLSearchParams({
|
||||
@@ -120,7 +124,10 @@ class APIService {
|
||||
console.error('[API] Token refreshed successfully');
|
||||
return this.token;
|
||||
} catch (error) {
|
||||
console.error('[API] Token refresh failed, re-authenticating:', error.message);
|
||||
// Même enrichissement que authenticate() : statut + corps STS, sans le
|
||||
// payload (refresh_token) ni les headers.
|
||||
const enriched = this._enrichHttpError(error, 'POST', profile.tokenUrl, undefined);
|
||||
console.error('[API] Token refresh failed, re-authenticating:', enriched.message);
|
||||
return await this.authenticate();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user