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

Mongodb “auth fails” with mongodb php driver and new php library #264

Closed
Zelfapp opened this issue Mar 15, 2016 · 4 comments
Closed
Labels

Comments

@Zelfapp
Copy link

Zelfapp commented Mar 15, 2016

I provided some more details on stackoverflow here: http://stackoverflow.com/questions/36021688/mongodb-auth-fails-with-mongodb-php-driver-and-new-php-library

Not sure this qualifies as a bug, most likely not, but transitioning from the legacy driver to mongodb with php library is ending up with auth failure message.

I'm using the same connection (mongodb://user:passwor@mymongoinstance:port/database) string that I used on legacy mongo driver. I'm running a simple find as you can see on stackoverflow. Why am I getting auth failure?

Below you can see in $this, the data being submitted to my collection. As soon as return new Query($this->filter, $options) is called passing query to mongodb driver I get "auth fails" in vendor/mongodb/mongodb/src/Operation/Find.php. I've tried setting readPreference to new MongoDB\Driver\ReadPreference(MongoDB\Driver\ReadPreference::RP_PRIMARY), but it makes no difference.

screenshot_1

screenshot_2

Environment:
Windows 10
Wamp
PHP 5.5.12
Mongodb driver 1.1.4
Latest version of new php library (Installed with composer: composer require "mongodb/mongodb=^1.0.0")
Mongo instance version 2.4.6

@derickr
Copy link
Contributor

derickr commented Mar 16, 2016

Looks like I answered this on StackOverflow before seeing this post. I'll repeat:

It is possible that the mongodb extension that you are using as not been compiled with SASL support. The older driver did not rely on any outside library, but the new one depends on OpenSSL for that. Sadly, there does not seem to be a way to check that by looking at phpinfo() output. You might be able to find whether it's linked to libsasl.lib with dependency walker (http://www.dependencywalker.com/), but I'm not a Windows expert.

I've added a jira ticket (with pull request) to track the addition of this information into phpinfo() output: https://jira.mongodb.org/browse/PHPC-633

@Zelfapp
Copy link
Author

Zelfapp commented Mar 16, 2016

So here's the solution. After 3 days of banging my head against a wall it turns out the new mongodb driver parses the mongodb uri differently than the legacy mongo driver. My password had a % sign in it. As soon as I changed the % sign to something else everything worked as expected.

@derickr
Copy link
Contributor

derickr commented Mar 16, 2016

Oh - right. That would do it. Instead of changing it away from %, you can also URL encode it (to %25).

@jmikola
Copy link
Member

jmikola commented Mar 17, 2016

We'll aim to get this clarified in the documentation for both the library and extension:

@jmikola jmikola closed this as completed Mar 17, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants