[LON-CAPA-cvs] cvs: loncom / lontrans.pm /lti ltiauth.pm
raeburn
raeburn at source.lon-capa.org
Sat Apr 21 16:34:50 EDT 2018
raeburn Sat Apr 21 20:34:50 2018 EDT
Modified files:
/loncom lontrans.pm
/loncom/lti ltiauth.pm
Log:
- Bug 6754 LON-CAPA as LTI Provider
- LTI launch results in call to ltiauth, even if user has existing LON-CAPA
session (role, course etc. will be updated).
- LTI launch can be for a published .sequence
Index: loncom/lontrans.pm
diff -u loncom/lontrans.pm:1.21 loncom/lontrans.pm:1.22
--- loncom/lontrans.pm:1.21 Tue Apr 17 14:02:56 2018
+++ loncom/lontrans.pm Sat Apr 21 20:34:44 2018
@@ -1,7 +1,7 @@
# The LearningOnline Network
# URL translation for User Files
#
-# $Id: lontrans.pm,v 1.21 2018/04/17 14:02:56 raeburn Exp $
+# $Id: lontrans.pm,v 1.22 2018/04/21 20:34:44 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -38,63 +38,7 @@
my $r = shift;
# FIXME line remove when mod_perl fixes BUG#4948
$r->notes->set('error-notes' => '');
- if ($r->uri =~ m{^/adm/lti/(.+)$}) {
- my $realuri = $1;
- my %user;
- my $handle = &Apache::lonnet::check_for_valid_session($r,undef,\%user);
- if (($handle ne '') && ($user{'lti'})) {
- if ($realuri =~ m{^uploaded/$match_domain/$match_courseid/(default|supplemental)(|_\d+)\.(?:sequence|page)___\d+___.+$}) {
- if ($user{'ltiuri'} ne $realuri) {
- &Apache::lonnet::appenv({'request.lti.uri' => $realuri});
- }
- my ($map,$resid,$url) = split(/___/,$realuri);
- $realuri = &Apache::lonnet::clutter($url).'?symb='.$realuri;
- } elsif ($realuri =~ m{^res/$match_domain/$match_username/.+\.(?:sequence|page)___\d+___.+$}) {
- if ($user{'ltiuri'} ne $realuri) {
- &Apache::lonnet::appenv({'request.lti.uri' => $realuri});
- }
- my ($map,$resid,$url) = split(/___/,$realuri);
- $realuri = &Apache::lonnet::clutter($url).'?symb='.$realuri;
- } elsif ($realuri =~ m{^tiny/$match_domain/\w+$}) {
- $realuri = '/'.$realuri;
- if ($user{'ltiuri'} ne $realuri) {
- &Apache::lonnet::appenv({'request.lti.uri' => $realuri});
- }
- } elsif ($realuri =~ m{($match_domain)/($match_courseid)$}) {
- $realuri = '/adm/navmaps';
- if ($user{'ltiuri'} ne '') {
- &Apache::lonnet::delenv('request.lti.uri');
- }
- } else {
- $realuri = '/'.$realuri;
- if ($realuri =~ m{/default_\d+\.sequence$}) {
- if ($user{'ltiuri'} ne $realuri) {
- &Apache::lonnet::appenv({'request.lti.uri' => $realuri});
- }
- $realuri .= (($realuri =~/\?/)?'&':'?').'navmap=1';
- } elsif ($realuri =~ m{^/res/.+\.sequence$}) {
- if ($user{'ltiuri'} ne $realuri) {
- &Apache::lonnet::appenv({'request.lti.uri' => $realuri});
- }
- $realuri .= (($realuri =~/\?/)?'&':'?').'navmap=1';
- } elsif ($realuri =~ m{\.page$}) {
- if ($user{'ltiuri'} ne $realuri) {
- &Apache::lonnet::appenv({'request.lti.uri' => $realuri});
- }
- }
- }
- my $host = $r->headers_in->get('Host');
- if ($host) {
- my $protocol = 'http';
- if ($r->get_server_port == 443) {
- $protocol = 'https';
- }
- my $location = $protocol.'://'.$host.$realuri;
- $r->headers_out->set(Location => $location);
- return REDIRECT;
- }
- }
- } elsif ($r->uri =~ m{^/+tiny/+($match_domain)/+(\w+)$}) {
+ if ($r->uri =~ m{^/+tiny/+($match_domain)/+(\w+)$}) {
my ($cdom,$key) = ($1,$2);
if (&Apache::lonnet::domain($cdom) ne '') {
my %user;
Index: loncom/lti/ltiauth.pm
diff -u loncom/lti/ltiauth.pm:1.8 loncom/lti/ltiauth.pm:1.9
--- loncom/lti/ltiauth.pm:1.8 Sat Apr 14 02:30:07 2018
+++ loncom/lti/ltiauth.pm Sat Apr 21 20:34:50 2018
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Basic LTI Authentication Module
#
-# $Id: ltiauth.pm,v 1.8 2018/04/14 02:30:07 raeburn Exp $
+# $Id: ltiauth.pm,v 1.9 2018/04/21 20:34:50 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -43,6 +43,20 @@
my $r = shift;
my $requri = $r->uri;
#
+# Check for existing session, and temporarily delete any form items
+# in %env, if session exists
+#
+ my %savedform;
+ my $handle = &Apache::lonnet::check_for_valid_session($r);
+ if ($handle ne '') {
+ foreach my $key (sort(keys(%env))) {
+ if ($key =~ /^form\.(.+)$/) {
+ $savedform{$1} = $env{$key};
+ delete($env{$key});
+ }
+ }
+ }
+#
# Retrieve data POSTed by LTI Consumer on launch
#
&Apache::lonacc::get_posted_cgi($r);
@@ -52,6 +66,17 @@
$params->{$1} = $env{$key};
}
}
+#
+# Check for existing session, and restored temporarily
+# deleted form items to %env, if session exists.
+#
+ if ($handle ne '') {
+ if (keys(%savedform)) {
+ foreach my $key (sort(keys(%savedform))) {
+ $env{'form.'.$key} = $savedform{$key};
+ }
+ }
+ }
unless (keys(%{$params})) {
&invalid_request($r,1);
@@ -140,7 +165,7 @@
# Order is:
#
# (a) from custom_coursedomain item in POSTed data
-# (b) from tail of requested URL (after /adm/lti) if it has format of a symb
+# (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/\w+
@@ -182,6 +207,13 @@
$symb = $tail;
$symb =~ s{^/+}{};
}
+ } elsif ($tail =~ m{^/res/(?:$match_domain)/(?:$match_username)/.+\.(?:sequence|page)(|___\d+___.+)$}) {
+ if ($1 eq '') {
+ $mapurl = $tail;
+ } else {
+ $symb = $tail;
+ $symb =~ s{^/+}{};
+ }
} elsif ($tail =~ m{^/($match_domain)/($match_courseid)$}) {
($urlcdom,$urlcnum) = ($1,$2);
if (($cdom ne '') && ($cdom ne $urlcdom)) {
@@ -329,7 +361,7 @@
#
# (a) from course mapping (if the link between Consumer "course" and
# Provider "course" has been established previously).
-# (b) from tail of requested URL (after /adm/lti) if it has format of a symb
+# (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/\w+
@@ -823,6 +855,9 @@
} elsif ($tail =~ m{^\Q/tiny/$cdom/\E\w+$}) {
$env{'form.origurl'} = $tail;
$env{'request.lti.uri'} = $tail;
+ } elsif ($tail eq "/$cdom/$cnum") {
+ $env{'form.origurl'} = '/adm/navmaps';
+ $env{'request.lti.uri'} = $tail;
} else {
unless ($tail eq '/adm/roles') {
$env{'form.origurl'} = '/adm/navmaps';
More information about the LON-CAPA-cvs
mailing list