Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/academic-innovation/django-lti
LTI Advantage support for Django projects.
https://github.com/academic-innovation/django-lti
django lti python
Last synced: 11 days ago
JSON representation
LTI Advantage support for Django projects.
- Host: GitHub
- URL: https://github.com/academic-innovation/django-lti
- Owner: academic-innovation
- License: mit
- Created: 2022-05-05T13:19:06.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-12-05T18:07:45.000Z (about 1 year ago)
- Last Synced: 2023-12-06T18:28:03.213Z (about 1 year ago)
- Topics: django, lti, python
- Language: Python
- Homepage: https://academic-innovation.github.io/django-lti/
- Size: 103 KB
- Stars: 11
- Watchers: 3
- Forks: 4
- Open Issues: 15
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
- awesome-lti - LTI 1.3 Advantage Django reusable app
- awesome-lti - LTI 1.3 Advantage Django reusable app
README
# django-lti
A [Django reusable app](https://docs.djangoproject.com/en/4.0/intro/reusable-apps/) providing support for LTI Advantage.
## Installation
Install using pip.
```
pip install django-lti
```## Setup
Start by adding `lti_tool` to your project's `INSTALLED_APPS`.
```python
INSTALLED_APPS = [
...
"lti_tool",
]
```Then, add `lti_tool.middleware.LtiLaunchMiddleware` to the `MIDDLEWARE` setting.
It's important to list the `LtiLaunchMiddleware` _after_ `SessionMiddleware`.```python
MIDDLEWARE = [
...
'django.contrib.sessions.middleware.SessionMiddleware',
'lti_tool.middleware.LtiLaunchMiddleware',
]
```Finally, run migrations to initialize the needed database tables.
```
python manage.py migrate lti_tool
```## Usage
### Adding JWKS and OIDC initiation URLs
To allow LTI platforms to retrieve a JWKS and initiate a launch, add paths for
`lti_tool.views.jwks` and `lti_tool.views.OIDCLoginInitView` to `urls.py````python
...from lti_tool.views import jwks, OIDCLoginInitView
urlpatterns = [
path(".well-known/jwks.json", jwks, name="jwks"),
path("init//", OIDCLoginInitView.as_view(), name="init"),
]```
### Generating and rotating keys
Keys for the JWKS can be generated using the `rotate_keys` management command.
```
python manage.py rotate_keys
```### Registering an LTI platform
An LTI platform can be registered through the Django admin, or using a custom
interface.### Handling an LTI launch
To handle the LTI launch, inherit from `LtiLaunchBaseView` and implement the handler
methods for the types of LTI message types that the application supports.```python
class ApplicationLaunchView(LtiLaunchBaseView):def handle_resource_launch(self, request, lti_launch):
... # Required. Typically redirects the users to the appropriate page.def handle_deep_linking_launch(self, request, lti_launch):
... # Optional.def handle_submission_review_launch(self, request, lti_launch):
... # Optional.def handle_data_privacy_launch(self, request, lti_launch):
... # Optional.
```Each handler method receives the request, as well as a `LtiLaunch` object.
When a session is initiated by an LTI launch, data about the launch is available from
the request at `request.lti_launch` as an `LtiLaunch` object. During a non-LTI session
`request.lti_launch` will refer to an `AbsentLtiLaunch` object.It is possible to distinguish between `LtiLaunch` and `AbsentLtiLaunch` objects using
the `.is_present` and `.is_absent` properties.