diff --git a/src/v1/index.js b/src/v1/index.js index d6ba4f2e2..bf02c05f3 100644 --- a/src/v1/index.js +++ b/src/v1/index.js @@ -31,8 +31,20 @@ export default { isInt, Neo4jError, auth: { - basic: (username, password) => { - return {scheme: "basic", principal: username, credentials: password}; + basic: (username, password, realm = undefined) => { + if (realm) { + return {scheme: "basic", principal: username, credentials: password, realm: realm}; + } else { + return {scheme: "basic", principal: username, credentials: password}; + } + }, + custom: (principal, credentials, realm, scheme, parameters = undefined ) => { + if (parameters) { + return {scheme: scheme, principal: principal, credentials: credentials, realm: realm, + parameters: parameters} + } else { + return {scheme: scheme, principal: principal, credentials: credentials, realm: realm} + } } }, types: { diff --git a/test/v1/driver.test.js b/test/v1/driver.test.js index 97fc7890a..ef695deb7 100644 --- a/test/v1/driver.test.js +++ b/test/v1/driver.test.js @@ -76,6 +76,45 @@ describe('driver', function() { driver.session(); }); + it('should be possible to pass a realm with basic auth tokens', function(done) { + // Given + var driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j", "native")); + + // Expect + driver.onCompleted = function (meta) { + done(); + }; + + // When + driver.session(); + }); + + it('should be possible to create custom auth tokens', function(done) { + // Given + var driver = neo4j.driver("bolt://localhost", neo4j.auth.custom("neo4j", "neo4j", "native", "basic")); + + // Expect + driver.onCompleted = function (meta) { + done(); + }; + + // When + driver.session(); + }); + + it('should be possible to create custom auth tokens with additional parameters', function(done) { + // Given + var driver = neo4j.driver("bolt://localhost", neo4j.auth.custom("neo4j", "neo4j", "native", "basic", {secret: 42})); + + // Expect + driver.onCompleted = function (meta) { + done(); + }; + + // When + driver.session(); + }); + var exposedTypes = [ 'Node', 'Path',