Skip to content

Commit

Permalink
LTI-327: add icons to deep_link and dynamic registration (#206)
Browse files Browse the repository at this point in the history
  • Loading branch information
jfederico committed Mar 27, 2024
1 parent c76d8b8 commit 5f028fc
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 9 deletions.
8 changes: 4 additions & 4 deletions app/controllers/concerns/apps_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,19 @@ def lti_app_url(name)
end

def lti_icon(app_name)
return "http://#{request.host_with_port}#{Rails.configuration.assets.prefix}/icon.svg" if app_name == 'default'

begin
app = lti_app(app_name)
uri = URI.parse(app['redirect_uri'].sub('https', 'http'))
site = "#{uri.scheme}://#{uri.host}#{uri.port != 80 ? ":#{uri.port}" : ''}/"
path = uri.path.split('/')
path_base = "#{(path[0].chomp(' ') == '' ? path[1] : path[0]).gsub('/', '')}/"
path_base = "#{(path[0].chomp(' ') == '' ? path[1] : path[0]).gsub('/', '')}/#{app_name}"
relative_url_root = Rails.configuration.relative_url_root
path_base = relative_url_root[0] == '/' ? relative_url_root[1..] : relative_url_root if app_name == 'default'
rescue StandardError
# TODO: handle exception
logger.error("App #{app_name} is not registered.")
return
end
"#{site}#{"#{path_base}#{app_name}/assets/icon.svg"}"
"#{site}#{"#{path_base}/assets/icon.svg"}"
end
end
10 changes: 8 additions & 2 deletions app/controllers/concerns/deep_link_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,17 @@ module DeepLinkService
include ActiveSupport::Concern

# custom_params are passed as a hash of {'key': 'value'} objects.
def deep_link_resource(url, title, custom_params = {})
def deep_link_resource(url, title, text, icon, custom_params = {})
{
'type' => 'ltiResourceLink',
'title' => title,
'url' => url,
'title' => title,
'text' => text,
'icon' => {
"url": icon,
"width": 100,
"height": 100,
},
'presentation' => {
'documentTarget' => 'window',
},
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/concerns/dynamic_registration_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def client_registration_request_body(key_token)
deep_link_request_launch_url(protocol: 'https'),],
"client_name": t("apps.#{tool}.title"),
"jwks_uri": jwks_uri,
# "logo_uri": 'https://client.example.org/logo.png',
"logo_uri": secure_url(lti_icon(params[:app])),
# "policy_uri": 'https://client.example.org/privacy',
# "policy_uri#ja": 'https://client.example.org/privacy?lang=ja',
# "tos_uri": 'https://client.example.org/tos',
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/message_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def deep_link
# Remove the default tool unless working in development mode.
apps -= ['default'] unless Rails.configuration.developer_mode_enabled
apps.each do |app|
resource = deep_link_resource(openid_launch_url, "My #{app.singularize}", { 'broker_app': app })
resource = deep_link_resource(openid_launch_url, "My #{app.singularize}", '', secure_url(lti_icon(app)), { 'broker_app': app })
deep_link_jwt_message = deep_link_jwt_response(lti_registration_params(@jwt_body['iss']), @jwt_header, @jwt_body, [resource])
@apps << { app_name: app, deep_link_jwt_message: deep_link_jwt_message }
end
Expand Down
2 changes: 1 addition & 1 deletion config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
# config.assets.css_compressor = :sass

# Do not fallback to assets pipeline if a precompiled asset is missed.
config.assets.compile = false
config.assets.compile = true

# Enable serving of images, stylesheets, and JavaScripts from an asset server.
# config.asset_host = 'http://assets.example.com'
Expand Down
2 changes: 2 additions & 0 deletions config/initializers/assets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,5 @@
# application.js, application.css, and all non-JS/CSS in the app/assets
# folder are already added.
# Rails.application.config.assets.precompile += %w( admin.js admin.css )

Rails.application.config.assets.prefix = '/assets'

0 comments on commit 5f028fc

Please sign in to comment.