Skip to content

Commit

Permalink
LTI-381: set custom parameters through dynamic registration qs (#249)
Browse files Browse the repository at this point in the history
* LTI-381: addedd support for setting custom parameters through dynamic registration qs

* LTI-381: solved issue with debugging when env exists but empty

* removed bug
  • Loading branch information
jfederico authored Jun 18, 2024
1 parent 70e479d commit dcc4865
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
34 changes: 29 additions & 5 deletions app/controllers/concerns/dynamic_registration_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def client_registration_request_header(token)
}
end

def client_registration_request_body(key_token, app, app_name, app_desciption, app_icon_url, app_label, message_types)
def client_registration_request_body(key_token, app, app_name, app_desciption, app_icon_url, app_label, message_types, custom_params)
jwks_uri = registration_pub_keyset_url(key_token: key_token)

tool = app || Rails.configuration.default_tool
Expand Down Expand Up @@ -58,7 +58,7 @@ def client_registration_request_body(key_token, app, app_name, app_desciption, a
"domain": URI.parse(openid_launch_url(protocol: 'https')).host,
"description": app_desciption || t("apps.#{tool}.description"),
"target_link_uri": openid_launch_url(protocol: 'https'),
"custom_parameters": {},
"custom_parameters": parse_custom_params(custom_params),
"claims": %w[iss sub name given_name family_name email nickname picture locale],
"messages": messages,
},
Expand All @@ -82,9 +82,7 @@ def client_registration_request_body_message_type(message_type, tool, label, ico
"target_link_uri": target_link_uri,
"label": label || t("apps.#{tool}.title"),
"icon_uri": icon_uri || secure_url(lti_app_icon_url(tool)),
"custom_parameters": {
"context_id": '$Context.id',
},
"custom_parameters": {},
# parameters supported by canvas only
"placements": placements,
"roles": [],
Expand Down Expand Up @@ -145,4 +143,30 @@ def filter_valid_message_types(message_types_str, default: 'LtiDeepLinkingReques

valid_message_types.empty? ? [default] : valid_message_types
end

def parse_custom_params(input_string)
key_value_pairs = input_string.split(',')

result = {}

key_value_pairs.each do |pair|
# Skip the pair if it does not contain a colon
next unless pair.presence && pair.include?(':')

# Split the pair by colon to get the key and value
key, value = pair.split(':')

# Validate that both key and value are present
next if key.nil? || value.nil? || key.strip.empty? || value.strip.empty?

# Strip any leading or trailing whitespace from key and value
key.strip!
value.strip!

# Add the valid key-value pair to the result hash
result[key] = value
end

result
end
end
3 changes: 2 additions & 1 deletion app/controllers/registration_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ def process_registration_initiation_request
key_pair = new_rsa_keypair
header = client_registration_request_header(registration_token)
logger.debug("registration_token header\n#{JSON.pretty_generate(header)}")
body = client_registration_request_body(key_pair.token, params[:app], params[:app_name], params[:app_description], params[:app_icon], params[:app_label], params[:message_types])
body = client_registration_request_body(key_pair.token, params[:app], params[:app_name], params[:app_description], params[:app_icon], params[:app_label], params[:message_types],
params[:custom_params])
logger.debug("registration_token body\n#{JSON.pretty_generate(body)}")
body = body.to_json

Expand Down
2 changes: 1 addition & 1 deletion config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
$stdout.sync = true
logger = ActiveSupport::Logger.new($stdout)

if ENV['RAILS_LOG_REMOTE_NAME'] && ENV['RAILS_LOG_REMOTE_PORT']
if ENV['RAILS_LOG_REMOTE_NAME'].present? && ENV['RAILS_LOG_REMOTE_PORT'].present?
require 'remote_syslog_logger'
logger_program = ENV['RAILS_LOG_REMOTE_TAG'] || "bbb-lti-broker-#{ENV['RAILS_ENV']}"
logger = RemoteSyslogLogger.new(ENV['RAILS_LOG_REMOTE_NAME'],
Expand Down

0 comments on commit dcc4865

Please sign in to comment.