From 2c28b8885adac7c99775d54a0f41aea5cbdfee50 Mon Sep 17 00:00:00 2001 From: Ray Luo Date: Sun, 5 May 2024 12:38:44 -0700 Subject: [PATCH] Fix doc errors --- README.md | 26 ++++++++++++++------------ docs/flask.rst | 6 +++--- docs/quart.rst | 31 ++++++++++++++++++++++++++++--- docs/quart.webp | Bin 0 -> 1170 bytes identity/django.py | 2 +- identity/flask.py | 18 ++++++++++-------- identity/quart.py | 29 ++++++++++++++++------------- 7 files changed, 72 insertions(+), 40 deletions(-) create mode 100644 docs/quart.webp diff --git a/README.md b/README.md index cb3937d..dbc509a 100644 --- a/README.md +++ b/README.md @@ -63,9 +63,22 @@ By using this library, it will automatically renew signed-in session when the ID * [Sample written in ![Django](https://raw.githubusercontent.com/rayluo/identity/dev/docs/django.webp)](https://github.com/Azure-Samples/ms-identity-python-webapp-django) * [Sample written in ![Flask](https://raw.githubusercontent.com/rayluo/identity/dev/docs/flask.webp)](https://github.com/Azure-Samples/ms-identity-python-webapp) +* [Sample written in ![Quart](https://raw.githubusercontent.com/rayluo/identity/dev/docs/quart.webp)](https://github.com/rayluo/python-webapp-quart) * Need support for more web frameworks? [Upvote existing feature request or create a new one](https://github.com/rayluo/identity/issues) + + + + + How to customize the login page + + +The default login page will typically redirect users to your Identity Provider, +so you don't have to customize it. +But if the default login page is shown in your browser, +you can read its HTML source code, and find the how-to instructions there. + @@ -90,18 +103,6 @@ They are demonstrated by the same samples above. In roadmap. - - - - - How to customize the login page - - -The default login page will typically redirect users to your Identity Provider, -so you don't have to customize it. -But if the default login page is shown in your browser, -you can read its HTML source code, and find the how-to instructions there. - @@ -134,6 +135,7 @@ Choose the package declaration that matches your web framework: * Django: `pip install identity[django]` * Flask: `pip install identity[flask]` +* Quart: `pip install identity[quart]` ## Versions diff --git a/docs/flask.rst b/docs/flask.rst index f3b90bb..014a777 100644 --- a/docs/flask.rst +++ b/docs/flask.rst @@ -73,19 +73,19 @@ Web app that logs in users and calls a web API on their behalf #. Decorate your token-consuming views using the same :py:func:`identity.flask.Auth.login_required` decorator, - this time with a parameter ``scopes=["your_scope_1", "your_scope_2"]``. + this time with a parameter ``scopes=["your_scope_1", "your_scope_2"]``. Then, inside your view, the token will be readily available via ``context['access_token']``. For example:: @app.route("/call_api") - @auth.login_required(scopes=os.getenv("SCOPE", "").split()) + @auth.login_required(scopes=["your_scope_1", "your_scope_2"]) def call_api(*, context): api_result = requests.get( # Use access token to call a web api "https://your_api.example.com", headers={'Authorization': 'Bearer ' + context['access_token']}, timeout=30, - ).json() # Here we assume the response format is json + ) ... All of the content above are demonstrated in diff --git a/docs/quart.rst b/docs/quart.rst index 5234309..afc86a3 100644 --- a/docs/quart.rst +++ b/docs/quart.rst @@ -35,20 +35,20 @@ Configuration #. Setup session management with the `Quart-session `_ package, which currently supports either Redis or MongoDB backing stores. To use Redis as the session store, you should first install the package with the extra dependency:: - + pip install quart-session[redis] #. Then add configuration to ``app.py`` pointing to your Redis instance:: app.config['SESSION_TYPE'] = 'redis' app.config['SESSION_URI'] = 'redis://localhost:6379' - + Sign In and Sign Out ---------------------------------- #. In your web project's ``app.py``, decorate some views with the - :py:func:`identity.flask.Auth.login_required` decorator. + :py:func:`identity.quart.Auth.login_required` decorator. It will automatically trigger sign-in. :: @app.route("/") @@ -63,6 +63,31 @@ Sign In and Sign Out Logout +Web app that logs in users and calls a web API on their behalf +-------------------------------------------------------------- + +#. Decorate your token-consuming views using the same + :py:func:`identity.quart.Auth.login_required` decorator, + this time with a parameter ``scopes=["your_scope_1", "your_scope_2"]``. + + Then, inside your view, the token will be readily available via + ``context['access_token']``. For example:: + + @app.route("/call_api") + @auth.login_required(scopes=["your_scope_1", "your_scope_2"]) + async def call_api(*, context): + async with httpx.AsyncClient() as client: + api_result = await client.get( # Use access token to call a web api + os.getenv("ENDPOINT"), + headers={'Authorization': 'Bearer ' + context['access_token']}, + ) + return await render_template('display.html', result=api_result) + + +All of the content above are demonstrated in +`this Quart web app sample `_. + + API reference -------------------------- diff --git a/docs/qu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