Skip to content

Commit 3bb2cb7

Browse files
authored
DOCSP-41990: Authentication mechanisms (#139)
* DOCSP-41990: Authentication mechanisms * client tabs * edits * edits * add info * reduce repetition * add section * fix link * MW feedback * fix * JM most feedback * move to code file * more JM edits * JM feedback 2
1 parent 855563c commit 3bb2cb7

File tree

3 files changed

+462
-1
lines changed

3 files changed

+462
-1
lines changed

source/includes/authentication.php

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
3+
require __DIR__ . '/../vendor/autoload.php';
4+
5+
// start-scram-sha-256-client
6+
$uriOptions = [
7+
'username' => '<username>',
8+
'password' => '<password>',
9+
'authSource' => '<authentication database>',
10+
'authMechanism' => 'SCRAM-SHA-256',
11+
];
12+
13+
$client = new MongoDB\Client(
14+
'mongodb://<hostname>:<port>',
15+
$uriOptions,
16+
);
17+
// end-scram-sha-256-client
18+
19+
// start-scram-sha-256-uri
20+
$uri = 'mongodb://<username>:<password>@<hostname>:<port>/?authSource=admin&authMechanism=SCRAM-SHA-256';
21+
$client = new MongoDB\Client($uri);
22+
// end-scram-sha-256-uri
23+
24+
// start-mongodb-X509-client
25+
$uriOptions = [
26+
'tls' => true,
27+
'tlsCertificateKeyFile' => '<file path>',
28+
'authMechanism' => 'MONGODB-X509',
29+
];
30+
31+
$client = new MongoDB\Client(
32+
'mongodb://<hostname>:<port>',
33+
$uriOptions,
34+
);
35+
// end-mongodb-X509-client
36+
37+
// start-mongodb-X509-uri
38+
$uri = 'mongodb://<hostname>:<port>/?tls=true&tlsCertificateKeyFile=<file path>&authMechanism=MONGODB-X509';
39+
$client = new MongoDB\Client($uri);
40+
// end-mongodb-X509-uri
41+
42+
// start-mongodb-aws-client
43+
$uriOptions = [
44+
'username' => '<AWS IAM access key ID>',
45+
'password' => '<AWS IAM secret access key>',
46+
'authMechanism' => 'MONGODB-AWS',
47+
];
48+
49+
$client = new MongoDB\Client(
50+
'mongodb://<hostname>:<port>',
51+
$uriOptions,
52+
);
53+
// end-mongodb-aws-client
54+
55+
// start-mongodb-aws-uri
56+
$uri = 'mongodb://<AWS IAM access key ID>:<AWS IAM secret access key>@<hostname>:<port>/?authMechanism=MONGODB-AWS';
57+
$client = new MongoDB\Client($uri);
58+
// end-mongodb-aws-uri
59+
60+
// start-mongodb-aws-env-client
61+
$client = new MongoDB\Client(
62+
'mongodb://<hostname>:<port>',
63+
['authMechanism' => 'MONGODB-AWS']
64+
);
65+
// end-mongodb-aws-env-client
66+
67+
// start-mongodb-aws-env-uri
68+
$uri = 'mongodb://<hostname>:<port>/?authMechanism=MONGODB-AWS';
69+
$client = new MongoDB\Client($uri);
70+
// end-mongodb-aws-env-uri

source/security.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ Secure Your Data
88
:titlesonly:
99
:maxdepth: 1
1010

11-
/security/in-use-encryption
11+
/security/authentication
12+
/security/in-use-encryption

0 commit comments

Comments
 (0)