Compare commits
No commits in common. "d5a8bb3acd1da5b5e26775813c4a03bdacd9ffe2" and "4f30756dc51a0a275c5d4684dcc77485d33d89a0" have entirely different histories.
d5a8bb3acd
...
4f30756dc5
19
README.rst
19
README.rst
@ -52,13 +52,6 @@ You may also install the latest source from the
|
||||
pip install git+https://github.com/imacat/flask-digestauth.git
|
||||
|
||||
|
||||
Configuration
|
||||
=============
|
||||
|
||||
Flask-DigestAuth takes the configuration ``DIGEST_AUTH_REALM`` as the
|
||||
realm. The default realm is ``Login Required``.
|
||||
|
||||
|
||||
Setting the Password
|
||||
====================
|
||||
|
||||
@ -96,7 +89,7 @@ In your ``my_app.py``:
|
||||
app: flask = Flask(__name__)
|
||||
... (Configure the Flask application) ...
|
||||
|
||||
auth: DigestAuth = DigestAuth()
|
||||
auth: DigestAuth = DigestAuth(realm="Admin")
|
||||
auth.init_app(app)
|
||||
|
||||
@auth.register_get_password
|
||||
@ -135,6 +128,7 @@ In your ``my_app/__init__.py``:
|
||||
app: flask = Flask(__name__)
|
||||
... (Configure the Flask application) ...
|
||||
|
||||
auth.realm = app.config["REALM"]
|
||||
auth.init_app(app)
|
||||
|
||||
@auth.register_get_password
|
||||
@ -213,7 +207,7 @@ In your ``my_app.py``:
|
||||
def load_user(user_id: str) -> t.Optional[User]:
|
||||
... (Load the user with the username) ...
|
||||
|
||||
auth: DigestAuth = DigestAuth()
|
||||
auth: DigestAuth = DigestAuth(realm="Admin")
|
||||
auth.init_app(app)
|
||||
|
||||
@auth.register_get_password
|
||||
@ -257,6 +251,7 @@ In your ``my_app/__init__.py``:
|
||||
def load_user(user_id: str) -> t.Optional[User]:
|
||||
... (Load the user with the username) ...
|
||||
|
||||
auth.realm = app.config["REALM"]
|
||||
auth.init_app(app)
|
||||
|
||||
@auth.register_get_password
|
||||
@ -345,9 +340,8 @@ A unittest Test Case
|
||||
|
||||
def create_app(self):
|
||||
app: Flask = create_app({
|
||||
"TESTING": True,
|
||||
"SECRET_KEY": token_urlsafe(32),
|
||||
"DIGEST_AUTH_REALM": "admin",
|
||||
"TESTING": True
|
||||
})
|
||||
app.test_client_class = Client
|
||||
return app
|
||||
@ -373,9 +367,8 @@ A pytest Test
|
||||
@pytest.fixture()
|
||||
def app():
|
||||
app: Flask = create_app({
|
||||
"TESTING": True,
|
||||
"SECRET_KEY": token_urlsafe(32),
|
||||
"DIGEST_AUTH_REALM": "admin",
|
||||
"TESTING": True
|
||||
})
|
||||
app.test_client_class = Client
|
||||
yield app
|
||||
|
@ -13,7 +13,7 @@ sys.path.insert(0, os.path.abspath('../../src/'))
|
||||
project = 'Flask-DigestAuth'
|
||||
copyright = '2022-2023, imacat'
|
||||
author = 'imacat'
|
||||
release = '0.5.0'
|
||||
release = '0.4.0'
|
||||
|
||||
# -- General configuration ---------------------------------------------------
|
||||
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
|
||||
|
@ -17,7 +17,7 @@ In your ``my_app.py``:
|
||||
app: flask = Flask(__name__)
|
||||
... (Configure the Flask application) ...
|
||||
|
||||
auth: DigestAuth = DigestAuth()
|
||||
auth: DigestAuth = DigestAuth(realm="Admin")
|
||||
auth.init_app(app)
|
||||
|
||||
@auth.register_get_password
|
||||
@ -58,6 +58,7 @@ In your ``my_app/__init__.py``:
|
||||
app: flask = Flask(__name__)
|
||||
... (Configure the Flask application) ...
|
||||
|
||||
auth.realm = app.config["REALM"]
|
||||
auth.init_app(app)
|
||||
|
||||
@auth.register_get_password
|
||||
@ -117,7 +118,7 @@ In your ``my_app.py``:
|
||||
def load_user(user_id: str) -> t.Optional[User]:
|
||||
... (Load the user with the username) ...
|
||||
|
||||
auth: DigestAuth = DigestAuth()
|
||||
auth: DigestAuth = DigestAuth(realm="Admin")
|
||||
auth.init_app(app)
|
||||
|
||||
@auth.register_get_password
|
||||
@ -163,6 +164,7 @@ In your ``my_app/__init__.py``:
|
||||
def load_user(user_id: str) -> t.Optional[User]:
|
||||
... (Load the user with the username) ...
|
||||
|
||||
auth.realm = app.config["REALM"]
|
||||
auth.init_app(app)
|
||||
|
||||
@auth.register_get_password
|
||||
@ -217,9 +219,8 @@ A unittest Test Case
|
||||
|
||||
def create_app(self):
|
||||
app: Flask = create_app({
|
||||
"TESTING": True,
|
||||
"SECRET_KEY": token_urlsafe(32),
|
||||
"DIGEST_AUTH_REALM": "admin",
|
||||
"TESTING": True
|
||||
})
|
||||
app.test_client_class = Client
|
||||
return app
|
||||
@ -248,9 +249,8 @@ A pytest Test
|
||||
@pytest.fixture()
|
||||
def app():
|
||||
app: Flask = create_app({
|
||||
"TESTING": True,
|
||||
"SECRET_KEY": token_urlsafe(32),
|
||||
"DIGEST_AUTH_REALM": "admin",
|
||||
"TESTING": True
|
||||
})
|
||||
app.test_client_class = Client
|
||||
yield app
|
||||
|
@ -46,13 +46,6 @@ You may also install the latest source from the
|
||||
pip install git+https://github.com/imacat/flask-digestauth.git
|
||||
|
||||
|
||||
Configuration
|
||||
-------------
|
||||
|
||||
Flask-DigestAuth takes the configuration ``DIGEST_AUTH_REALM`` as the
|
||||
realm. The default realm is ``Login Required``.
|
||||
|
||||
|
||||
Setting the Password
|
||||
--------------------
|
||||
|
||||
|
@ -17,7 +17,7 @@
|
||||
|
||||
[metadata]
|
||||
name = Flask-DigestAuth
|
||||
version = 0.5.0
|
||||
version = 0.4.0
|
||||
author = imacat
|
||||
author_email = imacat@mail.imacat.idv.tw
|
||||
description = The Flask HTTP Digest Authentication project.
|
||||
|
@ -46,8 +46,8 @@ class DigestAuth:
|
||||
self.__serializer: URLSafeTimedSerializer \
|
||||
= URLSafeTimedSerializer(token_urlsafe(32))
|
||||
"""The serializer to generate and validate the nonce and opaque."""
|
||||
self.realm: str = "Login Required" if realm is None else realm
|
||||
"""The realm. Default is "Login Required"."""
|
||||
self.realm: str = "" if realm is None else realm
|
||||
"""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."""
|
||||
@ -343,8 +343,6 @@ class DigestAuth:
|
||||
:return: None.
|
||||
"""
|
||||
app.extensions["digest_auth"] = self
|
||||
if "DIGEST_AUTH_REALM" in app.config:
|
||||
self.realm = app.config["DIGEST_AUTH_REALM"]
|
||||
|
||||
if hasattr(app, "login_manager"):
|
||||
from flask_login import LoginManager, login_user
|
||||
@ -383,7 +381,8 @@ class DigestAuth:
|
||||
raise UnauthorizedException(
|
||||
"Not an HTTP digest authorization")
|
||||
self.__authenticate(request._digest_auth_state)
|
||||
user = login_manager.user_callback(authorization.username)
|
||||
user = login_manager.user_callback(
|
||||
authorization.username)
|
||||
login_user(user)
|
||||
self.__on_login(user)
|
||||
return user
|
||||
|
@ -1,7 +1,7 @@
|
||||
# The Flask HTTP Digest Authentication Project.
|
||||
# Author: imacat@mail.imacat.idv.tw (imacat), 2022/10/22
|
||||
|
||||
# Copyright (c) 2022-2023 imacat.
|
||||
# Copyright (c) 2022 imacat.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
@ -57,13 +57,12 @@ class AuthenticationTestCase(TestCase):
|
||||
"""
|
||||
app: Flask = Flask(__name__)
|
||||
app.config.from_mapping({
|
||||
"TESTING": True,
|
||||
"SECRET_KEY": token_urlsafe(32),
|
||||
"DIGEST_AUTH_REALM": _REALM,
|
||||
"TESTING": True
|
||||
})
|
||||
app.test_client_class = Client
|
||||
|
||||
auth: DigestAuth = DigestAuth()
|
||||
auth: DigestAuth = DigestAuth(realm=_REALM)
|
||||
auth.init_app(app)
|
||||
self.user: User = User(_USERNAME, _PASSWORD)
|
||||
user_db: t.Dict[str, User] = {_USERNAME: self.user}
|
||||
|
@ -1,7 +1,7 @@
|
||||
# The Flask HTTP Digest Authentication Project.
|
||||
# Author: imacat@mail.imacat.idv.tw (imacat), 2022/11/23
|
||||
|
||||
# Copyright (c) 2022-2023 imacat.
|
||||
# Copyright (c) 2022 imacat.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
@ -77,9 +77,8 @@ class FlaskLoginTestCase(TestCase):
|
||||
"""
|
||||
app: Flask = Flask(__name__)
|
||||
app.config.from_mapping({
|
||||
"TESTING": True,
|
||||
"SECRET_KEY": token_urlsafe(32),
|
||||
"DIGEST_AUTH_REALM": _REALM,
|
||||
"TESTING": True
|
||||
})
|
||||
app.test_client_class = Client
|
||||
|
||||
@ -93,7 +92,7 @@ class FlaskLoginTestCase(TestCase):
|
||||
login_manager: flask_login.LoginManager = flask_login.LoginManager()
|
||||
login_manager.init_app(app)
|
||||
|
||||
auth: DigestAuth = DigestAuth()
|
||||
auth: DigestAuth = DigestAuth(realm=_REALM)
|
||||
auth.init_app(app)
|
||||
|
||||
self.user: User = User(_USERNAME, _PASSWORD)
|
||||
|
Loading…
Reference in New Issue
Block a user