Skip to content

Commit efada2d

Browse files
DOCSP-37509 - Authentication (#52)
Co-authored-by: Jordan Smith <[email protected]>
1 parent 89510d7 commit efada2d

File tree

7 files changed

+602
-356
lines changed

7 files changed

+602
-356
lines changed

source/connect/connection-options.txt

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,63 @@ Server Selection
146146
| **MongoClient Example**: ``server_selector = your_function``
147147
| **Connection URI Example**: N/A
148148

149+
Authentication
150+
~~~~~~~~~~~~~~
151+
152+
.. list-table::
153+
:header-rows: 1
154+
:widths: 30 70
155+
156+
* - Connection Option
157+
- Description
158+
159+
* - **authMechanism**
160+
- | The mechanism {+driver-short+} uses to authenticate the application. Valid
161+
| options are defined in `MECHANISMS. <{+api-root+}pymongo/database.html#pymongo.auth.MECHANISMS>`__
162+
|
163+
| **Data Type**: {+string-data-type+}
164+
| **Default**: ``"SCRAM-SHA-256"`` when connecting to MongoDB v4.0 or later.
165+
| ``"SCRAM-SHA-1"`` when connecting to MongoDB v3.0 through v3.13.
166+
| **MongoClient Example**: ``authMechanism = "MONGODB-X509"``
167+
| **Connection URI Example**: ``authMechanism=MONGODB-X509``
168+
169+
* - **authMechanismProperties**
170+
- | Options specific to the authentication mechanism. Not needed for all authentication
171+
| mechanisms.
172+
|
173+
| **Data Type**: {+string-data-type+}
174+
| **Default**: ``""``
175+
| **MongoClient Example**: ``authMechanismProperties = "AWS_SESSION_TOKEN:12345"``
176+
| **Connection URI Example**: ``authMechanismProperties=AWS_SESSION_TOKEN:12435``
177+
178+
* - **authSource**
179+
- | The database to authenticate against.
180+
|
181+
| **Data Type**: {+string-data-type+}
182+
| **Default**: The database in the connection URI, or ``"admin"`` if none is provided
183+
| **MongoClient Example**: ``authSource = "admin"``
184+
| **Connection URI Example**: ``authSource=admin``
185+
186+
* - **username**
187+
- | The username for authentication. When this option is included in a connection
188+
| URI, you must percent-escape it.
189+
|
190+
| **Data Type**: {+string-data-type+}
191+
| **Default**: ``""``
192+
| **MongoClient Example**: ``username = "my user"``
193+
| **Connection URI Example**: ``username=my+user``
194+
195+
* - **password**
196+
- | The password for authentication. When this option is included in a connection
197+
| URI, you must percent-escape it.
198+
|
199+
| **Data Type**: {+string-data-type+}
200+
| **Default**: ``""``
201+
| **MongoClient Example**: ``password = "strong password"``
202+
| **Connection URI Example**: ``password=strong+password``
203+
204+
For more information about the connection option in this section, see :ref:`pymongo-auth`.
205+
149206
.. _secondary-reads:
150207

151208
Secondary Reads

source/connect/network-compression.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ The following code example shows both options:
6060
.. code-block:: python
6161
:emphasize-lines: 2
6262

63-
client = pymongo.MongoClient("mongodb://<username>:<password>@<hostname@:<port>",
63+
client = pymongo.MongoClient("mongodb://<username>:<password>@<hostname>:<port>",
6464
compressors = "snappy,zstd,zlib")
6565

6666
.. tab:: Connection String
@@ -96,7 +96,7 @@ The following code example specifies the ``zlib`` compression algorithm and a va
9696
.. code-block:: python
9797
:emphasize-lines: 2-3
9898

99-
client = pymongo.MongoClient("mongodb://<username>:<password>@<hostname@:<port>",
99+
client = pymongo.MongoClient("mongodb://<username>:<password>@<hostname>:<port>",
100100
compressors = "zlib",
101101
zlibCompressionLevel=1)
102102

source/connect/tls.txt

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ option to ``True``. You can do this in two ways: by passing an argument to the
5555

5656
.. code-block:: python
5757

58-
client = pymongo.MongoClient("mongodb://<username>:<password>@<hostname@:<port>", tls=True)
58+
client = pymongo.MongoClient("mongodb://<username>:<password>@<hostname:<port>", tls=True)
5959

6060
.. tab:: Connection String
6161
:tabid: connectionstring
@@ -96,7 +96,7 @@ You can do this in two ways: by passing an argument to the
9696

9797
.. code-block:: python
9898

99-
client = pymongo.MongoClient("mongodb://<username>:<password>@<hostname@:<port>",
99+
client = pymongo.MongoClient("mongodb://<username>:<password>@<hostname>:<port>",
100100
tls=True,
101101
tlsCAFile="/path/to/ca.pem")
102102

@@ -126,7 +126,7 @@ To use the Online Certificate Status Protocol (OCSP) to validate a server certif
126126
you must install {+driver-short+} with the ``ocsp`` option, as shown in the following
127127
example:
128128

129-
.. code-block:: python
129+
.. code-block:: sh
130130

131131
python -m pip install pymongo[ocsp]
132132

@@ -154,7 +154,7 @@ You can do this in two ways: by passing an argument to the
154154

155155
.. code-block:: python
156156

157-
client = pymongo.MongoClient("mongodb://<username>:<password>@<hostname@:<port>",
157+
client = pymongo.MongoClient("mongodb://<username>:<password>@<hostname>:<port>",
158158
tls=True,
159159
tlsDisableOCSPEndpointCheck=True)
160160

@@ -188,7 +188,7 @@ You can do this in two ways: by passing an argument to the
188188

189189
.. code-block:: python
190190

191-
client = pymongo.MongoClient("mongodb://<username>:<password>@<hostname@:<port>",
191+
client = pymongo.MongoClient("mongodb://<username>:<password>@<hostname>:<port>",
192192
tls=True,
193193
tlsCRLFile="/path/to/crl.pem")
194194

@@ -221,7 +221,7 @@ You can do this in two ways: by passing an argument to the
221221

222222
.. code-block:: python
223223

224-
client = pymongo.MongoClient("mongodb://<username>:<password>@<hostname@:<port>",
224+
client = pymongo.MongoClient("mongodb://<username>:<password>@<hostname>:<port>",
225225
tls=True,
226226
tlsCertificateKeyFile='/path/to/client.pem')
227227

@@ -230,7 +230,7 @@ You can do this in two ways: by passing an argument to the
230230

231231
.. code-block:: python
232232

233-
uri = ("mongodb://<username>:<password>@<hostname@:<port>/?"
233+
uri = ("mongodb://<username>:<password>@<hostname:<port>/?"
234234
"tls=true"
235235
"&tlsCertificateKeyFile=path/to/client.pem")
236236
client = pymongo.MongoClient(uri)
@@ -262,7 +262,7 @@ You can do this in two ways: by passing an argument to the
262262

263263
.. code-block:: python
264264

265-
client = pymongo.MongoClient("mongodb://<username>:<password>@<hostname@:<port>",
265+
client = pymongo.MongoClient("mongodb://<username>:<password>@<hostname:<port>",
266266
tls=True,
267267
tlsCertificateKeyFile='/path/to/client.pem',
268268
tlsCertificateKeyFilePassword=<passphrase>)
@@ -272,7 +272,7 @@ You can do this in two ways: by passing an argument to the
272272

273273
.. code-block:: python
274274

275-
uri = ("mongodb://<username>:<password>@<hostname@:<port>/?"
275+
uri = ("mongodb://<username>:<password>@<hostname:<port>/?"
276276
"tls=true"
277277
"&tlsCertificateKeyFile=path/to/client.pem"
278278
"&tlsCertificateKeyFilePassword=<passphrase>")
@@ -311,7 +311,7 @@ option to ``True``. You can do this in two ways: by passing an argument to the
311311

312312
.. code-block:: python
313313

314-
client = pymongo.MongoClient("mongodb://<username>:<password>@<hostname@:<port>",
314+
client = pymongo.MongoClient("mongodb://<username>:<password>@<hostname:<port>",
315315
tls=True,
316316
tlsInsecure=True)
317317

@@ -320,7 +320,7 @@ option to ``True``. You can do this in two ways: by passing an argument to the
320320

321321
.. code-block:: python
322322

323-
uri = ("mongodb://<username>:<password>@<hostname@:<port>/?"
323+
uri = ("mongodb://<username>:<password>@<hostname>:<port>/?"
324324
"tls=true"
325325
"&tlsInsecure=true")
326326
client = pymongo.MongoClient(uri)
@@ -335,7 +335,7 @@ To disable only certificate validation, set the ``tlsAllowInvalidCertificates``
335335

336336
.. code-block:: python
337337

338-
client = pymongo.MongoClient("mongodb://<username>:<password>@<hostname@:<port>",
338+
client = pymongo.MongoClient("mongodb://<username>:<password>@<hostname>:<port>",
339339
tls=True,
340340
tlsAllowInvalidCertificates=True)
341341

@@ -344,7 +344,7 @@ To disable only certificate validation, set the ``tlsAllowInvalidCertificates``
344344

345345
.. code-block:: python
346346

347-
uri = ("mongodb://<username>:<password>@<hostname@:<port>/?"
347+
uri = ("mongodb://<username>:<password>@<hostname>:<port>/?"
348348
"tls=true"
349349
"&tlsAllowInvalidCertificates=true")
350350
client = pymongo.MongoClient(uri)
@@ -359,7 +359,7 @@ To disable only hostname verification, set the ``tlsAllowInvalidHostnames`` opti
359359

360360
.. code-block:: python
361361

362-
client = pymongo.MongoClient("mongodb://<username>:<password>@<hostname@:<port>",
362+
client = pymongo.MongoClient("mongodb://<username>:<password>@<hostname>:<port>",
363363
tls=True,
364364
tlsAllowInvalidHostnames=True)
365365

@@ -368,7 +368,7 @@ To disable only hostname verification, set the ``tlsAllowInvalidHostnames`` opti
368368

369369
.. code-block:: python
370370

371-
uri = ("mongodb://<username>:<password>@<hostname@:<port>/?"
371+
uri = ("mongodb://<username>:<password>@<hostname>:<port>/?"
372372
"tls=true"
373373
"&tlsAllowInvalidHostnames=true")
374374
client = pymongo.MongoClient(uri)

source/fundamentals.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ Fundamentals
1111
:titlesonly:
1212
:maxdepth: 1
1313

14-
/fundamentals/authentication
1514
/fundamentals/collations
1615
/fundamentals/databases-and-collections
1716
/fundamentals/dates-and-times

0 commit comments

Comments
 (0)