Compare commits
15 Commits
v0.2.4
...
79abdc9cde
Author | SHA1 | Date | |
---|---|---|---|
79abdc9cde | |||
038e7a8352 | |||
0387abb4f6 | |||
10e8add9e6 | |||
c004e28c37 | |||
46f05a1022 | |||
b9384150b7 | |||
4296756ae7 | |||
83cf83a67c | |||
7aaa7b9abe | |||
14b90de059 | |||
e9013017fb | |||
6e6ac8bbe7 | |||
7ec56ee52d | |||
b348c872dc |
@ -10,8 +10,6 @@ if "%SPHINXBUILD%" == "" (
|
|||||||
set SOURCEDIR=source
|
set SOURCEDIR=source
|
||||||
set BUILDDIR=build
|
set BUILDDIR=build
|
||||||
|
|
||||||
if "%1" == "" goto help
|
|
||||||
|
|
||||||
%SPHINXBUILD% >NUL 2>NUL
|
%SPHINXBUILD% >NUL 2>NUL
|
||||||
if errorlevel 9009 (
|
if errorlevel 9009 (
|
||||||
echo.
|
echo.
|
||||||
@ -21,10 +19,12 @@ if errorlevel 9009 (
|
|||||||
echo.may add the Sphinx directory to PATH.
|
echo.may add the Sphinx directory to PATH.
|
||||||
echo.
|
echo.
|
||||||
echo.If you don't have Sphinx installed, grab it from
|
echo.If you don't have Sphinx installed, grab it from
|
||||||
echo.http://sphinx-doc.org/
|
echo.https://www.sphinx-doc.org/
|
||||||
exit /b 1
|
exit /b 1
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if "%1" == "" goto help
|
||||||
|
|
||||||
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
|
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
|
||||||
goto end
|
goto end
|
||||||
|
|
||||||
|
@ -1,59 +1,32 @@
|
|||||||
# Configuration file for the Sphinx documentation builder.
|
# Configuration file for the Sphinx documentation builder.
|
||||||
#
|
#
|
||||||
# This file only contains a selection of the most common options. For a full
|
# For the full list of built-in configuration values, see the documentation:
|
||||||
# list see the documentation:
|
|
||||||
# https://www.sphinx-doc.org/en/master/usage/configuration.html
|
# https://www.sphinx-doc.org/en/master/usage/configuration.html
|
||||||
import os
|
import os
|
||||||
# -- Path setup --------------------------------------------------------------
|
|
||||||
|
|
||||||
# If extensions (or modules to document with autodoc) are in another directory,
|
|
||||||
# add these directories to sys.path here. If the directory is relative to the
|
|
||||||
# documentation root, use os.path.abspath to make it absolute, like shown here.
|
|
||||||
#
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
sys.path.insert(0, os.path.abspath('../../src/'))
|
sys.path.insert(0, os.path.abspath('../../src/'))
|
||||||
|
|
||||||
|
|
||||||
# -- Project information -----------------------------------------------------
|
# -- Project information -----------------------------------------------------
|
||||||
|
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
|
||||||
|
|
||||||
project = 'Flask-Digest-Auth'
|
project = 'Flask-Digest-Auth'
|
||||||
copyright = '2022, imacat'
|
copyright = '2022, imacat'
|
||||||
author = 'imacat'
|
author = 'imacat'
|
||||||
|
release = '0.3.0'
|
||||||
# The full version, including alpha/beta/rc tags
|
|
||||||
release = '0.2.4'
|
|
||||||
|
|
||||||
|
|
||||||
# -- General configuration ---------------------------------------------------
|
# -- General configuration ---------------------------------------------------
|
||||||
|
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
|
||||||
|
|
||||||
# Add any Sphinx extension module names here, as strings. They can be
|
extensions = ["sphinx.ext.autodoc"]
|
||||||
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
|
|
||||||
# ones.
|
|
||||||
extensions = [
|
|
||||||
"sphinx.ext.autodoc"
|
|
||||||
]
|
|
||||||
|
|
||||||
# Add any paths that contain templates here, relative to this directory.
|
|
||||||
templates_path = ['_templates']
|
templates_path = ['_templates']
|
||||||
|
|
||||||
# List of patterns, relative to source directory, that match files and
|
|
||||||
# directories to ignore when looking for source files.
|
|
||||||
# This pattern also affects html_static_path and html_extra_path.
|
|
||||||
exclude_patterns = []
|
exclude_patterns = []
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# -- Options for HTML output -------------------------------------------------
|
# -- Options for HTML output -------------------------------------------------
|
||||||
|
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
|
||||||
|
|
||||||
# The theme to use for HTML and HTML Help pages. See the documentation for
|
|
||||||
# a list of builtin themes.
|
|
||||||
#
|
|
||||||
html_theme = 'sphinx_rtd_theme'
|
html_theme = 'sphinx_rtd_theme'
|
||||||
|
|
||||||
# Add any paths that contain custom static files (such as style sheets) here,
|
|
||||||
# relative to this directory. They are copied after the builtin static files,
|
|
||||||
# so a file named "default.css" will overwrite the builtin "default.css".
|
|
||||||
html_static_path = ['_static']
|
html_static_path = ['_static']
|
||||||
|
|
||||||
# For readthedocs.io to work properly.
|
|
||||||
master_doc = 'index'
|
|
||||||
|
@ -1,24 +1,37 @@
|
|||||||
flask\_digest\_auth package
|
flask\_digest\_auth package
|
||||||
===========================
|
===========================
|
||||||
|
|
||||||
The ``DigestAuth`` Class
|
Submodules
|
||||||
------------------------
|
----------
|
||||||
.. autoclass:: flask_digest_auth.DigestAuth
|
|
||||||
:members:
|
|
||||||
:undoc-members:
|
|
||||||
:show-inheritance:
|
|
||||||
|
|
||||||
The ``make_password_hash`` Function
|
flask\_digest\_auth.algo module
|
||||||
-----------------------------------
|
-------------------------------
|
||||||
.. autofunction:: flask_digest_auth.make_password_hash
|
|
||||||
|
|
||||||
The ``calc_response`` Function
|
.. automodule:: flask_digest_auth.algo
|
||||||
------------------------------
|
:members:
|
||||||
.. autofunction:: flask_digest_auth.calc_response
|
:undoc-members:
|
||||||
|
:show-inheritance:
|
||||||
|
|
||||||
The ``Client`` Test Class
|
flask\_digest\_auth.auth module
|
||||||
-------------------------
|
-------------------------------
|
||||||
.. autoclass:: flask_digest_auth.Client
|
|
||||||
:members:
|
.. automodule:: flask_digest_auth.auth
|
||||||
:undoc-members:
|
:members:
|
||||||
:show-inheritance:
|
:undoc-members:
|
||||||
|
:show-inheritance:
|
||||||
|
|
||||||
|
flask\_digest\_auth.test module
|
||||||
|
-------------------------------
|
||||||
|
|
||||||
|
.. automodule:: flask_digest_auth.test
|
||||||
|
:members:
|
||||||
|
:undoc-members:
|
||||||
|
:show-inheritance:
|
||||||
|
|
||||||
|
Module contents
|
||||||
|
---------------
|
||||||
|
|
||||||
|
.. automodule:: flask_digest_auth
|
||||||
|
:members:
|
||||||
|
:undoc-members:
|
||||||
|
:show-inheritance:
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
.. flask-digest-auth documentation master file, created by
|
.. Flask-Digest-Auth documentation master file, created by
|
||||||
sphinx-quickstart on Tue Dec 6 15:15:08 2022.
|
sphinx-quickstart on Wed Dec 7 09:40:48 2022.
|
||||||
You can adapt this file completely to your liking, but it should at least
|
You can adapt this file completely to your liking, but it should at least
|
||||||
contain the root `toctree` directive.
|
contain the root `toctree` directive.
|
||||||
|
|
||||||
@ -26,6 +26,7 @@ Indices and tables
|
|||||||
==================
|
==================
|
||||||
|
|
||||||
* :ref:`genindex`
|
* :ref:`genindex`
|
||||||
|
* :ref:`modindex`
|
||||||
* :ref:`search`
|
* :ref:`search`
|
||||||
|
|
||||||
.. _HTTP Digest Authentication: https://en.wikipedia.org/wiki/Digest_access_authentication
|
.. _HTTP Digest Authentication: https://en.wikipedia.org/wiki/Digest_access_authentication
|
||||||
|
@ -63,7 +63,7 @@ The username is part of the hash. If the user changes their username,
|
|||||||
you need to ask their password, to generate and store the new password
|
you need to ask their password, to generate and store the new password
|
||||||
hash.
|
hash.
|
||||||
|
|
||||||
See :meth:`flask_digest_auth.make_password_hash`.
|
See :func:`flask_digest_auth.algo.make_password_hash`.
|
||||||
|
|
||||||
|
|
||||||
Flask-Digest-Auth Alone
|
Flask-Digest-Auth Alone
|
||||||
@ -118,7 +118,7 @@ logging the log in event, adding the log in counter, etc.
|
|||||||
def on_login(user: User) -> None:
|
def on_login(user: User) -> None:
|
||||||
user.visits = user.visits + 1
|
user.visits = user.visits + 1
|
||||||
|
|
||||||
See :meth:`flask_digest_auth.DigestAuth.register_on_login`.
|
See :meth:`flask_digest_auth.auth.DigestAuth.register_on_login`.
|
||||||
|
|
||||||
|
|
||||||
Log Out
|
Log Out
|
||||||
@ -127,7 +127,7 @@ Log Out
|
|||||||
Flask-Digest-Auth supports log out. The user will be prompted for the
|
Flask-Digest-Auth supports log out. The user will be prompted for the
|
||||||
new username and password.
|
new username and password.
|
||||||
|
|
||||||
See :meth:`flask_digest_auth.DigestAuth.logout`.
|
See :meth:`flask_digest_auth.auth.DigestAuth.logout`.
|
||||||
|
|
||||||
|
|
||||||
Test Client
|
Test Client
|
||||||
@ -136,7 +136,7 @@ Test Client
|
|||||||
Flask-Digest-Auth comes with a test client that supports HTTP digest
|
Flask-Digest-Auth comes with a test client that supports HTTP digest
|
||||||
authentication.
|
authentication.
|
||||||
|
|
||||||
See :class:`flask_digest_auth.Client`.
|
See :class:`flask_digest_auth.test.Client`.
|
||||||
|
|
||||||
Also see :ref:`example-unittest` and :ref:`example-pytest`.
|
Also see :ref:`example-unittest` and :ref:`example-pytest`.
|
||||||
|
|
||||||
|
7
docs/source/modules.rst
Normal file
7
docs/source/modules.rst
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
src
|
||||||
|
===
|
||||||
|
|
||||||
|
.. toctree::
|
||||||
|
:maxdepth: 4
|
||||||
|
|
||||||
|
flask_digest_auth
|
@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
[metadata]
|
[metadata]
|
||||||
name = flask-digest-auth
|
name = flask-digest-auth
|
||||||
version = 0.2.4
|
version = 0.3.0
|
||||||
author = imacat
|
author = imacat
|
||||||
author_email = imacat@mail.imacat.idv.tw
|
author_email = imacat@mail.imacat.idv.tw
|
||||||
description = The Flask HTTP Digest Authentication project.
|
description = The Flask HTTP Digest Authentication project.
|
||||||
|
@ -28,7 +28,7 @@ def make_password_hash(realm: str, username: str, password: str) -> str:
|
|||||||
"""Calculates the password hash for the HTTP digest authentication.
|
"""Calculates the password hash for the HTTP digest authentication.
|
||||||
Use this function to set the password for the user.
|
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 uri: The request URI.
|
||||||
:param password_hash: The password hash for the HTTP digest authentication.
|
:param password_hash: The password hash for the HTTP digest authentication.
|
||||||
:param nonce: The nonce.
|
: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 algorithm: The algorithm, either ``MD5`` or ``MD5-sess``.
|
||||||
:param cnonce: The client nonce, which must exists when qop exists or
|
:param cnonce: The client nonce, which must exists when qop exists or
|
||||||
algorithm is ``MD5-sess``.
|
algorithm is ``MD5-sess``.
|
||||||
|
@ -16,8 +16,9 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
"""The HTTP Digest Authentication.
|
"""The HTTP Digest Authentication.
|
||||||
See RFC 2617 HTTP Authentication: Basic and Digest Access Authentication
|
See `RFC 2617`_ HTTP Authentication: Basic and Digest Access Authentication
|
||||||
|
|
||||||
|
.. _RFC 2617: https://www.rfc-editor.org/rfc/rfc2617
|
||||||
"""
|
"""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
@ -41,27 +42,41 @@ class DigestAuth:
|
|||||||
|
|
||||||
:param realm: The realm.
|
:param realm: The realm.
|
||||||
"""
|
"""
|
||||||
self.secret_key: str = token_urlsafe(32)
|
self.__serializer: URLSafeTimedSerializer \
|
||||||
self.serializer: URLSafeTimedSerializer \
|
= URLSafeTimedSerializer(token_urlsafe(32))
|
||||||
= URLSafeTimedSerializer(self.secret_key)
|
"""The serializer to generate and validate the nonce and opaque."""
|
||||||
self.realm: str = "" if realm is None else realm
|
self.realm: str = "" if realm is None else realm
|
||||||
self.algorithm: t.Optional[str] = None
|
"""The realm. Default is an empty string."""
|
||||||
|
self.algorithm: t.Optional[t.Literal["MD5", "MD5-sess"]] = None
|
||||||
|
"""The algorithm, either None, ``MD5``, or ``MD5-sess``. Default is
|
||||||
|
None."""
|
||||||
self.use_opaque: bool = True
|
self.use_opaque: bool = True
|
||||||
self.domain: t.List[str] = []
|
"""Whether to use an opaque. Default is True."""
|
||||||
self.qop: t.List[str] = ["auth", "auth-int"]
|
self.__domain: t.List[str] = []
|
||||||
|
"""A list of directories that this username and password applies to.
|
||||||
|
Default is empty."""
|
||||||
|
self.__qop: t.List[t.Literal["auth", "auth-int"]] \
|
||||||
|
= ["auth", "auth-int"]
|
||||||
|
"""A list of supported quality of protection supported, either
|
||||||
|
``qop``, ``auth-int``, both, or empty. Default is both."""
|
||||||
self.app: t.Optional[Flask] = None
|
self.app: t.Optional[Flask] = None
|
||||||
|
"""The current Flask application."""
|
||||||
self.__get_password_hash: BasePasswordHashGetter \
|
self.__get_password_hash: BasePasswordHashGetter \
|
||||||
= BasePasswordHashGetter()
|
= BasePasswordHashGetter()
|
||||||
|
"""The callback to return the password hash."""
|
||||||
self.__get_user: BaseUserGetter = BaseUserGetter()
|
self.__get_user: BaseUserGetter = BaseUserGetter()
|
||||||
|
"""The callback to return the user."""
|
||||||
self.__on_login: BaseOnLogInCallback = BaseOnLogInCallback()
|
self.__on_login: BaseOnLogInCallback = BaseOnLogInCallback()
|
||||||
|
"""The callback to run when the user logs in."""
|
||||||
|
|
||||||
def login_required(self, view) -> t.Callable:
|
def login_required(self, view) -> t.Callable:
|
||||||
"""The view decorator for HTTP digest authentication.
|
"""The view decorator for the HTTP digest authentication.
|
||||||
|
|
||||||
For example:
|
:Example:
|
||||||
|
|
||||||
::
|
::
|
||||||
|
|
||||||
|
@app.get("/admin")
|
||||||
@auth.login_required
|
@auth.login_required
|
||||||
def admin():
|
def admin():
|
||||||
return f"Hello, {g.user.username}!"
|
return f"Hello, {g.user.username}!"
|
||||||
@ -152,7 +167,7 @@ class DigestAuth:
|
|||||||
raise UnauthorizedException(
|
raise UnauthorizedException(
|
||||||
"Missing \"opaque\" in the Authorization header")
|
"Missing \"opaque\" in the Authorization header")
|
||||||
try:
|
try:
|
||||||
self.serializer.loads(
|
self.__serializer.loads(
|
||||||
authorization.opaque, salt="opaque", max_age=1800)
|
authorization.opaque, salt="opaque", max_age=1800)
|
||||||
except BadData:
|
except BadData:
|
||||||
raise UnauthorizedException("Invalid opaque")
|
raise UnauthorizedException("Invalid opaque")
|
||||||
@ -173,7 +188,7 @@ class DigestAuth:
|
|||||||
state.stale = False
|
state.stale = False
|
||||||
raise UnauthorizedException("Incorrect response value")
|
raise UnauthorizedException("Incorrect response value")
|
||||||
try:
|
try:
|
||||||
self.serializer.loads(
|
self.__serializer.loads(
|
||||||
authorization.nonce,
|
authorization.nonce,
|
||||||
salt="nonce" if authorization.opaque is None
|
salt="nonce" if authorization.opaque is None
|
||||||
else f"nonce-{authorization.opaque}")
|
else f"nonce-{authorization.opaque}")
|
||||||
@ -197,16 +212,16 @@ class DigestAuth:
|
|||||||
return None
|
return None
|
||||||
if state.opaque is not None:
|
if state.opaque is not None:
|
||||||
return state.opaque
|
return state.opaque
|
||||||
return self.serializer.dumps(randbits(32), salt="opaque")
|
return self.__serializer.dumps(randbits(32), salt="opaque")
|
||||||
|
|
||||||
opaque: t.Optional[str] = get_opaque()
|
opaque: t.Optional[str] = get_opaque()
|
||||||
nonce: str = self.serializer.dumps(
|
nonce: str = self.__serializer.dumps(
|
||||||
randbits(32),
|
randbits(32),
|
||||||
salt="nonce" if opaque is None else f"nonce-{opaque}")
|
salt="nonce" if opaque is None else f"nonce-{opaque}")
|
||||||
|
|
||||||
header: str = f"Digest realm=\"{self.realm}\""
|
header: str = f"Digest realm=\"{self.realm}\""
|
||||||
if len(self.domain) > 0:
|
if len(self.__domain) > 0:
|
||||||
domain_list: str = ",".join(self.domain)
|
domain_list: str = ",".join(self.__domain)
|
||||||
header += f", domain=\"{domain_list}\""
|
header += f", domain=\"{domain_list}\""
|
||||||
header += f", nonce=\"{nonce}\""
|
header += f", nonce=\"{nonce}\""
|
||||||
if opaque is not None:
|
if opaque is not None:
|
||||||
@ -215,8 +230,8 @@ class DigestAuth:
|
|||||||
header += f", stale=TRUE" if state.stale else f", stale=FALSE"
|
header += f", stale=TRUE" if state.stale else f", stale=FALSE"
|
||||||
if self.algorithm is not None:
|
if self.algorithm is not None:
|
||||||
header += f", algorithm=\"{self.algorithm}\""
|
header += f", algorithm=\"{self.algorithm}\""
|
||||||
if len(self.qop) > 0:
|
if len(self.__qop) > 0:
|
||||||
qop_list: str = ",".join(self.qop)
|
qop_list: str = ",".join(self.__qop)
|
||||||
header += f", qop=\"{qop_list}\""
|
header += f", qop=\"{qop_list}\""
|
||||||
return header
|
return header
|
||||||
|
|
||||||
@ -224,7 +239,7 @@ class DigestAuth:
|
|||||||
-> None:
|
-> None:
|
||||||
"""The decorator to register the callback to obtain the password hash.
|
"""The decorator to register the callback to obtain the password hash.
|
||||||
|
|
||||||
For example:
|
:Example:
|
||||||
|
|
||||||
::
|
::
|
||||||
|
|
||||||
@ -256,7 +271,7 @@ class DigestAuth:
|
|||||||
-> None:
|
-> None:
|
||||||
"""The decorator to register the callback to obtain the user.
|
"""The decorator to register the callback to obtain the user.
|
||||||
|
|
||||||
For example:
|
:Example:
|
||||||
|
|
||||||
::
|
::
|
||||||
|
|
||||||
@ -286,7 +301,7 @@ class DigestAuth:
|
|||||||
def register_on_login(self, func: t.Callable[[t.Any], None]) -> None:
|
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.
|
"""The decorator to register the callback to run when the user logs in.
|
||||||
|
|
||||||
For example:
|
:Example:
|
||||||
|
|
||||||
::
|
::
|
||||||
|
|
||||||
@ -315,7 +330,7 @@ class DigestAuth:
|
|||||||
def init_app(self, app: Flask) -> None:
|
def init_app(self, app: Flask) -> None:
|
||||||
"""Initializes the Flask application.
|
"""Initializes the Flask application.
|
||||||
|
|
||||||
For example:
|
:Example:
|
||||||
|
|
||||||
::
|
::
|
||||||
|
|
||||||
@ -379,7 +394,7 @@ class DigestAuth:
|
|||||||
This actually causes the next authentication to fail, which forces
|
This actually causes the next authentication to fail, which forces
|
||||||
the browser to ask the user for the username and password again.
|
the browser to ask the user for the username and password again.
|
||||||
|
|
||||||
For example:
|
:Example:
|
||||||
|
|
||||||
::
|
::
|
||||||
|
|
||||||
@ -403,21 +418,30 @@ class DigestAuth:
|
|||||||
|
|
||||||
|
|
||||||
class AuthState:
|
class AuthState:
|
||||||
"""The authorization state."""
|
"""The authentication state. It keeps the status in the earlier
|
||||||
|
authentication stage, so that the latter response stage knows how to
|
||||||
|
response.
|
||||||
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
"""Constructs the authorization state."""
|
"""Constructs the authorization state."""
|
||||||
self.opaque: t.Optional[str] = None
|
self.opaque: t.Optional[str] = None
|
||||||
|
"""The opaque value specified by the client, if valid."""
|
||||||
self.stale: t.Optional[bool] = None
|
self.stale: t.Optional[bool] = None
|
||||||
|
"""The stale value, if there is a previous log in attempt."""
|
||||||
|
|
||||||
|
|
||||||
class UnauthorizedException(Exception):
|
class UnauthorizedException(Exception):
|
||||||
"""The exception thrown when the authentication is failed."""
|
"""The exception thrown when the authentication fails."""
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class BasePasswordHashGetter:
|
class BasePasswordHashGetter:
|
||||||
"""The base password hash getter."""
|
"""The base callback that given the username, returns the password hash,
|
||||||
|
or None if the user does not exist. The default is to raise an
|
||||||
|
:class:`UnboundLocalError` if the callback is not registered yet.
|
||||||
|
|
||||||
|
See :meth:`flask_digest_auth.auth.DigestAuth.register_get_password`
|
||||||
|
"""
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def __call__(username: str) -> t.Optional[str]:
|
def __call__(username: str) -> t.Optional[str]:
|
||||||
@ -433,7 +457,12 @@ class BasePasswordHashGetter:
|
|||||||
|
|
||||||
|
|
||||||
class BaseUserGetter:
|
class BaseUserGetter:
|
||||||
"""The base user getter."""
|
"""The base callback that given the username, returns the user, or None if
|
||||||
|
the user does not exist. The default is to raise an
|
||||||
|
:class:`UnboundLocalError` if the callback is not registered yet.
|
||||||
|
|
||||||
|
See :meth:`flask_digest_auth.auth.DigestAuth.register_get_user`
|
||||||
|
"""
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def __call__(username: str) -> t.Optional[t.Any]:
|
def __call__(username: str) -> t.Optional[t.Any]:
|
||||||
@ -449,7 +478,11 @@ class BaseUserGetter:
|
|||||||
|
|
||||||
|
|
||||||
class BaseOnLogInCallback:
|
class BaseOnLogInCallback:
|
||||||
"""The base callback when the user logs in."""
|
"""The base callback to run when the user logs in, given the logged-in
|
||||||
|
user. The default does nothing.
|
||||||
|
|
||||||
|
See :meth:`flask_digest_auth.auth.DigestAuth.register_on_login`
|
||||||
|
"""
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def __call__(user: t.Any) -> None:
|
def __call__(user: t.Any) -> None:
|
||||||
|
@ -31,7 +31,9 @@ from flask_digest_auth.algo import calc_response, make_password_hash
|
|||||||
class Client(WerkzeugClient):
|
class Client(WerkzeugClient):
|
||||||
"""The test client with HTTP digest authentication enabled.
|
"""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"))
|
"/admin", digest_auth=("my_name", "my_pass"))
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
For pytest example:
|
For pytest_:
|
||||||
|
|
||||||
::
|
::
|
||||||
|
|
||||||
@ -76,6 +78,9 @@ class Client(WerkzeugClient):
|
|||||||
response = client.get(
|
response = client.get(
|
||||||
"/admin", digest_auth=("my_name", "my_pass"))
|
"/admin", digest_auth=("my_name", "my_pass"))
|
||||||
assert response.status_code == 200
|
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,
|
def open(self, *args, digest_auth: t.Optional[t.Tuple[str, str]] = None,
|
||||||
|
Reference in New Issue
Block a user