Revised the documentations.

This commit is contained in:
依瑪貓 2022-12-06 23:50:46 +08:00
parent 14b90de059
commit 7aaa7b9abe
3 changed files with 22 additions and 10 deletions

View File

@ -28,7 +28,7 @@ def make_password_hash(realm: str, username: str, password: str) -> str:
"""Calculates the password hash for the HTTP digest authentication.
Use this function to set the password for the user.
For example:
:Example:
::
@ -54,7 +54,7 @@ def calc_response(
:param uri: The request URI.
:param password_hash: The password hash for the HTTP digest authentication.
:param nonce: The nonce.
:param qop: the quality of protection, either ``auth`` or ``auth-int``.
:param qop: The quality of protection, either ``auth`` or ``auth-int``.
:param algorithm: The algorithm, either ``MD5`` or ``MD5-sess``.
:param cnonce: The client nonce, which must exists when qop exists or
algorithm is ``MD5-sess``.

View File

@ -66,7 +66,7 @@ class DigestAuth:
def login_required(self, view) -> t.Callable:
"""The view decorator for HTTP digest authentication.
For example:
:Example:
::
@ -233,7 +233,7 @@ class DigestAuth:
-> None:
"""The decorator to register the callback to obtain the password hash.
For example:
:Example:
::
@ -265,7 +265,7 @@ class DigestAuth:
-> None:
"""The decorator to register the callback to obtain the user.
For example:
:Example:
::
@ -295,7 +295,7 @@ class DigestAuth:
def register_on_login(self, func: t.Callable[[t.Any], None]) -> None:
"""The decorator to register the callback to run when the user logs in.
For example:
:Example:
::
@ -324,7 +324,7 @@ class DigestAuth:
def init_app(self, app: Flask) -> None:
"""Initializes the Flask application.
For example:
:Example:
::
@ -388,7 +388,7 @@ class DigestAuth:
This actually causes the next authentication to fail, which forces
the browser to ask the user for the username and password again.
For example:
:Example:
::

View File

@ -31,7 +31,9 @@ from flask_digest_auth.algo import calc_response, make_password_hash
class Client(WerkzeugClient):
"""The test client with HTTP digest authentication enabled.
For unittest example:
:Example:
For unittest_:
::
@ -52,7 +54,7 @@ class Client(WerkzeugClient):
"/admin", digest_auth=("my_name", "my_pass"))
self.assertEqual(response.status_code, 200)
For pytest example:
For pytest_:
::
@ -76,12 +78,19 @@ class Client(WerkzeugClient):
response = client.get(
"/admin", digest_auth=("my_name", "my_pass"))
assert response.status_code == 200
.. _unittest: https://docs.python.org/3/library/unittest.html
.. _pytest: https://pytest.org
"""
def open(self, *args, digest_auth: t.Optional[t.Tuple[str, str]] = None,
**kwargs) -> TestResponse:
"""Opens a request.
.. warning::
This is to override the parent ``open`` method. You should call
the ``get``, ``post``, ``put``, and ``delete`` methods instead.
:param args: The arguments.
:param digest_auth: A tuple of the username and password for the HTTP
digest authentication.
@ -106,6 +115,9 @@ class Client(WerkzeugClient):
username: str, password: str) -> Authorization:
"""Composes and returns the request authorization.
.. warning::
This method is not for public.
:param www_authenticate: The ``WWW-Authenticate`` response.
:param uri: The request URI.
:param username: The username.