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
/ /

SCRAM

SCRAM(Salted Challenge Response Authentication Mechanism) は、ユーザー名とパスワードを使用してサーバーに認証する認証メカニズムのファミリーです。

Rustドライバーは、次の SCRAM ベースの認証メカニズムをサポートしています。

  • SCRAM-SHA-:256 SHA-256アルゴリズムで暗号化されたデータベースのユーザー名とパスワードを使用する認証メカニズム。これはデフォルトの認証メカニズムです。

  • SCRAM-SHA-1 : SHA-1アルゴリズムで暗号化されたデータベースのユーザー名とパスワードを使用する認証メカニズム。

SCRAM を使用して、 MongoDB Atlas、 MongoDB Enterprise Advanced、 MongoDB Community Edition を認証できます。

Tip

SCRAM メカニズム

SCRAM ファミリーの認証メカニズムの詳細については、 Wikipedia の RFC5802 および Salted Challenge Response Authentication Mechanism を参照してください。

MongoDBの SCRAM実装の詳細については、 MongoDB Serverマニュアルの「 SCRAM 」を参照してください。

このページのコード例では、次のプレースホルダーを使用します。

  • db_username: データベースのユーザー名

  • db_password: データベースのパスワード

  • db: ユーザーに関連付けられた認証データベース

SCRAM-SHA-256 はデフォルトの認証メカニズムであるため、このメカニズムを使用するために Credential 構造体をインスタンス化するときに mechanismフィールドを省略できます。

次の例では、デフォルトの認証メカニズムを指定します。

let uri = "<connection string>";
let mut client_options = ClientOptions::parse(uri).await?;
let default_cred = Credential::builder()
.username("<db_username>".to_string())
.password("<db_password>".to_string())
.source("<db>".to_string())
.build();
client_options.credential = Some(default_cred);
let client = Client::with_options(client_options)?;

SCRAM-SHA-256認証メカニズム を明示的に指定するには、Credential 構造体の mechanismフィールドをAuthMechanism::ScramSha256 に設定します。

let uri = "<connection string>";
let mut client_options = ClientOptions::parse(uri).await?;
let scram_sha_256_cred = Credential::builder()
.username("<db_username>".to_string())
.password("<db_password>".to_string())
.mechanism(AuthMechanism::ScramSha256)
.source("<db>".to_string())
.build();
client_options.credential = Some(scram_sha_256_cred);
let client = Client::with_options(client_options)?;

SCRAM-SHA-1認証メカニズムを指定するには、Credential 構造体の mechanismフィールドをAuthMechanism::ScramSha1 に設定します。

let uri = "<connection string>";
let mut client_options = ClientOptions::parse(uri).await?;
let scram_sha_1_cred = Credential::builder()
.username("<db_username>".to_string())
.password("<db_password>".to_string())
.mechanism(AuthMechanism::ScramSha1)
.source("<db>".to_string())
.build();
client_options.credential = Some(scram_sha_1_cred);
let client = Client::with_options(client_options)?;

MongoDB への認証の詳細については、サーバー マニュアルの認証を参照してください。

MongoDB 配置のユーザー管理の詳細については、サーバー マニュアルの「ユーザー」を参照してください。

このガイドで言及されているメソッドとタイプの詳細については、次のAPIドキュメントを参照してください。

戻る

認証

項目一覧