View | Details | Raw Unified | Return to bug 29873
Collapse All | Expand All

(-)a/Koha/Auth/TwoFactorAuth.pm (+22 lines)
Lines 17-22 package Koha::Auth::TwoFactorAuth; Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
use Auth::GoogleAuth;
19
use Auth::GoogleAuth;
20
use GD::Barcode;
21
use MIME::Base64 qw( encode_base64 );
20
22
21
use base qw( Auth::GoogleAuth );
23
use base qw( Auth::GoogleAuth );
22
24
Lines 66-69 sub new { Link Here
66
    );
68
    );
67
}
69
}
68
70
71
=head3 qr_code
72
73
    my $image_src = $auth->qr_code;
74
75
    Replacement for (unsafer) Auth::GoogleAuth::qr_code.
76
    Returns the data URL to fill the src attribute of the
77
    image tag on the registration form.
78
79
=cut
80
81
sub qr_code {
82
    my ( $self ) = @_;
83
84
    my $otpauth = $self->SUPER::qr_code( undef, undef, undef, 1);
85
        # no need to pass secret, key and issuer again
86
    my $qrcode = GD::Barcode->new( 'QRcode', $otpauth, { Ecc => 'M', Version => 8, ModuleSize => 4 } );
87
    my $data = $qrcode->plot->png;
88
    return "data:image/png;base64,". encode_base64( $data, q{} ); # does not contain newlines
89
}
90
69
1;
91
1;
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/two_factor_auth.tt (-1 / +1 lines)
Lines 55-61 Link Here
55
                            <ol>
55
                            <ol>
56
                                <li>
56
                                <li>
57
                                    <label for="qr_code">QR code: </label>
57
                                    <label for="qr_code">QR code: </label>
58
                                    <img id="qr_code" src="[% qr_code_url | $raw %]" />
58
                                    <img id="qr_code" src="[% qr_code | $raw %]" />
59
                                </li>
59
                                </li>
60
                                <li>
60
                                <li>
61
                                    <label for="pin_code">Pin code: </label>
61
                                    <label for="pin_code">Pin code: </label>
(-)a/members/two_factor_auth.pl (-5 / +2 lines)
Lines 86-99 if ( $op eq 'enable-2FA' ) { Link Here
86
    my $auth = Koha::Auth::TwoFactorAuth->new(
86
    my $auth = Koha::Auth::TwoFactorAuth->new(
87
        { patron => $logged_in_user, secret => $secret } );
87
        { patron => $logged_in_user, secret => $secret } );
88
88
89
    my $qr_code_url =
90
      $auth->qr_code( undef, $auth->key_id, $auth->issuer ); # no need to pass secret32
91
92
    $template->param(
89
    $template->param(
93
        issuer      => $auth->issuer,
90
        issuer      => $auth->issuer,
94
        key_id      => $auth->key_id,
91
        key_id      => $auth->key_id,
92
        qr_code  => $auth->qr_code,
95
        secret32    => $auth->secret32,
93
        secret32    => $auth->secret32,
96
        qr_code_url => $qr_code_url,
94
            # IMPORTANT: get secret32 after qr_code call !
97
    );
95
    );
98
    $auth->clear;
96
    $auth->clear;
99
    $op = 'register';
97
    $op = 'register';
100
- 

Return to bug 29873