@@ -56,14 +56,36 @@ To authenticate with this mechanism, set the following connection options:
56
56
- ``authSource``: The MongoDB database to authenticate against. By default, the
57
57
{+php-library+} authenticates against the database in the connection
58
58
URI, if you include one. If you don't, it authenticates against the ``admin`` database.
59
- - ``authMechanism``: Set to ``'SCRAM-SHA-256'``. When connected to {+mdb-server+} v4.0,
60
- setting ``authMechanism`` is optional.
61
59
62
60
You can set these options in two ways: by passing an options array to the
63
61
``MongoDB\Client`` constructor or through parameters in your connection URI.
64
62
Select the :guilabel:`MongoDB\\Client` or :guilabel:`Connection URI` tab to
65
63
see the corresponding code:
66
64
65
+ .. tabs::
66
+
67
+ .. tab:: MongoDB\\Client
68
+ :tabid: Client
69
+
70
+ .. literalinclude:: /includes/authentication.php
71
+ :language: php
72
+ :dedent:
73
+ :start-after: start-default-client
74
+ :end-before: end-default-client
75
+
76
+ .. tab:: Connection URI
77
+ :tabid: connectionstring
78
+
79
+ .. literalinclude:: /includes/authentication.php
80
+ :language: php
81
+ :dedent:
82
+ :start-after: start-default-uri
83
+ :end-before: end-default-uri
84
+
85
+ You can also explicitly specify the ``SCRAM-SHA-256`` authentication mechanism
86
+ by setting the ``authMechanism`` connection option to ``'SCRAM-SHA-256'``, as
87
+ shown in the following example:
88
+
67
89
.. tabs::
68
90
69
91
.. tab:: MongoDB\\Client
@@ -89,18 +111,46 @@ see the corresponding code:
89
111
SCRAM-SHA-1
90
112
-----------
91
113
92
- SCRAM-SHA-1, as defined by `RFC 5802 <https://www.rfc-editor.org/rfc/rfc5802>`__,
93
- is the default authentication mechanism on MongoDB deployments
94
- running {+mdb-server+} v3.6.
114
+ ``SCRAM-SHA-1``, as defined by `RFC 5802 <https://www.rfc-editor.org/rfc/rfc5802>`__,
115
+ is a Salted Challenge Response Authentication Mechanism (SCRAM) that uses your
116
+ username and password, encrypted with the ``SHA-1`` algorithm, to authenticate
117
+ your user.
95
118
96
- .. note: :
119
+ To authenticate with this mechanism, set the following connection options :
97
120
98
- {+php-library+} v1.20 drops support for {+mdb-server+} v3.6. When using v1.20+ of
99
- the library, all supported server versions default to the SCRAM-SHA-256 authentication
100
- mechanism.
121
+ - ``username``: The username to authenticate. Percent-encode this value before including
122
+ it in a connection URI.
123
+ - ``password``: The password to authenticate. Percent-encode this value before including
124
+ it in a connection URI.
125
+ - ``authSource``: The MongoDB database to authenticate against. By default, the
126
+ {+php-library+} authenticates against the database in the connection
127
+ URI, if you include one. If you don't, it authenticates against the ``admin`` database.
128
+ - ``authMechanism``: Set to ``'SCRAM-SHA-1'``.
129
+
130
+ You can set these options in two ways: by passing an options array to the
131
+ ``MongoDB\Client`` constructor or through parameters in your connection URI.
132
+ Select the :guilabel:`MongoDB\\Client` or :guilabel:`Connection URI` tab to
133
+ see the corresponding code:
134
+
135
+ .. tabs::
136
+
137
+ .. tab:: MongoDB\\Client
138
+ :tabid: Client
139
+
140
+ .. literalinclude:: /includes/authentication.php
141
+ :language: php
142
+ :dedent:
143
+ :start-after: start-scram-sha-1-client
144
+ :end-before: end-scram-sha-1-client
101
145
102
- To authenticate with this mechanism, use the same syntax as the :ref:`php-scram-sha-256`,
103
- but change the value of the ``authMechanism`` option to ``'SCRAM-SHA-1'``.
146
+ .. tab:: Connection URI
147
+ :tabid: connectionstring
148
+
149
+ .. literalinclude:: /includes/authentication.php
150
+ :language: php
151
+ :dedent:
152
+ :start-after: start-scram-sha-1-uri
153
+ :end-before: end-scram-sha-1-uri
104
154
105
155
Additional Information
106
156
----------------------
0 commit comments