From 4862bd7d31373dd9a79c4d4da655c588f1051caa Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Mon, 17 Jan 2022 15:28:46 +0000 Subject: [PATCH] Bug 29894: Module changes (preliminary) Content-Type: text/plain; charset=utf-8 --- Koha/Auth/TwoFactorAuth.pm | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/Koha/Auth/TwoFactorAuth.pm b/Koha/Auth/TwoFactorAuth.pm index 81ddf06a3d..de35166485 100644 --- a/Koha/Auth/TwoFactorAuth.pm +++ b/Koha/Auth/TwoFactorAuth.pm @@ -16,7 +16,8 @@ package Koha::Auth::TwoFactorAuth; # along with Koha; if not, see . use Modern::Perl; -use Auth::GoogleAuth; +#use Auth::GoogleAuth; +use Koha::Exceptions; use base qw( Auth::GoogleAuth ); @@ -40,30 +41,31 @@ It's based on Auth::GoogleAuth $obj = Koha::Auth::TwoFactorAuth->new({ patron => $p, secret => $s }); + The patron parameter is mandatory. If no secret is passed, the patron's + secret will be used. + =cut sub new { my ($class, $params) = @_; my $patron = $params->{patron}; - my $secret = $params->{secret}; - my $secret32 = $params->{secret32}; + Koha::Exceptions::MissingParameter->throw("Mandatory patron parameter missing") + unless $patron && ref($patron) eq 'Koha::Patron'; + my $secret = $params->{secret} || $patron->secret; + Koha::Exceptions::MissingParameter->throw("No secret passed or patron has no secret") + unless $secret; - if (!$secret && !$secret32){ - $secret32 = $patron->secret; - } + my $secret_type = $secret =~ /[^a-z2-7]/ ? 'secret' : 'secret32'; my $issuer = $patron->library->branchname; my $key_id = sprintf "%s_%s", $issuer, ( $patron->email || $patron->userid ); - return $class->SUPER::new( - { - ( $secret ? ( secret => $secret ) : () ), - ( $secret32 ? ( secret32 => $secret32 ) : () ), - issuer => $issuer, - key_id => $key_id, - } - ); + return $class->SUPER::new({ + $secret_type => $secret, + issuer => $issuer, + key_id => $key_id, + }); } 1; -- 2.20.1