diff --git a/Neo4j.Driver/Neo4j.Driver.Tests.TestBackend/Protocol/DriverQuery/ExecuteQuery.cs b/Neo4j.Driver/Neo4j.Driver.Tests.TestBackend/Protocol/DriverQuery/ExecuteQuery.cs index 47e9b09c6..22e6b1236 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests.TestBackend/Protocol/DriverQuery/ExecuteQuery.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests.TestBackend/Protocol/DriverQuery/ExecuteQuery.cs @@ -80,13 +80,20 @@ private QueryConfig BuildConfig() Metadata = data.config.txMeta != null ? CypherToNativeObject.ConvertDictionaryToNative(data.config.txMeta) : new Dictionary() }; + var authToken = data.config.authorizationToken switch + { + null => null, + not null => data.config.authorizationToken.AsToken() + }; + return new QueryConfig( routingControl, data.config.database, data.config.impersonatedUser, bookmarkManager, enableBookmarkManager, - transactionConfig); + transactionConfig, + authToken); } public override string Respond() @@ -132,5 +139,6 @@ public class ExecuteQueryConfigDto public int? timeout { get; set; } [JsonConverter(typeof(QueryParameterConverter))] public Dictionary txMeta { get; set; } + public AuthorizationToken authorizationToken { get; set; } } } diff --git a/Neo4j.Driver/Neo4j.Driver.Tests.TestBackend/SupportedFeatures.cs b/Neo4j.Driver/Neo4j.Driver.Tests.TestBackend/SupportedFeatures.cs index bfed58f0e..7938d4928 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests.TestBackend/SupportedFeatures.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests.TestBackend/SupportedFeatures.cs @@ -31,6 +31,7 @@ static SupportedFeatures() "Feature:API:BookmarkManager", "Feature:API:ConnectionAcquisitionTimeout", "Feature:API:Driver.ExecuteQuery", + "Feature:API:Driver.ExecuteQuery:WithAuth", "Feature:API:Driver:GetServerInfo", "Feature:API:Driver.IsEncrypted", "Feature:API:Driver:NotificationsConfig", diff --git a/Neo4j.Driver/Neo4j.Driver/Internal/Driver.cs b/Neo4j.Driver/Neo4j.Driver/Internal/Driver.cs index af8140a9c..985f11a5a 100644 --- a/Neo4j.Driver/Neo4j.Driver/Internal/Driver.cs +++ b/Neo4j.Driver/Neo4j.Driver/Internal/Driver.cs @@ -277,6 +277,11 @@ private void ApplyConfig(QueryConfig config, SessionConfigBuilder sessionConfigB sessionConfigBuilder.WithBookmarkManager(config.BookmarkManager ?? _bookmarkManager); } + if(config.AuthToken != null) + { + sessionConfigBuilder.WithAuthToken(config.AuthToken); + } + sessionConfigBuilder.WithDefaultAccessMode( config.Routing switch { diff --git a/Neo4j.Driver/Neo4j.Driver/Public/ExecuteQuery/QueryConfig.cs b/Neo4j.Driver/Neo4j.Driver/Public/ExecuteQuery/QueryConfig.cs index 5c53687e0..be7fd460e 100644 --- a/Neo4j.Driver/Neo4j.Driver/Public/ExecuteQuery/QueryConfig.cs +++ b/Neo4j.Driver/Neo4j.Driver/Public/ExecuteQuery/QueryConfig.cs @@ -16,6 +16,7 @@ using System; using System.Threading; using System.Threading.Tasks; +using Neo4j.Driver.Internal.Auth; namespace Neo4j.Driver; @@ -36,13 +37,15 @@ public class QueryConfig /// remove any usage or modification of . /// /// Transaction configuration. + /// Auth token to use for the session executing the query. public QueryConfig( RoutingControl routing = RoutingControl.Writers, string database = null, string impersonatedUser = null, IBookmarkManager bookmarkManager = null, bool enableBookmarkManager = true, - TransactionConfig transactionConfig = null) + TransactionConfig transactionConfig = null, + IAuthToken authToken = null) { Routing = routing; Database = database; @@ -50,7 +53,9 @@ public QueryConfig( BookmarkManager = bookmarkManager; EnableBookmarkManager = enableBookmarkManager; TransactionConfig = transactionConfig ?? TransactionConfig.Default; + AuthToken = authToken; } + /// Config for the transaction that will be used to execute the query. public TransactionConfig TransactionConfig { get; } @@ -71,6 +76,11 @@ public QueryConfig( /// Enables or disables the use of an for causal chaining. public bool EnableBookmarkManager { get; } + + /// + /// Auth token to use for the session executing the query. + /// + public IAuthToken AuthToken { get; } } /// Configuration for running queries using the simplified API. @@ -93,6 +103,7 @@ public class QueryConfig : QueryConfig /// remove any usage or modification of . /// /// Transaction configuration. + /// Auth token to use for the session executing the query. /// public QueryConfig( Func> cursorProcessor, @@ -101,8 +112,16 @@ public QueryConfig( string impersonatedUser = null, IBookmarkManager bookmarkManager = null, bool enableBookmarkManager = true, - TransactionConfig transactionConfig = null) - : base(routing, database, impersonatedUser, bookmarkManager, enableBookmarkManager, transactionConfig) + TransactionConfig transactionConfig = null, + IAuthToken authToken = null) + : base( + routing, + database, + impersonatedUser, + bookmarkManager, + enableBookmarkManager, + transactionConfig, + authToken) { CursorProcessor = cursorProcessor ?? throw new ArgumentNullException(nameof(cursorProcessor)); }