Skip to content

Commit bbe7469

Browse files
authored
OIDC fixes (#86)
1 parent 55751b2 commit bbe7469

File tree

5 files changed

+24
-25
lines changed

5 files changed

+24
-25
lines changed

source/includes/authentication/azure-envs-mongoclient.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from pymongo.auth_oidc import OIDCCallback, OIDCCallbackContext, OIDCCallbackResult
44

55
# define callback, properties, and MongoClient
6-
audience = "<audience configured on the MongoDB deployment>"
6+
audience = "<audience>"
77
client_id = "<Azure client ID>"
88
class MyCallback(OIDCCallback):
99
def fetch(self, context: OIDCCallbackContext) -> OIDCCallbackResult:

source/includes/authentication/azure-imds-connection-string.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
uri = ("mongodb://<hostname>:<port>/?"
55
"username=<Azure client ID or application ID>"
66
"&authMechanism=MONGODB-OIDC"
7-
"&authMechanismProperties=ENVIRONMENT:azure,TOKEN_RESOURCE:<audience>")
7+
"&authMechanismProperties=ENVIRONMENT:azure,TOKEN_RESOURCE:<percent-encoded audience>")
88
client = MongoClient(uri)

source/includes/authentication/gcp-imds-connection-string.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
# define URI and MongoClient
44
uri = ("mongodb://<hostname>:<port>/?"
5-
"username=<GCP identity client ID>"
65
"&authMechanism=MONGODB-OIDC"
7-
"&authMechanismProperties=ENVIRONMENT:gcp,TOKEN_RESOURCE:<audience>")
6+
"&authMechanismProperties=ENVIRONMENT:gcp,TOKEN_RESOURCE:<percent-encoded audience>")
87
client = MongoClient(uri)

source/includes/authentication/gcp-imds-mongoclient.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
properties = {"ENVIRONMENT": "gcp", "TOKEN_RESOURCE": "<audience>"}
55
client = MongoClient(
66
"mongodb://<hostname>:<port>",
7-
username="<GCP identity client ID>",
87
authMechanism="MONGODB-OIDC",
98
authMechanismProperties=properties
109
)

source/security/enterprise-authentication.txt

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,9 @@ The following sections describe how to use the MONGODB-OIDC authentication mecha
211211
authenticate to various platforms.
212212

213213
For more information about the MONGODB-OIDC authentication mechanism, see
214-
:manual:`OpenID Connect Authentication </core/security-oidc/>` in the MongoDB Server
215-
manual.
214+
:manual:`OpenID Connect Authentication </core/security-oidc/>` and
215+
:manual:`MongoDB Server Parameters </reference/parameters/#mongodb-parameter-param.oidcIdentityProviders>`
216+
in the MongoDB Server manual.
216217

217218
.. _pymongo-mongodb-oidc-azure-imds:
218219

@@ -233,9 +234,11 @@ You can configure OIDC for Azure IMDS in two ways: by passing arguments to the
233234
:tabid: mongoclient
234235

235236
First, create a Python dictionary for your authentication mechanism properties, as shown
236-
in the following example. Replace the ``<audience>`` placeholder with
237-
the percent-encoded audience configured on your MongoDB deployment.
238-
237+
in the following example. Replace the ``<audience>`` placeholder with the
238+
value of the ``audience`` parameter configured on your MongoDB deployment.
239+
240+
The following code example shows how to set these options in your connection string:
241+
239242
.. literalinclude:: /includes/authentication/azure-imds-mongoclient.py
240243
:language: python
241244
:copyable: true
@@ -268,12 +271,12 @@ You can configure OIDC for Azure IMDS in two ways: by passing arguments to the
268271
of the managed identity. If you're using a service principal to represent an
269272
enterprise application, set this to the application ID of the service principal.
270273
- ``authMechanism``: Set to ``MONGODB-OIDC``.
271-
- ``authMechanismProperties``: Set to ``ENVIRONMENT:azure,TOKEN_RESOURCE:<audience>``.
272-
Replace the ``<audience>`` placeholder with the audience
273-
configured on your MongoDB deployment. You must percent-encode the audience value
274-
if it contains a comma (``,``), plus sign (``+``), or ampersand (``&``).
275-
276-
The following code example shows how to set these options in your connection string:
274+
- ``authMechanismProperties``: Set to
275+
``ENVIRONMENT:azure,TOKEN_RESOURCE:<percent-encoded audience>``.
276+
Replace the ``<percent-encoded audience>`` placeholder with the percent-encoded
277+
value of the ``audience`` parameter configured on your MongoDB deployment.
278+
279+
The following code example shows how to set these options in your connection string:
277280

278281
.. literalinclude:: /includes/authentication/azure-imds-connection-string.py
279282
:language: python
@@ -305,7 +308,7 @@ You can configure OIDC for GCP IMDS in two ways: by passing arguments to the
305308

306309
First, create a Python dictionary for your authentication mechanism properties, as shown
307310
in the following example. Replace the ``<audience>`` placeholder with
308-
the percent-encoded audience configured on your MongoDB deployment.
311+
the value of the ``audience`` parameter configured on your MongoDB deployment.
309312

310313
.. literalinclude:: /includes/authentication/gcp-imds-mongoclient.py
311314
:language: python
@@ -315,7 +318,6 @@ You can configure OIDC for GCP IMDS in two ways: by passing arguments to the
315318

316319
Then, set the following connection options:
317320

318-
- ``username``: The client ID of the GCP managed identity.
319321
- ``authMechanism``: Set to ``"MONGODB-OIDC"``.
320322
- ``authMechanismProperties``: Set to the ``properties`` dictionary that you
321323
created in the previous step.
@@ -326,26 +328,25 @@ You can configure OIDC for GCP IMDS in two ways: by passing arguments to the
326328
.. literalinclude:: /includes/authentication/gcp-imds-mongoclient.py
327329
:language: python
328330
:copyable: true
329-
:emphasize-lines: 5-10
331+
:emphasize-lines: 5-9
330332

331333
.. tab:: Connection String
332334
:tabid: connectionstring
333335

334336
Include the following connection options in your connection string:
335337

336-
- ``username``: The client ID of the GCP managed identity.
337338
- ``authMechanism``: Set to ``MONGODB-OIDC``.
338-
- ``authMechanismProperties``: Set to ``ENVIRONMENT:gcp,TOKEN_RESOURCE:<audience>``.
339-
Replace the ``<audience>`` placeholder with the audience
340-
configured on your MongoDB deployment. You must percent-encode the audience value
341-
if it contains a comma (``,``), plus sign (``+``), or ampersand (``&``).
339+
- ``authMechanismProperties``: Set to
340+
``ENVIRONMENT:gcp,TOKEN_RESOURCE:<percent-encoded audience>``.
341+
Replace the ``<percent-encoded audience>`` placeholder with the percent-encoded
342+
value of the ``audience`` parameter configured on your MongoDB deployment.
342343

343344
The following code example shows how to set these options in your connection string:
344345

345346
.. literalinclude:: /includes/authentication/gcp-imds-connection-string.py
346347
:language: python
347348
:copyable: true
348-
:emphasize-lines: 4-7
349+
:emphasize-lines: 4-6
349350

350351
.. _pymongo-mongodb-oidc-azure-envs:
351352

0 commit comments

Comments
 (0)