Docs Menu

Docs HomeDevelop ApplicationsMongoDB DriversC#/.NET

Enterprise Authentication Mechanisms

On this page

  • Overview
  • Authenticate with GSSAPI/Kerberos
  • Additional Properties
  • Authenticate with LDAP (PLAIN)
  • API Documentation

In this guide, you can learn how to authenticate with MongoDB using the authentication mechanisms available only in the MongoDB Enterprise Edition. Authentication mechanisms are processes by which the driver and server confirm the identity of a client to ensure security before connecting.

You can use the following authentication mechanisms with the latest version of MongoDB Enterprise Edition.

  • GSSAPI/Kerberos

  • LDAP (Plain)

To authenticate using another mechanism, see the Authentication Mechanisms fundamentals page. For more information on establishing a connection to your MongoDB cluster, see the Connection Guide.

You can specify your authentication mechanism and credentials when connecting to MongoDB using either of the following methods:

  • A connection string, also known as a connection URI, which is a string that tells the driver how to connect to a MongoDB deployment and how to behave while connected.

  • A factory method for the supported authentication mechanism, contained in the MongoCredential class.

The Generic Security Services API (GSSAPI) authentication mechanism allows the user to authenticate to a Kerberos service using the user's principal name.

The following examples specify the authentication mechanism using the following placeholders:

  • <username>: Your URL-encoded principal name; for example "username%40REALM.ME"

  • <password>: Your Kerberos user's password

  • <hostname>: The network address of your MongoDB server, accessible by your client

Select the Connection String or MongoCredential tab to see the corresponding syntax for specifying the GSSAPI/Kerberos authentication mechanism:

Tip

Omitting the Password

You can omit the password if one of the following are true:

  • On Windows, the process owner running the application is the same as the user needing authentication.

  • On Linux, the user has initialized their keytab via kinit username@REALM.COM.

You can specify additional properties with your authentication mechanism using the connection string or a factory method in the MongoCredential class.

The following example shows how to use the DNS server to retrieve the fully qualified domain name of the host:

The following example shows how to specify the user's realm when it is different from the service's realm:

The following example shows how to specify the service name when it is not the default mongodb:

The following example shows how to specify multiple authentication mechanism properties:

You can authenticate to a Lightweight Directory Access Protocol (LDAP) server using your directory-server username and password.

The following examples specify the authentication mechanism using the following placeholders:

  • <username>: Your LDAP username

  • <password>: Your LDAP password

  • <hostname>: The network address of your MongoDB server, accessible by your client

  • <authenticationDb>: The MongoDB database that contains your user's authentication

Select the Connection String or MongoCredential tab to see the corresponding syntax for specifying the LDAP authentication mechanism:

To learn more about any of the methods or types discussed in this guide, see the following API Documentation:

← Authentication Mechanisms
LINQ →