Reputation: 325
I am trying to connect to a Neo4j via Invoke-RestMethod (PowerShell versions 3,4,5).
Based on web recommendations, I am setting URI: $Uri = "http://localhost:7474/db/data/cypher"
... followed by a call to invoke rest method (POST or GET, does not matter)
Invoke-RestMethod -Uri $Uri -Method Post -Body $Body -ContentType 'application/json'
Message I get is:
System.Net.WebException: The remote server returned an error: (401) Unauthorized.
at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetResponse(WebRequest request)
at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord()
I tried putting in http://userId/pwd@localhost:7474.... but the error is the same.
Is there another way to pass authentication information to Neo4j?
Disabling security is not an option.
Thank you!
--Alex
Upvotes: 0
Views: 312
Reputation: 390
The authetication havs to bee the http standard authentication. You can do this in powershell for example with the following code.
$user = 'user'
$pass = 'pass'
$pair = "$($user):$($pass)"
$encodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($pair))
$basicAuthValue = "Basic $encodedCreds"
$Headers = @{
Authorization = $basicAuthValue
}
Invoke-RestMethod -Uri $Uri -Method Post -Body $Body -ContentType 'application/json' -Headers $Headers
Background The error code 401 says that the authentication is not correct on the server.
I found this information in the documentation. https://neo4j.com/docs/developer-manual/3.4/http-api/authentication/
Upvotes: 0