Skip to content

Commit 286d77c

Browse files
committed
includes
1 parent a97dcdf commit 286d77c

File tree

2 files changed

+32
-20
lines changed

2 files changed

+32
-20
lines changed

source/includes/security/enterprise-auth.kt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,28 @@ val mongoClient = MongoClient.create(
121121
.build())
122122
// end-oidc-gcp-mongo-cred
123123

124+
// start-oidc-k8s-connect-str
125+
val connectionString = ConnectionString(
126+
"mongodb://<OIDC principal>@<hostname>:<port>/?" +
127+
"authMechanism=MONGODB-OIDC" +
128+
"&authMechanismProperties=ENVIRONMENT:k8s,TOKEN_RESOURCE:<percent-encoded audience>")
129+
val mongoClient = MongoClient.create(connectionString)
130+
// end-oidc-k8s-connect-str
131+
132+
// start-oidc-k8s-mongo-cred
133+
val credential = MongoCredential.createOidcCredential("<OIDC principal>")
134+
.withMechanismProperty("ENVIRONMENT", "k8s")
135+
.withMechanismProperty("TOKEN_RESOURCE", "<audience>")
136+
137+
val mongoClient = MongoClient.create(
138+
MongoClientSettings.builder()
139+
.applyToClusterSettings { builder ->
140+
builder.hosts(listOf(ServerAddress("<hostname>", <port>)))
141+
}
142+
.credential(credential)
143+
.build())
144+
// end-oidc-k8s-mongo-cred
145+
124146
// start-oidc-custom-callback
125147
val credential = MongoCredential.createOidcCredential(null)
126148
.withMechanismProperty("OIDC_CALLBACK") { context: Context ->

source/security/enterprise-auth.txt

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -445,13 +445,11 @@ Select from the :guilabel:`Connection String` or
445445
following code with the percent-encoded value of the audience server
446446
parameter configured on your MongoDB deployment.
447447

448-
.. code-block:: kotlin
449-
450-
val connectionString = ConnectionString(
451-
"mongodb://<OIDC principal>@<hostname>:<port>/?" +
452-
"authMechanism=MONGODB-OIDC" +
453-
"&authMechanismProperties=ENVIRONMENT:k8s,TOKEN_RESOURCE:<percent-encoded audience>")
454-
val mongoClient = MongoClient.create(connectionString)
448+
.. literalinclude:: /includes/security/enterprise-auth.kt
449+
:language: kotlin
450+
:dedent:
451+
:start-after: start-oidc-k8s-connect-str
452+
:end-before: end-oidc-k8s-connect-str
455453

456454
.. tab:: MongoCredential
457455
:tabid: mongodb-kubernetes-mongo-credential
@@ -461,19 +459,11 @@ Select from the :guilabel:`Connection String` or
461459
``<audience>`` placeholder with the value of the ``audience``
462460
server parameter configured on your MongoDB deployment.
463461

464-
.. code-block:: kotlin
465-
466-
val credential = MongoCredential.createOidcCredential("<OIDC principal>")
467-
.withMechanismProperty("ENVIRONMENT", "k8s")
468-
.withMechanismProperty("TOKEN_RESOURCE", "<audience>")
469-
470-
val mongoClient = MongoClient.create(
471-
MongoClientSettings.builder()
472-
.applyToClusterSettings { builder ->
473-
builder.hosts(listOf(ServerAddress("<hostname>", <port>)))
474-
}
475-
.credential(credential)
476-
.build())
462+
.. literalinclude:: /includes/security/enterprise-auth.kt
463+
:language: kotlin
464+
:dedent:
465+
:start-after: start-oidc-k8s-mongo-cred
466+
:end-before: end-oidc-k8s-mongo-cred
477467

478468
Custom Callback
479469
~~~~~~~~~~~~~~~

0 commit comments

Comments
 (0)