@@ -13,26 +13,26 @@ credentials can be specified through the MongoDB URI or passed to the
13
13
:meth: `~pymongo.database.Database.authenticate ` method::
14
14
15
15
>>> from pymongo import MongoClient
16
- >>> client = pymongo. MongoClient('example.com')
16
+ >>> client = MongoClient('example.com')
17
17
>>> client.the_database.authenticate('user', 'password')
18
18
True
19
19
>>>
20
20
>>> uri = "mongodb://user:password@example.com/the_database"
21
- >>> client = pymongo. MongoClient(uri)
21
+ >>> client = MongoClient(uri)
22
22
>>>
23
23
24
24
When using MongoDB's delegated authentication features, a separate
25
25
authentication source can be specified (using PyMongo 2.5 or newer)::
26
26
27
27
>>> from pymongo import MongoClient
28
- >>> client = pymongo. MongoClient('example.com')
28
+ >>> client = MongoClient('example.com')
29
29
>>> client.the_database.authenticate('user',
30
30
... 'password',
31
31
... source='source_database')
32
32
True
33
33
>>>
34
34
>>> uri = "mongodb://user:password@example.com/?authSource=source_database"
35
- >>> client = pymongo. MongoClient(uri)
35
+ >>> client = MongoClient(uri)
36
36
>>>
37
37
38
38
MONGODB-X509
@@ -47,11 +47,11 @@ and newer::
47
47
48
48
>>> import ssl
49
49
>>> from pymongo import MongoClient
50
- >>> client = pymongo. MongoClient('example.com',
51
- ... ssl=True,
52
- ... ssl_certfile='/path/to/client.pem',
53
- ... ssl_cert_reqs=ssl.CERT_REQUIRED,
54
- ... ssl_ca_certs='/path/to/ca.pem')
50
+ >>> client = MongoClient('example.com',
51
+ ... ssl=True,
52
+ ... ssl_certfile='/path/to/client.pem',
53
+ ... ssl_cert_reqs=ssl.CERT_REQUIRED,
54
+ ... ssl_ca_certs='/path/to/ca.pem')
55
55
>>> client.the_database.authenticate("<X.509 derived username>",
56
56
... mechanism='MONGODB-X509')
57
57
True
@@ -61,11 +61,11 @@ MONGODB-X509 authenticates against the $external virtual database, so you
61
61
do not have to specify a database in the URI::
62
62
63
63
>>> uri = "mongodb://<X.509 derived username>@example.com/?authMechanism=MONGODB-X509"
64
- >>> client = pymongo. MongoClient(uri,
65
- ... ssl=True,
66
- ... ssl_certfile='/path/to/client.pem',
67
- ... ssl_cert_reqs=ssl.CERT_REQUIRED,
68
- ... ssl_ca_certs='/path/to/ca.pem')
64
+ >>> client = MongoClient(uri,
65
+ ... ssl=True,
66
+ ... ssl_certfile='/path/to/client.pem',
67
+ ... ssl_cert_reqs=ssl.CERT_REQUIRED,
68
+ ... ssl_ca_certs='/path/to/ca.pem')
69
69
>>>
70
70
71
71
.. note ::
@@ -99,27 +99,27 @@ $external virtual database so you do not have to specify a database in the
99
99
URI::
100
100
101
101
>>> # Note: the kerberos principal must be url encoded.
102
- >>> import pymongo
102
+ >>> from pymongo import MongoClient
103
103
>>> uri = "mongodb://mongodbuser%40EXAMPLE.COM@example.com/?authMechanism=GSSAPI"
104
- >>> client = pymongo. MongoClient(uri)
104
+ >>> client = MongoClient(uri)
105
105
>>>
106
106
107
107
or using :meth: `~pymongo.database.Database.authenticate `::
108
108
109
- >>> import pymongo
110
- >>> client = pymongo. MongoClient('example.com')
109
+ >>> from pymongo import MongoClient
110
+ >>> client = MongoClient('example.com')
111
111
>>> db = client.test
112
112
>>> db.authenticate('mongodbuser@EXAMPLE.COM', mechanism='GSSAPI')
113
113
True
114
114
115
115
The default service name used by MongoDB and PyMongo is `mongodb `. You can
116
116
specify a custom service name with the ``gssapiServiceName `` option::
117
117
118
- >>> import pymongo
118
+ >>> from pymongo import MongoClient
119
119
>>> uri = "mongodb://mongodbuser%40EXAMPLE.COM@example.com/?authMechanism=GSSAPI&gssapiServiceName=myservicename"
120
- >>> client = pymongo. MongoClient(uri)
120
+ >>> client = MongoClient(uri)
121
121
>>>
122
- >>> client = pymongo. MongoClient('example.com')
122
+ >>> client = MongoClient('example.com')
123
123
>>> db = client.test
124
124
>>> db.authenticate('mongodbuser@EXAMPLE.COM', mechanism='GSSAPI', gssapiServiceName='myservicename')
125
125
True
@@ -141,15 +141,15 @@ to an LDAP server. Using the PLAIN mechanism is very similar to MONGODB-CR.
141
141
These examples use the $external virtual database for LDAP support::
142
142
143
143
>>> from pymongo import MongoClient
144
- >>> client = pymongo. MongoClient('example.com')
144
+ >>> client = MongoClient('example.com')
145
145
>>> client.the_database.authenticate('user',
146
146
... 'password',
147
147
... source='$external',
148
148
... mechanism='PLAIN')
149
149
True
150
150
>>>
151
151
>>> uri = "mongodb://user:password@example.com/?authMechanism=PLAIN&authSource=$external"
152
- >>> client = pymongo. MongoClient(uri)
152
+ >>> client = MongoClient(uri)
153
153
>>>
154
154
155
155
SASL PLAIN is a clear-text authentication mechanism. We **strongly ** recommend
@@ -158,22 +158,22 @@ the SASL PLAIN mechanism::
158
158
159
159
>>> import ssl
160
160
>>> from pymongo import MongoClient
161
- >>> client = pymongo. MongoClient('example.com',
162
- ... ssl=True,
163
- ... ssl_certfile='/path/to/client.pem',
164
- ... ssl_cert_reqs=ssl.CERT_REQUIRED,
165
- ... ssl_ca_certs='/path/to/ca.pem')
161
+ >>> client = MongoClient('example.com',
162
+ ... ssl=True,
163
+ ... ssl_certfile='/path/to/client.pem',
164
+ ... ssl_cert_reqs=ssl.CERT_REQUIRED,
165
+ ... ssl_ca_certs='/path/to/ca.pem')
166
166
>>> client.the_database.authenticate('user',
167
167
... 'password',
168
168
... source='$external',
169
169
... mechanism='PLAIN')
170
170
True
171
171
>>>
172
172
>>> uri = "mongodb://user:password@example.com/?authMechanism=PLAIN&authSource=$external"
173
- >>> client = pymongo. MongoClient(uri,
174
- ... ssl=True,
175
- ... ssl_certfile='/path/to/client.pem',
176
- ... ssl_cert_reqs=ssl.CERT_REQUIRED,
177
- ... ssl_ca_certs='/path/to/ca.pem')
173
+ >>> client = MongoClient(uri,
174
+ ... ssl=True,
175
+ ... ssl_certfile='/path/to/client.pem',
176
+ ... ssl_cert_reqs=ssl.CERT_REQUIRED,
177
+ ... ssl_ca_certs='/path/to/ca.pem')
178
178
>>>
179
179
0 commit comments