Authentication via runCommand()

163 views
Skip to first unread message

henning...@celeraone.com

unread,
Jun 30, 2016, 12:39:58 PM6/30/16
to mongodb-user
I try to check if a user has access rights to a database or not. I use the C++ API. Previous to version 3.0, i used the auth() function on a ScopedDBConnection. This function is no more available, so my workaround would be to use run_command() and try to provide a authentication command. But i can't figure out how it should look like, i tried the following layouts:

{ authenticate: 1, user: "foo", pwd: "bar" }
{ authenticate: { user: "foo", pwd: "bar" } }

{ authenticate: 1, user: "foo", password: "bar", source: "admin" }
{ authenticate: { user: "foo", password: "bar", source: "admin" } }

{ authenticate: 1, user: "foo", password: "bar", src: "admin" }
{ authenticate: { user: "foo", pwd: "bar", src: "admin" } }

None of those commans works, there is always an error message saying "field missing/wrong type in received authenticate command".
How does a "real" authentication command look like?!

I found the following document, but still could not authenticate via run command
https://github.com/mongodb/specifications/blob/master/source/auth/auth.rst#id45

This https://docs.mongodb.com/manual/reference/method/db.auth/#db.auth and this document https://docs.mongodb.com/manual/reference/command/authenticate/#dbcmd.authenticate don't provide the necessary information.

David Golden

unread,
Jun 30, 2016, 2:10:23 PM6/30/16
to mongodb-user
Hi.  Did you see my answer to https://groups.google.com/d/msg/mongodb-user/73-JLRPIUhM/XrKAN9boDAAJ ?

You should provide the username and password as part of the connection URI and the driver should do the rest when you attempt an operation that requires authentication.

Regards,
David 
Reply all
Reply to author
Forward
0 new messages