From 43f357cd9d30a564ca3371008f6248d0ab5769c7 Mon Sep 17 00:00:00 2001
From: Nick Clemens <nick@bywatersolutions.com>
Date: Fri, 7 Oct 2022 14:50:46 +0000
Subject: [PATCH] Bug 31378: Use base URLs for redirect uri

---
 Koha/REST/V1/OAuth/Client.pm | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/Koha/REST/V1/OAuth/Client.pm b/Koha/REST/V1/OAuth/Client.pm
index 36cca8aac6..ca63d00748 100644
--- a/Koha/REST/V1/OAuth/Client.pm
+++ b/Koha/REST/V1/OAuth/Client.pm
@@ -67,18 +67,22 @@ sub login {
     }
 
     my $uri;
+    my $base_url;
 
     if ( $interface eq 'opac' ) {
+        $base_url = C4::Context->preference('OPACBaseURL');
         if ( C4::Context->preference('OpacPublic') ) {
             $uri = '/cgi-bin/koha/opac-user.pl';
         } else {
             $uri = '/cgi-bin/koha/opac-main.pl';
         }
     } else {
+        $base_url = C4::Context->preference('staffClientBaseURL');
         $uri = '/cgi-bin/koha/mainpage.pl';
     }
 
-    return $c->oauth2->get_token_p($provider)->then(
+
+    return $c->oauth2->get_token_p( $provider, { redirect_uri => $base_url . '/api/v1/public/oauth/login/' . $provider . "/" . $interface } )->then(
         sub {
             return unless my $response = shift;
 
-- 
2.30.2