Skip to content

Commit 88fcdb6

Browse files
Emily Giurleop
authored andcommitted
Add information about user auth_source to the Ruby Driver documentation (#1593)
* provide info about the user auth source * add info about auth source to user-management docs
1 parent 548d6ac commit 88fcdb6

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

docs/tutorials/ruby-driver-authentication.txt

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ client.
3232
user: 'test',
3333
password: '123' )
3434

35-
For MongoDB 2.6 and later, ``:auth_source`` defaults to **admin**,
36-
otherwise the current database is used.
3735

3836
The current database can be changed with the client's ``use`` method.
3937

@@ -57,6 +55,30 @@ Alternatively, setting the current database and credentials can be done in one s
5755
user:'test',
5856
password:'123' )
5957

58+
Auth Source
59+
```````````
60+
61+
A user's auth source is the database where that user's authentication credentials are stored.
62+
63+
When creating a client with authentication credentials, you may specify an auth source
64+
for the user:
65+
66+
.. code-block:: ruby
67+
68+
client = Mongo::Client.new([ '127.0.0.1:27017' ],
69+
user: 'test',
70+
password: '123',
71+
auth_source: 'admin' )
72+
73+
If no auth source is specified, then a default will be assumed by the client. The default
74+
auth source depends on the authentication mechanism that is being used to connect.
75+
76+
For the ``MONGODB-CR``, ``SCRAM-SHA-1``, and ``SCRAM-SHA-256`` authentication mechanisms, the default
77+
auth source is the database to which the client is connecting; if no database is specified,
78+
`admin` becomes the default auth source. For the ``PLAIN`` mechanism (LDAP), the default auth source
79+
is the database to which the client is connecting; if no database is specified, ``$external`` is
80+
used as the auth source. For the ``GSSAPI`` and ``MONGODB_X509`` mechanisms,
81+
the auth source is always ``$external``.
6082

6183
MONGODB-CR Mechanism
6284
````````````````````

docs/tutorials/user-management.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ user information and then pass that object into the ``create`` method instead.
6262

6363
client.database.users.create(user)
6464

65+
Note that your new user's credentials will be stored in whatever database your ``client``
66+
object is currently connected to. This will be your user's ``auth_source``, and you must
67+
be connected to that same database in order to update, remove, or get information about
68+
the user you just created in the future.
69+
6570
The ``create`` method takes a ``Hash`` of options as an optional second argument.
6671
The ``:roles`` option allows you to grant permissions to the new user.
6772
For example, the ``Mongo::Auth::Roles::READ_WRITE`` role grants the user the ability to both

0 commit comments

Comments
 (0)