跳到主内容

SSF 事件流

检查 Casdoor 令牌的 MCP 服务器或 API 通常会缓存这些令牌,并在令牌过期前持续接受它们。借助 Shared Signals Framework (SSF),Casdoor 会在访问结束的那一刻向其推送签名事件,使其能够立即丢弃用户的会话。

Casdoor 是传输方。每个 SSF stream 将一个应用的事件发送给一个接收方:即信任该应用令牌的系统。

事件​

EventWhen Casdoor sends it
CAEP session-revoked用户在 AI apps 或 Consents 下撤销了应用,管理员在 AI connections 下撤销了应用,或者管理员禁用了应用的 agent 或设置了已过期的时间。
CAEP credential-change用户密码发生变化。
RISC account-disabled用户被禁止登录。
RISC account-enabled被禁止的用户可以再次登录。
RISC account-purged用户被删除。

事件的主体通过 iss 和 sub(用户 ID)标识用户,当事件涉及特定应用时,通过其客户端 ID 标识应用。

创建流​

打开 LLM AI > SSF Streams 并添加一个流:

字段描述
Application接收方接受其令牌的应用。Casdoor 使用该应用的证书对事件进行签名,其客户端 ID 作为受众(audience)。
Endpoint URLCasdoor 发布事件的位置(推送交付,RFC 8935)。
Authorization header可选,作为每次推送的 Authorization 头发送,例如 Bearer <secret>。
Events requested要发送的事件。
Statusenabled、paused 或 disabled。

Send verification event 检查接收方是否接受事件。流页面显示已交付的事件数量以及最后一次错误。

Casdoor 不会向私有网络地址发布事件,除非是 built-in 组织的流或在 conf/app.conf 中设置了 ssfAllowIntranet = true。

接收事件​

每个事件都是一个安全事件令牌 (RFC 8417):一个带有 typ: secevent+jwt 头的 JWT,以内容类型 application/secevent+jwt 发布。使用位于 https://<casdoor-host>/.well-known/jwks 的密钥进行验证,检查 aud 是否为应用的客户端 ID,并回复 202 Accepted。

{
"iss": "https://<casdoor-host>",
"aud": "<client-id>",
"jti": "2b2d3215-9cae-43d9-b3cd-ef14044fb153",
"iat": 1796488247,
"sub_id": {
"format": "complex",
"user": {"format": "iss_sub", "iss": "https://<casdoor-host>", "sub": "<user-id>"},
"application": {"format": "opaque", "id": "<client-id>"}
},
"events": {
"https://schemas.openid.net/secevent/caep/event-type/session-revoked": {
"event_timestamp": 1796488247,
"initiating_entity": "user",
"reason_user": {"en": "the access of my-agent was revoked"}
}
}
}

从接收方管理流​

接收方可以使用 SSF API 管理其流,并使用来自 client credentials grant 的应用访问令牌。Casdoor 在 https://<casdoor-host>/.well-known/ssf-configuration 描述该 API。

EndpointDescription
GET /api/ssf/stream?stream_id=<name>读取流配置。如果没有 stream_id,则列出应用的流。
POST /api/ssf/stream创建包含 delivery(method 必须为 push,endpoint_url)和 events_requested 的流。
PATCH / PUT /api/ssf/stream?stream_id=<name>修改流。
DELETE /api/ssf/stream?stream_id=<name>删除流。
GET / POST /api/ssf/status读取状态,或使用 reason 将其设置为 enabled、paused 或 disabled。
POST /api/ssf/verify请求验证事件,附带一个可选的 state,该状态将由事件返回。