1 package Koha::Auth::TwoFactorAuth;
3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
21 use base qw( Auth::GoogleAuth );
25 Koha::Auth::TwoFactorAuth- Koha class deal with Two factor authentication
29 use Koha::Auth::TwoFactorAuth;
31 my $secret = Koha::AuthUtils::generate_salt( 'weak', 16 );
32 my $auth = Koha::Auth::TwoFactorAuth->new({ patron => $patron, secret => $secret });
33 my $ok = $auth->verify( $pin_code, 1 );
35 It's based on Auth::GoogleAuth
41 $obj = Koha::Auth::TwoFactorAuth->new({ patron => $p, secret => $s });
46 my ($class, $params) = @_;
47 my $patron = $params->{patron};
48 my $secret = $params->{secret};
49 my $secret32 = $params->{secret32};
51 if (!$secret && !$secret32){
52 $secret32 = $patron->secret;
55 my $issuer = $patron->library->branchname;
56 my $key_id = sprintf "%s_%s",
57 $issuer, ( $patron->email || $patron->userid );
59 return $class->SUPER::new(
61 ( $secret ? ( secret => $secret ) : () ),
62 ( $secret32 ? ( secret32 => $secret32 ) : () ),