@@ -563,31 +563,34 @@ If your application runs on an Azure VM, or otherwise uses the
563563(IMDS), you can authenticate to MongoDB by using {+driver-short+}'s built-in Azure
564564support.
565565
566- First, create a Python dictionary for your authentication mechanism properties, as shown
567- in the following example. Replace the ``<audience>`` placeholder with
568- the percent-encoded application or service that the OIDC access token is intended for.
569-
570- .. literalinclude:: /includes/authentication/azure-imds-mongoclient.py
571- :language: python
572- :copyable: true
573- :start-after: # define properties and MongoClient
574- :end-before: client = MongoClient(
575-
576- Then, set the following connection options:
577-
578- - ``username``: The client ID of the Azure managed identity.
579- - ``authMechanism``: Set to ``"MONGODB-OIDC"``.
580- - ``authMechanismProperties``: Set to the ``properties`` dictionary that you
581- created in the previous step.
582-
583- You can set these options in two ways: by passing arguments to the
566+ You can configure OIDC for Azure IMDS in two ways: by passing arguments to the
584567``MongoClient`` constructor or through parameters in your connection string.
585568
586569.. tabs::
587570
588571 .. tab:: MongoClient
589572 :tabid: mongoclient
590573
574+ First, create a Python dictionary for your authentication mechanism properties, as shown
575+ in the following example. Replace the ``<audience>`` placeholder with
576+ the percent-encoded application or service that the OIDC access token is intended for.
577+
578+ .. literalinclude:: /includes/authentication/azure-imds-mongoclient.py
579+ :language: python
580+ :copyable: true
581+ :start-after: # define properties and MongoClient
582+ :end-before: client = MongoClient(
583+
584+ Then, set the following connection options:
585+
586+ - ``username``: The client ID of the Azure managed identity.
587+ - ``authMechanism``: Set to ``"MONGODB-OIDC"``.
588+ - ``authMechanismProperties``: Set to the ``properties`` dictionary that you
589+ created in the previous step.
590+
591+ The following code example shows how to set these options when creating a
592+ ``MongoClient``:
593+
591594 .. literalinclude:: /includes/authentication/azure-imds-mongoclient.py
592595 :language: python
593596 :copyable: true
@@ -596,10 +599,20 @@ You can set these options in two ways: by passing arguments to the
596599 .. tab:: Connection String
597600 :tabid: connectionstring
598601
602+ Include the following connection options in your connection string:
603+
604+ - ``username``: The client ID of the Azure managed identity.
605+ - ``authMechanism``: Set to ``MONGODB-OIDC``.
606+ - ``authMechanismProperties``: Set to ``environment:azure,token_resource:<audience>``.
607+ Replace the ``<audience>`` placeholder with the percent-encoded application or
608+ service that the OIDC access token is intended for.
609+
610+ The following code example shows how to set these options in your connection string:
611+
599612 .. literalinclude:: /includes/authentication/azure-imds-connection-string.py
600613 :language: python
601614 :copyable: true
602- :emphasize-lines: 5-8
615+ :emphasize-lines: 4-7
603616
604617.. tip::
605618
@@ -616,31 +629,34 @@ If your application runs on a GCP VM, or otherwise uses the
616629you can authenticate to MongoDB by using {+driver-short+}'s built-in GCP
617630support.
618631
619- First, create a Python dictionary for your authentication mechanism properties, as shown
620- in the following example. Replace the ``<audience>`` placeholder with
621- the percent-encoded application or service that the OIDC access token is intended for.
622-
623- .. literalinclude:: /includes/authentication/gcp-imds-mongoclient.py
624- :language: python
625- :copyable: true
626- :start-after: # define properties and MongoClient
627- :end-before: client = MongoClient(
628-
629- Then, set the following connection options:
630-
631- - ``username``: The client ID of the GCP managed identity.
632- - ``authMechanism``: Set to ``"MONGODB-OIDC"``.
633- - ``authMechanismProperties``: Set to the ``properties`` dictionary that you created
634- in the previous step.
635-
636- You can set these options in two ways: by passing arguments to the
632+ You can configure OIDC for GCP IMDS in two ways: by passing arguments to the
637633``MongoClient`` constructor or through parameters in your connection string.
638634
639635.. tabs::
640636
641637 .. tab:: MongoClient
642638 :tabid: mongoclient
643639
640+ First, create a Python dictionary for your authentication mechanism properties, as shown
641+ in the following example. Replace the ``<audience>`` placeholder with
642+ the percent-encoded application or service that the OIDC access token is intended for.
643+
644+ .. literalinclude:: /includes/authentication/gcp-imds-mongoclient.py
645+ :language: python
646+ :copyable: true
647+ :start-after: # define properties and MongoClient
648+ :end-before: client = MongoClient(
649+
650+ Then, set the following connection options:
651+
652+ - ``username``: The client ID of the GCP managed identity.
653+ - ``authMechanism``: Set to ``"MONGODB-OIDC"``.
654+ - ``authMechanismProperties``: Set to the ``properties`` dictionary that you
655+ created in the previous step.
656+
657+ The following code example shows how to set these options when creating a
658+ ``MongoClient``:
659+
644660 .. literalinclude:: /includes/authentication/gcp-imds-mongoclient.py
645661 :language: python
646662 :copyable: true
@@ -649,10 +665,20 @@ You can set these options in two ways: by passing arguments to the
649665 .. tab:: Connection String
650666 :tabid: connectionstring
651667
668+ Include the following connection options in your connection string:
669+
670+ - ``username``: The client ID of the GCP managed identity.
671+ - ``authMechanism``: Set to ``MONGODB-OIDC``.
672+ - ``authMechanismProperties``: Set to ``environment:gcp,token_resource:<audience>``.
673+ Replace the ``<audience>`` placeholder with the percent-encoded application or
674+ service that the OIDC access token is intended for.
675+
676+ The following code example shows how to set these options in your connection string:
677+
652678 .. literalinclude:: /includes/authentication/gcp-imds-connection-string.py
653679 :language: python
654680 :copyable: true
655- :emphasize-lines: 5-8
681+ :emphasize-lines: 4-7
656682
657683.. _pymongo-mongodb-oidc-azure-envs:
658684
@@ -694,32 +720,17 @@ After you define your callback class, create a Python dictionary that contains o
694720 :start-after: return OIDCCallbackResult(access_token=token)
695721 :end-before: client = MongoClient(
696722
697- Finally, set the following connection options:
723+ Finally, set the following connection options by passing arguments to the ``MongoClient``
724+ constructor:
698725
699726- ``authMechanism``: Set to ``"MONGODB-OIDC"``.
700727- ``authMechanismProperties``: Set to the ``properties`` dictionary that you created in the
701728 previous step.
702729
703- You can set these options in two ways: by passing arguments to the
704- ``MongoClient`` constructor or through parameters in your connection string.
705-
706- .. tabs::
707-
708- .. tab:: MongoClient
709- :tabid: mongoclient
710-
711- .. literalinclude:: /includes/authentication/azure-envs-mongoclient.py
712- :language: python
713- :copyable: true
714- :emphasize-lines: 14-18
715-
716- .. tab:: Connection String
717- :tabid: connectionstring
718-
719- .. literalinclude:: /includes/authentication/azure-envs-connection-string.py
720- :language: python
721- :copyable: true
722- :emphasize-lines: 14-16
730+ .. literalinclude:: /includes/authentication/azure-envs-mongoclient.py
731+ :language: python
732+ :copyable: true
733+ :emphasize-lines: 14-18
723734
724735.. _pymongo-mongodb-oidc-gcp-gke:
725736
@@ -753,32 +764,17 @@ After you define your callback class, create a Python dictionary that contains o
753764 :start-after: return OIDCCallbackResult(access_token=token)
754765 :end-before: client = MongoClient(
755766
756- Finally, set the following connection options:
767+ Finally, set the following connection options by passing arguments to the ``MongoClient``
768+ constructor:
757769
758770- ``authMechanism``: Set to ``"MONGODB-OIDC"``.
759771- ``authMechanismProperties``: Set to the ``properties`` dictionary that you created
760772 in the previous step.
761773
762- You can set these options in two ways: by passing arguments to the
763- ``MongoClient`` constructor or through parameters in your connection string.
764-
765- .. tabs::
766-
767- .. tab:: MongoClient
768- :tabid: mongoclient
769-
770- .. literalinclude:: /includes/authentication/gcp-gke-mongoclient.py
771- :language: python
772- :copyable: true
773- :emphasize-lines: 11-15
774-
775- .. tab:: Connection String
776- :tabid: connectionstring
777-
778- .. literalinclude:: /includes/authentication/gcp-gke-connection-string.py
779- :language: python
780- :copyable: true
781- :emphasize-lines: 11-13
774+ .. literalinclude:: /includes/authentication/gcp-gke-mongoclient.py
775+ :language: python
776+ :copyable: true
777+ :emphasize-lines: 11-15
782778
783779API Documentation
784780-----------------
0 commit comments