Added the DIGEST_AUTH_REALM configuration variable as the recommended way to set the authentication realm. Changed the default realm from an empty string to "Login Required".

This commit is contained in:
2023-01-06 00:19:24 +08:00
parent 5ebdea6d0a
commit 27d27127f6
6 changed files with 36 additions and 18 deletions

View File

@ -17,7 +17,7 @@ In your ``my_app.py``:
app: flask = Flask(__name__)
... (Configure the Flask application) ...
auth: DigestAuth = DigestAuth(realm="Admin")
auth: DigestAuth = DigestAuth()
auth.init_app(app)
@auth.register_get_password
@ -58,7 +58,6 @@ 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
@ -118,7 +117,7 @@ In your ``my_app.py``:
def load_user(user_id: str) -> t.Optional[User]:
... (Load the user with the username) ...
auth: DigestAuth = DigestAuth(realm="Admin")
auth: DigestAuth = DigestAuth()
auth.init_app(app)
@auth.register_get_password
@ -164,7 +163,6 @@ 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
@ -219,8 +217,9 @@ A unittest Test Case
def create_app(self):
app: Flask = create_app({
"TESTING": True,
"SECRET_KEY": token_urlsafe(32),
"TESTING": True
"DIGEST_AUTH_REALM": "admin",
})
app.test_client_class = Client
return app
@ -249,8 +248,9 @@ A pytest Test
@pytest.fixture()
def app():
app: Flask = create_app({
"TESTING": True,
"SECRET_KEY": token_urlsafe(32),
"TESTING": True
"DIGEST_AUTH_REALM": "admin",
})
app.test_client_class = Client
yield app

View File

@ -46,6 +46,13 @@ 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
--------------------