Auth-GoogleAuthenticator
view release on metacpan or search on metacpan
lib/Auth/GoogleAuthenticator.pm view on Meta::CPAN
# if we have an OTP, dislay the QRCode to the user
require Imager::QRCode;
my $qrcode = Imager::QRCode->new(
size => 4,
margin => 4,
version => 1,
level => 'M',
casesensitive => 1,
);
my $img = $qrcode->plot($self->registration_url($label, $type));
$img->write( data => \my $res, type => 'png' );
$res
}
sub registration_key {
return encode_base32( $_[0]->{secret} );
}
sub totp {
my ($self, $ts) = @_;
$self->auth->totp( $self->{secret}, $ts )
lib/Dancer/Auth/GoogleAuthenticator.pm view on Meta::CPAN
# Display otp_secret if we have it
# XX Maybe this should be over SSL only
template 'setup_twofactor', {
auth => $auth,
user => $user,
otp_secret => $otp_secret
};
};
get '/auth/setup/qrcode.png' => sub {
my ($user) = session->{user};
my ($otp_secret) = $user->{otp_secret};
if( $otp_secret ) {
my $auth = get_otp_auth( $user );
if( $auth ) {
warning $auth->registration_url($user->{name});
my $qr = $auth->registration_qr_code( "$user->{name}" );
return send_file( \$qr, content_type => 'image/png' );
} else {
warning "No auth despite user?!";
};
} else {
warning "No OTP set up for '$user->{name}'";
};
};
get '/auth/login' => sub {
my $return = vars->{requested_path} || '';
views/setup_twofactor.tt view on Meta::CPAN
<div id="page">
<div id="content">
<div id="header">
<h1>Configure two-factor authentification</h1>
</div>
<% IF session.user.otp_secret %>
<h2>Automatic configuration</h2>
<div>Scan this QR code</div>
<img src="/auth/setup/qrcode.png" alt="Google Authenticator QR code for setting up two-factor configuration">
<h2>Manual configuration</h2>
<ol>
<li>User account: <% session.user.name %></li>
<li>User key: <% auth.registration_key %></li>
</ol>
<form name="regenerate" method="POST" action="" enctype="multipart/data">
<input type="hidden" name="action" value="regenerate" />
<input type="submit" value="Regenerate" />
</form>
<form name="deactivate" method="POST" action="" enctype="multipart/data">
( run in 0.666 second using v1.01-cache-2.11-cpan-788537b7465 )