Skip to content

Commit dc91725

Browse files
committed
Added support for custom auth tokens
1 parent 647dfd0 commit dc91725

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

src/v1/index.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,20 @@ export default {
3131
isInt,
3232
Neo4jError,
3333
auth: {
34-
basic: (username, password) => {
35-
return {scheme: "basic", principal: username, credentials: password};
34+
basic: (username, password, realm = undefined) => {
35+
if (realm) {
36+
return {scheme: "basic", principal: username, credentials: password, realm: realm};
37+
} else {
38+
return {scheme: "basic", principal: username, credentials: password};
39+
}
40+
},
41+
custom: (principal, credentials, realm, scheme = "basic", parameters = undefined ) => {
42+
if (parameters) {
43+
return {scheme: scheme, principal: principal, credentials: credentials, realm: realm,
44+
parameters: parameters}
45+
} else {
46+
return {scheme: scheme, principal: principal, credentials: credentials, realm: realm}
47+
}
3648
}
3749
},
3850
types: {

test/v1/driver.test.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,32 @@ describe('driver', function() {
7676
driver.session();
7777
});
7878

79+
it('should be possible to create custom auth tokens', function(done) {
80+
// Given
81+
var driver = neo4j.driver("bolt://localhost", neo4j.auth.custom("neo4j", "neo4j", "native", "basic"));
82+
83+
// Expect
84+
driver.onCompleted = function (meta) {
85+
done();
86+
};
87+
88+
// When
89+
driver.session();
90+
});
91+
92+
it('should be possible to create custom auth tokens with additional parameters', function(done) {
93+
// Given
94+
var driver = neo4j.driver("bolt://localhost", neo4j.auth.custom("neo4j", "neo4j", "native", "basic", {secret: 42}));
95+
96+
// Expect
97+
driver.onCompleted = function (meta) {
98+
done();
99+
};
100+
101+
// When
102+
driver.session();
103+
});
104+
79105
var exposedTypes = [
80106
'Node',
81107
'Path',

0 commit comments

Comments
 (0)