Knowledge Base

A lightweight approach to testing the Neo4j REST API with Authentication

This article will show examples of how to test the Neo4j REST API for authentication via:

The Neo4j REST API describes each of the commands you can submit to the Neo4j server. The example below describes how to authenticate with the Neo4j server when authentication is enabled. To enable authentication, use parameter dbms.security.auth_enabled=true defined in the conf/neo4j-server.properties configuration file.

Google Chrome Advanced REST Client

After installing and launching the Google Chrome Advanced REST Client application, your browser should appear as follows:

image

For the field labeled URL, this should be replaced with the URL to the Neo4j server, for example, http://localhost:7474/user/neo4j.

For your instance, localhost may be an actual IP address, for example, http://192.168.1.106:7474/user/neo4j.

Per the documentation, /user/neo4j is the URI to which authentication occurs. Additionally, the HTTP method should be defined as GET.

Upon clicking the Form tab, you can define the payload for the REST request. Define the Name field as Authorization. Click the value field and you should see a CONSTRUCT pop-up, for example:

image

Clicking CONSTRUCT will then allow you to define the payload for this request. Specifically, we need to define the username/password, for example, neo4j/mypassword.

image

Clicking OK should then return you back to a display similar to:

image

Finally, clicking SEND will submit the request. You should see output similar to the following:

image

The output above including Status: 200 OK indicates the request was properly processed. A status of 4xx would be indicative of a failure. Further, the Response field details the JSON output provided by the REST API for the given command.

Linux curl command

On a single line (command line) issue the following command at the linux prompt:

$ curl -H accept:application/json -H content-type:application/json -H Authorization:"Basic bmVvNGo6cGFzc3dvcmQ=" http://192.168.1.106:7474/user/neo4j

Expected output:

{
 "password_change_required" : false,
 "password_change" : "http://192.168.1.106:7474/user/neo4j/password",
 "username" : "neo4j"
}

In the above example you may need to change the value of the IP address referenced in the http specification (i.e. http://192.168.1.106:7474/user/neo4j). Additionally, you will need to change the base64 encrypted value of the password (i.e. Basic bmVvNGo6cGFzc3dvcmQ=). To encrypt a string to base64 you can run:

$ echo -n 'neo4j:mypassword' | base64

Replace mypassword above with the actual password.