cURL command - Neo4j

你。 提交于 2020-01-04 02:53:27

问题


I have a problem in using of cURL as HTTP clinet with Neo4j. When I write this command : curl http://localhost:7474/db/data/ (or any URL, like http://localhost:7474/db/data/node/) Then I get this result in JSON format:

{   "errors" : [ {
    "message" : "No authorization token supplied.",
    "code" : "Neo.ClientError.Security.AuthorizationFailed"   } ],   "authentication" : "http://localhost:7474/authentication" }

回答1:


It seems that you have the authentication plugin enabled on your server. https://github.com/neo4j-contrib/authentication-extension

You should try something of the form

curl --user username:password http://localhost:7474/db/data/



回答2:


Disagreeing with @hydraruiz, I guess you're running a Neo4j 2.2.0-M0x version. This one has authentication enabled by default. You first need to acquire a token by providing your username and password.

curl -H "Content-Type: application/json" -d '{"username":"neo4j", "password":"mypassword"}' http://localhost:7474/authentication
{
  "username" : "neo4j",
  "password_change" : "http://localhost:7474/user/neo4j/password",
  "password_change_required" : false,
  "authorization_token" : "53eaa48a972439012868a8d5463e0c3d",
  "authorization_token_change" : "http://localhost:7474/user/neo4j/authorization_token"
}

Subsequent calls to the REST API use the token in the Authorization header. According to the docs the value of the http Authorization header is Basic realm="Neo4j" plus the base64 encoded token prefixed by a colon. We can use command line tools for this: echo -n ":tokenstring" | base64. For simplicity I emit a trivial cypher statement match (n) return count(n):

curl -H "Authorization: Basic realm=\"Neo4j\" `echo -n ":53eaa48a972439012868a8d5463e0c3d" | base64`" \
    -H "Content-Type: application/json" \
    -d '{"statements":[{"statement":"match (n) return count(n)"}]}' \
    http://localhost:7474/db/data/transaction/commit

returns:

{"results":[{"columns":["count(n)"],"data":[{"row":[0]}]}],"errors":[]}

That means the authentication worked.




回答3:


You can also disable authorization. In conf/neo4j-server.properties file:

# Require (or disable the requirement of) auth to access Neo4j
dbms.security.auth_enabled=false


来源:https://stackoverflow.com/questions/27822440/curl-command-neo4j

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!