Skip to content

Kerberos auth support #236

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 22 additions & 13 deletions src/v1/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,37 +17,46 @@
* limitations under the License.
*/

import {int, isInt, inSafeRange, toNumber, toString} from './integer';
import {Node, Relationship, UnboundRelationship, PathSegment, Path} from './graph-types'
import {Neo4jError, SERVICE_UNAVAILABLE, SESSION_EXPIRED, PROTOCOL_ERROR} from './error';
import {inSafeRange, int, isInt, toNumber, toString} from './integer';
import {Node, Path, PathSegment, Relationship, UnboundRelationship} from './graph-types';
import {Neo4jError, PROTOCOL_ERROR, SERVICE_UNAVAILABLE, SESSION_EXPIRED} from './error';
import Result from './result';
import ResultSummary from './result-summary';
import Record from './record';
import {Driver, READ, WRITE} from './driver';
import RoutingDriver from './routing-driver';
import VERSION from '../version';
import {parseScheme, parseUrl} from "./internal/connector";
import {assertString} from "./internal/util";
import {parseScheme, parseUrl} from './internal/connector';
import {assertString} from './internal/util';


const auth ={
const auth = {
basic: (username, password, realm = undefined) => {
if (realm) {
return {scheme: "basic", principal: username, credentials: password, realm: realm};
return {scheme: 'basic', principal: username, credentials: password, realm: realm};
} else {
return {scheme: "basic", principal: username, credentials: password};
return {scheme: 'basic', principal: username, credentials: password};
}
},
custom: (principal, credentials, realm, scheme, parameters = undefined ) => {
kerberos: (base64EncodedTicket) => {
return {
scheme: 'kerberos',
principal: '', // This empty string is required for backwards compatibility.
credentials: base64EncodedTicket
};
},
custom: (principal, credentials, realm, scheme, parameters = undefined) => {
if (parameters) {
return {scheme: scheme, principal: principal, credentials: credentials, realm: realm,
parameters: parameters}
return {
scheme: scheme, principal: principal, credentials: credentials, realm: realm,
parameters: parameters
};
} else {
return {scheme: scheme, principal: principal, credentials: credentials, realm: realm}
return {scheme: scheme, principal: principal, credentials: credentials, realm: realm};
}
}
};
let USER_AGENT = "neo4j-javascript/" + VERSION;
const USER_AGENT = "neo4j-javascript/" + VERSION;

/**
* Construct a new Neo4j Driver. This is your main entry point for this
Expand Down
73 changes: 73 additions & 0 deletions test/v1/auth.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/**
* Copyright (c) 2002-2017 "Neo Technology,","
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This file is part of Neo4j.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import neo4j from '../../src/v1';

describe('auth', () => {

it('should use correct username and password in basic auth', () => {
const token = neo4j.auth.basic('cat', 'dog');
expect(token).toEqual({
scheme: 'basic',
principal: 'cat',
credentials: 'dog'
});
});

it('should support realm in basic auth', () => {
const token = neo4j.auth.basic('cat', 'dog', 'apartment');
expect(token).toEqual({
scheme: 'basic',
principal: 'cat',
credentials: 'dog',
realm: 'apartment'
});
});

it('should use correct ticket in kerberos', () => {
const token = neo4j.auth.kerberos('my-ticket');
expect(token).toEqual({
scheme: 'kerberos',
principal: '',
credentials: 'my-ticket'
});
});

it('should construct correct custom auth', () => {
const token = neo4j.auth.custom('cat', 'dog', 'apartment', 'pets');
expect(token).toEqual({
scheme: 'pets',
principal: 'cat',
credentials: 'dog',
realm: 'apartment'
});
});

it('should support parameters in custom auth', () => {
const token = neo4j.auth.custom('cat', 'dog', 'apartment', 'pets', {key1: 'value1', key2: 42});
expect(token).toEqual({
scheme: 'pets',
principal: 'cat',
credentials: 'dog',
realm: 'apartment',
parameters: {key1: 'value1', key2: 42}
});
});

});