# IDENTITY\_PROVIDER\_FIRST\_LOGIN event is never triggered / saved

**URL:** <https://forum.keycloak.org/t/identity-provider-first-login-event-is-never-triggered-saved/9442>\
**Category:** Extending the server\
**Tags:** identity-brokering, oidc\
**Created:** [June 6, 2021, 5:19pm UTC](https://forum.keycloak.org/t/identity-provider-first-login-event-is-never-triggered-saved/9442 "2021-06-06T17:19:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![zak](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/zak/32/315_2.png) [@zak](https://forum.keycloak.org/u/zak)\
**Post date:** [June 6, 2021, 5:19pm UTC](https://forum.keycloak.org/t/identity-provider-first-login-event-is-never-triggered-saved/9442/1 "2021-06-06T17:19:02Z")

</div>

Hello,

I would like to capture the [IDENTITY\_PROVIDER\_FIRST\_LOGIN](https://github.com/keycloak/keycloak/blob/master/server-spi-private/src/main/java/org/keycloak/events/EventType.java#L103) event when it happens. For this purpose, I created a custom [EventListenerProvider](https://github.com/keycloak/keycloak/blob/master/server-spi-private/src/main/java/org/keycloak/events/EventListenerProvider.java) (and registered the factory as well). The event provider for now does nothing but printing the events triggered:

```auto
public class CustomEventListenerProvider implements EventListenerProvider {
  public CustomEventListenerProvider() {}

  @Override
  public void onEvent(Event event) {
    System.out.println(" ********************************************************************");
    System.out.println(event.getType().toString());
  }

  @Override
  public void onEvent(AdminEvent adminEvent, boolean b) {}

  @Override
  public void close() {}
}

```

for demo purposes, I configued google as idp, and tried logging in. It seems like only the REGISTER, LOGIN, and CODE\_TO\_TOKEN are captured by the listener. According to the keycloak codebase, the IDENTITY\_PROVIDER\_FIRST\_LOGIN is triggered here: [https://github.com/keycloak/keycloak/blob/master/services/src/main/java/org/keycloak/services/resources/LoginActionsService.java#L760](https://github.com/keycloak/keycloak/blob/master/services/src/main/java/org/keycloak/services/resources/LoginActionsService.java#L760)

even if this piece of code is called ( I checked by attaching the bebugger), the event it is still not sent to the Listener. I tried also storing events, same thing. Only the REGISTER, LOGIN, and CODE\_TO\_TOKEN are stored in the database. Anybody has an idea what is going on ? is this a keycloak bug ?

Thanks.  
Zakaria

---

<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 7, 2021, 7:40am UTC](https://forum.keycloak.org/t/identity-provider-first-login-event-is-never-triggered-saved/9442/2 "2021-06-07T07:40:26Z")

</div>

Might be a bug. I just noticed that I don’t see any `IDENTITY_PROVIDER_FIRST_LOGIN` in my events, even though there should be several of them.

Couple of questions:

1. Do you have a custom auth flow for “First Broker Login” that might be causing this not to be called?
2. Do you have Login Events turned on for storage? Do you see `IDENTITY_PROVIDER_FIRST_LOGIN` in the Admin UI?

I’ll keep looking to see if I can reproduce…

---

<div class="post-metadata">

**Author:** ![zak](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/zak/32/315_2.png) [@zak](https://forum.keycloak.org/u/zak)\
**Post date:** [June 7, 2021, 9:13am UTC](https://forum.keycloak.org/t/identity-provider-first-login-event-is-never-triggered-saved/9442/3 "2021-06-07T09:13:25Z")

</div>

Thanks. I am using a slightly modified copy of the “First Broker Login”. After reading your message, I switched the flow to the original “First Broker Login”, but still the event is not captured.

and Yes storage is turned on.

Maybe the event is overridden by the LOGIN event. I am gonna try to get some confirmation in the Keycloak developer group

---

<div class="post-metadata">

**Author:** ![zak](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/zak/32/315_2.png) [@zak](https://forum.keycloak.org/u/zak)\
**Post date:** [March 4, 2023, 6:35pm UTC](https://forum.keycloak.org/t/identity-provider-first-login-event-is-never-triggered-saved/9442/4 "2023-03-04T18:35:23Z")

</div>

Hello everyone,

I just wanted to let you know that I discovered that this was a bug indeed. A PR was merged yesterday to fix this: [trigger IDENTITY\_PROVIDER\_FIRST\_LOGIN (and UPDATE\_PROFILE ) event when identity provider flow succeeds by zak905 · Pull Request #15100 · keycloak/keycloak · GitHub](https://github.com/keycloak/keycloak/pull/15100)

for those interested, IDENTITY\_PROVIDER\_FIRST\_LOGIN event will be triggered starting from the next Keycloak release, whenever you login with an IDP.

---

<div class="post-metadata">

**Author:** ![paulkilla](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/paulkilla/32/1045_2.png) [@paulkilla](https://forum.keycloak.org/u/paulkilla)\
**Post date:** [March 5, 2023, 9:42pm UTC](https://forum.keycloak.org/t/identity-provider-first-login-event-is-never-triggered-saved/9442/5 "2023-03-05T21:42:33Z")

</div>

I’m hoping this will fix my issue:

> [@Enabling user via IDP login](http://forum.keycloak.org/t/enabling-user-via-idp-login/19976):
>
> We have a requirement where we 100% trust a login from IDP, so if we have a disabled user in our keycloak, and they try to login from the IDP we want to enable the user as part of the process. I have written a custom provider that hooks into the First Login Flow from the IDP and before attempting to link the IDP to Keycloak account we enable the account, and this works perfectly. My issue arises when the user is already linked to an existing keycloak user, but they are now disabled after a per…
