Skip to content

Commit 9dc18b0

Browse files
author
Chris Cho
authored
Merge pull request #44 from ccho-mongodb/DOCSP-13488-mongodb-aws-updates
DOCSP-13488: mongodb aws updates
2 parents 433771f + 2ef8c5a commit 9dc18b0

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-6
lines changed

source/fundamentals/auth.txt

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -281,12 +281,38 @@ mechanism:
281281

282282
.. include:: /includes/fundamentals/code-snippets/auth-credentials-aws.rst
283283

284-
If you need to specify an AWS session token, use the
285-
:java-docs:`applyConnectionString() </apidocs/mongodb-driver-core/com/mongodb/MongoClientSettings.Builder.html#applyConnectionString(com.mongodb.ConnectionString)>`
286-
method to specify a connection string that specifies the
287-
``authMechanism`` and ``AWS_SESSION_TOKEN`` parameter values.
284+
If you need to specify an AWS session token, you can add it using
285+
one of the following choices:
288286

289-
.. include:: /includes/fundamentals/code-snippets/auth-credentials-aws-session.rst
287+
- **Specify your AWS session token in a connection string.**
288+
289+
If you prefer to pass the AWS session token in the connection string
290+
alongside your MongoCredential specify your authentication mechanism
291+
in the ``authMechanism`` parameter and your session token in the
292+
``authMechanismProperties`` parameter. Then, add it to your
293+
``MongoClientSettings`` by calling the
294+
:java-docs:`applyConnectionString() </apidocs/mongodb-driver-core/com/mongodb/MongoClientSettings.Builder.html#applyConnectionString(com.mongodb.ConnectionString)>`
295+
method as follows:
296+
297+
.. include:: /includes/fundamentals/code-snippets/auth-credentials-aws-session.rst
298+
299+
- **Specify your AWS session token in a MongoCredential.**
300+
301+
You can include your AWS session token in your ``MongoCredential``
302+
instance by specifying it in a call to the
303+
:java-docs:`withMechanismProperty() </apidocs/mongodb-driver-core/com/mongodb/MongoCredential.html#withMechanismProperty(java.lang.String,T)>`
304+
method as shown below:
305+
306+
.. code-block:: java
307+
308+
MongoCredential.createAwsCredential("<username>", "<password>".toCharArray()) .withMechanismProperty("AWS_SESSION_TOKEN", "<awsSessionToken>");
309+
310+
- **Specify your AWS session token in an environment variable.**
311+
312+
In your client execution environment, set an environment variable
313+
called ``AWS_SESSION_TOKEN`` and assign your token to it. The value is
314+
automatically picked up by your MongoClient when you specify the
315+
``MONGODB-AWS`` authentication mechanism.
290316

291317
.. _x509-auth-mechanism:
292318

source/includes/fundamentals/code-snippets/auth-credentials-aws-session.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.. code-block:: java
22
33
MongoCredential credential = MongoCredential.createAwsCredential("<username>", "<password>");
4-
String connectionString = "mongodb://<hostname>:<port>/?authSource=<authenticationDb>&authMechanism=MONGODB-AWS&AWS_SESSION_TOKEN:<awsSessionToken>");
4+
String connectionString = "mongodb://<hostname>:<port>/?authSource=<authenticationDb>&authMechanism=MONGODB-AWS&authMechanismProperties=AWS_SESSION_TOKEN:<awsSessionToken>");
55
66
MongoClient mongoClient = MongoClients.create(
77
MongoClientSettings.builder()

0 commit comments

Comments
 (0)