Skip to content

Commit 6860f90

Browse files
authored
Docs: Fix typos, add details in auth management features (#1054)
* Fix typos. * Improved cross references. * Completed version history of stabilized auth manager APIs. * Amend preview remark to some mTLS APIs that already emitted an preview warning, but weren't clearly marked as preview in the API docs. * Extend details around the static and basic auth provider implementations.
1 parent 25515b5 commit 6860f90

File tree

3 files changed

+57
-33
lines changed

3 files changed

+57
-33
lines changed

src/neo4j/_async/auth_management.py

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ class AsyncAuthManagers:
126126
def static(auth: _TAuth) -> AsyncAuthManager:
127127
"""Create a static auth manager.
128128
129+
The manager will always return the auth info provided at its creation.
130+
129131
Example::
130132
131133
# NOTE: this example is for illustration purposes only.
@@ -164,9 +166,13 @@ def basic(
164166
"""Create an auth manager handling basic auth password rotation.
165167
166168
This factory wraps the provider function in an auth manager
167-
implementation that caches the provides auth info until either the
168-
server notifies the driver that the auth info is expired (by returning
169-
an error that indicates that basic auth has changed).
169+
implementation that caches the provided auth info until the server
170+
notifies the driver that the auth info has expired (by returning
171+
an error that indicates that the password is invalid).
172+
173+
Note that this implies that the provider function will be called again
174+
if it provides wrong auth info, potentially deferring failure due to a
175+
wrong password or username.
170176
171177
.. warning::
172178
@@ -176,8 +182,8 @@ def basic(
176182
The provider function must only ever return auth information
177183
belonging to the same identity.
178184
Switching identities is undefined behavior.
179-
You may use session-level authentication for such use-cases
180-
:ref:`session-auth-ref`.
185+
You may use :ref:`session-level authentication<session-auth-ref>`
186+
for such use-cases.
181187
182188
Example::
183189
@@ -201,13 +207,13 @@ async def auth_provider():
201207
... # do stuff
202208
203209
:param provider:
204-
A callable that provides a :class:`.ExpiringAuth` instance.
210+
A callable that provides new auth info whenever the server notifies
211+
the driver that the previous auth info is invalid.
205212
206213
:returns:
207214
An instance of an implementation of :class:`.AsyncAuthManager` that
208215
returns auth info from the given provider and refreshes it, calling
209-
the provider again, when the auth info expires (because the server
210-
flagged it as expired).
216+
the provider again, when the auth info was rejected by the server.
211217
212218
.. versionadded:: 5.12
213219
@@ -227,9 +233,9 @@ def bearer(
227233
"""Create an auth manager for potentially expiring bearer auth tokens.
228234
229235
This factory wraps the provider function in an auth manager
230-
implementation that caches the provides auth info until either the
231-
:attr:`.ExpiringAuth.expires_at` is exceeded the server notifies the
232-
driver that the auth info is expired (by returning an error that
236+
implementation that caches the provided auth info until either the
237+
:attr:`.ExpiringAuth.expires_at` exceeded or the server notified the
238+
driver that the auth info has expired (by returning an error that
233239
indicates that the bearer auth token has expired).
234240
235241
.. warning::
@@ -240,8 +246,8 @@ def bearer(
240246
The provider function must only ever return auth information
241247
belonging to the same identity.
242248
Switching identities is undefined behavior.
243-
You may use session-level authentication for such use-cases
244-
:ref:`session-auth-ref`.
249+
You may use :ref:`session-level authentication<session-auth-ref>`
250+
for such use-cases.
245251
246252
Example::
247253
@@ -364,7 +370,6 @@ class AsyncRotatingClientCertificateProvider(AsyncClientCertificateProvider):
364370
:param initial_cert: The certificate to use initially.
365371
366372
.. versionadded:: 5.19
367-
368373
"""
369374
def __init__(self, initial_cert: ClientCertificate) -> None:
370375
self._cert: t.Optional[ClientCertificate] = initial_cert

src/neo4j/_auth_management.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ class AuthManager(metaclass=abc.ABCMeta):
113113
114114
The token returned must always belong to the same identity.
115115
Switching identities using the `AuthManager` is undefined behavior.
116-
You may use session-level authentication for such use-cases
117-
:ref:`session-auth-ref`.
116+
You may use :ref:`session-level authentication<session-auth-ref>`
117+
for such use-cases.
118118
119119
.. seealso:: :class:`.AuthManagers`
120120
@@ -123,9 +123,11 @@ class AuthManager(metaclass=abc.ABCMeta):
123123
.. versionchanged:: 5.12
124124
``on_auth_expired`` was removed from the interface and replaced by
125125
:meth:`handle_security_exception`. The new method is called when the
126-
server returns any `Neo.ClientError.Security.*` error. It's signature
126+
server returns any `Neo.ClientError.Security.*` error. Its signature
127127
differs in that it additionally receives the error returned by the
128128
server and returns a boolean indicating whether the error was handled.
129+
130+
.. versionchanged:: 5.14 Stabilized from preview.
129131
"""
130132

131133
@abc.abstractmethod
@@ -140,8 +142,8 @@ def get_auth(self) -> _TAuth:
140142
The method must only ever return auth information belonging to the
141143
same identity.
142144
Switching identities using the `AuthManager` is undefined behavior.
143-
You may use session-level authentication for such use-cases
144-
:ref:`session-auth-ref`.
145+
You may use :ref:`session-level authentication<session-auth-ref>`
146+
for such use-cases.
145147
"""
146148
...
147149

@@ -181,6 +183,8 @@ class AsyncAuthManager(_Protocol, metaclass=abc.ABCMeta):
181183
.. versionchanged:: 5.12
182184
``on_auth_expired`` was removed from the interface and replaced by
183185
:meth:`handle_security_exception`. See :class:`.AuthManager`.
186+
187+
.. versionchanged:: 5.14 Stabilized from preview.
184188
"""
185189

186190
@abc.abstractmethod
@@ -211,6 +215,11 @@ class ClientCertificate:
211215
The attributes are the same as the arguments to
212216
:meth:`ssl.SSLContext.load_cert_chain()`.
213217
218+
**This is a preview** (see :ref:`filter-warnings-ref`).
219+
It might be changed without following the deprecation policy.
220+
See also
221+
https://github.com/neo4j/neo4j-python-driver/wiki/preview-features
222+
214223
.. versionadded:: 5.19
215224
"""
216225
certfile: t.Union[str, bytes, PathLike[str], PathLike[bytes]]
@@ -248,6 +257,11 @@ class ClientCertificateProvider(_Protocol, metaclass=abc.ABCMeta):
248257
The provider **must not** interact with the driver in any way as this
249258
can cause deadlocks and undefined behaviour.
250259
260+
**This is a preview** (see :ref:`filter-warnings-ref`).
261+
It might be changed without following the deprecation policy.
262+
See also
263+
https://github.com/neo4j/neo4j-python-driver/wiki/preview-features
264+
251265
.. versionadded:: 5.19
252266
"""
253267

src/neo4j/_sync/auth_management.py

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ class AuthManagers:
126126
def static(auth: _TAuth) -> AuthManager:
127127
"""Create a static auth manager.
128128
129+
The manager will always return the auth info provided at its creation.
130+
129131
Example::
130132
131133
# NOTE: this example is for illustration purposes only.
@@ -164,9 +166,13 @@ def basic(
164166
"""Create an auth manager handling basic auth password rotation.
165167
166168
This factory wraps the provider function in an auth manager
167-
implementation that caches the provides auth info until either the
168-
server notifies the driver that the auth info is expired (by returning
169-
an error that indicates that basic auth has changed).
169+
implementation that caches the provided auth info until the server
170+
notifies the driver that the auth info has expired (by returning
171+
an error that indicates that the password is invalid).
172+
173+
Note that this implies that the provider function will be called again
174+
if it provides wrong auth info, potentially deferring failure due to a
175+
wrong password or username.
170176
171177
.. warning::
172178
@@ -176,8 +182,8 @@ def basic(
176182
The provider function must only ever return auth information
177183
belonging to the same identity.
178184
Switching identities is undefined behavior.
179-
You may use session-level authentication for such use-cases
180-
:ref:`session-auth-ref`.
185+
You may use :ref:`session-level authentication<session-auth-ref>`
186+
for such use-cases.
181187
182188
Example::
183189
@@ -201,13 +207,13 @@ def auth_provider():
201207
... # do stuff
202208
203209
:param provider:
204-
A callable that provides a :class:`.ExpiringAuth` instance.
210+
A callable that provides new auth info whenever the server notifies
211+
the driver that the previous auth info is invalid.
205212
206213
:returns:
207214
An instance of an implementation of :class:`.AuthManager` that
208215
returns auth info from the given provider and refreshes it, calling
209-
the provider again, when the auth info expires (because the server
210-
flagged it as expired).
216+
the provider again, when the auth info was rejected by the server.
211217
212218
.. versionadded:: 5.12
213219
@@ -227,9 +233,9 @@ def bearer(
227233
"""Create an auth manager for potentially expiring bearer auth tokens.
228234
229235
This factory wraps the provider function in an auth manager
230-
implementation that caches the provides auth info until either the
231-
:attr:`.ExpiringAuth.expires_at` is exceeded the server notifies the
232-
driver that the auth info is expired (by returning an error that
236+
implementation that caches the provided auth info until either the
237+
:attr:`.ExpiringAuth.expires_at` exceeded or the server notified the
238+
driver that the auth info has expired (by returning an error that
233239
indicates that the bearer auth token has expired).
234240
235241
.. warning::
@@ -240,8 +246,8 @@ def bearer(
240246
The provider function must only ever return auth information
241247
belonging to the same identity.
242248
Switching identities is undefined behavior.
243-
You may use session-level authentication for such use-cases
244-
:ref:`session-auth-ref`.
249+
You may use :ref:`session-level authentication<session-auth-ref>`
250+
for such use-cases.
245251
246252
Example::
247253
@@ -364,7 +370,6 @@ class RotatingClientCertificateProvider(ClientCertificateProvider):
364370
:param initial_cert: The certificate to use initially.
365371
366372
.. versionadded:: 5.19
367-
368373
"""
369374
def __init__(self, initial_cert: ClientCertificate) -> None:
370375
self._cert: t.Optional[ClientCertificate] = initial_cert

0 commit comments

Comments
 (0)