Asp.net core 如何处理/拦截Identity Server 4.NET Core引发的事件
我在Identity Server 4文档中读到,可以打开以下事件:Asp.net core 如何处理/拦截Identity Server 4.NET Core引发的事件,asp.net-core,asp.net-core-mvc,identityserver4,Asp.net Core,Asp.net Core Mvc,Identityserver4,我在Identity Server 4文档中读到,可以打开以下事件: services.AddIdentityServer(options => { options.Events.RaiseSuccessEvents = true; options.Events.RaiseFailureEvents = true; options.Events.RaiseErrorEvents = true; }); 这很好,但我想知道如何在引发事件时侦听,例如“APAuthen
services.AddIdentityServer(options =>
{
options.Events.RaiseSuccessEvents = true;
options.Events.RaiseFailureEvents = true;
options.Events.RaiseErrorEvents = true;
});
这很好,但我想知道如何在引发事件时侦听,例如“APAuthenticationSuccessEvent”。如何侦听.NET核心web应用中引发的此事件?我不打算将事件持久化到某个地方的某个事件存储中,我只需要知道何时引发了这样的事件,这样我就可以检查事件并对信息进行处理
也许我做得不对,或者我错过了一些明显的东西 不幸的是,这些事件严格用于日志记录目的(并且仅在IS4内部使用
TokenRequestValidator
时)
我最近开了一家询问“真实”事件的网站,但他们并不那么热情。基本上,他们认为这些活动属于客户机(OIDC流起源或返回的任何地方)
我可以理解他们的观点,但我真的更愿意将IS4日志隔离到IS4…即使这是一个有点老的问题,我也遇到了同样的问题,并通过以下方式解决了。 您只需注册自己的
IEventSink
实现,并实现方法PersistAsync
public class CustomEventSink : IEventSink
{
public CustomEventSink()
{
}
public Task PersistAsync(Event evt)
{
// Log in the way you want the event
return Task.CompletedTask;
}
}
然后在你的Startup.cs中
// Do this AFTER having added IndentityServer with services.AddIdentityServer
services.AddTransient<IEventSink, CustomEventSink>();
//将IdentityServer与services一起添加后执行此操作。AddIdentityServer
services.AddTransient();
如果您查看Github中的IdentityServer4,就会发现他们正在将引发的事件记录到已注册的记录器中。我有点被困在这里了!我需要找到一些方法来知道js客户机何时使用令牌进行身份验证(对于具有持久化身份验证会话的用户)。我已在您的功能请求中添加了一条评论,以查看是否有任何有用的响应。文档中似乎也有建议这样做: