Skip to content

Commit 963f3c5

Browse files
authored
Merge pull request #134 from pontusmelke/1.1-custom-auth-token
Added support for custom auth tokens
2 parents 9fe1294 + 6f0e150 commit 963f3c5

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-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, 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: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,45 @@ describe('driver', function() {
7676
driver.session();
7777
});
7878

79+
it('should be possible to pass a realm with basic auth tokens', function(done) {
80+
// Given
81+
var driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j", "native"));
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', function(done) {
93+
// Given
94+
var driver = neo4j.driver("bolt://localhost", neo4j.auth.custom("neo4j", "neo4j", "native", "basic"));
95+
96+
// Expect
97+
driver.onCompleted = function (meta) {
98+
done();
99+
};
100+
101+
// When
102+
driver.session();
103+
});
104+
105+
it('should be possible to create custom auth tokens with additional parameters', function(done) {
106+
// Given
107+
var driver = neo4j.driver("bolt://localhost", neo4j.auth.custom("neo4j", "neo4j", "native", "basic", {secret: 42}));
108+
109+
// Expect
110+
driver.onCompleted = function (meta) {
111+
done();
112+
};
113+
114+
// When
115+
driver.session();
116+
});
117+
79118
var exposedTypes = [
80119
'Node',
81120
'Path',

0 commit comments

Comments
 (0)