You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Content hooks: say whether an action came from a session or an API token (a first slice of #1682)
#5141
In content:beforePublish, content:beforeSchedule and content:beforeUnpublish, a publish from the admin and a publish by a script with an API token look identical to a plugin: origin: { source: "api" }, actor: { id, role, source: "api" } (routes/api/content/[collection]/[id]/publish.ts:90-91; schedule.ts:84-85; unpublish.ts:62-63; [id].ts:124-125; the actor's source is copied at emdash-runtime.ts:5647-5652). content:beforeSave and content:afterSave get an actor with no source at all for REST saves (api/content-save.ts:137). The auth middleware knows which credential was used (astro/middleware/auth.ts:733-734), but nothing passes it to plugins. #1995 noted this and asked for a separate idea; #1682 lists "Agent/API actions are distinguishable from admin UI actions" as an acceptance criterion.
Reproduction
A plugin with capabilities: ["hooks.content-policy:register"] and:
Create an API token for the same user and run curl -X POST -H "Authorization: Bearer ec_pat_..." https://site/_emdash/api/content/posts/ID/publish on another draft.
Both log {"origin":{"source":"api"},"actor":{"id":"…","role":50,"source":"api"}}.
Possible shape
An optional ActorInfo.auth?: "session" | "api_token" | "oauth" (and perhaps tokenId, which api-tokens.ts:196-199 documents as safe to store and show), set from locals in the content routes and the save path, so the save hooks, the policy hooks and (with #4736) the after-hooks all carry it. It is additive, and sandboxed plugins receive it like the rest of the event.
Alternatives considered:
A new origin.source value would break plugins that check === "api".
Tests: a route test for each path asserting auth for a session, a personal token and an OAuth token, and that the visual editor reports session.
Prepared, reproduced and tested on EmDash 1.6.0; with the help of Claude, which I reviewed and sharing here.
Use case
An approval plugin holds publishes for review, and an audit plugin records who acted. Publishes through MCP can already be held (source: "mcp"), but a CI job or a script with an Admin's token publishes as if the Admin had clicked Publish. Saves matter too: SEO fields, taxonomies and bylines go live on save (api/handlers/content.ts:1864).
Current workarounds
Give automation its own non-Admin user and decide by role. That does not cover an Admin's own token.
Your involvement
I am requesting this capability.
I am offering to champion the design in a feature plan or RFC.
I am offering to implement it after the design is accepted.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Problem
In
content:beforePublish,content:beforeScheduleandcontent:beforeUnpublish, a publish from the admin and a publish by a script with an API token look identical to a plugin:origin: { source: "api" },actor: { id, role, source: "api" }(routes/api/content/[collection]/[id]/publish.ts:90-91;schedule.ts:84-85;unpublish.ts:62-63;[id].ts:124-125; the actor's source is copied atemdash-runtime.ts:5647-5652).content:beforeSaveandcontent:afterSaveget an actor with no source at all for REST saves (api/content-save.ts:137). The auth middleware knows which credential was used (astro/middleware/auth.ts:733-734), but nothing passes it to plugins. #1995 noted this and asked for a separate idea; #1682 lists "Agent/API actions are distinguishable from admin UI actions" as an acceptance criterion.Reproduction
A plugin with
capabilities: ["hooks.content-policy:register"]and:curl -X POST -H "Authorization: Bearer ec_pat_..." https://site/_emdash/api/content/posts/ID/publishon another draft.Both log
{"origin":{"source":"api"},"actor":{"id":"…","role":50,"source":"api"}}.Possible shape
An optional
ActorInfo.auth?: "session" | "api_token" | "oauth"(and perhapstokenId, whichapi-tokens.ts:196-199documents as safe to store and show), set fromlocalsin the content routes and the save path, so the save hooks, the policy hooks and (with #4736) the after-hooks all carry it. It is additive, and sandboxed plugins receive it like the rest of the event.Alternatives considered:
origin.sourcevalue would break plugins that check=== "api".content:publishtoken scope (Role level 30 is labelled "Editor" in the auth-provider JSDoc, but it is Author, which can publish its own content. There is also no built-in role for "draft-only" automation. #4030) can refuse a publish but cannot hold one for review, and does not help audit.Tests: a route test for each path asserting
authfor a session, a personal token and an OAuth token, and that the visual editor reportssession.Prepared, reproduced and tested on EmDash 1.6.0; with the help of Claude, which I reviewed and sharing here.
Use case
An approval plugin holds publishes for review, and an audit plugin records who acted. Publishes through MCP can already be held (
source: "mcp"), but a CI job or a script with an Admin's token publishes as if the Admin had clicked Publish. Saves matter too: SEO fields, taxonomies and bylines go live on save (api/handlers/content.ts:1864).Current workarounds
Give automation its own non-Admin user and decide by role. That does not cover an Admin's own token.
Your involvement
All reactions