1
1
class Lti13 ::DeepLinkLaunchesController < ApplicationController
2
- before_action :set_tool
3
- skip_before_action only : :create
4
-
5
- # POST lti/tools/#/deep_link_launches
6
- # Not much different than LTI launch endpoint inside a simple reference implementation but you
7
- # should have a diff endpoint for deeplinks than your LTI resource link request for single responsiblity
8
- def create
9
- if params [ :id_token ] &.present?
10
- @decoded_header = Jwt ::Header . new ( params [ :id_token ] ) . call
11
- kid = @decoded_header [ 'kid' ]
12
-
13
- @decoded_jwt = Lti13Service ::DecodePlatformJwt . new ( @tool , params [ :id_token ] , kid ) . call
14
- @launch = @tool . launches . build ( jwt : params [ :id_token ] , decoded_jwt : @decoded_jwt ? @decoded_jwt . first : nil , state : params [ :state ] )
15
- end
16
-
17
- @launch ||= Launch . new
18
- respond_to do |format |
19
- if @launch . save
20
- format . html { redirect_to [ :lti , @tool , @launch ] , notice : 'Successful Launch.' }
21
- format . json { render :show , status : :created , location : @launch }
22
- else
23
- format . html { render json : 'Invalid Launch' , status : :unprocessable_entity }
24
- format . json { render json : @launch . errors , status : :unprocessable_entity }
25
- end
26
- end
27
- end
28
-
29
- # GET lti/tools/#/deep_link_launch/*launch_id*
30
- # page that allows user to select content
31
- def show
32
- @launch = Launch . find ( params [ :id ] )
2
+ before_action :set_tool
3
+ skip_before_action only : :create
4
+
5
+ # POST lti/tools/#/deep_link_launches
6
+ # Handles the creation of a deep link launch
7
+ def create
8
+ if params [ :id_token ] &.present?
9
+ @decoded_header = Jwt ::Header . new ( params [ :id_token ] ) . call
10
+ kid = @decoded_header [ 'kid' ]
11
+
12
+ @decoded_jwt = Lti13Service ::DecodePlatformJwt . new ( @tool , params [ :id_token ] , kid ) . call
13
+ @launch = @tool . launches . build ( jwt : params [ :id_token ] , decoded_jwt : @decoded_jwt ? @decoded_jwt . first : nil , state : params [ :state ] )
33
14
end
34
-
35
- # GET lti/tools/#/deep_link_launch/*launch_id*/launch
36
- # takes selected content and launches back to platform with JWT
37
- def launch
38
- @launch = Launch . find ( params [ :deep_link_launch_id ] )
39
- @form_url = @launch . decoded_jwt [ Rails . configuration . lti_claims_and_scopes [ 'deep_linking_claim' ] ] [ 'deep_link_return_url' ]
40
- @deep_link_jwt = Lti13Service ::DeepLinkJwt . new ( @launch , lti_tool_launches_url ( @tool ) , params [ :content_items ] )
41
- end
42
-
43
- private
44
- def set_tool
45
- @tool = Tool . find_by_id ( params [ :tool_id ] )
46
- render json : { error : 'Tool not found' } , status : :not_found unless @tool
15
+
16
+ @launch ||= Launch . new
17
+ respond_to do |format |
18
+ if @launch . save
19
+ format . html { redirect_to [ :lti13 , @tool , @launch ] , notice : 'Successful Launch.' }
20
+ format . json { render :show , status : :created , location : @launch }
21
+ else
22
+ format . html { render json : 'Invalid Launch' , status : :unprocessable_entity }
23
+ format . json { render json : @launch . errors , status : :unprocessable_entity }
47
24
end
48
- end
25
+ end
26
+ end
27
+
28
+ # GET lti/tools/#/deep_link_launch/*launch_id*
29
+ # allows user to select content
30
+ def show
31
+ @launch = Launch . find ( params [ :id ] )
32
+ end
33
+
34
+ # GET lti/tools/#/deep_link_launch/*launch_id*/launch
35
+ # takes selected content and launches back to platform with JWT
36
+ def launch
37
+ @launch = Launch . find ( params [ :deep_link_launch_id ] )
38
+ @form_url = @launch . decoded_jwt [ Rails . configuration . lti_claims_and_scopes [ 'deep_linking_claim' ] ] [ 'deep_link_return_url' ]
39
+ @deep_link_jwt = Lti13Service ::DeepLinkJwt . new ( @launch , lti_tool_launches_url ( @tool ) , params [ :content_items ] )
40
+ end
41
+
42
+ # GET lti13/deep_linking/content_selection
43
+ def content_selection
44
+ @launch_url = request . protocol + request . host_with_port + "/lti13/launches"
45
+ module_info = InstModule . get_current_versions_dict ( )
46
+ @json = module_info . to_json
47
+
48
+ Rails . logger . info "Launch URL: #{ @launch_url } "
49
+ Rails . logger . debug "Module Info JSON: #{ @json . inspect } "
50
+ render 'resource' , layout : 'lti_resource'
51
+ end
52
+
53
+ # POST lti13/deep_linking/content_selected
54
+ def content_selected
55
+ @launch = Launch . find ( params [ :launch_id ] )
56
+ @form_url = @launch . decoded_jwt [ Rails . configuration . lti_claims_and_scopes [ 'deep_linking_claim' ] ] [ 'deep_link_return_url' ]
57
+ selected_content = params [ :selected_content ]
58
+ Rails . logger . info "Selected Content: #{ selected_content } "
59
+
60
+ deep_link_jwt_service = Lti13Service ::DeepLinkJwt . new ( @launch , selected_content )
61
+ deep_link_jwt = deep_link_jwt_service . call
62
+ Rails . logger . info "Deep Link JWT: #{ deep_link_jwt } "
63
+
64
+ # Return the selected content to LMS
65
+ redirect_to "#{ @form_url } ?JWT=#{ deep_link_jwt } "
66
+ end
67
+
68
+ #~ Private methods ..........................................................
69
+
70
+ private
71
+ # -------------------------------------------------------------
72
+
73
+ def set_tool
74
+ @tool = Tool . find_by_id ( params [ :tool_id ] )
75
+ render json : { error : 'Tool not found' } , status : :not_found unless @tool
76
+ end
77
+ end
0 commit comments