version 1.17.2.6, 2025/01/16 21:52:05
|
version 1.21, 2024/02/27 04:04:06
|
Line 1
|
Line 1
|
# The LearningOnline Network with CAPA |
# The LearningOnline Network with CAPA |
# Utility functions for managing LON-CAPA LTI interactions |
# Utility functions for managing LON-CAPA LTI interactions |
# |
# |
# $Id$ |
# $Id$ |
# |
# |
Line 34 use Digest::SHA;
|
Line 34 use Digest::SHA;
|
use Digest::MD5 qw(md5_hex); |
use Digest::MD5 qw(md5_hex); |
use Encode; |
use Encode; |
use UUID::Tiny ':std'; |
use UUID::Tiny ':std'; |
use HTTP::Status; |
|
use LWP::UserAgent(); |
|
use Apache::lonnet; |
use Apache::lonnet; |
use Apache::loncommon; |
use Apache::loncommon; |
use Apache::loncoursedata; |
use Apache::loncoursedata; |
Line 56 use LONCAPA qw(:DEFAULT :match);
|
Line 54 use LONCAPA qw(:DEFAULT :match);
|
# When LON-CAPA is operating as a Consumer, nonce checking |
# When LON-CAPA is operating as a Consumer, nonce checking |
# occurs when a Tool Provider launched from an instance of |
# occurs when a Tool Provider launched from an instance of |
# an external tool in a LON-CAPA course makes a request to |
# an external tool in a LON-CAPA course makes a request to |
# (a) /adm/service/roster or (b) /adm/service/passback to, |
# (a) /adm/service/roster or (b) /adm/service/passback to, |
# respectively, retrieve a roster or store the grade for |
# respectively, retrieve a roster or store the grade for |
# the original launch by a specific user. |
# the original launch by a specific user. |
# |
# |
# When LON-CAPA is operating as a Provider, nonce checking |
# When LON-CAPA is operating as a Provider, nonce checking |
# occurs when a user in course context in another LMS (the |
# occurs when a user in course context in another LMS (the |
# Consumer) launches an external tool to access a LON-CAPA URL: |
# Consumer) launches an external tool to access a LON-CAPA URL: |
# /adm/lti/ with LON-CAPA symb, map, or deep-link ID appended. |
# /adm/lti/ with LON-CAPA symb, map, or deep-link ID appended. |
# |
# |
|
|
Line 360 sub verify_lis_item {
|
Line 358 sub verify_lis_item {
|
# LON-CAPA as LTI Consumer |
# LON-CAPA as LTI Consumer |
# |
# |
# Sign a request used to launch an instance of an external |
# 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. |
# by the Tool Provider. |
# |
# |
|
|
sub sign_params { |
sub sign_params { |
my ($url,$key,$secret,$paramsref,$sigmethod,$type,$callback,$post) = @_; |
my ($url,$key,$secret,$paramsref,$sigmethod,$type,$callback,$post) = @_; |
Line 694 sub get_roster {
|
Line 692 sub get_roster {
|
? join("&$name=", map {escape($_) } @{$hashref->{$_}}) |
? join("&$name=", map {escape($_) } @{$hashref->{$_}}) |
: &escape($hashref->{$_}) ); |
: &escape($hashref->{$_}) ); |
} keys(%{$hashref}))); |
} keys(%{$hashref}))); |
my $ua=new LWP::UserAgent; |
my $response = &LONCAPA::LWPReq::makerequest('',$request,'','',10); |
$ua->timeout(10); |
|
my $response=$ua->request($request); |
|
my $message=$response->status_line; |
my $message=$response->status_line; |
if (($response->is_success) && ($response->content ne '')) { |
if (($response->is_success) && ($response->content ne '')) { |
my %data = (); |
my %data = (); |
Line 762 sub send_grade {
|
Line 758 sub send_grade {
|
if ($sigmethod eq '') { |
if ($sigmethod eq '') { |
$sigmethod = 'HMAC-SHA1'; |
$sigmethod = 'HMAC-SHA1'; |
} |
} |
my ($request,$sendit,$respcode,$result); |
my $request; |
if ($msgformat eq '1.0') { |
if ($msgformat eq '1.0') { |
my $date = &Apache::loncommon::utc_string(time); |
my $date = &Apache::loncommon::utc_string(time); |
my %ltiparams = ( |
my %ltiparams = ( |
Line 789 sub send_grade {
|
Line 785 sub send_grade {
|
? join("&$name=", map {escape($_) } @{$hashref->{$_}}) |
? join("&$name=", map {escape($_) } @{$hashref->{$_}}) |
: &escape($hashref->{$_}) ); |
: &escape($hashref->{$_}) ); |
} keys(%{$hashref}))); |
} keys(%{$hashref}))); |
$sendit = 1; |
#FIXME Need to handle case where passback failed. |
} |
} |
} else { |
} else { |
srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand. |
srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand. |
Line 846 END
|
Line 842 END
|
], |
], |
$gradexml, |
$gradexml, |
); |
); |
$sendit = 1; |
my $response = &LONCAPA::LWPReq::makerequest('',$request,'','',10); |
|
my $message=$response->status_line; |
|
#FIXME Handle case where pass back of score to LTI Consumer failed. |
} |
} |
} |
} |
if ($sendit) { |
|
my $ua=new LWP::UserAgent; |
|
$ua->timeout(10); |
|
my $response=$ua->request($request); |
|
my $message=$response->status_line; |
|
$respcode = $response->code; |
|
$result = HTTP::Status::status_message($respcode); |
|
} |
|
return ($sendit,$score,$respcode,$result); |
|
} |
} |
|
|
sub setup_logout_callback { |
sub setup_logout_callback { |
Line 879 sub setup_logout_callback {
|
Line 868 sub setup_logout_callback {
|
&Apache::lonnet::sign_lti($cdom,$cnum,$crstool,'lti','logout',$service_url,$idx, |
&Apache::lonnet::sign_lti($cdom,$cnum,$crstool,'lti','logout',$service_url,$idx, |
$keynum,\%ltiparams,\%info); |
$keynum,\%ltiparams,\%info); |
if (($status eq 'ok') && ($post ne '')) { |
if (($status eq 'ok') && ($post ne '')) { |
my $ua=new LWP::UserAgent; |
|
$ua->timeout(10); |
|
my $request=new HTTP::Request('POST',$service_url); |
my $request=new HTTP::Request('POST',$service_url); |
$request->content($post); |
$request->content($post); |
my $response=$ua->request($request); |
my $response = &LONCAPA::LWPReq::makerequest('',$request,'','',10); |
} |
} |
} |
} |
} |
} |
Line 893 sub setup_logout_callback {
|
Line 880 sub setup_logout_callback {
|
# |
# |
# LON-CAPA as LTI Provider |
# 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 |
# includes rules for format of "official" usernames, those rules |
# will apply when determining if a user is to be created. In |
# will apply when determining if a user is to be created. In |
# additional if institutional user information is available that |
# additional if institutional user information is available that |
Line 1034 sub create_passwd {
|
Line 1021 sub create_passwd {
|
# in the Consumer, user privs will be added to the user's environment for |
# in the Consumer, user privs will be added to the user's environment for |
# the new role. |
# 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. |
# if the current user is also the course owner. |
# |
# |
|
|
Line 1326 sub batchaddroster {
|
Line 1313 sub batchaddroster {
|
# |
# |
# Which LON-CAPA roles are assignable by the current user |
# Which LON-CAPA roles are assignable by the current user |
# and how LTI roles map to LON-CAPA roles (as defined in |
# 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. |
# factored in when compiling the list of available roles. |
# |
# |
# Inputs: 3 |
# Inputs: 3 |