From 068db12616f56c45bc430013bff079597c68344a Mon Sep 17 00:00:00 2001 From: Nicholas van Oudtshoorn Date: Wed, 20 Mar 2024 10:45:27 +0800 Subject: [PATCH] Allow old googleopenidconnect service to redirect to referring page if possible and appropriate --- opac/svc/auth/googleopenidconnect | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/opac/svc/auth/googleopenidconnect b/opac/svc/auth/googleopenidconnect index 5a18c87a38..75a053212e 100755 --- a/opac/svc/auth/googleopenidconnect +++ b/opac/svc/auth/googleopenidconnect @@ -214,10 +214,16 @@ elsif ( defined $query->param('code') ) { #handle redirect to main.pl, for private opac my $uri; - if (C4::Context->preference('OpacPublic') ) { - $uri = '/cgi-bin/koha/opac-user.pl'; - } else { - $uri = '/cgi-bin/koha/opac-main.pl'; + 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 { + $uri = '/cgi-bin/koha/opac-main.pl'; + } } print $query->redirect( -uri => $uri, @@ -244,6 +250,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