Skip to content

Commit

Permalink
Add LTI 1.3 JSON config view
Browse files Browse the repository at this point in the history
This allows us to create a Developer Key in Canvas via single JSON URL
rather than filling in all these fields manually.

https://canvas.instructure.com/doc/api/file.lti_dev_key_config.html
  • Loading branch information
nikolas committed Jan 22, 2025
1 parent 5879bb9 commit b1cae39
Showing 1 changed file with 98 additions and 0 deletions.
98 changes: 98 additions & 0 deletions lti_auth/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
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
Expand Down Expand Up @@ -126,6 +127,103 @@ def get_context_data(self, **kwargs):
return ctx


class LTI13JSONConfigView(View):
def get(self, **kwargs):
json_obj = {
"title": "The Best Tool",
"description": "1.3 Test Tool used for documentation purposes.",
"oidc_initiation_url": "https://your.oidc_initiation_url",
"oidc_initiation_urls": {
"eu-west-1": "https://your.eu-specific1.oidc_initiation_url",
"eu-central-1": "https://your.eu-specific2.oidc_initiation_url"
},
"target_link_uri": "https://your.target_link_uri",
"scopes": [
"https://purl.imsglobal.org/spec/lti-ags/scope/lineitem",
"https://purl.imsglobal.org/spec/lti-ags/scope/result.readonly"
],
"extensions": [
{
"domain": "thebesttool.com",
"tool_id": "the-best-tool",
"platform": "canvas.instructure.com",
"privacy_level": "public",
"settings": {
"text": "Launch The Best Tool",
"labels": {
"en": "Launch The Best Tool",
"en-AU": "G'day, Launch The Best Tool",
"es": "Lanzar la mejor herramienta",
"zh-Hans": "启动最佳工具"
},
"icon_url": "https://some.icon.url/tool-level.png",
"selection_height": 800,
"selection_width": 800,
"placements": [
{
"text": "User Navigation Placement",
"icon_url": "https://some.icon.url/my_dashboard.png",
"placement": "user_navigation",
"message_type": "LtiResourceLinkRequest",
"target_link_uri": "https://your.target_link_uri/my_dashboard",
"canvas_icon_class": "icon-lti",
"custom_fields": {
"foo": "$Canvas.user.id"
}
},
{
"text": "Editor Button Placement",
"icon_url": "https://some.icon.url/editor_tool.png",
"placement": "editor_button",
"message_type": "LtiDeepLinkingRequest",
"target_link_uri": "https://your.target_link_uri/content_selector",
"selection_height": 500,
"selection_width": 500
},
{
"text": "Course Navigation Placement",
"icon_url": "https://static.thenounproject.com/png/131630-200.png",
"placement": "course_navigation",
"message_type": "LtiResourceLinkRequest",
"target_link_uri": "https://your.target_link_uri/launch?placement=course_navigation",
"required_permissions": "manage_calendar",
"selection_height": 500,
"selection_width": 500
}
]
}
}
],
"public_jwk": {
"kty": "RSA",
"alg": "RS256",
"e": "AQAB",
"kid": "8f796169-0ac4-48a3-a202-fa4f3d814fcd",
"n": "nZD7QWmIwj-3N_RZ1qJjX6CdibU87y2l02yMay4KunambalP9g0fU9yZLwLX9WYJINcXZDUf6QeZ-SSbblET-h8Q4OvfSQ7iuu0WqcvBGy8M0qoZ7I-NiChw8dyybMJHgpiP_AyxpCQnp3bQ6829kb3fopbb4cAkOilwVRBYPhRLboXma0cwcllJHPLvMp1oGa7Ad8osmmJhXhM9qdFFASg_OCQdPnYVzp8gOFeOGwlXfSFEgt5vgeU25E-ycUOREcnP7BnMUk7wpwYqlE537LWGOV5z_1Dqcqc9LmN-z4HmNV7b23QZW4_mzKIOY4IqjmnUGgLU9ycFj5YGDCts7Q",
"use": "sig"
},
"custom_fields": {
"bar": "$Canvas.user.sisid"
}
}

domain = self.request.get_host()
launch_url = '%s://%s/%s' % (
self.request.scheme, domain,
settings.LTI_TOOL_CONFIGURATION['launch_url'])

ctx = {
'domain': domain,
'launch_url': launch_url,
'title': settings.LTI_TOOL_CONFIGURATION['title'],
'description': settings.LTI_TOOL_CONFIGURATION['description'],
'embed_icon_url':
settings.LTI_TOOL_CONFIGURATION['embed_icon_url'],
'embed_tool_id': settings.LTI_TOOL_CONFIGURATION['embed_tool_id'],
}
return ctx


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

0 comments on commit b1cae39

Please sign in to comment.