--- loncom/lti/ltiauth.pm 2018/01/03 22:04:19 1.4 +++ loncom/lti/ltiauth.pm 2018/01/12 20:42:38 1.5 @@ -1,7 +1,7 @@ # The LearningOnline Network # Basic LTI Authentication Module # -# $Id: ltiauth.pm,v 1.4 2018/01/03 22:04:19 raeburn Exp $ +# $Id: ltiauth.pm,v 1.5 2018/01/12 20:42:38 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -142,8 +142,8 @@ sub handler { # (b) from tail of requested URL (after /adm/lti) if it has format of a symb # (c) from tail of requested URL (after /adm/lti) if it has format of a map # (d) from tail of requested URL (after /adm/lti) if it has format /domain/courseID -# (e) from tail of requested URL (after /adm/lti) if it has format /tiny/domain/... -# i.e., a shortened URL (see bug #6400) -- not implemented yet. +# (e) from tail of requested URL (after /adm/lti) if it has format /tiny/domain/\w+ +# i.e., a shortened URL (see bug #6400). # (f) same as user's domain # # Request invalid if custom_coursedomain is defined and is inconsistent with @@ -181,13 +181,34 @@ sub handler { $symb = $tail; $symb =~ s{^/+}{}; } -#FIXME Need to handle encrypted URLs +#FIXME Need to handle encrypted URLs } elsif ($tail =~ m{^/($match_domain)/($match_courseid)$}) { ($urlcdom,$urlcnum) = ($1,$2); if (($cdom ne '') && ($cdom ne $urlcdom)) { &invalid_request($r,4); return OK; } + } elsif ($tail =~ m{^/tiny/($match_domain)/(\w+)$}) { + ($urlcdom,my $key) = ($1,$2); + if (($cdom ne '') && ($cdom ne $urlcdom)) { + &invalid_request($r,5); + return OK; + } + my $tinyurl; + my ($result,$cached)=&Apache::lonnet::is_cached_new('tiny',$urlcdom."\0".$key); + if (defined($cached)) { + $tinyurl = $result; + } else { + my $configuname = &Apache::lonnet::get_domainconfiguser($urlcdom); + my %currtiny = &Apache::lonnet::get('tiny',[$key],$urlcdom,$configuname); + if ($currtiny{$key} ne '') { + $tinyurl = $currtiny{$key}; + &Apache::lonnet::do_cache_new('tiny',$urlcdom."\0".$key,$currtiny{$key},600); + } + } + if ($tinyurl ne '') { + $urlcnum = (split(/\&/,$tinyurl))[0]; + } } if (($cdom eq '') && ($urlcdom ne '')) { my $cprimary_id = &Apache::lonnet::domain($urlcdom,'primary'); @@ -217,7 +238,7 @@ sub handler { my %lti = &Apache::lonnet::get_domain_lti($cdom,'provider'); unless (keys(%lti) > 0) { - &invalid_request($r,5); + &invalid_request($r,6); return OK; } my %lti_by_key; @@ -265,7 +286,7 @@ sub handler { # configuration in LON-CAPA for that LTI Consumer. # unless (($itemid) && (ref($lti{$itemid}) eq 'HASH')) { - &invalid_request($r,6); + &invalid_request($r,7); return OK; } @@ -275,7 +296,7 @@ sub handler { # unless (&LONCAPA::ltiutils::check_nonce($params->{'oauth_nonce'},$params->{'oauth_timestamp'}, $lti{$itemid}{'lifetime'},$cdom,$r->dir_config('lonLTIDir'))) { - &invalid_request($r,7); + &invalid_request($r,8); return OK; } @@ -311,8 +332,8 @@ sub handler { # (b) from tail of requested URL (after /adm/lti) if it has format of a symb # (c) from tail of requested URL (after /adm/lti) if it has format of a map # (d) from tail of requested URL (after /adm/lti) if it has format /domain/courseID -# (e) from tail of requested URL (after /adm/lti) if it has format /tiny/domain/... -# i.e., a shortened URL (see bug #6400) -- not implemented yet. +# (e) from tail of requested URL (after /adm/lti) if it has format /tiny/domain/\w+ +# i.e., a shortened URL (see bug #6400). # # If Consumer course included in POSTed data points as a target course which # has a format which matches a LON-CAPA courseID, but the course does not @@ -335,7 +356,7 @@ sub handler { if ($consumers{$sourcecrs} =~ /^$match_courseid$/) { my $crshome = &Apache::lonnet::homeserver($consumers{$sourcecrs},$cdom); if ($crshome =~ /(con_lost|no_host|no_such_host)/) { - &invalid_request($r,8); + &invalid_request($r,9); return OK; } else { $posscnum = $consumers{$sourcecrs}; @@ -347,7 +368,7 @@ sub handler { if ($urlcnum ne '') { if ($posscnum ne '') { if ($posscnum ne $urlcnum) { - &invalid_request($r,9); + &invalid_request($r,10); return OK; } else { $cnum = $posscnum; @@ -355,7 +376,7 @@ sub handler { } else { my $crshome = &Apache::lonnet::homeserver($urlcnum,$cdom); if ($crshome =~ /(con_lost|no_host|no_such_host)/) { - &invalid_request($r,10); + &invalid_request($r,11); return OK; } else { $cnum = $urlcnum; @@ -427,12 +448,12 @@ sub handler { #FIXME Do user creation here. return OK } else { - &invalid_request($r,11); + &invalid_request($r,12); return OK; } } } else { - &invalid_request($r,12); + &invalid_request($r,13); return OK; } @@ -448,7 +469,7 @@ sub handler { #FIXME Create a new LON-CAPA course here. return OK; } else { - &invalid_request($r,13); + &invalid_request($r,14); return OK; } } @@ -482,7 +503,7 @@ sub handler { #FIXME Do self-enrollment here return OK; } else { - &invalid_request($r,14); + &invalid_request($r,15); return OK; } }