Bug 16818: External auth redirect broken under Plack
[koha.git] / C4 / Auth.pm
index 985bd39..582eefc 100644 (file)
@@ -32,7 +32,7 @@ use C4::Languages;
 use C4::Branch;       # GetBranches
 use C4::Search::History;
 use Koha;
-use Koha::AuthUtils qw(hash_password);
+use Koha::AuthUtils qw(get_script_name hash_password);
 use Koha::LibraryCategories;
 use Koha::Libraries;
 use POSIX qw/strftime/;
@@ -194,7 +194,7 @@ sub get_template_and_user {
 
             $template->param(
                 loginprompt => 1,
-                script_name => _get_script_name(),
+                script_name => get_script_name(),
             );
             print $in->{query}->header(
                 {   type              => 'text/html',
@@ -1211,7 +1211,7 @@ sub checkauth {
         opaclayoutstylesheet                  => C4::Context->preference("opaclayoutstylesheet"),
         login                                 => 1,
         INPUTS                                => \@inputs,
-        script_name                           => _get_script_name(),
+        script_name                           => get_script_name(),
         casAuthentication                     => C4::Context->preference("casAuthentication"),
         shibbolethAuthentication              => $shib,
         SessionRestrictionByIP                => C4::Context->preference("SessionRestrictionByIP"),
@@ -2050,24 +2050,6 @@ sub getborrowernumber {
     return 0;
 }
 
-=head2 _get_script_name
-
-This returns the correct script name, for use in redirecting back to the correct page after showing
-the login screen. It depends on details of the package Plack configuration, and should not be used
-outside this context.
-
-=cut
-
-sub _get_script_name {
-    # This is the method about.pl uses to detect Plack; now that two places use it, it MUST be
-    # right.
-    if ( ( any { /(^psgi\.|^plack\.)/i } keys %ENV ) && $ENV{SCRIPT_NAME} =~ m,^/(intranet|opac)(.*), ) {
-        return '/cgi-bin/koha' . $2;
-    } else {
-        return $ENV{SCRIPT_NAME};
-    }
-}
-
 END { }    # module clean-up code here (global destructor)
 1;
 __END__