问题
I am looking at options to log client id for every request (if available), so that it can be used for reporting purpose to find out the number of request per client. Ids logs the client id for token request when LogLevel is Information. Looking at IDS code, we need to extract the client id from AuthenticationHeader or from Body of the request. Wanted to know if there anything that is already built into ids to do this. Any other ways to do this?
回答1:
Absolutely!
Implementing the IEventService is what you're after.
An overview of all the events being transmitted to the IEventService can be viewed in the source of these internal extension methods; IEventServiceExtensions.
The AccessTokenIssuedEvent
, AuthorizationCodeDetails
and RefreshTokenDetails
events will include the ClientId receiving the token - so you can create an audit log.
The default implementation of IEventService
is the DefaultEventService, which will use the logging mechanism you're using for IdentityServer, but you can swap that out to log to a DB if you prefer.
来源:https://stackoverflow.com/questions/38770098/identity-server-3-logging-client-id-for-reporting