Class: PandaPal::LtiV1P3Controller

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

Instance Method Summary collapse

Instance Method Details

#loginObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/controllers/panda_pal/lti_v1_p3_controller.rb', line 8

def 
  current_session_data[:lti_oauth_nonce] = SecureRandom.uuid

  @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



87
88
89
90
91
# File 'app/controllers/panda_pal/lti_v1_p3_controller.rb', line 87

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


27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/controllers/panda_pal/lti_v1_p3_controller.rb', line 27

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



46
47
48
49
50
51
52
53
54
55
56
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
# File 'app/controllers/panda_pal/lti_v1_p3_controller.rb', line 46

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 = opts.dup
    opts.delete(:route_helper_key)
    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),
    })
    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