Auth: verify credentials with RETURN 1 before accepting connection

Replace BoltGraphClient.ConnectAsync() which swallowed AuthenticationException
with an explicit RETURN 1 query via raw driver session; fails fast on wrong password.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Gerwin Kuijntjes
2026-03-31 14:47:11 +02:00
parent ad1547db6d
commit bdbf738fe3

View File

@@ -51,18 +51,20 @@ namespace Xamarin.Neo4j.Services
config.WithTrustManager(_nativeTrustManager);
});
GraphClient = new BoltGraphClient(driver);
// Verify credentials with a real round-trip — this is the only reliable
// way to catch auth failures, since the driver connects lazily.
var verifySession = driver.AsyncSession();
try
{
await GraphClient.ConnectAsync();
var cursor = await verifySession.RunAsync("RETURN 1");
await cursor.ConsumeAsync();
}
catch
finally
{
// ConnectAsync runs Neo4j-specific metadata queries that non-Neo4j
// servers (e.g. Memgraph) don't support. The underlying driver is
// still connected and usable for running queries.
await verifySession.CloseAsync();
}
GraphClient = new BoltGraphClient(driver);
}
catch (ServiceUnavailableException e)