strongmind-auth 1.1.118 → 1.1.124

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 54012245095295e150196fc80e2ad10c7a302b2ccf90481b0f9d29045891ad79
4
- data.tar.gz: 9c960c366e9d77d1dd0f7bc1ec65bb7a5033a64708a9ee9bf20416289d7570c0
3
+ metadata.gz: '048a0f120c80b6cf5fd9434d55faac903ee8b5b77f086f96c125b464d7eb5c10'
4
+ data.tar.gz: 68ae3c3300beba2fc9f5a3734a1c42fc3924dbbf20289069bddd16cf4b8c4739
5
5
  SHA512:
6
- metadata.gz: 0a48379813bce8d02c83994b36cb3e3c797f23a40ccbf873b5a02f12de69b120ba895381c39694340a795093dae9e2d7fd4379bc12edc2a460227e34851b5028
7
- data.tar.gz: '085d8271e0aac7b174bf8f97fca85bc6657bc05841d9e4da3811805d2400ce752e2365a98fb0c64275f32377faedaa6e45aaff9d6479c7e7af312a11fd9099e8'
6
+ metadata.gz: a964d1571ff5c9ff1ea898439d5e76f704bf279879cf176f90e6ff3de363509cbd8e4e6bfd409071242b608707c6174ea8fa2c79308595f294adf5611f7fb6d4
7
+ data.tar.gz: a040a080edcac1cc3d9cd9acc591f720fa61ac7e22fd2128c5356244ef4264b600cb99bc4bcd9f6ef82ea16f24f70914db023e323da53090c5c503114c27c550
@@ -0,0 +1,111 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LtiSessionAuthable
4
+ extend ActiveSupport::Concern
5
+
6
+ SESSION_HEADER_NAME = 'HTTP_LTI_SESSION_ID'
7
+ UNAUTHORIZED_MESSAGE = 'Session not found. Please refresh the page.'
8
+
9
+ def initialize_lti_session
10
+ @lti_session_id = SecureRandom.uuid
11
+ initialize_lti_parameters
12
+ end
13
+
14
+ def initialize_lti_parameters
15
+ @lti_context_id = fetch_param('context_id')
16
+ @lti_context_title = fetch_param('context_title')
17
+ @lti_resource_link_title = fetch_param('resource_link_title')
18
+ @lti_consumer_key = fetch_param('oauth_consumer_key')
19
+ @lti_user_email = fetch_param('lis_person_contact_email_primary')
20
+ @lti_custom_canvas_api_domain = fetch_param('custom_canvas_api_domain')
21
+ @lti_custom_canvas_course_id = fetch_param('custom_canvas_course_id')
22
+ @lti_custom_canvas_user_id = fetch_param('custom_canvas_user_id')
23
+ @lis_person_name_given = fetch_param('lis_person_name_given')
24
+ @lis_person_name_family = fetch_param('lis_person_name_family')
25
+ @user_ext_roles = fetch_param('ext_roles')
26
+ end
27
+
28
+ def fetch_param(key)
29
+ request.parameters[key]
30
+ end
31
+
32
+ def write_session_to_cache
33
+ Rails.cache.write(@lti_session_id, {
34
+ record_id: @lti_session_id,
35
+ context_id: @lti_context_id,
36
+ context_title: @lti_context_title,
37
+ resource_link_title: @lti_resource_link_title,
38
+ consumer_key: @lti_consumer_key,
39
+ user_email: @lti_user_email,
40
+ custom_canvas_api_domain: @lti_custom_canvas_api_domain,
41
+ custom_canvas_course_id: @lti_custom_canvas_course_id,
42
+ custom_canvas_user_id: @lti_custom_canvas_user_id,
43
+ user_first_name: @lis_person_name_given,
44
+ user_last_name: @lis_person_name_family,
45
+ user_ext_roles: @user_ext_roles
46
+ }, expires_in: 12.hours)
47
+ end
48
+
49
+ def lti_session_id
50
+ request.headers[SESSION_HEADER_NAME] || params[:lti_session_id]
51
+ end
52
+
53
+ def validate_session
54
+ @lti_session_id = lti_session_id
55
+ unauthorized_response and return unless @lti_session_id.present?
56
+
57
+ @lti_session = Rails.cache.read(@lti_session_id)
58
+
59
+ handle_existing_session
60
+ rotate_session_if_needed
61
+ unauthorized_response if @lti_session.nil?
62
+ end
63
+
64
+ def handle_existing_session
65
+ read_session unless @lti_session.nil?
66
+ end
67
+
68
+ def unauthorized_response
69
+ render plain: UNAUTHORIZED_MESSAGE, status: :unauthorized
70
+ end
71
+
72
+ def rotate_session_if_needed
73
+ return if params[:dont_rotate_session]
74
+ return if request.method == 'POST'
75
+
76
+ @old_session_id = @lti_session_id
77
+ @lti_session_id = SecureRandom.uuid
78
+ end
79
+
80
+ def read_session
81
+ @lti_context_id = @lti_session[:context_id]
82
+ @lti_context_title = @lti_session[:context_title]
83
+ @lti_resource_link_title = @lti_session[:resource_link_title]
84
+ @lti_consumer_key = @lti_session[:consumer_key]
85
+ @lti_custom_canvas_api_domain = @lti_session[:custom_canvas_api_domain]
86
+ @lti_custom_canvas_course_id = @lti_session[:custom_canvas_course_id]
87
+ @lti_custom_canvas_user_id = @lti_session[:custom_canvas_user_id]
88
+ @lti_user_email = @lti_session[:user_email]
89
+ @lis_person_name_given = @lti_session[:user_first_name]
90
+ @lis_person_name_family = @lti_session[:user_last_name]
91
+ @user_ext_roles = @lti_session[:user_ext_roles]
92
+ end
93
+
94
+ def rotate_session_id
95
+ return unless @old_session_id
96
+
97
+ write_session_to_cache
98
+ Rails.cache.delete(@old_session_id)
99
+ end
100
+
101
+ def lti_launch_validator
102
+ @lti_launch_validator ||= LtiLaunchValidator.new(request)
103
+ end
104
+
105
+ def validate_lti_launch
106
+ raise RequestNotFoundError unless request.is_a? ActionDispatch::Request
107
+
108
+ head(:unauthorized) unless lti_launch_validator.is_valid?
109
+ end
110
+ end
111
+
@@ -1,5 +1,5 @@
1
1
  module Strongmind
