Skip to content Skip to sidebar Skip to footer

How To Use Transactional Cypher Http Endpoint And New Rest Api Authentication And Authorization In Neo4j 2.2.x With Jquery

I'm looking for a code example creating a REST POST request with JQuery on Neo4j 2.2.x Transactional Cypher HTTP endpoint with new REST API Authentication and Authorization paramet

Solution 1:

For authentication you need to supply an additional HTTP header to your request:

Authorization: Basic realm="Neo4j" <base64>

where <base64> is the base64 encoded string of username:password.

Not being a jquery ninja, but I guess the most simple way is to set the authorization header using ajax defaults:

$.ajaxSetup({
   headers: { "Authorization": 'Basic realm="Neo4j' <base64>'}
});

When this default has been applied your $.post above should work.

Solution 2:

The issue has been fixed in 2.2.0-RC01 and I can use transactional Cypher HTTP endpoint with authentication using the following example code:

$.ajaxSetup({
    headers: {
        // Add authorization header in all ajax requests// bmVvNGo6cGFzc3dvcmQ= is "password" base64 encoded"Authorization": "Basic bmVvNGo6cGFzc3dvcmQ=" 
    }
});

$.ajax({
    type: "POST",
    url: "http://localhost:7474/db/data/transaction/commit ",
    dataType: "json",
    contentType: "application/json;charset=UTF-8",
    data: JSON.stringify({"statements": [{"statement": "MATCH (n) RETURN n LIMIT 10"}]}),
    success: function (data, textStatus, jqXHR) {
        // use result data...
    },
    error: function (jqXHR, textStatus, errorThrown) {
        // handle errors
    }
});

Solution 3:

Authorization means that the browser will send a preflight OPTIONS request which does not embed authorization headers.

This is most known as CORS.

Currently the Neo4j server do not reply to the OPTIONS request with the appropriate Access-Control-Allow-Headers. This feature has been implemented in the source code and will be shipped with the GA release which I hope will come out this week.

Post a Comment for "How To Use Transactional Cypher Http Endpoint And New Rest Api Authentication And Authorization In Neo4j 2.2.x With Jquery"