Skip to content

Commit

Permalink
LTI-255: allows the overriding of params based on custom params (#150)
Browse files Browse the repository at this point in the history
* LTI-255: allows the overriding of params based on custom params

* LTI-255: cleaned rubocops

* reverted doorkeeper to 5.4
  • Loading branch information
jfederico authored May 11, 2023
1 parent 2473cca commit 7eac562
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ gem 'redis', '~> 4.2'
gem 'jwt', '~> 2.2.2'
gem 'oauth', '~> 0.5.1'

gem 'doorkeeper', '~> 5.5.0'
gem 'doorkeeper', '~> 5.4.0'
gem 'repost', '~> 0.3.8'

gem 'lodash-rails'
Expand Down
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ GEM
docile (1.4.0)
domain_name (0.5.20190701)
unf (>= 0.0.5, < 1.0.0)
doorkeeper (5.5.4)
doorkeeper (5.4.0)
railties (>= 5)
dotenv (2.8.1)
dotenv-rails (2.8.1)
Expand Down Expand Up @@ -426,7 +426,7 @@ DEPENDENCIES
byebug
coffee-rails (~> 5.0, >= 5.0.0)
coveralls
doorkeeper (~> 5.5.0)
doorkeeper (~> 5.4.0)
dotenv-rails
faraday
font-awesome-sass (~> 5.9.0)
Expand Down
23 changes: 22 additions & 1 deletion lib/bbb_lti_broker/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def standarized_message(message_json)
message['resource_link_description'] = message['unknown_params']['https://purl.imsglobal.org/spec/lti/claim/resource_link']['description']
message['launch_presentation_locale'] = message['unknown_params']['https://purl.imsglobal.org/spec/lti/claim/launch_presentation']['locale']
end
message.to_json
custom_overrides(message).to_json
end

def user_params(tc_instance_guid, params)
Expand All @@ -86,5 +86,26 @@ def user_params(tc_instance_guid, params)
last_accessed_at: Time.current,
}
end

##
# Overrides core parameters with custom parameters when following certain pattern.
#
# Core parameters may have to be overriden in order to make the applications behave differently
# for that, the LTI link in the tool consumer would need to include a custom parameter in the form:
#
# custom_resource_link_id=static:"some value" -> resource_link_id="some value"
# custom_resource_link_id=param:contenxt_id -> resource_link_id=<value obtained from context_id>
# custom_resource_link_id="another value" -> resource_link_id=<no overriding is made>
#
def custom_overrides(message)
custom_params = message['custom_params'].to_h
custom_params.each do |key, value|
custom_param = key.delete_prefix('custom_')
pattern = value.split(':')
message[custom_param] = pattern[1] if pattern[0] == 'static'
message[custom_param] = message[pattern[1]] if pattern[0] == 'param'
end
message
end
end
end
4 changes: 2 additions & 2 deletions lib/tasks/db_registration.rake
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ namespace :db do
)

puts(jwk) if args[:type] == 'jwk'
puts(public_key.to_s) if args[:type] == 'key'
puts(public_key) if args[:type] == 'key'
rescue StandardError => e
puts(e.backtrace)
exit(1)
Expand Down Expand Up @@ -139,7 +139,7 @@ namespace :db do
registration.update(tool_settings: tool_settings.to_json, shared_secret: client_id)

puts(jwk) if args[:type] == 'jwk'
puts(public_key.to_s) if args[:type] == 'key'
puts(public_key) if args[:type] == 'key'
end

desc 'Lists the Registration Configuration URLs need to register an app'
Expand Down
2 changes: 1 addition & 1 deletion spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
end
RSpec.configure do |config|
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.fixture_path = "#{::Rails.root}/spec/fixtures"
config.fixture_path = Rails.root.join('spec/fixtures')

# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
Expand Down

0 comments on commit 7eac562

Please sign in to comment.