version 1.3, 2017/12/30 14:04:00
|
version 1.9, 2018/05/15 04:33:17
|
Line 51 use LONCAPA qw(:DEFAULT :match);
|
Line 51 use LONCAPA qw(:DEFAULT :match);
|
# |
# |
# 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 286 sub verify_lis_item {
|
Line 286 sub verify_lis_item {
|
my $expected_sig; |
my $expected_sig; |
if ($context eq 'grade') { |
if ($context eq 'grade') { |
my $uniqid = $digsymb.':::'.$diguser.':::'.$cdom.'_'.$cnum; |
my $uniqid = $digsymb.':::'.$diguser.':::'.$cdom.'_'.$cnum; |
$expected_sig = &get_service_id($secret,$uniqid); |
$expected_sig = (split(/:::/,&get_service_id($secret,$uniqid)))[0]; |
if ($expected_sig eq $sigrec) { |
if ($expected_sig eq $sigrec) { |
return 1; |
return 1; |
} else { |
} else { |
Line 294 sub verify_lis_item {
|
Line 294 sub verify_lis_item {
|
} |
} |
} elsif ($context eq 'roster') { |
} elsif ($context eq 'roster') { |
my $uniqid = $digsymb.':::'.$cdom.'_'.$cnum; |
my $uniqid = $digsymb.':::'.$cdom.'_'.$cnum; |
$expected_sig = &get_service_id($secret,$uniqid); |
$expected_sig = (split(/:::/,&get_service_id($secret,$uniqid)))[0]; |
if ($expected_sig eq $sigrec) { |
if ($expected_sig eq $sigrec) { |
return 1; |
return 1; |
} else { |
} else { |
Line 314 sub verify_lis_item {
|
Line 314 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 |
# too 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. |
# |
# |
|
|
Line 324 sub sign_params {
|
Line 324 sub sign_params {
|
if ($sigmethod eq '') { |
if ($sigmethod eq '') { |
$sigmethod = 'HMAC-SHA1'; |
$sigmethod = 'HMAC-SHA1'; |
} |
} |
|
srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand. |
my $nonce = Digest::SHA::sha1_hex(sprintf("%06x%06x",rand(0xfffff0),rand(0xfffff0))); |
my $nonce = Digest::SHA::sha1_hex(sprintf("%06x%06x",rand(0xfffff0),rand(0xfffff0))); |
my $request = Net::OAuth->request("request token")->new( |
my $request = Net::OAuth->request("request token")->new( |
consumer_key => $key, |
consumer_key => $key, |
Line 458 sub release_tool_lock {
|
Line 459 sub release_tool_lock {
|
} |
} |
} |
} |
|
|
|
# |
|
# LON-CAPA as LTI Provider |
|
# |
|
# Use the part of the launch URL after /adm/lti to determine |
|
# the scope for the current session (i.e., restricted to a |
|
# single resource, to a single folder/map, or to an entire |
|
# course). |
|
# |
|
# Returns an array containing scope: resource, map, or course |
|
# and the LON-CAPA URL that is displayed post-launch, including |
|
# accommodation of URL encryption, and translation of a tiny URL |
|
# to the actual URL |
|
# |
|
|
|
sub lti_provider_scope { |
|
my ($tail,$cdom,$cnum) = @_; |
|
my ($scope,$realuri); |
|
if ($tail =~ m{^/uploaded/$cdom/$cnum/(?:default|supplemental)(?:|_\d+)\.(?:sequence|page)(|___\d+___.+)$}) { |
|
my $rest = $1; |
|
if ($rest eq '') { |
|
$scope = 'map'; |
|
$realuri = $tail; |
|
} else { |
|
my ($map,$resid,$url) = &Apache::lonnet::decode_symb($tail); |
|
$realuri = &Apache::lonnet::clutter($url); |
|
if ($url =~ /\.sequence$/) { |
|
$scope = 'map'; |
|
} else { |
|
$scope = 'resource'; |
|
$realuri .= '?symb='.$tail; |
|
} |
|
} |
|
} elsif ($tail =~ m{^/res/$match_domain/$match_username/.+\.(?:sequence|page)(|___\d+___.+)$}) { |
|
my $rest = $1; |
|
if ($rest eq '') { |
|
$scope = 'map'; |
|
$realuri = $tail; |
|
} else { |
|
my ($map,$resid,$url) = &Apache::lonnet::decode_symb($tail); |
|
$realuri = &Apache::lonnet::clutter($url); |
|
if ($url =~ /\.sequence$/) { |
|
$scope = 'map'; |
|
} else { |
|
$scope = 'resource'; |
|
$realuri .= '?symb='.$tail; |
|
} |
|
} |
|
} elsif ($tail =~ m{^/tiny/$cdom/(\w+)$}) { |
|
my $key = $1; |
|
my $tinyurl; |
|
my ($result,$cached)=&Apache::lonnet::is_cached_new('tiny',$cdom."\0".$key); |
|
if (defined($cached)) { |
|
$tinyurl = $result; |
|
} else { |
|
my $configuname = &Apache::lonnet::get_domainconfiguser($cdom); |
|
my %currtiny = &Apache::lonnet::get('tiny',[$key],$cdom,$configuname); |
|
if ($currtiny{$key} ne '') { |
|
$tinyurl = $currtiny{$key}; |
|
&Apache::lonnet::do_cache_new('tiny',$cdom."\0".$key,$currtiny{$key},600); |
|
} |
|
} |
|
if ($tinyurl ne '') { |
|
my ($cnum,$symb) = split(/\&/,$tinyurl,2); |
|
my ($map,$resid,$url) = &Apache::lonnet::decode_symb($symb); |
|
if ($url =~ /\.(page|sequence)$/) { |
|
$scope = 'map'; |
|
} else { |
|
$scope = 'resource'; |
|
} |
|
if ((&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i) && |
|
(!$env{'request.role.adv'})) { |
|
$realuri = &Apache::lonenc::encrypted(&Apache::lonnet::clutter($url)); |
|
if ($scope eq 'resource') { |
|
$realuri .= '?symb='.&Apache::lonenc::encrypted($symb); |
|
} |
|
} else { |
|
$realuri = &Apache::lonnet::clutter($url); |
|
if ($scope eq 'resource') { |
|
$realuri .= '?symb='.$symb; |
|
} |
|
} |
|
} |
|
} elsif ($tail =~ m{^/$cdom/$cnum$}) { |
|
$scope = 'course'; |
|
$realuri = '/adm/navmaps'; |
|
} |
|
return ($scope,$realuri); |
|
} |
|
|
1; |
1; |