Skip to content

Commit

Permalink
feat: add logs before redirect_post calls
Browse files Browse the repository at this point in the history
  • Loading branch information
wpramio committed Jan 30, 2024
1 parent c31e831 commit d13683b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
4 changes: 1 addition & 3 deletions app/controllers/apps_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,14 @@ def launch
tool = RailsLti2Provider::Tool.where(uuid: params[:oauth_consumer_key]).last
lti_launch = RailsLti2Provider::LtiLaunch.find_by(nonce: params[:oauth_nonce])

Rails.logger.info("Creating a launch for tool=#{tool.uuid} and " \
"oauth_nonce=#{params[:oauth_nonce]}")

# add the oauth key to the data of this launch
message = lti_launch.message
message.custom_params['oauth_consumer_key'] = params[:oauth_consumer_key]

lti_launch.update(tool_id: tool.id, message: message.to_json)

redirector = "#{lti_app_url(params[:app])}?#{{ launch_nonce: lti_launch.nonce }.to_query}"
logger.info("redirect_post to LTI app url=#{redirector}")
redirect_post(redirector, options: { authenticity_token: :auto })
end
end
1 change: 1 addition & 0 deletions app/controllers/auth_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def login
auth_params[:lti_message_hint] = params[:lti_message_hint] if params.key?(:lti_message_hint)

aparams = URI.encode_www_form(auth_params)
logger.info("AuthController: redirect_post back to LMS with params #{aparams}")
redirect_post("#{@registration['auth_login_url']}?#{aparams}", options: { authenticity_token: :auto })
end

Expand Down
4 changes: 4 additions & 0 deletions app/controllers/message_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class MessageController < ApplicationController
)
if request.request_parameters.key?('launch_presentation_return_url')
launch_presentation_return_url = "#{request.request_parameters['launch_presentation_return_url']}&lti_errormsg=#{@error}"
logger.info("redirect_post to launch_presentation_return_url=#{launch_presentation_return_url}")
redirect_post(launch_presentation_return_url, options: { authenticity_token: :auto })
else
render(:basic_lti_launch_request, status: :ok)
Expand All @@ -81,6 +82,7 @@ def basic_lti_launch_request
Rails.cache.write(params[:oauth_nonce], message: @message, oauth: { consumer_key: params[:oauth_consumer_key], timestamp: params[:oauth_timestamp] })
session[:user_id] = @current_user.id
redirector = app_launch_path(params.to_unsafe_h)
logger.info("redirect_post to app_launch_path=#{redirector}")
redirect_post(redirector, options: { authenticity_token: :auto })
end

Expand Down Expand Up @@ -116,6 +118,7 @@ def openid_launch_request
Rails.cache.write(params[:oauth_nonce], message: @message, oauth: { consumer_key: params[:oauth_consumer_key], timestamp: @jwt_body['exp'] })
session[:user_id] = @current_user.id
redirector = app_launch_path(params.to_unsafe_h)
logger.info("redirect_post to app_launch_path=#{redirector}")
redirect_post(redirector, options: { authenticity_token: :auto })
end

Expand Down Expand Up @@ -156,6 +159,7 @@ def process_openid_message

tool = lti_registration(@jwt_body['iss'])
tool.lti_launches.where('created_at < ?', 1.day.ago).delete_all
logger.info("Creating a launch for tool=#{tool.uuid} with nonce=#{@jwt_body['nonce']}")
@lti_launch = tool.lti_launches.create(nonce: @jwt_body['nonce'], message: @jwt_body.merge(@jwt_header).merge)

@message = IMS::LTI::Models::Messages::Message.generate(params)
Expand Down

0 comments on commit d13683b

Please sign in to comment.