This project provides a Keycloak Event Listener SPI that updates a user's attributes with their last login time whenever they successfully log in.
-
On user login, sets the following attributes:
- last-login: ISO-8601 UTC timestamp of the login
- last-login-timestamp: raw epoch milliseconds of the login
- Java 17
- Maven
- Keycloak 21 or newer
-
Build the project:
mvn clean package
-
Deploy the JAR: Copy target/keycloak-last-login-spi.jar to your Keycloak server:
- For standalone deployments: place in standalone/deployments/
- For Quarkus-based Keycloak: place in providers/
- Register the provider: Ensure your JAR includes a file at
META-INF/services/org.keycloak.events.EventListenerProviderFactorywith the fully qualified factory class name.
- Login to Keycloak Admin Console.
- Go to Realm Settings > Events > Config.
- In the Event Listeners section, add pagewiser_last_login_attribute (the provider ID) to the list.
- Save changes.
To enable event logging for user actions:
- In the Admin Console, go to Realm Settings > Events > Config.
- Under Save Events, enable User Events and select event types (e.g., LOGIN).
- Optionally, configure Admin Events and set retention policies.
- Save changes.
Run unit tests with:
mvn testMIT