Skip to content

Implement Initial LTI 1.3 Launch#1635

Merged
20wildmanj merged 28 commits into
masterfrom
joeywildman-init-lti-setup
Nov 13, 2022
Merged

Implement Initial LTI 1.3 Launch#1635
20wildmanj merged 28 commits into
masterfrom
joeywildman-init-lti-setup

Conversation

@20wildmanj

@20wildmanj 20wildmanj commented Nov 2, 2022

Copy link
Copy Markdown
Contributor

Description

This PR implements the LTI Advantage launch flow described in LMS Integration Design Doc V2.0. It is recommended to view "Implementation and Technical Details" as well as "LTI Advantage Launch Flow" sections. The full LTI 1.3 launch specification for tools such as Autolab can be found here.

Most of the code in this PR is based off the LTI 1.3 PHP library and the pylti1.3 library, specifically LTI_OIDC_Login.php, and LTI_Message_Launch.php.

Specific changes:

  • Build initial LTI 1.3 Integration Library in controllers/lti_launch_controller.rb
    • /lti_launch/oidc_login/ endpoint handles Step 1 and Step 2 of the launch flow (see design doc for more details),
      • Ensure that iss parameter from platform matches our configuration settings, lti_message_hint exists
      • create state, nonce params using SecureRandom, with state stored as a short lived cookie and nonce as a cache entry (to prevent replay attacks)
      • Generate authentication parameters based off rails configuration settings (in lti_settings.yml), and redirect to authorization url of platform.
    • /lti_launch/launch/ endpoint handles Step 4 of the launch flow (see design doc for more details),
      • mainly validation of data received from platform, and sends off received JWT body data to lti_launch_initialize
      • validate both state and nonce received match the ones generated during oidc_login
      • validate response from platform is a valid JWT with correct signature by platform
      • validate client_id received from platform to that in configuration settings
      • Ensure that request is a "LtiResourceLinkRequest" with version "1.3.0"
      • validate we have access to NRPS and that we receive "context_memberships_url"
  • display final resource (course context, etc. in users/:id/lti_launch_initialize) via lti_launch_initialize in users_controller.rb

How Has This Been Tested?

  • Go to /config and run:
    cp lti_settings.yml.template lti_settings.yml

  • Fill in lti_settings.yml

  • enable cache by running rails dev:cache

  • Go to the LTI Reference Tool main page

  • Go to "Manage Platforms"

  • Click on "Unclaimed Platforms"

  • Find the "Autolab Test" platform (ctrl-f)

  • Click on "View Platform". Make sure client id, OIDC Auth URL, platform public key matches the rails config file.

Screen Shot 2022-11-08 at 15 20 57

  • Click on "Resource Links" for Autolab Test
  • Click "Select User for Launch" for Resource Link with Title "Autolab PR test"

Screen Shot 2022-11-08 at 15 19 48

  • Choose user with "Student: No", and click "Launch Resource Link (OIDC)". For example, you should launch as Davida in the example below.

Screen Shot 2022-11-08 at 15 18 05

  • Choose either to send a POST or GET request (either works) on the next page
  • You should immediately be redirected to a page similar to the one below. If you have to log into Autolab, or receive a message that you are already logged into autolab, try going back to the Resource Link page and clicking "Launch Resource Link (OIDC)" again. If you received an error from the oidc_login endpoint, make sure your lti_settings.yml information is correct, and try again.

Screen Shot 2022-11-08 at 15 25 11

  • Click "launch resource link"
  • Scroll down past the JWT and click "Perform Launch." Again, if you receive an auth request from Autolab, log in, but then restart the launch process. If you receive an error message along the lines of "state/nonce not correct" you may have been too slow to complete the launch flow. Otherwise, you should be viewing this page:

Screen Shot 2022-11-08 at 15 29 00

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • I have run rubocop for style check. If you haven't, run overcommit --install && overcommit --sign to use pre-commit hook for linting
  • I have updated the documentation accordingly, included in this PR
    -> will update documentation in a later PR

To do: figure out why "already logged in" auth error shows up and interrupts launch flow

Comment thread app/controllers/lti_launch_controller.rb Fixed
@20wildmanj 20wildmanj marked this pull request as ready for review November 8, 2022 22:42
@20wildmanj 20wildmanj requested a review from najclark November 8, 2022 22:42
@20wildmanj 20wildmanj changed the title [WIP] Implement Initial LTI 1.3 Launch Implement Initial LTI 1.3 Launch Nov 8, 2022
@20wildmanj 20wildmanj requested a review from damianhxy November 8, 2022 23:15
Comment thread app/views/users/lti_launch_initialize.html.erb
@damianhxy

Copy link
Copy Markdown
Member

Screenshot 2022-11-10 at 22 13 48

Steps successfully followed, although I think it's missing the step where we need to click the POST request button
Screenshot 2022-11-10 at 22 11 54

@damianhxy damianhxy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Left some clarifying comments

Comment thread config/routes.rb Outdated
Comment thread app/controllers/users_controller.rb Outdated
Comment thread app/controllers/users_controller.rb Outdated
Comment thread app/controllers/lti_launch_controller.rb Outdated
Comment thread app/controllers/lti_launch_controller.rb Outdated
@najclark

Copy link
Copy Markdown
Contributor

Was able to follow the testing steps. PR looks good to me, besides the few things @damianhxy mentioned.

- rework lti_launch_initialize to have more readable logic
- add user-id to nonce to prevent overwrite from multiple launches by different users
@20wildmanj

Copy link
Copy Markdown
Contributor Author
Screenshot 2022-11-10 at 22 13 48

Steps successfully followed, although I think it's missing the step where we need to click the POST request button Screenshot 2022-11-10 at 22 11 54

Updated documentation, either GET or POST works for the oidc_login

skip_before_action :authenticate_for_action

# have to do because we are making a POST request from Canvas
skip_before_action :verify_authenticity_token

Check failure

Code scanning / CodeQL

CSRF protection weakened or disabled

Potential CSRF vulnerability due to forgery protection being disabled or weakened.
@20wildmanj 20wildmanj merged commit 9da0c43 into master Nov 13, 2022
@20wildmanj 20wildmanj deleted the joeywildman-init-lti-setup branch November 13, 2022 20:43
@najclark najclark mentioned this pull request Jan 6, 2023
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants