Skip to content

Commit

Permalink
Merge pull request #17 from dpoerschke/main
Browse files Browse the repository at this point in the history
KeyCloak 22.0.1 support
  • Loading branch information
mesutpiskin authored Jul 26, 2023
2 parents b3ab772 + ddf8f13 commit 9e00c21
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 16 deletions.
40 changes: 28 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,54 @@
# 🔒 Keycloak 2FA Email Authenticator

Keycloak Authentication Provider implementation to get a two factor authentication with an OTP/code/token send via Email (through SMTP)
Keycloak Authentication Provider implementation to get a two factor authentication with an OTP (One-time-password) send via Email (through SMTP).

When logging in with this provider, you can send a verification code (otp) to the user's e-mail address.
Tested with Keycloak version 21.x, if you are using different Keycloak version, don't forget to change the version in pom.xml file.
When logging in with this provider, you can send a verification code (OTP) to the user's e-mail address.
Tested with Keycloak version 22.0.1. If you are using a different Keycloak version, don't forget to change the version in pom.xml file.

The [Server Development part of the Keycloak reference documentation](https://www.keycloak.org/docs/latest/server_development/index.html) contains additional resources and examples for developing custom Keycloak extensions.

# Development

If you are using Eclipse, you need to install the Lombok plugin, otherwise Eclipse cannot resolve `log` which is declared at runtim through @JBossLog annotation.
Find further information at https://projectlombok.org/setup/eclipse


# 🚀 Deployment

## Artifact

You can download the necessary artifacts for Keycloak 2FA Email Authenticator from the [release on GitHub.](https://github.com/mesutpiskin/keycloak-2fa-email-authenticator/releases/tag/v0.4) Please choose the appropriate version based on your Keycloak installation.

## Provider
## Providers

`mvn package` will be create a jar file.
copy _keycloak-2fa-email-authenticator.jar_ to _keycloak/providers/_ directory.
`mvn package` will create a jar file.
copy `keycloak-2fa-email-authenticator.jar` to `keycloak/providers/` directory.

if you are Dockerized keycloak then copy to _/opt/jboss/keycloak/standalone/deployments/_ directory.
If you are Dockerized keycloak then copy to `/opt/jboss/keycloak/standalone/deployments/` directory.

## Theme Resources

**html/code-email.ftl** is a html email template. Copy to _themes/base/email/html/_
- **html/code-email.ftl** is a html email template. Copy to `themes/base/email/html/`

- copy **text/code-email.ftl** to `themes/base/email/text/`

**text/code-email.ftl** Copy to _themes/base/email/text/_
- append **messages/*.properties** to `themes/base/email/messages/messages_en.properties`

**messages/*.properties** Append to _themes/base/email/messages/messages_en.properties_
## Build

Don't forget to start kc.sh with build parameter to make KeyCloak recognize the new povider:

> bin/kc.sh build
# Configuration

## Email Configuration
SMTP setting configure for e-mail send.
_Realm Settings/Email_

Don't forget to configure your realm's SMTP settings, otherwise no email will be send:
1. Login as admin on your KeyCloak installation.
2. Switch to your realm
3. Click `Realm settings` from the menu on the left.
4. Click on the `Email`-tab and enter your smpt data.

## Authentication Flow
Create new browser login authentication flow and add Email OTP flow before Username Password Form.
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>11</java.version>
<java.version>17</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<lombok.version>1.18.22</lombok.version>
<keycloak.version>20.0.2</keycloak.version>
<keycloak.version>22.0.1</keycloak.version>
<auto-service.version>1.0.1</auto-service.version>
</properties>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
import org.keycloak.models.utils.FormMessage;
import org.keycloak.services.messages.Messages;

import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response;
import jakarta.ws.rs.core.MultivaluedMap;
import jakarta.ws.rs.core.Response;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
com.mesutpiskin.keycloak.auth.email.EmailAuthenticatorFormFactory

0 comments on commit 9e00c21

Please sign in to comment.