Cant authenticate request with SCRAM-SHA-1 mechanism

910 views
Skip to first unread message

Guillermo

unread,
Jan 25, 2016, 7:32:13 AM1/25/16
to mongodb-user
I am trying to do a simple request to a mongo database, but it terminates after the following error

terminate called after throwing an instance of 'mongo::UserException'
what():  SCRAM-SHA-1 mechanism support not compiled into client library. (Some mechanisms require the driver be compiled with the flags --ssl or --use-sasl-client)

 I dont understand why its complaining about that. I have installed the library libsasl2-dev, and my scons command is the following: 

sudo scons -j 4 --disable-warnings-as-errors --c++11=on --ssl --sharedclient --prefix=/opt/mongo-client install

And the code Im using to do the request is the following:


    mongo::DBClientConnection conn;
    std::string url = host + ":" + port;
    //Connect to database
    conn.connect(url);
    conn.auth(dbname,user,password,errmsg, true);

I have also tried this, instead of the last line:

    conn.auth( BSON(
    "user" << user <<
    "pwd" << password <<
    "mechanism" << "SCRAM-SHA-1" <<
    "db" << dbname ) );

 Any ideas? Why is it complaining about not having compiled with --ssl or --use-sasl-client? I did use those options!

Wan Bachtiar

unread,
Jan 28, 2016, 6:47:58 PM1/28/16
to mongodb-user

sudo scons -j 4 —disable-warnings-as-errors —c++11=on —ssl —sharedclient —prefix=/opt/mongo-client install

Hi Guillermo,

I compiled the legacy branch with the same options as you have and tested it with success. I used Ubuntu 14.04 and MongoDB v3.2.1 for the test.

The test code is also similar to yours:

  mongo::client::initialize();
  mongo::DBClientConnection c;
  try {
    c.connect("localhost");
    mongo::BSONObj params = BSON("mechanism" << "SCRAM-SHA-1" << "user" << "myuser" << "db" << "database" << "pwd" << "mypwd");
    c.auth(params);
  } catch( const mongo::DBException &e ) {
    std::cout << "caught " << e.what() << std::endl;
  }
  std::auto_ptr<mongo::DBClientCursor> cursor = c.query( "database.collection", mongo::BSONObj());
  while(cursor->more()){
      std::cout << cursor->next().toString() << std::endl;
  }

Did you have an existing include and library files that were compiled without --ssl ? Perhaps it was linked incorrectly at your code compilation time ?

Also, could you provide the following information :

Regards,

Wan.

Guillermo

unread,
Feb 1, 2016, 9:21:06 AM2/1/16
to mongodb-user
Ok sorry, I wasnt initializing the driver properly. Its working now.
Reply all
Reply to author
Forward
0 new messages