Search code examples
c#asp.net-core-mvcidentityserver4

What is Identity Server 4 Raise Event


I have downloaded IdentityServer4 Quickstart example and I am going through it to try and understand everything that happens here. What I have managed to do so far is replace the TestUsers with my own custom Identity Implementation that uses Identity Core + Dapper. However, there are still some parts of the code that do not make sense to me and I cannot figure out what they do. The full code example can be found here: https://github.com/IdentityServer/IdentityServer4.Quickstart.UI/tree/release/Quickstart

Throughout the many of these controllers I find the following line of code:

await _events.RaiseAsync(new UserLoginSuccessEvent(provider, providerUserId, user.Id.ToString(), user.Email));

now the UserLoginSuccessEvent is part of the IdentityServer4.Events library and the _events is actually IEventService. There are other calls such as UserLogoutSuccessEvent, ConsentDeniedEvent, and more.

My question is what does the above actually do? Is it supposed to trigger some sort of logging, if so where? Am I suppose to maybe implement something that would inject here and trigger my own thing or something completely else.


Solution

  • DefaultEventService class, provided by IdentityServer4, is the default implementation of IEventService. DefaultEventService uses an IEventSink object to sink the raised events. (see its RaiseAsync implementation). DefaultEventSink, again part of IdentityServer4, is registered as IEventSink. DefaultEventSink persists\logs the events.

    So, caller code calls DefaultEventService.RaiseAsync(..) method which in turns calls DefaultEventSink.PersistAsync method which logs the events.

    You can provide your own implementation of IEventService or IEventSink interface or both.