Bugzilla – Attachment 163493 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.49 KB, created by
Nicholas van Oudtshoorn
on 2024-03-20 05:52:34 UTC
(
hide
)
Description:
Redirect to referring URL on successful OAuth2 Login
Filename:
MIME Type:
Creator:
Nicholas van Oudtshoorn
Created:
2024-03-20 05:52:34 UTC
Size:
2.49 KB
patch
obsolete
>From 2dccc28e6d3b1dfb358c461361258a68f794bfc7 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 | 24 ++++++++++++++++++------ > 1 file changed, 18 insertions(+), 6 deletions(-) > >diff --git a/Koha/REST/V1/OAuth/Client.pm b/Koha/REST/V1/OAuth/Client.pm >index ad15a87967..b58523cf60 100644 >--- a/Koha/REST/V1/OAuth/Client.pm >+++ b/Koha/REST/V1/OAuth/Client.pm >@@ -42,6 +42,7 @@ Controller method handling login requests > > sub login { > my $c = shift->openapi->valid_input or return; >+ Koha::Logger->get->debug("referer " . $c->referer . "HAHA" ); > > my $provider = $c->param('provider_code'); > my $interface = $c->param('interface'); >@@ -50,15 +51,24 @@ sub login { > > my $uri; > my $redirect_url; >+ my $referrer_url; > > 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'; >- } else { >- $uri = '/cgi-bin/koha/opac-main.pl'; >+ my $host = C4::Context->preference('OPACBaseURL'); >+ $redirect_url = $host . '/api/v1/public/oauth/login/'; >+ # Determine that the referring_url is on our server >+ if ( $referrer_url =~ /^$host/ ) { >+ # Strip out the logout tag >+ my $regex = qr/logout\.x=1/mp; >+ $uri = $referrer_url =~ s/$regex//rg; >+ } else { >+ 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 +107,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