Skip to content

Commit

Permalink
LTI-382: generalized code and fixed format for 1.1 launches (#255)
Browse files Browse the repository at this point in the history
* LTI-382: generalized code and fixed format for 1.1 launches

* LTI-382: generalized code and fixed format for 1.1 launches
  • Loading branch information
jfederico authored Jun 20, 2024
1 parent 7aaf4ce commit fa23d13
Showing 1 changed file with 29 additions and 21 deletions.
50 changes: 29 additions & 21 deletions lib/bbb_lti_broker/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ def secure_url(url)
#
def standarized_message(message_json)
message = JSON.parse(message_json)

# Consider for conversion all 1.3 launches, which even though , b) launches that did not come in common format
custom_params = message['custom_params'] || {}
ext_params = message['ext_params'] || {}
if message['user_id'].blank?
migration_map.each do |param, claim|
claims = claim.split('#')
Expand All @@ -72,28 +72,23 @@ def standarized_message(message_json)
end

custom_params = message['unknown_params']['https://purl.imsglobal.org/spec/lti/claim/custom'] || {}
custom_params.each do |key, value|
# for following the format used by LTI 1.1 apps.
message["custom_#{key}"] = value
# for following a standard format used by our own apps.
prefixed_key = key.start_with?('custom_') ? key : "custom_#{key}"
message['custom_params'][prefixed_key] = value
end
# message['custom_params'] = keys_with_prefix(custom_params, 'custom_')

ext_params = message['unknown_params']['https://purl.imsglobal.org/spec/lti/claim/ext'] || {}
ext_params.each do |key, value|
# for following the format used by LTI 1.1 apps.
message["ext_#{key}"] = value
# for following a standard format used by our own apps.
prefixed_key = key.start_with?('ext_') ? key : "ext_#{key}"
message['ext_params'][prefixed_key] = value
end
# message['ext_params'] = keys_with_prefix(ext_params, 'ext_')

end

curated_message = custom_overrides(message)
curated_message.to_json
custom_params_prefixed = keys_with_prefix(custom_params, 'custom_')
ext_params_prefixed = keys_with_prefix(ext_params, 'ext_')

# backward compatible with format used by LTI 1.1 apps.
message.merge!(custom_params_prefixed)
message.merge!(ext_params_prefixed)

# for following a standard format used by our own apps.
message['custom_params'] = custom_params_prefixed
message['ext_params'] = ext_params_prefixed

message_with_custom_overrides = custom_overrides(message)
message_with_custom_overrides.to_json
end

def user_params(tc_instance_guid, params)
Expand Down Expand Up @@ -189,5 +184,18 @@ def safe_custom_override_params
# 2) set the overriding rules through tenant settings (safest)
['user_image']
end

def keys_with_prefix(keys, prefix)
logger.debug("Keys: #{keys}")
prefixed_keys = {}

keys.each do |key, value|
prefixed_key = key.start_with?(prefix) ? key : "#{prefix}#{key}"
prefixed_keys[prefixed_key] = value
end
logger.debug("Prefixed keys: #{prefixed_keys}")

prefixed_keys
end
end
end

0 comments on commit fa23d13

Please sign in to comment.