Revised README.rst for various places.
This commit is contained in:
parent
5e5d929676
commit
c748fcdb16
34
README.rst
34
README.rst
@ -16,15 +16,17 @@ modules that work with different authentication mechanisms.
|
|||||||
.. _Flask-Login: https://flask-login.readthedocs.io
|
.. _Flask-Login: https://flask-login.readthedocs.io
|
||||||
|
|
||||||
|
|
||||||
Flask-Digest-Auth Alone without Flask-Login
|
Flask-Digest-Auth Alone
|
||||||
===========================================
|
=======================
|
||||||
|
|
||||||
Flask-Digest-Auth can authenticate the users alone without Flask-Login.
|
Flask-Digest-Auth can authenticate the users alone.
|
||||||
|
|
||||||
|
|
||||||
Example for Simple Applications with Flask-Digest-Auth Alone
|
Example for Simple Applications with Flask-Digest-Auth Alone
|
||||||
------------------------------------------------------------
|
------------------------------------------------------------
|
||||||
|
|
||||||
|
In your ``my_app.py``:
|
||||||
|
|
||||||
::
|
::
|
||||||
|
|
||||||
from flask import Flask
|
from flask import Flask
|
||||||
@ -52,14 +54,16 @@ Example for Simple Applications with Flask-Digest-Auth Alone
|
|||||||
Example for Larger Applications with ``create_app()`` with Flask-Digest-Auth Alone
|
Example for Larger Applications with ``create_app()`` with Flask-Digest-Auth Alone
|
||||||
----------------------------------------------------------------------------------
|
----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
In your ``my_app/__init__.py``:
|
||||||
|
|
||||||
:::
|
:::
|
||||||
|
|
||||||
from flask import Flask
|
from flask import Flask
|
||||||
from flask_digest_auth import DigestAuth
|
from flask_digest_auth import DigestAuth
|
||||||
|
|
||||||
auth: DigestAuth = DigestAuth(realm="Admin")
|
auth: DigestAuth = DigestAuth()
|
||||||
|
|
||||||
def create_app(test_config) -> Flask:
|
def create_app(test_config = None) -> Flask:
|
||||||
app: flask = Flask(__name__)
|
app: flask = Flask(__name__)
|
||||||
... (Configure the Flask application) ...
|
... (Configure the Flask application) ...
|
||||||
|
|
||||||
@ -75,11 +79,11 @@ Example for Larger Applications with ``create_app()`` with Flask-Digest-Auth Alo
|
|||||||
|
|
||||||
return app
|
return app
|
||||||
|
|
||||||
In your views:
|
In your ``my_app/views.py``:
|
||||||
|
|
||||||
::
|
::
|
||||||
|
|
||||||
from . import auth
|
from my_app import auth
|
||||||
from flask import Flask, Blueprint
|
from flask import Flask, Blueprint
|
||||||
|
|
||||||
bp = Blueprint("admin", __name__, url_prefix="/admin")
|
bp = Blueprint("admin", __name__, url_prefix="/admin")
|
||||||
@ -99,12 +103,14 @@ Flask-Login Integration
|
|||||||
Flask-Digest-Auth can work with Flask-Login. You can write a Flask
|
Flask-Digest-Auth can work with Flask-Login. You can write a Flask
|
||||||
module that requires log in, without specifying the authentication
|
module that requires log in, without specifying the authentication
|
||||||
mechanism. The Flask application can specify the actual
|
mechanism. The Flask application can specify the actual
|
||||||
authentication mechanism as they see fit.
|
authentication mechanism as it sees fit.
|
||||||
|
|
||||||
|
|
||||||
Example for Simple Applications with Flask-Login Integration
|
Example for Simple Applications with Flask-Login Integration
|
||||||
------------------------------------------------------------
|
------------------------------------------------------------
|
||||||
|
|
||||||
|
In your ``my_app.py``:
|
||||||
|
|
||||||
::
|
::
|
||||||
|
|
||||||
from flask import Flask
|
from flask import Flask
|
||||||
@ -137,13 +143,15 @@ Example for Simple Applications with Flask-Login Integration
|
|||||||
Example for Larger Applications with ``create_app()`` with Flask-Login Integration
|
Example for Larger Applications with ``create_app()`` with Flask-Login Integration
|
||||||
----------------------------------------------------------------------------------
|
----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
In your ``my_app/__init__.py``:
|
||||||
|
|
||||||
:::
|
:::
|
||||||
|
|
||||||
from flask import Flask
|
from flask import Flask
|
||||||
from flask_digest_auth import DigestAuth
|
from flask_digest_auth import DigestAuth
|
||||||
from flask_login import LoginManager
|
from flask_login import LoginManager
|
||||||
|
|
||||||
def create_app(test_config) -> Flask:
|
def create_app(test_config = None) -> Flask:
|
||||||
app: flask = Flask(__name__)
|
app: flask = Flask(__name__)
|
||||||
... (Configure the Flask application) ...
|
... (Configure the Flask application) ...
|
||||||
|
|
||||||
@ -163,7 +171,7 @@ Example for Larger Applications with ``create_app()`` with Flask-Login Integrati
|
|||||||
|
|
||||||
return app
|
return app
|
||||||
|
|
||||||
In your views:
|
In your ``my_app/views.py``:
|
||||||
|
|
||||||
::
|
::
|
||||||
|
|
||||||
@ -190,8 +198,8 @@ mechanism.
|
|||||||
Writing Tests
|
Writing Tests
|
||||||
=============
|
=============
|
||||||
|
|
||||||
A test client that handles HTTP Digest Authentication is included.
|
You can write tests with our test client that handles HTTP Digest
|
||||||
Example for a unittest testcase:
|
Authentication. Example for a unittest testcase:
|
||||||
|
|
||||||
::
|
::
|
||||||
|
|
||||||
@ -210,6 +218,8 @@ Example for a unittest testcase:
|
|||||||
return app
|
return app
|
||||||
|
|
||||||
def test_admin(self):
|
def test_admin(self):
|
||||||
|
response = self.client.get("/admin")
|
||||||
|
self.assertEqual(response.status_code, 401)
|
||||||
response = self.client.get(
|
response = self.client.get(
|
||||||
"/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)
|
||||||
|
Loading…
Reference in New Issue
Block a user