Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#The Client is unauthorized due to authentication failure #660

Closed
harikanani opened this issue Dec 31, 2020 · 16 comments
Closed

#The Client is unauthorized due to authentication failure #660

harikanani opened this issue Dec 31, 2020 · 16 comments

Comments

@harikanani
Copy link

The client is unauthorized due to authentication failure.

  • Complete Error

  • Neo4jError: The client is unauthorized due to authentication failure. at captureStacktrace (C:\Users\sensei infotech\Desktop\hari\expressneo4jcrud\node_modules\neo4j-driver\lib\result.js:277:15) at new Result (C:\Users\sensei infotech\Desktop\hari\expressneo4jcrud\node_modules\neo4j-driver\lib\result.js:68:19) at Session._run (C:\Users\sensei infotech\Desktop\hari\expressneo4jcrud\node_modules\neo4j-driver\lib\session.js:174:14) at Session.run (C:\Users\sensei infotech\Desktop\hari\expressneo4jcrud\node_modules\neo4j-driver\lib\session.js:135:19) at Object.executeCypherQuery (C:\Users\sensei infotech\Desktop\hari\expressneo4jcrud\middleware\graphDBConnect.js:16:34) at C:\Users\sensei infotech\Desktop\hari\expressneo4jcrud\routes\users.js:32:42 at newFn (C:\Users\sensei infotech\Desktop\hari\expressneo4jcrud\node_modules\express-async-errors\index.js:16:20) at Layer.handle [as handle_request] (C:\Users\sensei infotech\Desktop\hari\expressneo4jcrud\node_modules\express\lib\router\layer.js:95:5) at next (C:\Users\sensei infotech\Desktop\hari\expressneo4jcrud\node_modules\express\lib\router\route.js:137:13) at Route.dispatch (C:\Users\sensei infotech\Desktop\hari\expressneo4jcrud\node_modules\express\lib\router\route.js:112:3)
  • My File Where i'm trying to login

const neo4j = require('neo4j-driver');
const config = require('config');
const uri = config.get('dbHost');
const user = config.get('dbUser');
const password = config.get('dbPass');
const driver = neo4j.driver(uri, neo4j.auth.basic(user, password), {
  maxConnectionLifetime: 3 * 60 * 60 * 1000, // 3 hours
  maxConnectionPoolSize: 50,
  connectionAcquisitionTimeout: 2 * 60 * 1000, // 120 seconds
  disableLosslessIntegers: true
});
const session = driver.session();
async function executeCypherQuery(statement, params = {}) {
  try {
    const result = await session.run(statement, params);
    session.close();
    return result;
  } catch (error) {
    throw error; // we are logging this error at the time of calling this method
  }
}
module.exports = { executeCypherQuery };

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

@fbiville
Copy link
Contributor

fbiville commented Jan 4, 2021

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
Copy link
Contributor

bigmontz commented Jan 4, 2021

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
Copy link
Contributor

bigmontz commented Jan 4, 2021

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
Copy link
Author

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

  • code

const neo4j = require('neo4j-driver');
const config = require('config');
const uri = config.get('dbHost');
const user = config.get('dbUser');
const password = config.get('dbPass');
const driver = neo4j.driver(uri, neo4j.auth.basic(user, password), {
 maxConnectionLifetime: 3 * 60 * 60 * 1000, // 3 hours
 maxConnectionPoolSize: 50,
 connectionAcquisitionTimeout: 2 * 60 * 1000, // 120 seconds
 disableLosslessIntegers: true
});
const session = driver.session();
async function executeCypherQuery(statement, params = {}) {
 try {
   const result = session.run(statement, params);
   // session.close();
   return result;
 }
  finally {
   session.close();
 }
}
module.exports = { executeCypherQuery };
  • Error

    at captureStacktrace (C:\Users\sensei infotech\Desktop\hari\expressneo4jcrud\node_modules\neo4j-driver\lib\result.js:277:15)
    at new Result (C:\Users\sensei infotech\Desktop\hari\expressneo4jcrud\node_modules\neo4j-driver\lib\result.js:68:19)
    at Session._run (C:\Users\sensei infotech\Desktop\hari\expressneo4jcrud\node_modules\neo4j-driver\lib\session.js:174:14)
    at Session.run (C:\Users\sensei infotech\Desktop\hari\expressneo4jcrud\node_modules\neo4j-driver\lib\session.js:135:19)
    at Object.executeCypherQuery (C:\Users\sensei infotech\Desktop\hari\expressneo4jcrud\middleware\graphDBConnect.js:16:28)
    at C:\Users\sensei infotech\Desktop\hari\expressneo4jcrud\routes\products.js:63:44
    at newFn (C:\Users\sensei infotech\Desktop\hari\expressneo4jcrud\node_modules\express-async-errors\index.js:16:20)
    at Layer.handle [as handle_request] (C:\Users\sensei infotech\Desktop\hari\expressneo4jcrud\node_modules\express\lib\router\layer.js:95:5)
    at next (C:\Users\sensei infotech\Desktop\hari\expressneo4jcrud\node_modules\express\lib\router\route.js:137:13)
    at Route.dispatch (C:\Users\sensei infotech\Desktop\hari\expressneo4jcrud\node_modules\express\lib\router\route.js:112:3) {
  code: 'N/A'
}

@harikanani
Copy link
Author

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
Copy link
Contributor

bigmontz commented Jan 4, 2021

@harikanani Did you try the new password set?

@harikanani
Copy link
Author

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

@fbiville
Copy link
Contributor

fbiville commented Jan 4, 2021

@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
Copy link
Contributor

bigmontz commented Mar 9, 2021

Hi @harikanani ,

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

Many thanks

@harikanani
Copy link
Author

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
Copy link
Contributor

Thanks, so i will close the issue.

@ddemydenko
Copy link

@harikanani How did you solve the issue?

@harikanani
Copy link
Author

@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
Copy link
Contributor

@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
Copy link

ducknificient commented Oct 5, 2023

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
Copy link

edge-rps commented Oct 5, 2023

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));`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants