Docs Menu
Docs Home
/ / /
Go Driver
/ /

LDAP (PLAIN) Authentication Mechanism

The PLAIN authentication mechanism allows you to use your Lightweight Directory Access Protocol (LDAP) username and password to authenticate to MongoDB. LDAP authentication uses the PLAIN Simple Authentication and Security Layer (SASL) defined in RFC-4616.

You can use this mechanism only when authenticating to MongoDB Atlas or MongoDB Enterprise Advanced.

The code examples on this page use the following placeholders:

  • ldap_username: Your LDAP username

  • password: Your LDAP password

  • connection_uri: Your connection string URI

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

Warning

This authentication mechanism sends the password to the server in plaintext, so use this mechanism only with TLS connections.

The following code shows how you can define a Credential struct to authenticate to LDAP and create a client with your authentication preferences:

credential := options.Credential{
AuthMechanism: "PLAIN",
Username: "<ldap_username>",
Password: "<password>",
}
uri := "<connection_uri>"
clientOpts := options.Client().ApplyURI(uri).SetAuth(credential)
client, err := mongo.Connect(clientOpts)

You can alternatively authenticate using a connection string URI, specifying your LDAP username, password, and hostname, the network address of your MongoDB server:

uri := "mongodb://<ldap_username>:<password>@<hostname>/?authMechanism=PLAIN"

Note

The method refers to PLAIN instead of LDAP since it authenticates using the PLAIN Simple Authentication and Security Layer (SASL) defined in RFC-4616.

To learn more about any of the methods or types discussed on this page, see the following API documentation:

Back

OIDC

On this page