View | Details | Raw Unified | Return to bug 31378
Collapse All | Expand All

(-)a/Koha/Template/Plugin/AuthClient.pm (-1 / +73 lines)
Line 0 Link Here
0
- 
1
package Koha::Template::Plugin::AuthClient;
2
3
# Copyright Theke Solutions 2022
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
22
use Template::Plugin;
23
use base qw( Template::Plugin );
24
25
use Koha::Auth::Providers;
26
27
=head1 NAME
28
29
Koha::Template::Plugin::AuthClient
30
31
=head1 DESCRIPTION
32
33
This plugin is used to retrieve configured and valid authentication
34
providers in the caller context.
35
36
=head1 API
37
38
=head2 Methods
39
40
=head3 get_providers
41
42
    [% FOREACH provider IN AuthClient.get_providers %] ...
43
44
=cut
45
46
sub get_providers {
47
    my ( $self, $interface ) = @_;
48
49
    $interface = 'staff'
50
      if $interface eq 'intranet';
51
52
    my $providers = Koha::Auth::Providers->search( { "domains.allow_$interface" => 1 }, { prefetch => 'domains' } );
53
    my $base_url  = ( $interface ne 'staff' ) ? "/api/v1/public/oauth/login" : "/api/v1/public/oauth/login";
54
55
    my @urls;
56
57
    while ( my $provider = $providers->next ) {
58
59
        my $code = $provider->code;
60
61
        if ( $provider->protocol eq 'OIDC' || $provider->protocol eq 'OAuth' ) {
62
            push @urls,
63
              { code        => $code,
64
                description => $provider->description,
65
                icon_url    => $provider->icon_url,
66
                url         => "$base_url/$code/$interface",
67
              };
68
        }
69
    }
70
    return \@urls;
71
}
72
73
1;

Return to bug 31378