2
2
  module Auth
3
- VERSION = "1.1.118"
3
+ VERSION = "1.1.124"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: strongmind-auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.118
4
+ version: 1.1.124
5
5
  platform: ruby
6
6
  authors:
7
7
  - Team Belding
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-11-11 00:00:00.000000000 Z
11
+ date: 2024-12-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -106,6 +106,7 @@ files:
106
106
  - app/assets/config/strongmind_auth_manifest.js
107
107
  - app/assets/stylesheets/strongmind/auth/application.css
108
108
  - app/controllers/concerns/jwt_utilities.rb
109
+ - app/controllers/concerns/lti_session_authable.rb
109
110
  - app/controllers/concerns/strong_mind_nav.rb
110
111
  - app/controllers/logins_controller.rb
111
112
  - app/controllers/users/omniauth_callbacks_controller.rb
@@ -137,7 +138,7 @@ licenses:
137
138
  metadata:
138
139
  homepage_uri: https://www.strongmind.com
139
140
  source_code_uri: https://github.com/StrongMind/rails-auth
140
- post_install_message:
141
+ post_install_message:
141
142
  rdoc_options: []
142
143
  require_paths:
143
144
  - lib
@@ -153,7 +154,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
153
154
  version: '0'
154
155
  requirements: []
155
156
  rubygems_version: 3.4.10
156
- signing_key:
157
+ signing_key:
157
158
  specification_version: 4
158
159
  summary: Ruby gem for StrongMind authentication in a strongmind app
159
160
  test_files: []