Search code examples
mongodbmlabrobo3tfantom

Auth Failed trying to connect from a Fantom script to a MongoDB hosted in MongoLab. What's wrong?


I'm trying to connect to a remote MongoDB v3.0.8 hosted in MongoLab using a Fantom v1.0.67 script. The driver I'm using is afMongo v1.0.4. The connection line is:

mongoClient := MongoClient(
    ActorPool(),
    `mongodb://mydbuser:mydbpassword@ds0#####.mongolab.com:#####/mymongodb`
)

Please note that the placeholders mydbuser, mydbpassword and ##### are replaced with the correct values. The connection is successful when I run the following command from a shell:

mongo ds0#####.mongolab.com:#####/mymongodb -u mydbuser -p mydbpassword

but from the Fantom script, I get this error:

afMongo::MongoCmdErr: Command 'authenticate' failed. MongoDB says: auth failed
  afMongo::Operation.runCommand (Operation.fan:36)
  afMongo::Operation.runCommand (Operation.fan)
  afMongo::Connection$.authenticate (Connection.fan:34)
  afMongo::TcpConnection.authenticate (Connection.fan:51)
  afMongo::ConnectionManagerPooled.checkOut (ConnectionManagerPooled.fan:458)
  afMongo::ConnectionManagerPooled.leaseConnection (ConnectionManagerPooled.fan:320)
  afMongo::Cmd.run (Cmd.fan:71)
  afMongo::Database.runCmd (Database.fan:36)
  afMongo::MongoClient.runAdminCmd (MongoClient.fan:107)
  afMongo::MongoClient.buildInfo (MongoClient.fan:64)
  afMongo::MongoClient.startup (MongoClient.fan:119)
  afMongo::MongoClient.makeFromUri$ (MongoClient.fan:41)
  afMongo::MongoClient.makeFromUri$ (MongoClient.fan)
  afMongo::MongoClient.makeFromUri (MongoClient.fan:38)

I have also tried Robomongo v0.8.4 with a similar result: A pop-up dialog saying...

  • Successfully connected to ds0#####.mongolab.com:#####
  • Authorization failed

I ran the Fantom script as well as Robomongo connecting and authenticating successfully against MongoDB v2.6.3 and v3.0.8 databases hosted locally.

My Java version is Java(TM) SE Runtime Environment (build 1.8.0_05-b13)

I don't know if Robomongo or Fantom/afMongo depend on a Java or System library that is out of date.

What is wrong or what I should be checking, please?


Solution

  • The auth failures in both Robomongo v0.8.4 and afMongo 1.0.4 are due to a new authentication mechanism in MongoDB v3 called SCRAM-SHA-1.

    afMongo has been updated with an implementation of SCRAM-SHA-1 over SASL. It auto detects Mongo v3 databases and switches the auth protocol, falling back to the older MONGODB-CR when needed - see this commit.

    These changes haven't been released yet because it depends on a new method Buf.pbk(...) that is only available in Fantom 1.0.68 - which itself is unreleased. An updated afMongo v1.0.6 will be released as soon as Fantom 1.0.68 is.

    You could compile Fantom 1.0.68 and afMongo 1.0.6 from source, but to be honest, the easiest fix (in the meantime) is to just use a v2.6 MongoDB database.

    Note that, if needed, the MongoChef GUI client can authenticate against MongoDB v3 databases.