@@ -323,6 +323,56 @@ see the corresponding syntax.
323
323
.WithMechanismProperty("TOKEN_RESOURCE", "<audience>");
324
324
var client = new MongoClient(mongoClientSettings);
325
325
326
+ .. _csharp-mongodb-oidc-gcp-imds:
327
+
328
+ GCP IMDS
329
+ ~~~~~~~~
330
+
331
+ If your application runs on a Google Compute Engine VM, or otherwise uses the
332
+ `GCP Instance Metadata Service <https://cloud.google.com/compute/docs/metadata/querying-metadata>`__,
333
+ you can authenticate to MongoDB by using the {+driver-short+}'s built-in GCP
334
+ support.
335
+
336
+ You can specify GCP IMDS OIDC authentication on a ``MongoClientSettings`` object either by
337
+ using a ``MongoCredential`` object or as part of the connection string. Select the
338
+ :guilabel:`Connection String` or :guilabel:`MongoCredential` tab to
339
+ see the corresponding syntax.
340
+
341
+ .. tabs::
342
+
343
+ .. tab:: Connection String
344
+ :tabid: mongodb-gcp-imds-connection-string
345
+
346
+ The following code example shows how to specify GCP IMDS OIDC authentication as
347
+ part of the authentication string.
348
+ Replace the ``<audience>`` placeholder with the
349
+ value of the ``audience`` parameter configured on your MongoDB deployment.
350
+
351
+ .. code-block:: csharp
352
+
353
+ var connectionString = "mongodb://<hostname>[:<port>]/?" +
354
+ "authMechanism=MONGODB-OIDC" +
355
+ "&authMechanismProperties=ENVIRONMENT:gcp,TOKEN_RESOURCE:<audience>");
356
+ var mongoClientSettings = MongoClientSettings.FromConnectionString(connectionString);
357
+ var client = new MongoClient(mongoClientSettings);
358
+
359
+ .. tab:: MongoCredential
360
+ :tabid: mongodb-gcp-mongo-credential
361
+
362
+ The following code example shows how to specify GCP IMDS OIDC authentication by using
363
+ a ``MongoCredential`` object.
364
+ Replace the ``<audience>``
365
+ placeholder with the value of the ``audience`` parameter configured on your MongoDB
366
+ deployment.
367
+
368
+ .. code-block:: csharp
369
+
370
+ var mongoClientSettings = MongoClientSettings.FromConnectionString(
371
+ "mongodb+srv://<hostname>[:<port>]");
372
+ mongoClientSettings.Credential = MongoCredential.CreateOidcCredential("gcp")
373
+ .WithMechanismProperty("TOKEN_RESOURCE", "<audience>");
374
+ var client = new MongoClient(mongoClientSettings);
375
+
326
376
Custom Callback
327
377
~~~~~~~~~~~~~~~
328
378
0 commit comments