Skip to content

Commit

Permalink
Add LTI 1.3 JSON configuration endpoint at /lti/config.json
Browse files Browse the repository at this point in the history
In Canvas LMS, an LTI Developer Key can be created via Manual
Entry, or by URL. This view provides the JSON necessary for URL
configuration in Canvas.

https://canvas.instructure.com/doc/api/file.lti_dev_key_config.html
  • Loading branch information
nikolas committed Jan 23, 2025
1 parent 1eb7c91 commit da5009a
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lti_auth/urls.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
from django.urls import path

from lti_auth.views import LTIConfigView, LTILandingPage, LTIRoutingView, \
LTICourseEnableView
from lti_auth.views import (
LTIConfigView, LTILandingPage, LTIRoutingView,
LTICourseEnableView, LTI1p3JSONConfigView
)
from lti_tool.views import jwks, OIDCLoginInitView


urlpatterns = [
path('config.xml', LTIConfigView.as_view(), {}, 'lti-config'),
path('config.json', LTI1p3JSONConfigView.as_view(), name='lti-1p3-config'),
path('enable/', LTICourseEnableView.as_view(), {}, 'lti-enable-course'),
path('landing/<slug:context>/',
LTILandingPage.as_view(), {}, 'lti-landing-page'),
Expand Down
87 changes: 87 additions & 0 deletions lti_auth/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
from django.contrib.auth import authenticate, login
from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import Group
from django.http import JsonResponse
from django.http.response import HttpResponseRedirect
from django.shortcuts import get_object_or_404, render
from django.urls import reverse
from django.utils.decorators import method_decorator
from django.views.decorators.clickjacking import xframe_options_exempt
from django.views.decorators.csrf import csrf_exempt
from django.views.generic.base import View, TemplateView
from urllib.parse import urljoin

from lti_auth.lti import LTI
from lti_auth.models import LTICourseContext

Expand Down Expand Up @@ -126,6 +129,90 @@ def get_context_data(self, **kwargs):
return ctx


class LTI1p3JSONConfigView(View):
"""
JSON configuration endpoint for LTI 1.3.
In Canvas LMS, an LTI Developer Key can be created via Manual
Entry, or by URL. This view provides the JSON necessary for URL
configuration in Canvas.
https://canvas.instructure.com/doc/api/file.lti_dev_key_config.html
"""
def get(self, request, *args, **kwargs):
domain = request.get_host()
title = settings.LTI_TOOL_CONFIGURATION['title']
icon_url = urljoin(settings.STATIC_URL,
settings.LTI_TOOL_CONFIGURATION['embed_icon_url'])

json_obj = {
'title': title,
'description': settings.LTI_TOOL_CONFIGURATION['description'],
'oidc_initiation_url': 'https://{}.oidc_initiation_url'.format(
domain),
'target_link_uri': 'https://{}.target_link_uri'.format(domain),
'scopes': [
'https://purl.imsglobal.org/spec/lti-ags/scope/lineitem',
'https://purl.imsglobal.org/spec/lti-ags/scope/result.readonly'
],
'extensions': [
{
'domain': domain,
'tool_id': 'mediathread',
'platform': 'canvas.instructure.com',
'privacy_level': 'public',
'settings': {
'text': 'Launch ' + title,
'labels': {
'en': 'Launch ' + title,
},
'icon_url': icon_url,
'selection_height': 800,
'selection_width': 800,
'placements': [
{
'text': 'User Navigation Placement',
'icon_url': icon_url,
'placement': 'user_navigation',
'message_type': 'LtiResourceLinkRequest',
'target_link_uri': None,
'canvas_icon_class': 'icon-lti',
'custom_fields': {
'foo': '$Canvas.user.id'
}
},
{
'text': 'Editor Button Placement',
'icon_url': icon_url,
'placement': 'editor_button',
'message_type': 'LtiDeepLinkingRequest',
'target_link_uri': None,
'selection_height': 500,
'selection_width': 500
},
{
'text': 'Course Navigation Placement',
'icon_url': icon_url,
'placement': 'course_navigation',
'message_type': 'LtiResourceLinkRequest',
'target_link_uri': None,
'required_permissions': 'manage_calendar',
'selection_height': 500,
'selection_width': 500
}
]
}
}
],
'public_jwk_url': urljoin(
'https://{}'.format(domain), reverse('jwks')),
'custom_fields': {
'bar': '$Canvas.user.sisid'
}
}
return JsonResponse(json_obj)


@method_decorator(xframe_options_exempt, name='dispatch')
class LTILandingPage(TemplateView):
template_name = 'lti_auth/landing_page.html'
Expand Down

0 comments on commit da5009a

Please sign in to comment.