Skip to content

DOCSP-41990: Authentication mechanisms #139

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
70 changes: 70 additions & 0 deletions source/includes/authentication.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

require __DIR__ . '/../vendor/autoload.php';

// start-scram-sha-256-client
$uriOptions = [
'username' => '<username>',
'password' => '<password>',
'authSource' => '<authentication database>',
'authMechanism' => 'SCRAM-SHA-256',
];

$client = new MongoDB\Client(
'mongodb://<hostname>:<port>',
$uriOptions,
);
// end-scram-sha-256-client

// start-scram-sha-256-uri
$uri = 'mongodb://<username>:<password>@<hostname>:<port>/?authSource=admin&authMechanism=SCRAM-SHA-256';
$client = new MongoDB\Client($uri);
// end-scram-sha-256-uri

// start-mongodb-X509-client
$uriOptions = [
'tls' => true,
'tlsCertificateKeyFile' => '<file path>',
'authMechanism' => 'MONGODB-X509',
];

$client = new MongoDB\Client(
'mongodb://<hostname>:<port>',
$uriOptions,
);
// end-mongodb-X509-client

// start-mongodb-X509-uri
$uri = 'mongodb://<hostname>:<port>/?tls=true&tlsCertificateKeyFile=<file path>&authMechanism=MONGODB-X509';
$client = new MongoDB\Client($uri);
// end-mongodb-X509-uri

// start-mongodb-aws-client
$uriOptions = [
'username' => '<AWS IAM access key ID>',
'password' => '<AWS IAM secret access key>',
'authMechanism' => 'MONGODB-AWS',
];

$client = new MongoDB\Client(
'mongodb://<hostname>:<port>',
$uriOptions,
);
// end-mongodb-aws-client

// start-mongodb-aws-uri
$uri = 'mongodb://<AWS IAM access key ID>:<AWS IAM secret access key>@<hostname>:<port>/?authMechanism=MONGODB-AWS';
$client = new MongoDB\Client($uri);
// end-mongodb-aws-uri

// start-mongodb-aws-env-client
$client = new MongoDB\Client(
'mongodb://<hostname>:<port>',
['authMechanism' => 'MONGODB-AWS']
);
// end-mongodb-aws-env-client

// start-mongodb-aws-env-uri
$uri = 'mongodb://<hostname>:<port>/?authMechanism=MONGODB-AWS';
$client = new MongoDB\Client($uri);
// end-mongodb-aws-env-uri
3 changes: 2 additions & 1 deletion source/security.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ Secure Your Data
:titlesonly:
:maxdepth: 1

/security/in-use-encryption
/security/authentication
/security/in-use-encryption
Loading
Loading