-
Notifications
You must be signed in to change notification settings - Fork 5
Closed
Description
Context
Phase 2 of agent runtime authentication (#740). Phase 1 (PR #853) added the token CRUD layer — datamachine_agent_tokens table with create/revoke/list via abilities, CLI, and REST.
This phase adds the middleware that actually authenticates incoming requests using those tokens.
What to Build
inc/Core/Auth/AgentAuthMiddleware.php (new file)
Hooks rest_authentication_errors filter — runs before any permission_callback.
Flow:
- Check
Authorizationheader forBearer datamachine_*prefix hash('sha256', $token)→ lookup indatamachine_agent_tokensviaAgentTokens::resolve_token()- Validate: token not expired, agent is active (
status = 'active'), owner user is active AgentTokens::touch_last_used()— track usagewp_set_current_user($owner_id)— WordPress sees the owner (for WP cap checks)PermissionHelper::set_agent_context($agent_id, $owner_id, $token_capabilities)— set agent scope- Return
true(authenticated) — all subsequentpermission_callbackchecks run with agent context
Security:
- Only intercepts tokens with
datamachine_prefix — does not interfere with other auth mechanisms - Token hash lookup is O(1) via UNIQUE index
- Must not interfere with existing WordPress Application Passwords or cookie auth
- Non-matching Authorization headers pass through to WordPress's normal auth chain
data-machine.php changes
Register the middleware on init or rest_api_init:
new \DataMachine\Core\Auth\AgentAuthMiddleware();Depends On
- PR feat: Agent runtime token system — Phase 1 (token CRUD) #853 — Agent token CRUD (Phase 1)
Related
- Consider agent-level runtime authentication #740 — Parent issue: agent-level runtime authentication
- Phase 3 issue (capability ceiling in PermissionHelper) — depends on this
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels