fix(agent): authentifie le heartbeat via X-API-Key au lieu de Bearer
Le central (ApiKeyAuthenticationHandler) ne lit que le header X-API-Key. L'agent posait Authorization: Bearer <apiKey> sur le client 'Central' → tout heartbeat et le heartbeat final de StopAsync renvoyait 401. Corrige les deux chemins (identité existante + post-registration) et verrouille le comportement avec deux tests (nouvelle identité, identité réutilisée).
This commit is contained in:
1 parent
42a441a7ab
commit
4516761a3a
2 files changed
+80
-5
No files matched your search
@@ -77,8 +77,8 @@ public class AgentRegistrationService : BackgroundService
|
||||
_state.ApiKeyPrefix = existing.ApiKeyPrefix;
|
||||
_state.PublicIp = existing.PublicIp;
|
||||
|
||||
client.DefaultRequestHeaders.Remove("Authorization");
|
||||
client.DefaultRequestHeaders.Add("Authorization", $"Bearer {existing.ApiKey}");
|
||||
client.DefaultRequestHeaders.Remove("X-API-Key");
|
||||
client.DefaultRequestHeaders.Add("X-API-Key", existing.ApiKey);
|
||||
_client = client;
|
||||
|
||||
_logger.LogInformation(
|
||||
@@ -131,9 +131,9 @@ public class AgentRegistrationService : BackgroundService
|
||||
// Persist identity so subsequent restarts reuse it
|
||||
await _state.SaveAsync(stoppingToken);
|
||||
|
||||
// Set API Key header for subsequent requests
|
||||
client.DefaultRequestHeaders.Remove("Authorization");
|
||||
client.DefaultRequestHeaders.Add("Authorization", $"Bearer {registration.ApiKey}");
|
||||
// Set API Key header for subsequent requests (Central's ApiKey scheme reads X-API-Key)
|
||||
client.DefaultRequestHeaders.Remove("X-API-Key");
|
||||
client.DefaultRequestHeaders.Add("X-API-Key", registration.ApiKey);
|
||||
_client = client;
|
||||
|
||||
_logger.LogInformation(
|
||||
|
||||
Reference in new issue
Block a user