Join us Sept 17 at .local NYC! Use code WEB50 to save 50% on tickets. Learn more >
MongoDB Event
Docs Menu
Docs Home
/ / /
Go Driver
/ /

SCRAM 認証メカニズム

Salted Challenge Response Authentication Mechanism(SCRAM)は、チャレンジ レスポンス メカニズムを使用してユーザーを認証する認証メカニズムのファミリーです。SHA-256アルゴリズムを使用してパスワードをハッシュする SCRAM-SHA-256 は、デフォルトの認証メカニズムです。

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

Tip

SCRAM メカニズム

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

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

各認証メカニズムには、次のプレースホルダーが含まれています。

  • db_username - MongoDB database のユーザー名

  • db_password - MongoDB database ユーザーのパスワード

  • hostname - クライアントからアクセス可能な MongoDB Server のネットワーク アドレス

  • port - MongoDB Server のポート番号

  • authenticationDb - ユーザーの認証データを含む MongoDB database。このオプションを省略すると、ドライバーはデフォルト値の admin を使用します。

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

デフォルトの認証メカニズムを指定するには、AuthMechanism オプションを省略します。

credential := options.Credential{
AuthSource: "<authenticationDb>",
Username: "<db_username>",
Password: "<db_password>",
}
clientOpts := options.Client().ApplyURI("mongodb://<hostname>:<port>").
SetAuth(credential)
client, err := mongo.Connect(clientOpts)

SCRAM-SHA-256認証メカニズムを明示的に指定するには、AuthMechanismオプションに"SCRAM-SHA-256"という値を割り当てます。

credential := options.Credential{
AuthMechanism: "SCRAM-SHA-256",
AuthSource: "<authenticationDb>",
Username: "<db_username>",
Password: "<db_password>",
}
clientOpts := options.Client().ApplyURI("mongodb://<hostname>:<port>").
SetAuth(credential)
client, err := mongo.Connect(clientOpts)

このページで説明するメソッドやタイプの詳細については、次のAPIドキュメントを参照してください。

戻る

認証

項目一覧