<html>
  <head>
    <meta content="text/html; charset=windows-1252"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <div class="moz-cite-prefix">On 24/02/16 10:57, Maciek Dawidowicz
      wrote:<br>
    </div>
    <blockquote
cite="mid:CAL1OwZquZ1uidJQLPqZQ5K0qeCKrRjMPHoHJtQWi12JkWpeFtw@mail.gmail.com"
      type="cite">
      <div dir="ltr">
        <div>
          <div>
            <div>
              <div>
                <div>
                  <div>Hello,<br>
                    <br>
                  </div>
                  I am trying to log information about successful login
                  and logouts in my application. I've written a simple
                  event listener to pass data to my application audit
                  logger in correct format. In case of Login event there
                  are following details available:<br>
                  auth_method: openid-connect<br>
                  auth_type: code<br>
                  redirect_uri: <a moz-do-not-send="true"
href="http://localhost:8080/auth/admin/master/console/?redirect_fragment=%2Frealms%2Fmaster%2Fevents">http://localhost:8080/auth/admin/master/console/?redirect_fragment=%2Frealms%2Fmaster%2Fevents</a><br>
                  consent: no_consent_required<br>
                  code_id: 28e74ada-cb0e-4901-91bb-2915f1a3b8e0<br>
                  <b>username: admin<br>
                  </b><br>
                </div>
                however in logout event details there is only:<br>
                redirect_uri: <a moz-do-not-send="true"
href="http://localhost:8080/auth/admin/master/console/#/realms/master/events">http://localhost:8080/auth/admin/master/console/#/realms/master/events</a><br>
                <br>
              </div>
              This means all i get in this event related to User is his
              id:<br>
              <b>User: a680de68-1c9a-40dd-a642-c56d5912b7b6<br>
                <br>
              </b></div>
            Is there a simple way for my event listener to get username
            based on User Id? Or perhaps a way to enable putting
            username in logout event details?<br>
          </div>
        </div>
      </div>
    </blockquote>
    Feel free to create JIRA for put username in logout event details.<br>
    <br>
    The possibility to retrieve username in logout events is alreadt
    doable though, but it's a bit complicated. You will need to pass
    KeycloakSession to your EventListener implementation
    (KeycloakSession is available in
    EventListenerProviderFactory.create() ). Then once you have
    KeycloakSession you can use it to lookup realm and then username
    based on userId. Something like this:<br>
    RealmModel realm = session.getContext().getRealm();<br>
    UserModel user = session.users().getUserById(userId, realm);<br>
    String username = user.getUsername();<br>
    <br>
    Marek<br>
    <blockquote
cite="mid:CAL1OwZquZ1uidJQLPqZQ5K0qeCKrRjMPHoHJtQWi12JkWpeFtw@mail.gmail.com"
      type="cite">
      <div dir="ltr">
        <div>
          <div><br>
          </div>
          thanks,<br>
        </div>
        Maciej Dawidowicz<br>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
keycloak-user mailing list
<a class="moz-txt-link-abbreviated" href="mailto:keycloak-user@lists.jboss.org">keycloak-user@lists.jboss.org</a>
<a class="moz-txt-link-freetext" href="https://lists.jboss.org/mailman/listinfo/keycloak-user">https://lists.jboss.org/mailman/listinfo/keycloak-user</a></pre>
    </blockquote>
    <br>
  </body>
</html>