version 1.17.2.6, 2025/01/16 21:52:05
|
version 1.22, 2024/11/21 07:26:04
|
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 35 use Digest::MD5 qw(md5_hex);
|
Line 35 use Digest::MD5 qw(md5_hex);
|
use Encode; |
use Encode; |
use UUID::Tiny ':std'; |
use UUID::Tiny ':std'; |
use HTTP::Status; |
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 55 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 359 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 693 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 849 END
|
Line 846 END
|
$sendit = 1; |
$sendit = 1; |
} |
} |
} |
} |
if ($sendit) { |
if ($sendit) { |
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; |
$respcode = $response->code; |
$respcode = $response->code; |
$result = HTTP::Status::status_message($respcode); |
$result = HTTP::Status::status_message($respcode); |
} |
} |
return ($sendit,$score,$respcode,$result); |
return ($sendit,$score,$respcode,$result); |
} |
} |
Line 879 sub setup_logout_callback {
|
Line 874 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 886 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 1027 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 1319 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 |