From f01b485986fb5fb85f653b7d1605d19a033fddbf Mon Sep 17 00:00:00 2001 From: Nicholas van Oudtshoorn Date: Thu, 14 Mar 2024 12:36:09 +0800 Subject: [PATCH] Redirect to the referring url on login, excluding logout parameters. Redirect to the main page or user page if the referring url isn't part of this koah installation. --- opac/cgi-bin/opac/svc/auth/googleopenidconnect | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/opac/cgi-bin/opac/svc/auth/googleopenidconnect b/opac/cgi-bin/opac/svc/auth/googleopenidconnect index 5a18c87..ad43f0b 100755 --- a/opac/cgi-bin/opac/svc/auth/googleopenidconnect +++ b/opac/cgi-bin/opac/svc/auth/googleopenidconnect @@ -211,14 +211,19 @@ elsif ( defined $query->param('code') ) { my ( $userid, $cookie, $session_id ) = checkauth( $query, 1, {}, 'opac', $email ); if ($userid) { # A user with this email is registered in koha - #handle redirect to main.pl, for private opac my $uri; - if (C4::Context->preference('OpacPublic') ) { + my $referer = $session->param( 'auth-refer-uri' ); + if ( $referer =~ /^$host/ ) { + my $regex = qr/logout\.x=1/mp; + $uri = $referer =~ s/$regex//rg; + } else { + if (C4::Context->preference('OpacPublic') ) { $uri = '/cgi-bin/koha/opac-user.pl'; - } else { + } else { $uri = '/cgi-bin/koha/opac-main.pl'; - } + } + } print $query->redirect( -uri => $uri, -cookie => $cookie @@ -244,6 +249,7 @@ else { my $openidstate = 'auth_'; $openidstate .= sprintf( "%x", rand 16 ) for 1 .. 32; $session->param( 'google-openid-state', $openidstate ); + $session->param( 'auth-refer-uri', $ENV{HTTP_REFERER} ); $session->flush(); my $prompt = $query->param('reauthenticate') // q{}; -- 2.34.1