From bdbf738fe32f11f9252cad1b41c4eb8ce9cbdacd Mon Sep 17 00:00:00 2001 From: Gerwin Kuijntjes Date: Tue, 31 Mar 2026 14:47:11 +0200 Subject: [PATCH] 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 --- .../Xamarin.Neo4j/Services/Neo4jService.cs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/Xamarin.Neo4j/Xamarin.Neo4j/Xamarin.Neo4j/Services/Neo4jService.cs b/Xamarin.Neo4j/Xamarin.Neo4j/Xamarin.Neo4j/Services/Neo4jService.cs index cd7d35a..b7c20d6 100644 --- a/Xamarin.Neo4j/Xamarin.Neo4j/Xamarin.Neo4j/Services/Neo4jService.cs +++ b/Xamarin.Neo4j/Xamarin.Neo4j/Xamarin.Neo4j/Services/Neo4jService.cs @@ -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)