neo4j / neo4j-javascript-driver

Neo4j Bolt driver for JavaScript
https://neo4j.com/docs/javascript-manual/current/
Apache License 2.0
856 stars 147 forks source link

#The Client is unauthorized due to authentication failure #660

Closed harikanani closed 3 years ago

harikanani commented 3 years ago

The client is unauthorized due to authentication failure.

fbiville commented 3 years ago

I'm not 100% sure it's related, but you usually have to set the password to a non-default value before being able to connect. Have you tried that?

bigmontz commented 3 years ago

Hi @harikanani,

could you share the driver and server versions?

About the code you shared, I could spot an issue not related with the error reported. The method executeCypherQuery will only work once, since the session is being closed on the end of the method and never re-recreated after. You could change a bit the code to the executeCypherQuery receive the session as parameter and change the usage to be something like this:

async function runSomeQueries() {
  const session = driver.session();
  try {
     const result1 = await executeCypherQuery(session, `query`, {})
      ...
     const resultn = await executeCypherQuery(session, `query`, {})
  } finally {
    session.close()
 }
}

Also, I recommend the usage of transaction functions. See here

bigmontz commented 3 years ago

I'm not 100% sure it's related, but you usually have to set the password to a non-default value before being able to connect. Have you tried that?

I've tried with a docker instance without set the password and got this:

Neo4jError: Permission denied.

The credentials you provided were valid, but must be changed before you can use this instance. If this is the first time you are using Neo4j, this is to ensure you are not using the default credentials in production. If you are not using default credentials, you are getting this message because an administrator requires a password change.
Changing your password is easy to do via the Neo4j Browser.
If you are connecting via a shell or programmatically via a driver, just issue a `ALTER CURRENT USER SET PASSWORD FROM 'current password' TO 'new password'` statement against the system database in the current session, and then restart your driver with the new password configured.

So, It could be the case of change the password.

The docker run without change the password:

docker run --name neo4j  -p7687:7687 -p7474:7474

The docker run changing the password:

docker run --name neo4j --env NEO4J_AUTH=neo4j/pass -p7687:7687 -p7474:7474
harikanani commented 3 years ago

@bigmontz please check my code still getting error but now error is different

harikanani commented 3 years ago

I'm not 100% sure it's related, but you usually have to set the password to a non-default value before being able to connect. Have you tried that?

I've tried with a docker instance without set the password and got this:

Neo4jError: Permission denied.

The credentials you provided were valid, but must be changed before you can use this instance. If this is the first time you are using Neo4j, this is to ensure you are not using the default credentials in production. If you are not using default credentials, you are getting this message because an administrator requires a password change.
Changing your password is easy to do via the Neo4j Browser.
If you are connecting via a shell or programmatically via a driver, just issue a `ALTER CURRENT USER SET PASSWORD FROM 'current password' TO 'new password'` statement against the system database in the current session, and then restart your driver with the new password configured.

So, It could be the case of change the password.

The docker run without change the password:

docker run --name neo4j  -p7687:7687 -p7474:7474

The docker run changing the password:

docker run --name neo4j --env NEO4J_AUTH=neo4j/pass -p7687:7687 -p7474:7474

i think you should restart the session after you change the user password

bigmontz commented 3 years ago

@harikanani Did you try the new password set?

harikanani commented 3 years ago

yes i tried and got error that i've opned issue #660

fbiville commented 3 years ago

@harikanani in your initial description, you are saying:

I'm Using Default Username and Password username : neo4j password : neo4j

As far as I know, you cannot connect to a Neo4j server until the default password for the default user has been changed to another value.

Are you saying that changing the password to another value, updating the credentials and re-running your program still leads to the same error, i.e. the one included in your initial report?

bigmontz commented 3 years ago

Hi @harikanani ,

Did you try @fbiville suggestions? Does the issue still occur after that?

Many thanks

harikanani commented 3 years ago

Hi @harikanani ,

Did you try @fbiville suggestions? Does the issue still occur after that?

Many thanks

Yes issue was solved 😊 Thank you for helping me out 🙏

bigmontz commented 3 years ago

Thanks, so i will close the issue.

ddemydenko commented 1 year ago

@harikanani How did you solve the issue?

harikanani commented 1 year ago

@harikanani How did you solve the issue?

It's been a long I've used neo4j, but as far as I remember, I tried changing the password and it worked for me.

fbiville commented 1 year ago

@ddemydenko if the issue was about not overriding the default admin password AND assuming you're using Docker, you can override the password with:

docker run --env NEO4J_AUTH=neo4j/aNewPassword [...] neo4j:5
ducknificient commented 1 year ago

i'm experiencing same issue from golang driver. Here's my neo4j information

Neo4j Browser version: [5.11.0](https://github.com/neo4j/neo4j-browser/releases/tag/5.11.0)
Neo4j Server version: [5.12.0](https://github.com/neo4j/neo4j/wiki/Neo4j-5.12-changelog#5120) (community)
[Neo4j Browser Changelog](https://github.com/neo4j/neo4j-browser/wiki/changelog)
Build number: 219
Build date: 8/1/2023

go mod version

require github.com/neo4j/neo4j-go-driver/v5 v5.13.0 // indirect
edge-rps commented 1 year ago

I fixed the error by adding the port to the end of the connection URI and also double check your username and password the default username is neo4j.

` // Neo4j database connection configuration

const uri = "neo4j+s://65cafc91.databases.neo4j.io:7687"; // Update with your Neo4j server URI (✔with port included) const username = process.env.NEO4J_USERNAME; // Update with your Neo4j username const password = process.env.NEO4J_PASSWORD; // Update with your Neo4j password

const driver = neo4j.driver(uri, neo4j.auth.basic(username, password));`