|
6 | 6 | Authentication and authorization are enabled by default in Neo4j (refer to link:{neo4j-docs-base-uri}/operations-manual/{page-version}/authentication-authorization#auth[Operations Manual -> Authentication and authorization]).
|
7 | 7 | With authentication and authorization enabled, requests to the HTTP API must be authorized using the username and password of a valid user.
|
8 | 8 |
|
| 9 | +[NOTE] |
| 10 | +==== |
| 11 | +If authentication and authorization have been disabled, HTTP API requests can be sent without an `Authorization` header. |
| 12 | +==== |
| 13 | + |
| 14 | + |
| 15 | +[[http-api-successful-authorization]] |
| 16 | +== Authorizing a Request |
| 17 | + |
| 18 | +Each HTTP request requires a `Authorization` header. The header value encoding follows standard format for `Basic` authentication (RFC 7617) and therefore must be in the following format: |
| 19 | + |
| 20 | +---- |
| 21 | +Authorization: Basic <base64 encoding of username:credential> |
| 22 | +---- |
| 23 | + |
| 24 | +For example, if we wish to authenticate as user `neo4j` with credential `verysecret` we combine them with `:` so that we have: |
| 25 | +---- |
| 26 | +neo4j:verysecret |
| 27 | +---- |
| 28 | +Then we base64 encode that value to: |
| 29 | +---- |
| 30 | +bmVvNGo6dmVyeXNlY3JldA== |
| 31 | +---- |
| 32 | + |
| 33 | +Finally we append `Basic` to the beginning to have the following as the final header: |
| 34 | + |
| 35 | + |
| 36 | +---- |
| 37 | +Authorization: Basic bmVvNGo6dmVyeXNlY3JldA== |
| 38 | +---- |
| 39 | + |
| 40 | + |
| 41 | +_Complete Request Example_ |
| 42 | + |
| 43 | +* *+POST+* +http://localhost:7474/db/neo4j/tx/commit+ |
| 44 | +* *+Accept:+* +application/json;charset=UTF-8+ |
| 45 | +* *+Content-Type:+* +application/json+ |
| 46 | +* *+Authorization:+* +Basic bmVvNGo6dmVyeXNlY3JldA==+ |
| 47 | + |
| 48 | +[source, JSON, role="nocopy"] |
| 49 | +---- |
| 50 | +{ |
| 51 | + "statements": [ |
| 52 | + { |
| 53 | + "statement": "RETURN 1" |
| 54 | + } |
| 55 | + ] |
| 56 | +} |
| 57 | +---- |
| 58 | + |
| 59 | +_Example response_ |
| 60 | + |
| 61 | +* *+200:+* +OK+ |
| 62 | +* *+Content-Type:+* +application/json;charset=utf-8+ |
| 63 | + |
| 64 | +[source, JSON, role="nocopy"] |
| 65 | +---- |
| 66 | +{ |
| 67 | + "results": [ { |
| 68 | + "columns": ["1"], |
| 69 | + "data": [{"row": [1], "meta": [null]}] }], |
| 70 | + "errors": [] |
| 71 | +} |
| 72 | +---- |
9 | 73 |
|
10 | 74 | [[http-api-missing-authorization]]
|
11 | 75 | == Missing authorization
|
|
0 commit comments