Manage Users, Login screen, Password policy and Two factor authentication in keycloak

keycloak_password_otp

Manage Users, Login screen, Password policy and Two factor authentication in keycloak

Table of Contents

Skills required


  • In this post we will learn how to setup Password policy and Two factor authentication in keycloak
  • By default two factor authentication is disabled and no password policy is configured in keycloak
  • Configuring a better password policy and two factor authentication helps in drastically improving the security of the user login process

Creating and managing users in keycloak

  • Users can be managed from the “Users” tab of a keycloak realm as shown below
    users_tab_in_keycloak
  • Password can be set in the “Credentials” tab of the user
    users_password_keycloak.png

User Login screen settings

  • Forgot password, Remember me, Email verification, User registration can be enabled or disabled in the Reals Settings menu, Login tab as shown below.

keycloak_login_screen_settings.png

keycloak_email_settings.png

Set Password Policy

  • Password policy of a keycloak realm can be easily configured in the Authentication menu, Policies tab as shown below
    password_policy_keycloak_setting.png
  • A variety of useful settings like password expiry days, recent passwords usage, password blacklist, minimum and maximum password length, minimum number of uppercase, lowercase and special characters can be specified easily in the password policy page
  • Password blacklist file should be kept in the data\password-blacklists\ folder of the keycloak folder. Also the password blacklist text file should have Unix style line endings (This needs to checked in windows)

Enable and configure Two factor Authentication in Keycloak

  • By default two factor authentication is disabled in a Keycloak realm
  • Two factor authentication can be enabled in the Authentication menu, Flows tab, browser flow as shown below

keycloak_otp_enable.png

  • Two factor authentication policy can be configured from Authentication menu, Policies tab, OTP Policy tab as shown below

keycloak_otp_policy.png

Using Two factor authentication by the users

  • For Two factor authentication, users can use any one of the FreeOTP, Google Authenticator, Microsoft Authenticator apps. In this demo, we are using Microsoft Authenticator app.
  • Since our realm name is ‘myorg’, go to the URL http://localhost:8080/realms/myorg/account for login screen.
  • After logging in for the first time with password, user will be shown a QR code to configure the Authenticator app as shown below

keycloak_otp_qr_code_setup.png

  • The one time code can be entered using the authenticator app by adding a new account in the Authenticator app as shown below

keycloak_microsoft_authenticator_steps.png

  • After completing the Two factor authentication setup with an Authenticator app, the user will be asked for an OTP to login as shown below

keycloak_login_otp.png

Video

You can see the video for this post here

References

Comments