# How to Fire a Script On User Login

**URL:** <https://forum.keycloak.org/t/how-to-fire-a-script-on-user-login/30049>\
**Category:** Getting advice\
**Created:** [May 30, 2025, 3:28pm UTC](https://forum.keycloak.org/t/how-to-fire-a-script-on-user-login/30049 "2025-05-30T15:28:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![red-drover](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/red-drover/32/11606_2.png) [@red-drover](https://forum.keycloak.org/u/red-drover)\
**Post date:** [May 30, 2025, 3:28pm UTC](https://forum.keycloak.org/t/how-to-fire-a-script-on-user-login/30049/1 "2025-05-30T15:28:35Z")

</div>

I want Keycloak to fire a script - say startup a docker container - when a user logs in. What is the easiest way to achieve this?

---

<div class="post-metadata">

**Author:** ![dasniko](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/dasniko/32/2969_2.png) [@dasniko](https://forum.keycloak.org/u/dasniko)\
**Post date:** [May 30, 2025, 8:15pm UTC](https://forum.keycloak.org/t/how-to-fire-a-script-on-user-login/30049/2 "2025-05-30T20:15:43Z")

</div>

You can implement an [event listener](https://www.keycloak.org/docs/latest/server_development/index.html#_events), listening to the `LOGIN` event which does anything, e.g. sending a message to another system, where the container can be started…

---

<div class="post-metadata">

**Author:** ![red-drover](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/red-drover/32/11606_2.png) [@red-drover](https://forum.keycloak.org/u/red-drover)\
**Post date:** [June 2, 2025, 5:31pm UTC](https://forum.keycloak.org/t/how-to-fire-a-script-on-user-login/30049/3 "2025-06-02T17:31:05Z")

</div>

It seems like the only way to do that is custom Java code then?

---

<div class="post-metadata">

**Author:** ![xgp](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/xgp/32/2589_2.png) [@xgp](https://forum.keycloak.org/u/xgp)\
**Post date:** [June 4, 2025, 11:17am UTC](https://forum.keycloak.org/t/how-to-fire-a-script-on-user-login/30049/4 "2025-06-04T11:17:13Z")

</div>

> [@red-drover](#):
>
> It seems like the only way to do that is custom Java code then?

Using what is built in to Keycloak, yes.

There is an extension we built that allows loading of JS scripts at runtime that can be run as event listener [GitHub - p2-inc/keycloak-events: Useful Keycloak event listener implementations and utilities.](https://github.com/p2-inc/keycloak-events?tab=readme-ov-file#script)
