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 <[email protected]>
This commit is contained in:
Gerwin Kuijntjes
2026-03-31 14:47:11 +02:00
co-authored by Claude Sonnet 4.6
parent ad1547db6d
commit bdbf738fe3
@@ -51,18 +51,20 @@ namespace Xamarin.Neo4j.Services
config.WithTrustManager(_nativeTrustManager); 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 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 await verifySession.CloseAsync();
// servers (e.g. Memgraph) don't support. The underlying driver is
// still connected and usable for running queries.
} }
GraphClient = new BoltGraphClient(driver);
} }
catch (ServiceUnavailableException e) catch (ServiceUnavailableException e)