--- loncom/lti/ltiutils.pm 2023/07/05 21:25:10 1.17.2.4 +++ loncom/lti/ltiutils.pm 2024/02/27 04:04:06 1.21 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA -# Utility functions for managing LON-CAPA LTI interactions +# Utility functions for managing LON-CAPA LTI interactions # -# $Id: ltiutils.pm,v 1.17.2.4 2023/07/05 21:25:10 raeburn Exp $ +# $Id: ltiutils.pm,v 1.21 2024/02/27 04:04:06 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -34,7 +34,6 @@ use Digest::SHA; use Digest::MD5 qw(md5_hex); use Encode; use UUID::Tiny ':std'; -use LWP::UserAgent(); use Apache::lonnet; use Apache::loncommon; use Apache::loncoursedata; @@ -55,13 +54,13 @@ use LONCAPA qw(:DEFAULT :match); # When LON-CAPA is operating as a Consumer, nonce checking # occurs when a Tool Provider launched from an instance of # an external tool in a LON-CAPA course makes a request to -# (a) /adm/service/roster or (b) /adm/service/passback to, -# respectively, retrieve a roster or store the grade for +# (a) /adm/service/roster or (b) /adm/service/passback to, +# respectively, retrieve a roster or store the grade for # the original launch by a specific user. # -# When LON-CAPA is operating as a Provider, nonce checking -# occurs when a user in course context in another LMS (the -# Consumer) launches an external tool to access a LON-CAPA URL: +# When LON-CAPA is operating as a Provider, nonce checking +# occurs when a user in course context in another LMS (the +# Consumer) launches an external tool to access a LON-CAPA URL: # /adm/lti/ with LON-CAPA symb, map, or deep-link ID appended. # @@ -359,9 +358,9 @@ sub verify_lis_item { # LON-CAPA as LTI Consumer # # Sign a request used to launch an instance of an external -# tool in a LON-CAPA course, using the key and secret supplied +# tool in a LON-CAPA course, using the key and secret supplied # by the Tool Provider. -# +# sub sign_params { my ($url,$key,$secret,$paramsref,$sigmethod,$type,$callback,$post) = @_; @@ -693,9 +692,7 @@ sub get_roster { ? join("&$name=", map {escape($_) } @{$hashref->{$_}}) : &escape($hashref->{$_}) ); } keys(%{$hashref}))); - my $ua=new LWP::UserAgent; - $ua->timeout(10); - my $response=$ua->request($request); + my $response = &LONCAPA::LWPReq::makerequest('',$request,'','',10); my $message=$response->status_line; if (($response->is_success) && ($response->content ne '')) { my %data = (); @@ -755,7 +752,7 @@ sub send_grade { $score = Math::Round::round($score); } else { $score = $total/$possible; - $score = sprintf("%.2f",$score); + $score = sprintf("%.4f",$score); } } if ($sigmethod eq '') { @@ -845,9 +842,7 @@ END ], $gradexml, ); - my $ua=new LWP::UserAgent; - $ua->timeout(10); - my $response=$ua->request($request); + my $response = &LONCAPA::LWPReq::makerequest('',$request,'','',10); my $message=$response->status_line; #FIXME Handle case where pass back of score to LTI Consumer failed. } @@ -873,11 +868,9 @@ sub setup_logout_callback { &Apache::lonnet::sign_lti($cdom,$cnum,$crstool,'lti','logout',$service_url,$idx, $keynum,\%ltiparams,\%info); if (($status eq 'ok') && ($post ne '')) { - my $ua=new LWP::UserAgent; - $ua->timeout(10); my $request=new HTTP::Request('POST',$service_url); $request->content($post); - my $response=$ua->request($request); + my $response = &LONCAPA::LWPReq::makerequest('',$request,'','',10); } } } @@ -887,7 +880,7 @@ sub setup_logout_callback { # # LON-CAPA as LTI Provider # -# Create a new user in LON-CAPA. If the domain's configuration +# Create a new user in LON-CAPA. If the domain's configuration # includes rules for format of "official" usernames, those rules # will apply when determining if a user is to be created. In # additional if institutional user information is available that @@ -1028,7 +1021,7 @@ sub create_passwd { # in the Consumer, user privs will be added to the user's environment for # the new role. # -# If this is a self-enroll case, a Course Coordinator role will only be assigned +# If this is a self-enroll case, a Course Coordinator role will only be assigned # if the current user is also the course owner. # @@ -1320,7 +1313,7 @@ sub batchaddroster { # # Which LON-CAPA roles are assignable by the current user # and how LTI roles map to LON-CAPA roles (as defined in -# the domain configuration for the specific Consumer) are +# the domain configuration for the specific Consumer) are # factored in when compiling the list of available roles. # # Inputs: 3