Skip to content

Commit

Permalink
Merge pull request #123 from uw-it-aca/feature/additive-1-point-3
Browse files Browse the repository at this point in the history
target link uri
  • Loading branch information
mikeseibel authored Jan 25, 2025
2 parents d193362 + 29360dd commit 035ae7d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 13 deletions.
22 changes: 22 additions & 0 deletions blti/templates/blti/500.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{% extends 'blti/base.html' %}

{% load static %}

{% block mobile_css %}
<link rel="stylesheet" type="text/css" href="{% static "blti/css/mobile.css" %}"/>
{% endblock mobile_css %}


{% block content %}
<div id="unauthorized_holder">
<div id="unauthorized_message">
<h2 class="ui-state-error">
<i class="fa fa-warning"></i> <span>Page Error</span>
</h2>
<p><strong>{{ error }}</strong></p>
<p>
An error has occured while producing this page. If this page does not load properly after a few minutes, please use the "Help" link to notify support of the problem.
</p>
</div>
</div>
{% endblock content %}
25 changes: 12 additions & 13 deletions blti/views/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,36 @@
# SPDX-License-Identifier: Apache-2.0

from django.views.decorators.csrf import csrf_exempt
from django.http import HttpResponse
from django.template.response import TemplateResponse
from blti.config import get_tool_conf, get_launch_data_storage
from blti.exceptions import BLTIException
from pylti1p3.contrib.django import DjangoOIDCLogin
import logging


logger = logging.getLogger(__name__)


def get_launch_url(request):
try:
return request.POST.get(
'target_link_uri', request.GET['target_link_uri'])
except KeyError:
raise BLTIException('Missing "target_link_uri" param')


@csrf_exempt
def login(request):
try:
tool_conf = get_tool_conf()
launch_data_storage = get_launch_data_storage()
oidc_login = DjangoOIDCLogin(
request, tool_conf, launch_data_storage=launch_data_storage)
target_link_uri = get_launch_url(request)

target_link_uri = getattr(request, request.method)['target_link_uri']

if target_link_uri.startswith('http:') and request.is_secure():
target_link_uri = f"https:{target_link_uri[5:]}"

return oidc_login.enable_check_cookies().redirect(target_link_uri)
except KeyError:
logger.error(f"Missing 'target_link_uri' in {request.method} params: "
"{request.body.decode('utf-8')}")
return TemplateResponse(request, 'blti/500.html',
context={'error': 'Missing Target Link URI'},
status=500)
except Exception as ex:
logger.error(f"LTI 1.3 login exception: {ex}")
return HttpResponse(str(ex), status=401)
logger.exception(f"LTI 1.3 login exception: {ex}")
return TemplateResponse(request, 'blti/500.html',
context={'error': str(ex)}, status=500)

0 comments on commit 035ae7d

Please sign in to comment.