Bugzilla – Attachment 164979 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]
[PATCH] Allow OAuth login to redirect to referring url on successful login
0001-PATCH-Allow-OAuth-login-to-redirect-to-referring-url.patch (text/plain), 2.95 KB, created by
Nicholas van Oudtshoorn
on 2024-04-17 08:22:16 UTC
(
hide
)
Description:
[PATCH] Allow OAuth login to redirect to referring url on successful login
Filename:
MIME Type:
Creator:
Nicholas van Oudtshoorn
Created:
2024-04-17 08:22:16 UTC
Size:
2.95 KB
patch
obsolete
>From 083de6eb81c591d293e5c3db7e7ea9bd45aac647 Mon Sep 17 00:00:00 2001 >From: Nicholas van Oudtshoorn <vanoudt@gmail.com> >Date: Wed, 17 Apr 2024 16:11:59 +0800 >Subject: [PATCH] [PATCH] Allow OAuth login to redirect to referring url on > successful login. > >--- > Koha/REST/V1/OAuth/Client.pm | 36 ++++++++++++++++++++++++++++++------ > 1 file changed, 30 insertions(+), 6 deletions(-) > >diff --git a/Koha/REST/V1/OAuth/Client.pm b/Koha/REST/V1/OAuth/Client.pm >index 2840b18715..a629c4b750 100644 >--- a/Koha/REST/V1/OAuth/Client.pm >+++ b/Koha/REST/V1/OAuth/Client.pm >@@ -42,7 +42,6 @@ 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'); >@@ -51,17 +50,27 @@ sub login { > > my $uri; > my $redirect_url; >+ my $referrer_url; > >+ $referrer_url = $c->session('auth-refer-uri'); > 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'; >+ if ( $referrer_url ) { >+ $uri = $referrer_url; > } 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 { >- $redirect_url = C4::Context->preference('staffClientBaseURL') . '/api/v1/oauth/login/'; >- $uri = '/cgi-bin/koha/mainpage.pl'; >+ $redirect_url = C4::Context->preference('staffClientBaseURL') . '/api/v1/oauth/login/'; >+ if ( $referrer_url ) { >+ $uri = $referrer_url; >+ } else { >+ $uri = '/cgi-bin/koha/mainpage.pl'; >+ } > } > > unless ( $provider_config && $provider_config->{authorize_url} ) { >@@ -98,6 +107,21 @@ sub login { > else { > # initial request, generate CSRF token > $state = Koha::Token->new->generate_csrf( { session_id => $c->req->cookie('CGISESSID')->value } ); >+ >+ # Check to see if the current referrer is part of the staff of opac interfaces, and store it if it is >+ my $interface = $c->param('interface'); >+ my $referrer_uri = $c->req->headers->referrer; >+ my $logoutregex = qr/logout\.x=1/mp; >+ my $int_host; >+ if ($interface eq 'opac') { >+ $int_host = C4::Context->preference('OPACBaseURL'); >+ } else { >+ $int_host = C4::Context->preference('staffClientBaseURL'); >+ } >+ if ($referrer_uri && ($referrer_uri =~ /^\Q$int_host\E/ )) { >+ $referrer_uri =~ s/$logoutregex//rg; >+ $c->session({'auth-refer-uri' => $referrer_uri }); >+ } > } > > 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