Skip to content

Pass credentials as parameters #753

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

Merged
merged 7 commits into from
Feb 25, 2016
Merged

Conversation

rjvandoesburg
Copy link
Contributor

These changes will pass the credentials as parameters at the creation of a new MongoDB connection instead of passing them on the DSN.

reference: #748

Username and password now need to be in the options section of the DB config

@jenssegers
Copy link
Contributor

I would prefer having the username and password outside of the options in the Laravel configuration (like it used to be). And pass them to the options in the Connection class.

That way it is a bit more similar to the mysql connection configuration, and might be more obvious for new users.

@rjvandoesburg
Copy link
Contributor Author

Ok, I will change that back and add the credentials to the constructor in the Connection class

- Reverted the config changes
- The credentials are now added to the MongoDB constructor if they are not already present
- Also fixed failing test by changing method access level
@rjvandoesburg
Copy link
Contributor Author

Ok, so the changes I've made are as followed.
In the Connection class I've added a couple of checks to see if a person has already provided credentials in the options, if not the credentials will be used from the config (the old way)

I've reverted the readme as no changes are there and I've changed the access level of a method because it was different from the access level of the method it was overriding.

But it seems I've managed to mess up the tests... I'll be fixing those next :)

@@ -136,6 +136,14 @@ protected function createConnection($dsn, array $config, array $options)
$driverOptions = $config['driver_options'];
}

// Check if the credentials are not already set in the options
if (!isset($options['username'])) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you turn this into:

if (! isset($options['username']) && isset($config['username'])) {
    $options['username'] = $config['username'];

And below as well:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I've seen that that is indeed where the problem was.

I've got the test suite running locally now as well so I can test before pushing bad code again.
I want to test the entire suite before pushing so I just need to get MySQL up and running, after that I will submit the new changes again

- If no user was given an empy user was set resulting in an error
@rjvandoesburg
Copy link
Contributor Author

Tests are working again. Applied the change you found as well.

@jenssegers
Copy link
Contributor

Can you squash your commits?

jenssegers added a commit that referenced this pull request Feb 25, 2016
Pass credentials as parameters
@jenssegers jenssegers merged commit 9baab58 into mongodb:master Feb 25, 2016
@rjvandoesburg
Copy link
Contributor Author

Ah sorry missed the notification.
Cheers for accepting the PR

@texxlan
Copy link

texxlan commented Feb 26, 2016

You are not checking if the credentials are empty. This resulty in an "Authentication failed." exception.
Two options:

  • add empty() check
    or
  • edit readme:
    remove 'DB_USERNAME/DB_PASSWORD' from .env if empty and change database.php from:
env('DB_USERNAME', '')
env('DB_PASSWORD', '')

to:

env('DB_USERNAME')
env('DB_PASSWORD')

Or is it just me?

jenssegers added a commit that referenced this pull request Feb 26, 2016
@jenssegers
Copy link
Contributor

I added it back again.

@rjvandoesburg
Copy link
Contributor Author

Hmm, I see what you mean.
However I do think there is a difference in having empty fields or no fields at all.
I'd suggest changing the readme so it states to remove the username and password if you wish to use anonymous login.

By having an empty username and password a user might be alerted for a misconfiguration in the .env file.

*edit: Because this has no inpact on my way of using it what so ever I don't mind the empty check t.b.h.

mnphpexpert added a commit to mnphpexpert/laravel-mongodb that referenced this pull request Sep 2, 2024
mnphpexpert added a commit to mnphpexpert/laravel-mongodb that referenced this pull request Sep 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants