Class: PandaPal::LtiV1P3Controller

Inherits:
ApplicationController show all
Defined in:
app/controllers/panda_pal/lti_v1_p3_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#share_controller_on_thread

Instance Method Details

#loginObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/controllers/panda_pal/lti_v1_p3_controller.rb', line 14

def 
  @current_lti_platform = PandaPal::Platform.resolve_platform(params)

  current_session_data[:lti_platform] = @current_lti_platform&.serialize
  current_session_data[:lti_oauth_nonce] = SecureRandom.uuid
  current_session.panda_pal_organization_id = -1

  @form_action = current_lti_platform.authentication_redirect_url
  @method = :post
  @form_data = {
    scope: 'openid',
    response_type: 'id_token',
    response_mode: 'form_post',
    prompt: 'none',
    redirect_uri: params[:target_link_uri] || v1p3_resource_link_request_url,
    client_id: params.require(:client_id),
    login_hint: params.require(:login_hint),
    lti_message_hint: params.require(:lti_message_hint),
    state: current_session.session_key,
    nonce: current_session_data[:lti_oauth_nonce]
  }
end

#public_jwksObject



102
103
104
105
106
# File 'app/controllers/panda_pal/lti_v1_p3_controller.rb', line 102

def public_jwks
  render json: {
    keys: [JWT::JWK.new(PandaPal.lti_private_key).export]
  }
end


37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/controllers/panda_pal/lti_v1_p3_controller.rb', line 37

def resource_link_request
  # Redirect to correct region/env?

  if params[:launch_type]
    current_session_data.merge!({
      lti_version: 'v1p3',
      lti_launch_placement: params[:launch_type],
      launch_params: @decoded_lti_jwt,
    })

    redirect_with_session_to(:"#{LaunchUrlHelpers.launch_route(params[:launch_type])}_url", route_context: main_app)
  end
  # render json: {
  #   launch_type: params[:launch_type],
  #   final_url: LaunchUrlHelpers.launch_url(params[:launch_type]),
  #   final_route: LaunchUrlHelpers.launch_route(params[:launch_type]),
  #   decoded_jwt: @decoded_lti_jwt,
  # }
end

#tool_configObject



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'app/controllers/panda_pal/lti_v1_p3_controller.rb', line 57

def tool_config
  if PandaPal.lti_environments.empty?
    render plain: 'Domains must be set in lti_environments'
    return
  end

  platform = PandaPal.lti_options.delete(:platform) || 'canvas.instructure.com'
  request_url = "#{request.scheme}://#{request.host_with_port}"
  parsed_request_url = URI.parse(request_url)

  mapped_placements = PandaPal.lti_paths.map do |k, opts|
    opts = LaunchUrlHelpers.normalize_lti_launch_desc(opts)
    opts.merge!({
      placement: k,
      target_link_uri: LaunchUrlHelpers.absolute_launch_url(
        k.to_sym,
        host: parsed_request_url,
        launch_handler: v1p3_resource_link_request_path,
        default_auto_launch: true
      ),
    })
    opts
  end

  config_json = {
    title: PandaPal.lti_options[:title],
    scopes: [],
    public_jwk_url: v1p3_public_jwks_url,
    description: PandaPal.lti_options[:description] || 'PandaPal LTI',
    target_link_uri: v1p3_resource_link_request_url, #app_url(:resource_link_request, request),
    oidc_initiation_url: ,
    extensions: [{
      platform: platform,
      privacy_level: "public",
      settings: {
        placements: mapped_placements,
        environments: PandaPal.lti_environments,
      },
    }],
    custom_fields: PandaPal.lti_custom_params, # PandaPal.lti_options[:custom_fields],
  }

  render json: config_json
end