Skip to content

Commit

Permalink
support alternative cookie messages in UI (iss. #107) (#109)
Browse files Browse the repository at this point in the history
* #107 - support alternative messages

This could be used as…

```python
    path("init/<uuid:registration_uuid>/", OIDCLoginInitView.as_view(
        main_msg='Your browser prevents embedded content from using cookies.',
        click_msg='Instead, you must open the content in a new tab.',
        loading_msg='Loading…'
    ), name="init"),
```

* #107 - nox/black formatting and comments

After running `nox`, `black` said a blank line was needed.  After I looked, I decided a comment would be helpful, too.

* #107 - set better default message values

* #107 - document optional message arguments

* added common `virtualenv` direcory name, `.venv`

* #109 - clean up code

* #109 - keep old example; add cookie lang. example
  • Loading branch information
lsloan authored Jun 25, 2024
1 parent afae630 commit 3eb1afd
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 5 deletions.
39 changes: 36 additions & 3 deletions docs/oidc_initiation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,52 @@ to return an authentication request to the platform

.. code-block:: python
...
# ...
from lti_tool.views import OIDCLoginInitView
urlpatterns = [
path("init/<uuid:registration_uuid/", OIDCLoginInitView.as_view(), name="init"),
...
# ...
]
The ``registration_uuid`` parameter is a reference to the
:attr:`LtiRegistration.uuid <lti_tool.models.LtiRegistration.uuid>` property, and is
used to identify the platform registration associated with the initiation request.


Customizing language for blocked cookies
----------------------------------------

When the user's browser prevents embedded content from setting cookies within an
``iframe``, the module displays a message about it and a link to open the
content in a new tab or window. The language of the message and link may be
customized using optional message arguments to ``OIDCLoginInitView.as_view()``…

.. code-block:: python
# ...
from lti_tool.views import OIDCLoginInitView
urlpatterns = [
path("init/<uuid:registration_uuid/", OIDCLoginInitView.as_view(
main_msg=(
"Your browser prevents embedded content from using cookies. To work "
"around this, the content must be opened in a new tab or window. "
),
click_msg="Open a new tab or window now.",
loading_msg="Loading..."
), name="init"),
# ...
]
The ``main_msg``, ``click_msg``, and ``loading_msg`` **optional** arguments are
passed to ``DjangoOIDCLogin.enable_check_cookies()`` to generate messages shown
in the UI. The values shown here are the default values used by
``OIDCLoginInitView``. If cookies are not allowed by the browser, the value of
``main_msg`` will be shown. That will be followed by a link with label
containing the value of ``click_msg``, which opens the content in a new tab or
window.

Customizing the authentication request
--------------------------------------

Expand Down
11 changes: 10 additions & 1 deletion lti_tool/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ def jwks(request):
class OIDCLoginInitView(View):
"""Handles OIDC 3rd-party login initiation for an LTI launch."""

main_msg = (
"Your browser prevents embedded content from using cookies. To work "
"around this, the content must be opened in a new tab or window. "
)
click_msg = "Open a new tab or window now."
loading_msg = "Loading..."

def get(self, request, *args, **kwargs):
registration_uuid = kwargs.get("registration_uuid")
return self.get_oidc_response(request, registration_uuid, request.GET)
Expand All @@ -52,7 +59,9 @@ def get_oidc_response(self, request, registration_uuid, params):
if target_link_uri is None:
return HttpResponseBadRequest("Missing target_link_uri parameter.")
redirect_url = self.get_redirect_url(target_link_uri)
return oidc_login.enable_check_cookies().redirect(redirect_url)
return oidc_login.enable_check_cookies(
self.main_msg, self.click_msg, self.loading_msg
).redirect(redirect_url)


@method_decorator(csrf_exempt, name="dispatch")
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ extend-ignore =
D105, # Missing docstring in magic method
D106, # Missing docstring in public nested class
D107, # Missing docstring in __init__
exclude = build/*, env/*, venv/*, .nox, lti_tool/migrations/*
exclude = build/*, env/*, venv/*, .venv/*, .nox, lti_tool/migrations/*

0 comments on commit 3eb1afd

Please sign in to comment.