Bugzilla – Attachment 163496 Details for
Bug 34164
OAuth2/OIDC should redirect to page that initiated login
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Redirect to referring URL on successful OAuth2 Login
0001-Allow-OAuth-login-to-redirect-to-referring-url-on-su.patch (text/plain), 2.24 KB, created by
Nicholas van Oudtshoorn
on 2024-03-20 06:00:19 UTC
(
hide
)
Description:
Redirect to referring URL on successful OAuth2 Login
Filename:
MIME Type:
Creator:
Nicholas van Oudtshoorn
Created:
2024-03-20 06:00:19 UTC
Size:
2.24 KB
patch
obsolete
>From 78255c1f8006bd9f8378ee67b3e140dab86e3d16 Mon Sep 17 00:00:00 2001 >From: Nicholas van Oudtshoorn <vanoudt@gmail.com> >Date: Wed, 20 Mar 2024 13:48:31 +0800 >Subject: [PATCH] Allow OAuth login to redirect to referring url on successful > login > >--- > Koha/REST/V1/OAuth/Client.pm | 21 ++++++++++++++++----- > 1 file changed, 16 insertions(+), 5 deletions(-) > >diff --git a/Koha/REST/V1/OAuth/Client.pm b/Koha/REST/V1/OAuth/Client.pm >index ad15a87967..dcba9013b9 100644 >--- a/Koha/REST/V1/OAuth/Client.pm >+++ b/Koha/REST/V1/OAuth/Client.pm >@@ -50,15 +50,24 @@ sub login { > > my $uri; > my $redirect_url; >+ my $referrer_url; > >+ $referrer_url = $c->session('referrer'); > if ( $interface eq 'opac' ) { >- $redirect_url = C4::Context->preference('OPACBaseURL') . '/api/v1/public/oauth/login/'; >- if ( C4::Context->preference('OpacPublic') ) { >- $uri = '/cgi-bin/koha/opac-user.pl'; >+ my $host = C4::Context->preference('OPACBaseURL'); >+ $redirect_url = $host . '/api/v1/public/oauth/login/'; >+ if ((defined $referrer_url) && ($referrer_url ne '') && ($referrer_url =~ /^$host/ )) { >+ # Strip out the logout tag >+ my $regex = qr/logout\.x=1/mp; >+ $uri = $referrer_url =~ s/$regex//rg; > } else { >- $uri = '/cgi-bin/koha/opac-main.pl'; >+ if ( C4::Context->preference('OpacPublic') ) { >+ $uri = '/cgi-bin/koha/opac-user.pl'; >+ } else { >+ $uri = '/cgi-bin/koha/opac-main.pl'; >+ } > } >- } else { >+ } else { # Staff can't access anything until they login, so no need to bother with referring URL > $redirect_url = C4::Context->preference('staffClientBaseURL') . '/api/v1/oauth/login/'; > $uri = '/cgi-bin/koha/mainpage.pl'; > } >@@ -97,6 +106,8 @@ sub login { > else { > # initial request, generate CSRF token > $state = Koha::Token->new->generate_csrf( { session_id => $c->req->cookie('CGISESSID')->value } ); >+ my $r = $c->req->headers->referrer; >+ $c->session({referrer => $r}); > } > > return $c->oauth2->get_token_p( $provider => { ( !$is_callback ? ( state => $state ) : () ), redirect_uri => $redirect_url . $provider . "/" . $interface } )->then( >-- >2.34.1 >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 34164
:
163127
|
163128
|
163129
|
163493
|
163494
|
163495
|
163496
|
164979
|
164980