Join us at MongoDB.local London on 7 May to unlock new possibilities for your data. Use WEB50 to save 50%.
Register now >
Docs Menu
Docs Home
/ /

Kerberos (GSSAPI)

The Generic Security Services API (GSSAPI) authentication mechanism allows you to authenticate to a Kerberos service by using your principal name.

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

The code examples on this page use the following placeholders:

  • <username>: Your URL-encoded principal name

  • <password>: Your Kerberos password

To use the code examples on this page, replace these placeholders with your own values.

To specify the GSSAPI authentication mechanism, set the mechanism field of your Credential struct to AuthMechanism::Gssapi.

Optionally, you can specify authentication mechanism properties by setting the SERVICE_REALM, SERVICE_NAME, and SERVICE_HOST properties in the mechanism_properties field of your Credential struct.

The following code example shows how to authenticate by using Kerberos:

let gssapi_cred = Credential::builder()
.username("<username>".to_string())
.password("<password>".to_string())
.mechanism(AuthMechanism::Gssapi)
.mechanism_properties(
doc! { "SERVICE_REALM": "<service_realm>", "SERVICE_NAME": "<service_name>", "SERVICE_HOST": "<service_host>" }
)
.build();
client_options.credential = Some(gssapi_cred);
let client = Client::with_options(client_options)?;

For more information about Kerberos authentication, see Kerberos Authentication in the MongoDB Server manual.

To learn more about the concepts in this guide, see the following documentation:

  • Specify Connection Options guide

  • Connection Strings in the MongoDB Server manual

To learn more about the methods and types mentioned in this guide, see the following API documentation:

Back

LDAP (PLAIN)

On this page