Merge branch 'issue-2690-2FA-logo-label' into 'v2.0'

Fix for #2690

See merge request lemonldap-ng/lemonldap-ng!275
This commit is contained in:
Clément OUDOT 2022-07-07 12:16:13 +00:00
commit 4601879832
10 changed files with 89 additions and 29 deletions

View File

@ -72,6 +72,35 @@ The :doc:`mail <mail2f>`, :doc:`external <external2f>` and :doc:`REST <rest2f>`
If you are using the default templates from the ``bootstrap`` theme, you don't need to change anything.
Customizing the 2FA logo in the registration screen
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The 2FA registration screen now displays the custom logo and label set in configuration. If you use custom templates, you should update ``2fregisters.tpl``
.. code:: diff
@@ -77,10 +77,16 @@
<div class="card border-secondary">
<div class="card-body py-3">
<a href="<TMPL_VAR NAME="URL">" class="nodecor">
- <img src="<TMPL_VAR NAME="STATIC_PREFIX"><TMPL_VAR NAME="SKIN">/<TMPL_VAR NAME="LOGO">" alt="<TMPL_VAR NAME="CODE">2F" title="<TMPL_VAR NAME="CODE">2F" />
+ <img src="<TMPL_VAR NAME="STATIC_PREFIX"><TMPL_VAR NAME="SKIN">/<TMPL_VAR NAME="LOGO">" alt="<TMPL_VAR NAME="CODE">2f" title="<TMPL_VAR NAME="LABEL">" />
</a>
</div>
- <div class="card-footer text-white text-uppercase bg-secondary"><TMPL_VAR NAME="CODE">2F</div>
+ <div class="card-footer text-white text-uppercase bg-secondary">
+ <TMPL_IF LABEL>
+ <p><TMPL_VAR NAME="LABEL"></p>
+ <TMPL_ELSE>
+ <p trspan="<TMPL_VAR NAME="CODE">2f"></p>
+ </TMPL_IF>
+ </div>
</div>
</div>
</TMPL_LOOP>
If you are using the default templates from the ``bootstrap`` theme, you don't need to change anything.
2.0.14
------

View File

@ -9,6 +9,7 @@ lib/Lemonldap/NG/Portal/2F/Engines/Default.pm
lib/Lemonldap/NG/Portal/2F/Ext2F.pm
lib/Lemonldap/NG/Portal/2F/Mail2F.pm
lib/Lemonldap/NG/Portal/2F/Radius.pm
lib/Lemonldap/NG/Portal/2F/Register/Base.pm
lib/Lemonldap/NG/Portal/2F/Register/TOTP.pm
lib/Lemonldap/NG/Portal/2F/Register/U2F.pm
lib/Lemonldap/NG/Portal/2F/Register/WebAuthn.pm
@ -792,6 +793,7 @@ t/71-2F-U2F-with-History.t
t/71-2F-U2F-with-TTL-and-msg.t
t/71-2F-U2F-with-TTL.t
t/71-2F-U2F.t
t/72-2F-REST-CodeActivation-Resend.t
t/72-2F-REST-with-History.t
t/73-2F-UTOTP-TOTP-and-U2F-with-History.t
t/73-2F-UTOTP-TOTP-and-U2F.t
@ -801,6 +803,7 @@ t/74-2F-Required-Issuer-Timeouts.t
t/74-2F-Required.t
t/75-2F-Registers.t
t/76-2F-Ext-with-BruteForce.t
t/76-2F-Ext-with-CodeActivation-Resend.t
t/76-2F-Ext-with-CodeActivation.t
t/76-2F-Ext-with-GrantSession.t
t/76-2F-Ext-with-History.t

View File

