Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
LTI 1.3 Advantage Tool implementation in Python
===============================================

.. image:: https://img.shields.io/pypi/v/PyLTI1p3
This is a fork of the `pylti1p3 <https://github.com/dmitry-viskov/pylti1.3>`_ package, originally written by Dmitry Viskov.

.. image:: https://img.shields.io/pypi/v/pylti1p3next
:scale: 100%
:target: https://pypi.python.org/pypi/PyLTI1p3
:target: https://pypi.python.org/pypi/pylti1p3next
:alt: PyPI

.. image:: https://img.shields.io/pypi/pyversions/PyLTI1p3
.. image:: https://img.shields.io/pypi/pyversions/pylti1p3next
:scale: 100%
:target: https://www.python.org/
:alt: Python

.. image:: https://github.com/dmitry-viskov/pylti1.3/actions/workflows/tox.yml/badge.svg
.. image:: https://github.com/pymsglobal/pylti1p3next/actions/workflows/tox.yml/badge.svg
:scale: 100%
:target: https://github.com/dmitry-viskov/pylti1.3/actions
:target: https://github.com/pymsglobal/pylti1p3next/actions
:alt: Build Status

.. image:: https://img.shields.io/github/license/dmitry-viskov/pylti1.3
.. image:: https://img.shields.io/github/license/pymsglobal/pylti1p3next
:scale: 100%
:target: https://raw.githubusercontent.com/dmitry-viskov/pylti1.3/master/LICENSE
:target: https://raw.githubusercontent.com/pymsglobal/pylti1p3next/master/LICENSE
:alt: MIT


Expand All @@ -30,9 +32,9 @@ This library contains adapters for use with the Django and Flask web frameworks.
Usage Examples
=================

Django: https://github.com/dmitry-viskov/pylti1.3-django-example
Django: https://github.com/pymsglobal/pylti1p3next-django-example

Flask: https://github.com/dmitry-viskov/pylti1.3-flask-example
Flask: https://github.com/pymsglobal/pylti1p3next-flask-example

Configuration
=============
Expand Down Expand Up @@ -581,7 +583,7 @@ After this, the special JS code will try to write and then read test cookie inst
`special page`_ that will ask them to open the current URL in the new window if cookies are unavailable. If
cookies are allowed, the user will be transparently redirected to the next page. All texts are configurable with passing arguments:

.. _special page: https://raw.githubusercontent.com/dmitry-viskov/repos-assets/master/pylti1p3/examples/cookies-check/001.png
.. _special page: https://raw.githubusercontent.com/pymsglobal/repos-assets/master/pylti1p3/examples/cookies-check/001.png

.. code-block:: python

Expand Down
11 changes: 6 additions & 5 deletions pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ fail-under=10
#from-stdin=

# Files or directories to be skipped. They should be base names, not paths.
ignore=CVS
ignore=

# Add files or directories matching the regular expressions patterns to the
# ignore-list. The regex matches against paths and can be in Posix or Windows
# format. Because '\' represents the directory delimiter on Windows systems, it
# can't be used as an escape character.
ignore-paths=
ignore-paths=^.*/migrations/.*$

# Files or directories matching the regular expression patterns are skipped.
# The regex matches against base names, not paths. The default value ignores
Expand Down Expand Up @@ -77,7 +77,7 @@ limit-inference-results=100

# List of plugins (as comma separated values of python module names) to load,
# usually to register additional checkers.
load-plugins=
load-plugins=pylint_django

# Pickle collected data for later comparisons.
persistent=yes
Expand Down Expand Up @@ -307,8 +307,8 @@ min-public-methods=2
[EXCEPTIONS]

# Exceptions that will emit a warning when caught.
overgeneral-exceptions=BaseException,
Exception
overgeneral-exceptions=builtins.BaseException,
builtins.Exception


[FORMAT]
Expand Down Expand Up @@ -428,6 +428,7 @@ disable=bad-inline-option,
use-symbolic-message-instead,
useless-option-value,
useless-suppression,
django-not-configured,


# Enable the message, report, category or checker with the given id(s). You can
Expand Down
72 changes: 72 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
[project]
name = "pylti1p3next"
dynamic = ["version"]
authors = [
{ name="Christian Lawson-Perfect", email="[email protected]"},
{ name="Dmitry Viskov", email="[email protected]"}
]
maintainers = [
{ name="Sébastien Philippot", email="[email protected]" },
{ name="Christian Lawson-Perfect", email="[email protected]"}
]
description = "LTI 1.3 Advantage Tool implementation in Python"
readme = "README.rst"
license = "MIT"
license-files = ["LICENSE"]
requires-python = ">=3.8"
keywords = [
"pylti",
"pylti1p3",
"lti",
"lti1.3",
"lti1p3",
"django",
"flask"
]
classifiers = [
"Development Status :: 5 - Production/Stable",
"Environment :: Web Environment",
"Framework :: Django",
"Framework :: Flask",
"Intended Audience :: Developers",
"Intended Audience :: Information Technology",
"Intended Audience :: Education",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Programming Language :: Python :: 3 :: Only",
"Topic :: Internet :: WWW/HTTP",
"Topic :: Internet :: WWW/HTTP :: WSGI",
"Topic :: Security",
"Topic :: Software Development :: Libraries :: Application Frameworks",
"Topic :: Internet :: WWW/HTTP :: Dynamic Content",
"Topic :: Software Development :: Libraries :: Python Modules",
]
dependencies = [
"jwcrypto~=1.5",
"pyjwt~=1.5",
"requests~=2.32",
"typing_extensions~=4.2",
]

