You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In mongodb/src/Connection.php
There is those lines
protected function createConnection($dsn, array $config, array $options)
{
// By default driver options is an empty array.
$driverOptions = [];
if (isset($config['driver_options']) && is_array($config['driver_options'])) {
$driverOptions = $config['driver_options'];
}
// Check if the credentials are not already set in the options
if (! isset($options['username']) && ! empty($config['username'])) {
$options['username'] = $config['username'];
}
if (! isset($options['password']) && ! empty($config['password'])) {
$options['password'] = $config['password'];
}
return new Client($dsn, $options, $driverOptions);
}
Where username and password are considered as options if they exist in the database configuration.
But later in
protected function getHostDsn(array $config)
{
// Treat host option as array of hosts
$hosts = is_array($config['host']) ? $config['host'] : [$config['host']];
foreach ($hosts as &$host) {
// Check if we need to add a port to the host
if (strpos($host, ':') === false && ! empty($config['port'])) {
$host = $host.':'.$config['port'];
}
}
// Check if we want to authenticate against a specific database.
$auth_database = isset($config['options']) && ! empty($config['options']['database']) ? $config['options']['database'] : null;
return 'mongodb://'.implode(',', $hosts).($auth_database ? '/'.$auth_database : '');
}
When composing the DSN to be used, then username and password are not inserted or used at all.
Actually I did not find anywhere where those values are actually used.
Steps to reproduce
Add the username and password configuration entries.
2.
Try a query
3.
Authentication fails (as the credentials are not passed on the DSN
Expected behaviour
username and `password should be used when resolving the DSN.
Ok, I think I figured it out. DB_AUTHENTICATION_DATABASE needs to be the database on which the user has been created.
I will close this issue.
Sorry for the disturbance.
Noted that you resolved the issue while I was typing this, but posting it anyways for the benefit of others:
While you can add username and pas
5E95
sword to the connection string for MongoDB, these can also be passed via the $uriOptions argument to MongoDB\Driver\Manager::__construct, which is invoked in the constructor for MongoDB\Client (created in createConnection). This options argument takes any connection string option.
The AuthenticationException indicates that the driver attempted authentication, which then failed. This can be caused due to attempting to authenticate against the wrong authentication database. As is currently happening, this library expects the configured database (where data is stored) to also be used as the default authentication database (as indicated by it being passed as default value for the authentication database). Setting the authSource connection string option to the correct database will resolve this issue.
Description:
In
mongodb/src/Connection.php
There is those lines
Where
username
andpassword
are considered as options if they exist in the database configuration.But later in
When composing the DSN to be used, then
username
andpassword
are not inserted or used at all.Actually I did not find anywhere where those values are actually used.
Steps to reproduce
Add the
username
andpassword
configuration entries.2.
Try a query
3.
Authentication fails (as the credentials are not passed on the DSN
Expected behaviour
username
and `password should be used when resolving the DSN.Actual behaviour
Authentication fails so fails the query
Logs:
[2022-09-15 06:47:47] local.ERROR: Authentication failed. {"exception":"[object] (MongoDB\\Driver\\Exception\\AuthenticationException(code: 11): Authentication failed. at /srv/lrvl.dev.timesofmalta.com/source/1/vendor/mongodb/mongodb/src/Operation/Find.php:317) [stacktrace] #0 /srv/lrvl.dev.timesofmalta.com/source/1/vendor/mongodb/mongodb/src/Operation/Find.php(317): MongoDB\\Driver\\Server->executeQuery() #1 /srv/lrvl.dev.timesofmalta.com/source/1/vendor/mongodb/mongodb/src/Collection.php(666): MongoDB\\Operation\\Find->execute() #2 [internal function]: MongoDB\\Collection->find() #3 /srv/lrvl.dev.timesofmalta.com/source/1/vendor/jenssegers/mongodb/src/Collection.php(45): call_user_func_array() #4 /srv/lrvl.dev.timesofmalta.com/source/1/vendor/jenssegers/mongodb/src/Query/Builder.php(410): Jenssegers\\Mongodb\\Collection->__call() #5 /srv/lrvl.dev.timesofmalta.com/source/1/vendor/jenssegers/mongodb/src/Query/Builder.php(201): Jenssegers\\Mongodb\\Query\\Builder->getFresh() #6 /srv/lrvl.dev.timesofmalta.com/source/1/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php(699): Jenssegers\\Mongodb\\Query\\Builder->get() #7 /srv/lrvl.dev.timesofmalta.com/source/1/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php(683): Illuminate\\Database\\Eloquent\\Builder->getModels() #8 /srv/lrvl.dev.timesofmalta.com/source/1/vendor/laravel/framework/src/Illuminate/Database/Concerns/BuildsQueries.php(296): Illuminate\\Database\\Eloquent\\Builder->get() #9 /srv/lrvl.dev.timesofmalta.com/source/1/app/Http/Controllers/ArticleController.php(17): Illuminate\\Database\\Eloquent\\Builder->first() #10 /srv/lrvl.dev.timesofmalta.com/source/1/vendor/laravel/framework/src/Illuminate/Routing/Controller.php(54): App\\Http\\Controllers\\ArticleController->index() #11 /srv/lrvl.dev.timesofmalta.com/source/1/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(45): Illuminate\\Routing\\Controller->callAction() #12 /srv/lrvl.dev.timesofmalta.com/source/1/vendor/laravel/fThe text was updated successfully, but these errors were encountered: