Skip to content

Commit

Permalink
add .editorconfig and format files
Browse files Browse the repository at this point in the history
  • Loading branch information
LouisSchmieder committed Mar 5, 2024
1 parent b868393 commit 1ec3e44
Show file tree
Hide file tree
Showing 8 changed files with 141 additions and 117 deletions.
16 changes: 16 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true

[{*.java,*.xml}]
indent_size = 4
indent_style = tab
max_line_length = 120
tab_width = 4

[*.yml]
indent_size = 2
indent_style = space
4 changes: 2 additions & 2 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Maven CI

on:
push:
branches: [main]
branches: [ main ]
pull_request:
branches: [main]
branches: [ main ]

jobs:
build:
Expand Down
84 changes: 42 additions & 42 deletions .run/Build keycloak 2fa email.run.xml
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Build keycloak 2fa email" type="MavenRunConfiguration" factoryName="Maven">
<MavenSettings>
<option name="myGeneralSettings" />
<option name="myRunnerSettings" />
<option name="myRunnerParameters">
<MavenRunnerParameters>
<option name="cmdOptions" />
<option name="profiles">
<set />
</option>
<option name="goals">
<list>
<option value="clean" />
<option value="package" />
</list>
</option>
<option name="multimoduleDir" />
<option name="pomFileName" value="pom.xml" />
<option name="profilesMap">
<map />
</option>
<option name="projectsCmdOptionValues">
<list />
</option>
<option name="resolveToWorkspace" value="false" />
<option name="workingDirPath" value="$PROJECT_DIR$" />
</MavenRunnerParameters>
</option>
</MavenSettings>
<extension name="net.ashald.envfile">
<option name="IS_ENABLED" value="false" />
<option name="IS_SUBST" value="false" />
<option name="IS_PATH_MACRO_SUPPORTED" value="false" />
<option name="IS_IGNORE_MISSING_FILES" value="false" />
<option name="IS_ENABLE_EXPERIMENTAL_INTEGRATIONS" value="false" />
<ENTRIES>
<ENTRY IS_ENABLED="true" PARSER="runconfig" IS_EXECUTABLE="false" />
</ENTRIES>
</extension>
<method v="2" />
</configuration>
</component>
<configuration default="false" name="Build keycloak 2fa email" type="MavenRunConfiguration" factoryName="Maven">
<MavenSettings>
<option name="myGeneralSettings"/>
<option name="myRunnerSettings"/>
<option name="myRunnerParameters">
<MavenRunnerParameters>
<option name="cmdOptions"/>
<option name="profiles">
<set/>
</option>
<option name="goals">
<list>
<option value="clean"/>
<option value="package"/>
</list>
</option>
<option name="multimoduleDir"/>
<option name="pomFileName" value="pom.xml"/>
<option name="profilesMap">
<map/>
</option>
<option name="projectsCmdOptionValues">
<list/>
</option>
<option name="resolveToWorkspace" value="false"/>
<option name="workingDirPath" value="$PROJECT_DIR$"/>
</MavenRunnerParameters>
</option>
</MavenSettings>
<extension name="net.ashald.envfile">
<option name="IS_ENABLED" value="false"/>
<option name="IS_SUBST" value="false"/>
<option name="IS_PATH_MACRO_SUPPORTED" value="false"/>
<option name="IS_IGNORE_MISSING_FILES" value="false"/>
<option name="IS_ENABLE_EXPERIMENTAL_INTEGRATIONS" value="false"/>
<ENTRIES>
<ENTRY IS_ENABLED="true" PARSER="runconfig" IS_EXECUTABLE="false"/>
</ENTRIES>
</extension>
<method v="2"/>
</configuration>
</component>
26 changes: 14 additions & 12 deletions .run/Deploy local keycloak.run.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Deploy local keycloak" type="docker-deploy" factoryName="docker-compose.yml" server-name="Docker">
<deployment type="docker-compose.yml">
<settings>
<option name="envFilePath" value="" />
<option name="sourceFilePath" value="docker-compose.yml" />
</settings>
</deployment>
<method v="2">
<option name="RunConfigurationTask" enabled="true" run_configuration_name="Build keycloak 2fa email" run_configuration_type="MavenRunConfiguration" />
</method>
</configuration>
</component>
<configuration default="false" name="Deploy local keycloak" type="docker-deploy" factoryName="docker-compose.yml"
server-name="Docker">
<deployment type="docker-compose.yml">
<settings>
<option name="envFilePath" value=""/>
<option name="sourceFilePath" value="docker-compose.yml"/>
</settings>
</deployment>
<method v="2">
<option name="RunConfigurationTask" enabled="true" run_configuration_name="Build keycloak 2fa email"
run_configuration_type="MavenRunConfiguration"/>
</method>
</configuration>
</component>
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ Copy the generated `.jar` file from the `target/` directory, into the `keycloak/
## Setup

### SMTP Server

Connect Keycloak to an SMTP server in your realm's email settings.
See the [official Keycloak documentation](https://www.keycloak.org/docs/latest/server_admin/index.html#_email) for more
details on how to do so.

### Authentication Flows

The SPI adds aa new authentication provider that can be used in browser-based Auth-flows.
First make a copy of the built-in browser flow.
Add the step `Email Verification Code` to the flow and set it to be conditional.
Expand All @@ -40,6 +42,7 @@ There are three settings for the `Email Verification Code` step:
| Time-to-live | Time to live of the code to be valid in seconds | `300` |

### User requirements

A user hat to meet the following requirements to use the email 2FA provider:

- User needs an email address in their profile
Expand All @@ -52,6 +55,7 @@ The `Email Verification Code` can be added to a conditional flow, so that is onl
We are happy to receive pull request and issues.

### Development

First clone the repository and build the project:

```shell
Expand All @@ -69,4 +73,4 @@ docker-compose up

