==================================
Enabling two-factor authentication
==================================

Two-factor authentication (2FA) can be enabled in Keycloak using either Google Authenticator or the One-Time Password(OTP) tool FreeOTP.

For more background on OTPs, see `Keycloak's documentation on OTP <https://www.keycloak.org/docs/latest/server_admin/#one-time-password-otp-policies>`_.

For all new users
=================

#. :ref:`Log in to the Keycloak administrative console <access_kc>`.
#. Navigate to the dev realm. 
#. Select **Realm settings** from the left-hand navigation.
#. Select the **Themes** tab. 

   .. thumbnail:: ../../img/kc_realm_theme.png
       :align: center

#. Open the **Account theme** dropdown menu and select **keycloak** from the list. 
#. Click **Save**. 
#. Select **Authentication** from the left-hand navigation.
#. Select the **Required actions** tab.
#. Find **Configure OTP** in the **Required actions** column, and toggle **Set as default action** to ``ON``. 

   .. thumbnail:: ../../img/kc_configure_2fa.png       
      :align: center

For existing users
==================

.. note::

    This must be done for every user that does not have an OTP configured.

#. :ref:`Log in to the Keycloak administrative console <access_kc>`.
#. Navigate to the dev realm.
#. Select **Users** from the left-hand navigation.
#. Select a user from the list to view their profile page.
#. Open the **Required user actions** dropdown menu and select **Configure OTP**. 
#. Click **Save**. 
