|
Lines 16-22
package Koha::Auth::TwoFactorAuth;
Link Here
|
| 16 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
16 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
| 17 |
|
17 |
|
| 18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
| 19 |
use Auth::GoogleAuth; |
19 |
#use Auth::GoogleAuth; |
|
|
20 |
use Koha::Exceptions; |
| 20 |
|
21 |
|
| 21 |
use base qw( Auth::GoogleAuth ); |
22 |
use base qw( Auth::GoogleAuth ); |
| 22 |
|
23 |
|
|
Lines 40-69
It's based on Auth::GoogleAuth
Link Here
|
| 40 |
|
41 |
|
| 41 |
$obj = Koha::Auth::TwoFactorAuth->new({ patron => $p, secret => $s }); |
42 |
$obj = Koha::Auth::TwoFactorAuth->new({ patron => $p, secret => $s }); |
| 42 |
|
43 |
|
|
|
44 |
The patron parameter is mandatory. If no secret is passed, the patron's |
| 45 |
secret will be used. |
| 46 |
|
| 43 |
=cut |
47 |
=cut |
| 44 |
|
48 |
|
| 45 |
sub new { |
49 |
sub new { |
| 46 |
my ($class, $params) = @_; |
50 |
my ($class, $params) = @_; |
| 47 |
my $patron = $params->{patron}; |
51 |
my $patron = $params->{patron}; |
| 48 |
my $secret = $params->{secret}; |
52 |
Koha::Exceptions::MissingParameter->throw("Mandatory patron parameter missing") |
| 49 |
my $secret32 = $params->{secret32}; |
53 |
unless $patron && ref($patron) eq 'Koha::Patron'; |
|
|
54 |
my $secret = $params->{secret} || $patron->secret; |
| 55 |
Koha::Exceptions::MissingParameter->throw("No secret passed or patron has no secret") |
| 56 |
unless $secret; |
| 50 |
|
57 |
|
| 51 |
if (!$secret && !$secret32){ |
58 |
my $secret_type = $secret =~ /[^a-z2-7]/ ? 'secret' : 'secret32'; |
| 52 |
$secret32 = $patron->secret; |
|
|
| 53 |
} |
| 54 |
|
59 |
|
| 55 |
my $issuer = $patron->library->branchname; |
60 |
my $issuer = $patron->library->branchname; |
| 56 |
my $key_id = sprintf "%s_%s", |
61 |
my $key_id = sprintf "%s_%s", |
| 57 |
$issuer, ( $patron->email || $patron->userid ); |
62 |
$issuer, ( $patron->email || $patron->userid ); |
| 58 |
|
63 |
|
| 59 |
return $class->SUPER::new( |
64 |
return $class->SUPER::new({ |
| 60 |
{ |
65 |
$secret_type => $secret, |
| 61 |
( $secret ? ( secret => $secret ) : () ), |
66 |
issuer => $issuer, |
| 62 |
( $secret32 ? ( secret32 => $secret32 ) : () ), |
67 |
key_id => $key_id, |
| 63 |
issuer => $issuer, |
68 |
}); |
| 64 |
key_id => $key_id, |
|
|
| 65 |
} |
| 66 |
); |
| 67 |
} |
69 |
} |
| 68 |
|
70 |
|
| 69 |
1; |
71 |
1; |
| 70 |
- |
|
|