After the first start you have to configure Keycloak to use `localhost:1025` as host and port for the SMTP server.
Then navigate your browser to `http://localhost:8025` to see all emails that have been sent by Keycloak.
To access the Keycloak admin console, use `http://localhost:8080` and log in with the credentials `admin` and `admin`.
To access the Keycloak admin console, use `http://localhost:8080` and log in with the credentials `admin` and `admin`.
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ services:
image: quay.io/keycloak/keycloak:23.0.0
ports:
- "8080:8080"
command: ['start-dev']
command: [ 'start-dev' ]
environment:
KEYCLOAK_ADMIN: admin
KEYCLOAK_ADMIN_PASSWORD: admin
Expand Down
116 changes: 58 additions & 58 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,60 +1,60 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.it-solutions</groupId>
<artifactId>keycloak-2fa-email</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>

<keycloak.version>23.0.0</keycloak.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-server-spi</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-server-spi-private</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-services</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.30</version>
<scope>provided</scope>
</dependency>
</dependencies>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-parent</artifactId>
<version>${keycloak.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<build>
<finalName>keycloak-2fa-email</finalName>
</build>

</project>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.it-solutions</groupId>
<artifactId>keycloak-2fa-email</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>

<keycloak.version>23.0.0</keycloak.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-server-spi</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-server-spi-private</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-services</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.30</version>
<scope>provided</scope>
</dependency>
</dependencies>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-parent</artifactId>
<version>${keycloak.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<build>
<finalName>keycloak-2fa-email</finalName>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
* Copyright
*/

package com.mt_itsolutions.keycloak.email2fa;

import org.keycloak.models.AuthenticatorConfigModel;
Expand All @@ -16,7 +17,8 @@ public record AuthCodeConfig(int length, int ttl, String base) {
public static AuthCodeConfig readFromConfig(AuthenticatorConfigModel configModel) {
var config = configModel.getConfig();

int length = Integer.parseInt(config.getOrDefault(AuthFactory.AUTH_CODE_LENGTH, AuthFactory.AUTH_CODE_LENGTH_DEFAULT));
int length =
Integer.parseInt(config.getOrDefault(AuthFactory.AUTH_CODE_LENGTH, AuthFactory.AUTH_CODE_LENGTH_DEFAULT));
String base = config.getOrDefault(AuthFactory.AUTH_CODE_CHARACTERS, AuthFactory.AUTH_CODE_CHARACTERS_DEFAULT);
int ttl = Integer.parseInt(config.getOrDefault(AuthFactory.AUTH_CODE_TTL, AuthFactory.AUTH_CODE_TTL_DEFAULT));

Expand Down

0 comments on commit 1ec3e44

Please sign in to comment.