Keycloak Authentication Provider implementation that sends a one-time code (OTP) via email using the SMTP server configured in the Keycloak realm.
- Go to https://github.com/netzbegruenung/keycloak-mfa-plugins/releases and download the latest
netzbegruenung.email-authenticator-*.jar. - Copy the jar into the
providersdirectory of your Keycloak:cp netzbegruenung.email-authenticator-*.jar /path/to/keycloak/providers - Run the
buildcommand and restart Keycloak:/path/to/keycloak/bin/kc.sh build [your-additional-flags] systemctl restart keycloak.service
- Log in to the Keycloak Admin Console and select your realm.
- Make sure the realm's Email settings point to a working SMTP server.
- Go to Authentication in the left sidebar and select the flow you want to use (e.g.,
browser). - Since built-in flows are read-only, duplicate the flow if you haven't already: click the three dots in the top right of the flow details and select Duplicate.
- In your new flow, click Add step.
- Search for
Email Authentication (2FA)and click Add. - Set the requirement to
Alternative(orRequiredto enforce it). - Click the Actions menu (three dots) next to the
Email Authentication (2FA)step and select Config. The following options are available:
| Parameter | Description | Default |
|---|---|---|
| Code length | Number of digits of the generated OTP. | 6 |
| Time-to-live | Validity period of the OTP in seconds. | 300 |
| Force 2FA | If no other 2FA method is configured, the user is forced to verify their email and use Email OTP. | false |
The email subject and body are taken from the theme message bundle (keys emailAuthSubject and emailAuthText) and can be customised per realm/theme. The body supports %1$s (code) and %2$d (validity in minutes) placeholders.
After the authenticator is wired into the flow, users with a verified email address automatically receive a login code on the second-factor step.
If the option Force 2FA is enabled and a user has no other 2FA method set up, Keycloak will add the built-in VERIFY_EMAIL required action so the user verifies their address before continuing.
Apache License 2.0