Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

P20-848: Add error page for unsupported LTI message type #58024

Merged
merged 2 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion dashboard/app/assets/stylesheets/errors.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@import "color";
@import "font";

.not-found-page {
.error-page, .not-found-page {
body {
@include main-font-regular;
font-size: 14px;
Expand Down Expand Up @@ -102,3 +102,9 @@
line-height: 1.2em;
}
}

#lti-unsupported-message-type.error-page {
& .error-child {
max-width: 450px;
}
}
12 changes: 6 additions & 6 deletions dashboard/app/controllers/lti_v1_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,12 @@ def authenticate
jwt_verifier = JwtVerifier.new(decoded_jwt, integration)

if jwt_verifier.verify_jwt
message_type = decoded_jwt[:'https://purl.imsglobal.org/spec/lti/claim/message_type']
return wrong_resource_type unless message_type == 'LtiResourceLinkRequest'
message_type = decoded_jwt[Policies::Lti::MessageType::CLAIM]
if Policies::Lti::MessageType::SUPPORTED.exclude?(message_type)
return render status: :not_acceptable, template: 'lti/v1/authenticate/unsupported_message_type', locals: {
message_type: message_type,
}
end

user = Queries::Lti.get_user(decoded_jwt)
target_link_uri = decoded_jwt[:'https://purl.imsglobal.org/spec/lti/claim/target_link_uri']
Expand Down Expand Up @@ -424,10 +428,6 @@ def confirm_upgrade_account
render(status: :unauthorized, json: {error: 'Unauthorized'})
end

private def wrong_resource_type
render(status: :not_acceptable, json: {error: I18n.t('lti.error.wrong_resource_type')})
end

private def create_state_and_nonce
state = generate_random_string 10
nonce = Digest::SHA2.hexdigest(generate_random_string(10))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#lti-unsupported-message-type.error-page
.error-parent
.error-child
= image_tag '/shared/images/sad-bee-avatar.png'
%br
.error-message
%h1= t('lti.error.unsupported_message_type')
!= t('lti.error.unsupported_message_type_desc', message_type: message_type, supported_methods_url: SharedConstants::LMS_LINKS.SUPPORTED_METHODS_URL, markdown: true)
%br
%br
%a{href: root_url}
%button= I18n.t(:page_not_found_button)
6 changes: 5 additions & 1 deletion dashboard/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1423,7 +1423,11 @@ en:
integration_exists: "Lti Integration already exists for this Client ID"
missing_params: "Missing required param(s): School/District name, Client ID, LMS, Email"
unsupported_lms_type: "Unsupported LMS platform type"
wrong_resource_type: "Only LtiResourceLink is supported right now"
unsupported_message_type: Unsupported LTI message type
unsupported_message_type_desc: |
Sorry! It looks like you are trying to launch the Code.org Integration via a %{message_type}.
This isn't currently supported.
Please try launching Code.org again from a [supported method](%{supported_methods_url}).
missing_tool_config: 'Your LTI Tool configuration is missing the required "%{field}" field'
iframe_button: "Open in New Tab"
iframe_message: "Code.org cannot be run in an embedded window. Please open it in a new tab."
Expand Down
4 changes: 2 additions & 2 deletions dashboard/config/locales/pt-BR.yml
Git LFS file not shown
4 changes: 2 additions & 2 deletions dashboard/config/locales/tr-TR.yml
Git LFS file not shown
7 changes: 7 additions & 0 deletions dashboard/lib/policies/lti.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ module AccessTokenScopes
CONTEXT_MEMBERSHIP = 'https://purl.imsglobal.org/spec/lti-nrps/scope/contextmembership.readonly'.freeze
end

module MessageType
CLAIM = :'https://purl.imsglobal.org/spec/lti/claim/message_type'
SUPPORTED = [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, should be easy to add deep linking message type support later.

RESOURCE_LINK_REQUEST = 'LtiResourceLinkRequest'.freeze,
].freeze
end

ALL_SCOPES = AccessTokenScopes.constants.map do |scope|
AccessTokenScopes.const_get(scope)
end
Expand Down
3 changes: 3 additions & 0 deletions dashboard/test/controllers/lti_v1_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,9 @@ def create_valid_jwt_raise_error
jwt = create_jwt(payload)
post '/lti/v1/authenticate', params: {id_token: jwt, state: @state}
assert_response :not_acceptable
assert_match 'Unsupported LTI message type', @response.body
assert_match 'Sorry! It looks like you are trying to launch the Code.org Integration via a file.', @response.body
assert_match 'Please try launching Code.org again from a <a href="https://github.com/code-dot-org/code-dot-org/blob/staging/docs/lti-integration.md#option-2-manual-entry">supported method</a>.', @response.body
end

test 'auth - error raised in decoding jwt' do
Expand Down
2 changes: 2 additions & 0 deletions lib/cdo/shared_constants.rb
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,8 @@ module SharedConstants
INTEGRATION_EARLY_ACCESS_URL: 'https://docs.google.com/forms/d/e/1FAIpQLScjfVR4CZs8Utf5vI4mz3e1q8vdH6RNIgTUWygZXN0oovBSQg/viewform',
INTEGRATION_BUG_REPORT_URL: 'https://support.code.org/hc/en-us/requests/new?ticket_form_id=14998494738829&tf_23889708=lms_eaf',
ADDITIONAL_FEEDBACK_URL: 'https://studio.code.org/form/lms_integration_modal_feedback',
# TODO(P20-873): Replace SUPPORTED_METHODS_URL with the link to the supported methods documentation
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for creating the jira and leaving a reminder

SUPPORTED_METHODS_URL: 'https://github.com/code-dot-org/code-dot-org/blob/staging/docs/lti-integration.md#option-2-manual-entry',
}
).freeze

Expand Down