@ -497,7 +497,6 @@ sub _displayRegister {
);
}
# If only one 2F is available, redirect to it
my @am;
foreach my $m ( @{ $self->sfRModules } ) {
$self->logger->debug(
@ -505,9 +504,10 @@ sub _displayRegister {
if ( $m->{r}->( $req, $req->userData ) ) {
push @am,
{
CODE => $m->{m}->prefix,
URL => '/2fregisters/' . $m->{m}->prefix,
LOGO => $m->{m}->logo,
CODE => $m->{m}->prefix,
URL => '/2fregisters/' . $m->{m}->prefix,
LOGO => $m->{m}->logo,
LABEL => $m->{m}->label
};
}
}
@ -529,6 +529,7 @@ sub _displayRegister {
$self->userLogger->warn("Do not display 2F devices!");
}
# If only one 2F is available, redirect to it
return [ 302, [ Location => $self->conf->{portal} . $am[0]->{URL} ], [] ]
if (
@am == 1

View File

@ -0,0 +1,28 @@
# Base package for 2F Register modules
package Lemonldap::NG::Portal::2F::Register::Base;
use strict;
use Mouse;
our $VERSION = '2.0.15';
extends 'Lemonldap::NG::Portal::Main::Plugin';
has logo => ( is => 'rw', default => '2f.png' );
has label => ( is => 'rw' );
sub init {
my ($self) = @_;
# Set logo if overridden
$self->logo( $self->conf->{ $self->prefix . "2fLogo" } )
if ( $self->conf->{ $self->prefix . "2fLogo" } );
# Set label if provided, translation files will be used otherwise
$self->label( $self->conf->{ $self->prefix . "2fLabel" } )
if ( $self->conf->{ $self->prefix . "2fLabel" } );
return 1;
}
1;

View File

@ -5,10 +5,10 @@ use strict;
use Mouse;
use JSON qw(from_json to_json);
our $VERSION = '2.0.14';
our $VERSION = '2.0.15';
extends qw(
Lemonldap::NG::Portal::Main::Plugin
Lemonldap::NG::Portal::2F::Register::Base
Lemonldap::NG::Common::TOTP
);
@ -31,10 +31,6 @@ has ott => (
}
);
sub init {
return 1;
}
sub run {
my ( $self, $req, $action ) = @_;
my $user = $req->userData->{ $self->conf->{whatToTrace} };

View File

@ -6,10 +6,10 @@ use Mouse;
use JSON qw(from_json to_json);
use MIME::Base64 qw(encode_base64url decode_base64url);
our $VERSION = '2.0.12';
our $VERSION = '2.0.15';
extends qw(
Lemonldap::NG::Portal::Main::Plugin
Lemonldap::NG::Portal::2F::Register::Base
Lemonldap::NG::Portal::Lib::U2F
);
@ -22,8 +22,8 @@ has logo => ( is => 'rw', default => 'u2f.png' );
sub init {
my ($self) = @_;
return 0 unless $self->SUPER::init;
return 1;
return 0 unless ( $self->Lemonldap::NG::Portal::Lib::U2F::init() );
return ( $self->Lemonldap::NG::Portal::2F::Register::Base::init() );
}
# RUNNING METHODS

View File

@ -9,7 +9,7 @@ use Crypt::URandom;
our $VERSION = '2.0.12';
extends 'Lemonldap::NG::Portal::Main::Plugin';
extends 'Lemonldap::NG::Portal::2F::Register::Base';
with 'Lemonldap::NG::Portal::Lib::WebAuthn';
# INITIALIZATION
@ -52,8 +52,6 @@ has rpName => (
}
);
sub init { return 1; }
# RUNNING METHODS
# Return a Base64url encoded user handle

View File

@ -9,9 +9,9 @@ use Lemonldap::NG::Portal::Main::Constants qw(
PE_ERROR
);
our $VERSION = '2.0.10';
our $VERSION = '2.0.15';
extends 'Lemonldap::NG::Portal::Main::Plugin';
extends 'Lemonldap::NG::Portal::2F::Register::Base';
# INITIALIZATION
@ -20,11 +20,6 @@ has template => ( is => 'ro', default => 'yubikey2fregister' );
has welcome => ( is => 'ro', default => 'clickOnYubikey' );
has logo => ( is => 'rw', default => 'yubikey.png' );
sub init {
my ($self) = @_;
return 1;
}
# RUNNING METHODS
# Main method

View File

@ -77,10 +77,16 @@
<div class="card border-secondary">
<div class="card-body py-3">
<a href="<TMPL_VAR NAME="URL">" class="nodecor">
<img src="<TMPL_VAR NAME="STATIC_PREFIX"><TMPL_VAR NAME="SKIN">/<TMPL_VAR NAME="LOGO">" alt="<TMPL_VAR NAME="CODE">2F" title="<TMPL_VAR NAME="CODE">2F" />
<img src="<TMPL_VAR NAME="STATIC_PREFIX"><TMPL_VAR NAME="SKIN">/<TMPL_VAR NAME="LOGO">" alt="<TMPL_VAR NAME="CODE">2f" title="<TMPL_VAR NAME="LABEL">" />
</a>
</div>
<div class="card-footer text-white text-uppercase bg-secondary"><TMPL_VAR NAME="CODE">2F</div>
<div class="card-footer text-white text-uppercase bg-secondary">
<TMPL_IF LABEL>
<p><TMPL_VAR NAME="LABEL"></p>
<TMPL_ELSE>
<p trspan="<TMPL_VAR NAME="CODE">2f"></p>
</TMPL_IF>
</div>
</div>
</div>
</TMPL_LOOP>

View File

@ -5,7 +5,7 @@ use Data::Dumper;
use MIME::Base64;
require 't/test-lib.pm';
my $maintests = 77;
my $maintests = 78;
SKIP: {
eval { require Convert::Base32 };
@ -26,6 +26,8 @@ SKIP: {
totp2fSelfRegistration => 1,
totp2fActivation => 1,
totp2fAuthnLevel => 1,
totp2fLogo => 'mytotp.png',
totp2fLabel => 'My TOTP',
u2fSelfRegistration => 1,
u2fActivation => 1,
u2fAuthnLevel => 5,
@ -165,8 +167,10 @@ SKIP: {
);
ok( $res->[2]->[0] =~ /2fregistration\.(?:min\.)?js/,
'Found 2f registration js' );
ok( $res->[2]->[0] =~ qr%<img src="/static/bootstrap/totp.png".*?/>%,
'Found totp.png' )
ok( $res->[2]->[0] =~ qr%<img src="/static/bootstrap/mytotp.png".*?/>%,
'Found custom totp logo' )
or print STDERR Dumper( $res->[2]->[0] );
ok( $res->[2]->[0] =~ qr%<p>My TOTP</p>%, 'Found custom totp label' )
or print STDERR Dumper( $res->[2]->[0] );
ok( $res->[2]->[0] =~ qr%<img src="/static/bootstrap/u2f.png".*?/>%,
'Found u2f.png' )