3

I'm trying to understand the functionalities of Keycloak and trying to find a way to monitor request flows (like in Wireshark) in a local environment (localhost). What tool could I use for this purpose in a Windows environment? I've got an Angular app that is integrated with Keycloak, and it works. When I request localhost:4200, the browser takes me to Keycloak login screen.

To view logs, I changed the log level in the Keycloak server at ..\keycloak-4.8.3.Final\standalone\configuration from INFO to ALL. It did expand the log entries that showed in the console but it didn't show any logs when my angular application redirects to Keycloak and when I enter user credentials in Keycloak login screen.

I would like to see the request flow from browser to Keycloak and all the auth requests and so on. Is there a tool that I could use for this purpose?

Darth Shirr
  • 527
  • 1
  • 7
  • 24
  • 1
    Keycloak works on top of WildFly Application Server. For req/res logging check this out https://stackoverflow.com/questions/26715552/dump-http-requests-in-wildfly-8 – Vadim Ashikhman May 21 '19 at 16:52

2 Answers2

4

Configure the events part of the server the way you prefer. They are stored in the DB.

Keycloak includes a suite of auditing capabilities. You can record every login and administrator action and review those actions in the Admin Console. Keycloak also includes a Listener SPI that listens for events and can trigger actions. Examples of built-in listeners include log files and sending emails if an event occurs.

Event config 1

Event config 2

Still I don't know if this covers the specific case of your application redirecting to the KC login screen. If not, you might need to log this in your application, but it might be a little bit tricky if you use the Angular adapter, as it gets executed in client side (you would need to do POST to some server that you own to get it logged, or directly switch to any server side based KC adapter).

Aritz
  • 30,971
  • 16
  • 136
  • 217
  • Can you tell me how can I see the database where these events are stored ? I can not find anything in the documentation. – Vijay Jul 10 '20 at 07:43
  • @Vijay https://www.keycloak.org/docs/latest/server_installation/#_database – Aritz Jul 10 '20 at 08:32
  • Thanks for the details. I could see it is using in-memory H2 database, but I can not locate how it is managing the event store. Can you help me locate which table is it using to store the login events ? – Vijay Jul 10 '20 at 09:14
  • 1
    @Aritz dead link – DAB Feb 26 '23 at 11:05
0

another way to get the event is from the

Keycloak keycloak = KeycloakBuilder.builder()
            .serverUrl("localhost")
            .realm("myRealm")
            .grantType(OAuth2Constants.PASSWORD)
            .clientId("myclient")
            .clientSecret("xxxx-xxxxx-xxxx-xxx")
            .username("foo")//the admin user
            .password("password")
            .build();

List<EventRepresentation> events = keycloak.realm("myRealm").getEvents();

then you choose the type of event you want to target

Noa
  • 315
  • 1
  • 7
  • 31