[project.urls]
Homepage = "https://github.com/pymsglobal/pylti1p3next#readme"
Issues = "https://github.com/pymsglobal/pylti1p3next/issues"
Source = "https://github.com/pymsglobal/pylti1p3next"

[build-system]
requires = ["setuptools>=61.0"]
build-backend = "setuptools.build_meta"

[tool.setuptools.dynamic]
version = {attr = "pylti1p3.__version__"}

[tool.coverage.paths]
pylti1p3next = ["pylti1p3"]
tests = ["tests"]
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ license_file = LICENSE

[flake8]
max_line_length=120
exclude=.git,.idea,.tox,build,venv,venv3,env
exclude=.git,.idea,.tox,build,venv,venv3,env,migrations
extend-ignore=E203

[coverage:run]
Expand Down
72 changes: 0 additions & 72 deletions setup.py

This file was deleted.

File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -249,17 +249,17 @@ def find_or_create_lineitem(
if not self.can_create_lineitem():
raise LtiException("Can't create lineitem: Missing required scope")

created_lineitem = self._service_connector.make_service_request(
self._service_data["scope"],
self._service_data["lineitems"],
response = self._service_connector.make_service_request(
scopes=self._service_data["scope"],
url=self._service_data["lineitems"],
is_post=True,
data=new_lineitem.get_value(),
content_type="application/vnd.ims.lis.v2.lineitem+json",
accept="application/vnd.ims.lis.v2.lineitem+json",
)
if not isinstance(created_lineitem["body"], dict):
if not isinstance(response["body"], dict):
raise LtiException("Unknown response type received for create line item")
return LineItem(t.cast(TLineItem, created_lineitem["body"]))
return LineItem(t.cast(TLineItem, response["body"]))

def get_grades(self, lineitem: t.Optional[LineItem] = None) -> list:
"""
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import json

from pylti1p3.deployment import Deployment
from pylti1p3.exception import LtiException
from pylti1p3.registration import Registration
Expand Down
112 changes: 112 additions & 0 deletions src/pylti1p3/contrib/django/lti1p3_tool_config/dynamic_registration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
from typing import Any, Dict

from django.urls import reverse_lazy
from django.templatetags.static import static

from pylti1p3.dynamic_registration import DynamicRegistration, generate_key_pair

from .models import LtiTool, LtiToolKey


class DjangoDynamicRegistration(DynamicRegistration):

initiate_login_url = reverse_lazy("lti:login")

jwks_url = reverse_lazy("lti:jwks")

launch_url = reverse_lazy("lti:launch")

# The path of the tool's logo image, under ``STATIC_ROOT``.
logo_file = "lti/logo.png"

def __init__(self, request):
super().__init__()

self.request = request

def get_issuer_keys(self, issuer_name: str):
key_obj, created = LtiToolKey.objects.get_or_create(name=issuer_name)
if created:
private_key, public_key = generate_key_pair()
key_obj.private_key = private_key
key_obj.public_key = public_key
key_obj.save()
return key_obj

def get_initiate_login_uri(self) -> str:
return self.request.build_absolute_uri(str(self.initiate_login_url))

def get_jwks_uri(self) -> str:
return self.request.build_absolute_uri(str(self.jwks_url))

def get_redirect_uris(self) -> list[str]:
return [self.get_target_link_uri()]

def get_domain(self) -> str:
return self.request.get_host()

def get_target_link_uri(self) -> str:
return self.request.build_absolute_uri(self.launch_url)

def get_logo_uri(self) -> str:
return self.request.build_absolute_uri(static(self.logo_file))

def get_openid_configuration_endpoint(self):
return self.request.GET.get("openid_configuration")

def get_registration_token(self):
return self.request.GET.get("registration_token")

def get_platform_name(self, openid_configuration: Dict[str, Any]) -> str:
"""
Get the name of the platform this tool is registering with.
"""
return openid_configuration.get(
"https://purl.imsglobal.org/spec/lti-platform-configuration", {}
).get("product_family_code", "")

def complete_registration(
self, openid_configuration: Dict[str, Any], openid_registration: Dict[str, Any]
):
title = self.get_platform_name(openid_configuration)

tool_key = self.get_issuer_keys(openid_configuration["issuer"])

tool_spec = "https://purl.imsglobal.org/spec/lti-tool-configuration"
deployment_id = openid_registration[tool_spec].get("deployment_id")

deployment_ids = []

if deployment_id is not None:
deployment_ids.append(deployment_id)

platform_config, _created = LtiTool.objects.update_or_create(
issuer=openid_configuration["issuer"],
client_id=openid_registration["client_id"],
defaults={
"title": title,
"auth_login_url": openid_configuration["authorization_endpoint"],
"auth_token_url": openid_configuration["token_endpoint"],
"auth_audience": openid_configuration["token_endpoint"],
"key_set_url": openid_configuration["jwks_uri"],
"tool_key": tool_key,
"deployment_ids": deployment_ids,
},
)

platform_config.save() # type: ignore
return platform_config

def keys_for_issuer(self, issuer_name: str) -> LtiToolKey:
"""
Get the public and private keys for a given issuer.
If they don't exist yet, then create them.
"""
key_obj, created = LtiToolKey.objects.get_or_create(name=issuer_name)
if created:
private_key, public_key = generate_key_pair()
key_obj.private_key = private_key
key_obj.public_key = public_key
key_obj.save()
return key_obj
Loading