Bug 30588: Add the option to require 2FA setup on first staff login
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Mon, 25 Jul 2022 14:53:02 +0000 (16:53 +0200)
committerTomas Cohen Arazi <tomascohen@theke.io>
Fri, 21 Oct 2022 14:36:57 +0000 (11:36 -0300)
commitb93e15c235c77ad557b73f49f93e29b0669ee82b
tree3fa44d973aa3115cf033b6f37af87c14171e792c
parent8511750de92e98b53e5bd9c0eaec045deba49016
Bug 30588: Add the option to require 2FA setup on first staff login

Bug 28786 added the ability to turn on a two-factor authentication,
using a One Time Password (OTP).
Once enabled on the system, librarian had the choice to enable or
disable it for themselves.
For security reason an administrator could decide to force the
librarians to use this second authentication step.

This patch adds a third option to the existing syspref, 'Enforced', for
that purpose.

QA notes: the code we had in the members/two_factor_auth.pl controller
has been moved to REST API controller methods (with their tests and
swagger specs), for reusability reason. Code from template has been
moved to an include file for the same reason.

Test plan:
A. Regression tests
As we modified the code we need first to confirm the existing features
are still working as expected.
1. Turn off TwoFactorAuthentication (disabled) and confirm that you are not able to
enable and access the second authentication step
2. Turn it on (enabled) and confirm that you are able to enable it in your account
3. Logout and confirm then that you are able to login into Koha

B. The new option
1. Set the pref to "enforced"
2. You are not logged out, logged in users stay logged in
3. Pick a user that does not have 2FA setup, login
4. Notice the new screen (UI is a bit ugly, suggestions welcomed)
5. Try to access Koha without enabling 2FA, you shouldn't be able to
access any pages
6. Setup 2FA and confirm that you are redirected to the login screen
7. Login, send the correct pin code
=> You are fully logged in!

Note that at 6 we could redirect to the mainpage, without the need to
login again, but I think it's preferable to reduce the change to
C4::Auth. If it's considered mandatory by QA I could have a look on
another bug report.

Sponsored-by: Rijksmuseum, Netherlands
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
C4/Auth.pm
Koha/Auth/TwoFactorAuth.pm
Koha/REST/V1/Auth.pm
Koha/REST/V1/TwoFactorAuth.pm
api/v1/swagger/paths/auth.yaml
api/v1/swagger/swagger.yaml
koha-tmpl/intranet-tmpl/prog/en/modules/auth.tt
koha-tmpl/intranet-tmpl/prog/en/modules/members/two_factor_auth.tt
members/two_factor_auth.pl