Skip to content

DOCSP-13829 authentication mechanism #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Aug 16, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions source/fundamentals/auth.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ The Go Driver establishes a connection with an authentication mechanism
through a `Client <https://pkg.go.dev/go.mongodb.org/[email protected]/mongo#Client>`__
type. The ``Client`` type specifies the mechanism and credentials to use
as connection options in a `Credential <https://pkg.go.dev/go.mongodb.org/[email protected]/mongo/options#Credential>`__
type . To configure these options, pass a ``Credential`` type to a `ClientOptions
<https://pkg.go.dev/go.mongodb.org/[email protected]/mongo/options#ClientOptions>`__
type . To configure these options, pass a ``Credential`` type to the
`SetAuth() <https://pkg.go.dev/go.mongodb.org/[email protected]/mongo/options#ClientOptions.SetAuth>`__
function of the `ClientOptions <https://pkg.go.dev/go.mongodb.org/[email protected]/mongo/options#ClientOptions>`__
type.

The following sections demonstrate this process with the five
Expand Down Expand Up @@ -72,7 +73,7 @@ mechanisms depending on what MongoDB versions your server supports:
- MongoDB 3.0, 3.2, 3.4, and 3.6

* - ``MONGODB-CR``
- MongoDB 3.6 and earlier
- MongoDB 3.6 and earlier if the server doesn't support``SCRAM-SHA-1``
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still isn't correct. This table is for the default it looks like. MongoDB 3.0 changed the default from MongoDB-CR to SCRAM-*.


To specify the default authentication mechanism, omit the
``AuthMechanism`` option:
Expand Down Expand Up @@ -106,7 +107,7 @@ see the :manual:`SCRAM </core/security-scram/>` section of the server manual.
algorithm, to authenticate your user.

To specify the ``SCRAM-SHA-256`` authentication mechanism, assign the
``AuthMechanism`` option the value ``SCRAM-SHA-256``:
``AuthMechanism`` option the value ``"SCRAM-SHA-256"``:

.. code-block:: go
:emphasize-lines: 2
Expand Down Expand Up @@ -137,16 +138,16 @@ username and password, encrypted with the ``SHA-1`` algorithm, to authenticate
your user.

To specify the ``SCRAM-SHA-1`` authentication mechanism, assign the
``AuthMechanism`` option the value ``SCRAM-SHA-1``:
``AuthMechanism`` option the value ``"SCRAM-SHA-1"``:

.. code-block:: go
:emphasize-lines: 2

credential := options.Credential{
AuthMechanism: "SCRAM-SHA-1",
AuthSource: "<authenticationDb>",
Username: "<username>",
Password: "<password>",
Username: "<username>",
Password: "<password>",
}
clientOpts := options.Client().ApplyURI("mongodb://<hostname>:<port>").
SetAuth(credential)
Expand Down Expand Up @@ -191,8 +192,8 @@ following:
awsCredential := options.Credential{
AuthMechanism: "MONGODB-AWS",
AuthSource: "<authenticationDb>",
Username: accessKeyID,
Password: secretAccessKey,
Username: "<accessKeyID>",
Password: "<secretAccessKey>",
}
awsIAMClient, err := mongo.Connect(
context.TODO(),
Expand All @@ -215,10 +216,10 @@ option the value of your ``sessionToken``:
assumeRoleCredential := options.Credential{
AuthMechanism: "MONGODB-AWS",
AuthSource: "<authenticationDb>",
Username: accessgKeyID,
Password: secretAccessKey,
Username: "<accessKeyID>",
Password: "<secretAccessKey>",
AuthMechanismProperties: map[string]string{
"AWS_SESSION_TOKEN": sessionToken,
"AWS_SESSION_TOKEN": "<sessionToken>",
},
}
assumeRoleClient, err := mongo.Connect(context.TODO(),
Expand All @@ -242,7 +243,7 @@ following:

- Assign the ``tlsCAFile`` the path to its file in the connection string
- Assign the ``tlsCertificateKeyFile`` the path to its file in the connection string
- Assign the ``AuthMechanism`` option the value ``X.509``
- Assign the ``AuthMechanism`` option the value ``"MONGODB-X509"``

.. code-block:: go
:emphasize-lines: 4-5, 7
Expand Down