From ced6b40e07ba37d6f7e7e98e0d56e8c04595423a Mon Sep 17 00:00:00 2001 From: Agustin Moyano Date: Tue, 23 Aug 2022 11:58:58 -0300 Subject: [PATCH] Bug 31378: Add auth providers template plugin Signed-off-by: Lukasz Koszyk Signed-off-by: Tomas Cohen Arazi Signed-off-by: Nick Clemens --- Koha/Template/Plugin/AuthClient.pm | 73 ++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 Koha/Template/Plugin/AuthClient.pm diff --git a/Koha/Template/Plugin/AuthClient.pm b/Koha/Template/Plugin/AuthClient.pm new file mode 100644 index 00000000000..6e4ee144b03 --- /dev/null +++ b/Koha/Template/Plugin/AuthClient.pm @@ -0,0 +1,73 @@ +package Koha::Template::Plugin::AuthClient; + +# Copyright Theke Solutions 2022 +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . + +use Modern::Perl; + +use Template::Plugin; +use base qw( Template::Plugin ); + +use Koha::Auth::Providers; + +=head1 NAME + +Koha::Template::Plugin::AuthClient + +=head1 DESCRIPTION + +This plugin is used to retrieve configured and valid authentication +providers in the caller context. + +=head1 API + +=head2 Methods + +=head3 get_providers + + [% FOREACH provider IN AuthClient.get_providers %] ... + +=cut + +sub get_providers { + my ( $self, $interface ) = @_; + + $interface = 'staff' + if $interface eq 'intranet'; + + my $providers = Koha::Auth::Providers->search( { "domains.allow_$interface" => 1 }, { prefetch => 'domains' } ); + my $base_url = ( $interface ne 'staff' ) ? "/api/v1/public/oauth/login" : "/api/v1/public/oauth/login"; + + my @urls; + + while ( my $provider = $providers->next ) { + + my $code = $provider->code; + + if ( $provider->protocol eq 'OIDC' || $provider->protocol eq 'OAuth' ) { + push @urls, + { code => $code, + description => $provider->description, + icon_url => $provider->icon_url, + url => "$base_url/$code/$interface", + }; + } + } + return \@urls; +} + +1; -- 2.34.1