--- loncom/interface/lonexttool.pm 2022/03/29 20:12:46 1.23 +++ loncom/interface/lonexttool.pm 2023/05/22 21:10:55 1.24 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Launch External Tool Provider (LTI) # -# $Id: lonexttool.pm,v 1.23 2022/03/29 20:12:46 raeburn Exp $ +# $Id: lonexttool.pm,v 1.24 2023/05/22 21:10:55 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -96,13 +96,20 @@ sub handler { my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; my $chome = $env{'course.'.$env{'request.course.id'}.'.home'}; - my ($idx,$is_tool,%toolhash,%toolsettings); + my ($idx,$crstool,$is_tool,%toolhash,%toolsettings); if ($r->uri eq "/adm/$cdom/$cnum/$marker/$exttool") { %toolsettings=&Apache::lonnet::dump('exttool_'.$marker,$cdom,$cnum); if ($toolsettings{'id'}) { - $idx = $toolsettings{'id'}; - my %ltitools = &Apache::lonnet::get_domain_lti($cdom,'consumer'); + my %ltitools; + if ($toolsettings{'id'} =~ /^c(\d+)$/) { + $idx = $1; + $crstool = 1; + %ltitools = &Apache::lonnet::get_course_lti($cnum,$cdom,'consumer'); + } else { + $idx = $toolsettings{'id'}; + %ltitools = &Apache::lonnet::get_domain_lti($cdom,'consumer'); + } if (ref($ltitools{$idx}) eq 'HASH') { %toolhash = %{$ltitools{$idx}}; $toolhash{'display'} = { @@ -204,17 +211,19 @@ sub handler { } } my $submittext = &mt('Launch [_1]',$toolhash{'title'}); - if (($toolhash{'key'} ne '') && ($toolhash{'secret'} ne '') && - ($toolhash{'url'} ne '') && ($launchok)) { + if (($toolhash{'url'} ne '') && ($launchok)) { my %lti = <i_params($r,$cnum,$cdom,$idx,$submittext,\%toolhash); my $url = $toolhash{'url'}; if ($toolhash{'crsappend'} ne '') { $url .= $toolhash{'crsappend'}; } - $r->print(&launch_html($url,$toolhash{'key'},$toolhash{'secret'}, - $toolhash{'sigmethod'},$submittext,\%lti)); + my %info = ( + method => $toolhash{'sigmethod'}, + ); + $r->print(&launch_html($cdom,$cnum,$crstool,$url,$idx, + $toolhash{'cipher'},$submittext,\%lti,\%info)); } else { - $r->print('
'.&mt('External Tool Unavailable').'
'); + $r->print('
'.&mt('External Tool Unavailable').'
'); } } return OK; @@ -434,8 +443,13 @@ sub lti_params { } sub launch_html { - my ($url,$key,$secret,$sigmethod,$submittext,$paramsref) = @_; - my $hashref = &LONCAPA::ltiutils::sign_params($url,$key,$secret,$paramsref,$sigmethod); + my ($cdom,$cnum,$crstool,$url,$idx,$keynum,$submittext,$paramsref,$inforef) = @_; + my ($status,$hashref) = + &Apache::lonnet::sign_lti($cdom,$cnum,$crstool,$url,$idx,$keynum, + '',$paramsref,$inforef); + unless ($status eq 'ok') { + return '
'.&mt('External Tool Unavailable').'
'; + } my $action = &HTML::Entities::encode($url,'<>&"'); my $form = <<"END";