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

(-)a/Koha/Auth/TwoFactorAuth.pm (+26 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 Imager::QRCode;
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_dataurl
72
73
=cut
74
75
sub qr_dataurl {
76
    my ( $self ) = @_;
77
78
    my $otpauth = $self->qr_code( undef, undef, undef, 1);
79
        # no need to pass secret, key and issuer again
80
    my $qrcode = Imager::QRCode->new({
81
        size          => 8, # 200 x 200
82
        margin        => 2,
83
        version       => 1,
84
        level         => 'M',
85
        casesensitive => 1,
86
        lightcolor    => Imager::Color->new(255, 255, 255),
87
        darkcolor     => Imager::Color->new(0, 0, 0),
88
    });
89
    my $img = $qrcode->plot( $otpauth );
90
    my $data;
91
    $img->write( data => \$data, type => 'png' );
92
    return "data:image/png;base64,". encode_base64( $data, q{} ); # does not contain newlines
93
}
94
69
1;
95
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_dataurl | $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_dataurl  => $auth->qr_dataurl,
95
        secret32    => $auth->secret32,
93
        secret32    => $auth->secret32,
96
        qr_code_url => $qr_code_url,
94
            # IMPORTANT: get secret32 after qr_dataurl call !
97
    );
95
    );
98
    $auth->clear;
96
    $auth->clear;
99
    $op = 'register';
97
    $op = 'register';
100
- 

Return to bug 29873