Skip to main content

LTI 1.3 Platform implementation

Project description

LTI 1.3 Platform implementation in Python

Usage

Register your platform

The platform should prepare the launch by gathering the necessary context information, including details about the user, the course, and any custom parameters that need to be included in the launch request.

from lti1p3platform.ltiplatform import LTI1P3PlatformConfAbstract
from lti1p3platform.registration import Registration

class LTIPlatformConf(LTI1P3PlatformConfAbstract):
    def init_platform_config(self, platform_settings, platform_key_set):
        """
        register platform configuration
        """
        registration = Registration() \
            .set_client_id(platform_settings.client_id) \
            .set_deployment_id(platform_settings.deployment_id) \
            .set_launch_url(platform_settings.launch_url) \
            .set_deeplink_launch_url(platform_settings.deeplink_launch_url) \
            .set_oidc_login_url(platform_settings.oidc_login_url) \
            .set_tool_key_set_url(platform_settings.key_set_url) \
            .set_platform_public_key(platform_key_set.public_key) \
            .set_platform_private_key(platform_key_set.private_key)

        self._registration = registration

def get_registered_platform(*args, **kwargs):
    ...

    return LTIPlatformConf(*args, **kwargs)

# public JWK endpoint
def get_jwks(request, *args, **kwargs):
    platform = get_registered_platform(*args, **kwargs)

    return HttpResponseJSON(platform.get_jwks())

OIDC initiate login

The tool consumer (i.e., the LMS) sends a request to the tool provider's application to initiate the OIDC authentication flow.

from lti1p3platform.oidc_login import OIDCLoginAbstract

class OIDCLogin(OIDCLoginAbstract):
    def set_lti_message_hint(self, **kwargs):
        """ set your own lti_message_hint """
        pass

    def get_lti_message_hint(self):
        """ get your lti_message_hint """
        pass

    def get_redirect(self, url):
        """
        This will be invoked in initiate_login, and it depends on which web framework you are using.
        Here is an example for Django framework:
        """
        return HttpResponseRedirect(url)

# Initiate login endpoint
def preflight_lti_1p3_launch(request, user_id, *args, **kwargs):
    platform = get_registered_platform(*args, **kwargs)
    oidc_login = OLOIDCLogin(request, platform)

    # Redirect the current login user to the tool provider,
    return redirect_url.initiate_login(user_id)

LTI Message launch

The tool provider redirect to the platform's OIDC auth request endpoint. The platform received the auth request and it will do some little bit of validation, it needs to ensure user is login, also check the login_hint is matched with the user_id. The platform also could get the context from the lti_message_hint which is sent in the initiating request and do some other validation.

After all verifications, the platform will generate a id_token. The platform encodes all important launch message payload as a JWT and send it as id_token parameter in a post request to the tool launch url.

from lti1p3platform.message_launch import MessageLaunchAbstract

class LTI1p3MessageLaunch(MessageLaunchAbstract):
    def render_launch_form(self, launch_data, **kwargs):
        """
        This will be invoked in the last step of `lti_launch`.
        So you could render a template in this method. This template should render a form, and then submit it to the tool's launch URL. There is a django example in framework/django/message_launch.py
        """
        pass

    def prepare_launch(self, preflight_response, **kwargs):
        """
        You could do some other checks and get some contexts from `lti_message_hint` you've set in previous request
        Also you could call these methods to prepare your own jwt payload:
            - set_user_data
            - set_resource_link_claim
            - set_launch_context_claim
            - set_custom_parameters_claim

        Make sure do these things before lti_launch, it could send necessary launch parameters to the tool.
        """
        pass

def lti_resource_link_launch(request, *args, **kwargs):
    platform = get_registered_platform(*args, **kwargs)
    message_launch = LTI1p3MessageLaunch(request, *args, **kwargs)

    return launch.lti_launch(*args, **kwargs)

Examples

Django example

Development

Run test

Prerequisite: tox and python 3.7, 3.8, 3.9, 3.10

If you are using pyenv virtualenv, you might need to install all python versions and run pyenv local 3.7.x 3.8.x 3.9.x 3.10.x at the first time.

cd lti1p3platform
tox

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lti1p3platform-0.1.8.tar.gz (24.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lti1p3platform-0.1.8-py3-none-any.whl (30.4 kB view details)

Uploaded Python 3

File details

Details for the file lti1p3platform-0.1.8.tar.gz.

File metadata

  • Download URL: lti1p3platform-0.1.8.tar.gz
  • Upload date:
  • Size: 24.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.18

File hashes

Hashes for lti1p3platform-0.1.8.tar.gz
Algorithm Hash digest
SHA256 46f9927d5c1826b63e2645b4ff6602fa548c06bf624ec961431e29a30134efea
MD5 868d2dca4d89f98f50b34e678aff8b93
BLAKE2b-256 ef74cc40ea66b89fe2530d0b0e1cd27afb5f4b8a136bcac517906131478f503d

See more details on using hashes here.

File details

Details for the file lti1p3platform-0.1.8-py3-none-any.whl.

File metadata

  • Download URL: lti1p3platform-0.1.8-py3-none-any.whl
  • Upload date:
  • Size: 30.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.18

File hashes

Hashes for lti1p3platform-0.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 37892b7bf76b159ad36ad085d3e724379818585ab695acfcc872cbd2be8bec76
MD5 c1abfb655e04bf5610629b471650fda8
BLAKE2b-256 ba8ecfaa8cc80185339688b62f906459a4608ae457538495cbce111e651c4f4c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page