diff --git a/Koha/Auth/TwoFactorAuth.pm b/Koha/Auth/TwoFactorAuth.pm index 81ddf06a3d..e2cff4487f 100644 --- a/Koha/Auth/TwoFactorAuth.pm +++ b/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; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/two_factor_auth.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/two_factor_auth.tt index cddac9f1b4..feb86b9586 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/two_factor_auth.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/two_factor_auth.tt @@ -55,7 +55,7 @@