[LON-CAPA-cvs] cvs: loncom /lti ltiauth.pm
raeburn
raeburn at source.lon-capa.org
Fri Jan 12 15:42:38 EST 2018
raeburn Fri Jan 12 20:42:38 2018 EDT
Modified files:
/loncom/lti ltiauth.pm
Log:
- Bug 6754 LON-CAPA as LTI Provider
- Tiny URLs can be part of the launch URL used to access a LON-CAPA
assignment from another CMS. On launch (in the Consumer), POSTed data
would be sent to a URL such as: /adm/lti/tiny/<domain>/<key>, where key
is six characters.
Index: loncom/lti/ltiauth.pm
diff -u loncom/lti/ltiauth.pm:1.4 loncom/lti/ltiauth.pm:1.5
--- loncom/lti/ltiauth.pm:1.4 Wed Jan 3 22:04:19 2018
+++ loncom/lti/ltiauth.pm Fri Jan 12 20:42:38 2018
@@ -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 @@
# (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 @@
$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 @@
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 @@
# 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 @@
#
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 @@
# (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 @@
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 @@
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 @@
} 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 @@
#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 @@
#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 @@
#FIXME Do self-enrollment here
return OK;
} else {
- &invalid_request($r,14);
+ &invalid_request($r,15);
return OK;
}
}
More information about the LON-CAPA-cvs
mailing list