@@ -, +, @@ by logging in again. --- Koha/Auth/TwoFactorAuth.pm | 22 +++++++++++++++++++ .../en/modules/members/two_factor_auth.tt | 2 +- members/two_factor_auth.pl | 6 ++--- 3 files changed, 25 insertions(+), 5 deletions(-) --- a/Koha/Auth/TwoFactorAuth.pm +++ a/Koha/Auth/TwoFactorAuth.pm @@ -17,6 +17,8 @@ package Koha::Auth::TwoFactorAuth; use Modern::Perl; use Auth::GoogleAuth; +use GD::Barcode; +use MIME::Base64 qw( encode_base64 ); use base qw( Auth::GoogleAuth ); @@ -66,4 +68,24 @@ sub new { ); } +=head3 qr_code + + my $image_src = $auth->qr_code; + + Replacement for (unsafer) Auth::GoogleAuth::qr_code. + Returns the data URL to fill the src attribute of the + image tag on the registration form. + +=cut + +sub qr_code { + my ( $self ) = @_; + + my $otpauth = $self->SUPER::qr_code( undef, undef, undef, 1); + # no need to pass secret, key and issuer again + my $qrcode = GD::Barcode->new( 'QRcode', $otpauth, { Ecc => 'M', Version => 8, ModuleSize => 4 } ); + my $data = $qrcode->plot->png; + return "data:image/png;base64,". encode_base64( $data, q{} ); # does not contain newlines +} + 1; --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/two_factor_auth.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/members/two_factor_auth.tt @@ -55,7 +55,7 @@
  1. - +
  2. --- a/members/two_factor_auth.pl +++ a/members/two_factor_auth.pl @@ -86,14 +86,12 @@ if ( $op eq 'enable-2FA' ) { my $auth = Koha::Auth::TwoFactorAuth->new( { patron => $logged_in_user, secret => $secret } ); - my $qr_code_url = - $auth->qr_code( undef, $auth->key_id, $auth->issuer ); # no need to pass secret32 - $template->param( issuer => $auth->issuer, key_id => $auth->key_id, + qr_code => $auth->qr_code, secret32 => $auth->secret32, - qr_code_url => $qr_code_url, + # IMPORTANT: get secret32 after qr_code call ! ); $auth->clear; $op = 'register'; --