]> git.koha-community.org Git - koha.git/blob - Koha/Auth/TwoFactorAuth.pm
Bug 28786: DBIC schema changes
[koha.git] / Koha / Auth / TwoFactorAuth.pm
1 package Koha::Auth::TwoFactorAuth;
2
3 # This file is part of Koha.
4 #
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.
9 #
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.
14 #
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>.
17
18 use Modern::Perl;
19 use Auth::GoogleAuth;
20
21 use base qw( Auth::GoogleAuth );
22
23 =head1 NAME
24
25 Koha::Auth::TwoFactorAuth- Koha class deal with Two factor authentication
26
27 =head1 SYNOPSIS
28
29 use Koha::Auth::TwoFactorAuth;
30
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 );
34
35 It's based on Auth::GoogleAuth
36
37 =head2 METHODS
38
39 =head3 new
40
41     $obj = Koha::Auth::TwoFactorAuth->new({ patron => $p, secret => $s });
42
43 =cut
44
45 sub new {
46     my ($class, $params) = @_;
47     my $patron   = $params->{patron};
48     my $secret   = $params->{secret};
49     my $secret32 = $params->{secret32};
50
51     if (!$secret && !$secret32){
52         $secret32 = $patron->secret;
53     }
54
55     my $issuer = $patron->library->branchname;
56     my $key_id = sprintf "%s_%s",
57       $issuer, ( $patron->email || $patron->userid );
58
59     return $class->SUPER::new(
60         {
61             ( $secret   ? ( secret   => $secret )   : () ),
62             ( $secret32 ? ( secret32 => $secret32 ) : () ),
63             issuer => $issuer,
64             key_id => $key_id,
65         }
66     );
67 }
68
69 1;