Add browser-based agent authorization flow#940
Merged
Conversation
OAuth-style consent flow for agents to obtain bearer tokens: 1. Agent opens authorize URL with agent_slug + redirect_uri 2. User logs in (if needed) and sees consent screen 3. User clicks Authorize → token minted → redirected to callback with token 4. User clicks Deny → redirected with error Security: WordPress nonce CSRF protection, redirect_uri validated against localhost/same-site/registered domains (filterable via datamachine_authorize_allowed_domains). Enables self-service token acquisition for local and remote agents without manual token copying.
- Redirect URIs validated against agent_config.allowed_redirect_uris instead of a global allowlist. Scopes blast radius per-agent. - Localhost and same-site always allowed (dev + network). - URI patterns support: exact match, wildcard path, domain-only. - AgentAuthCallback receives tokens from external DM authorize flows and stores them in datamachine_external_tokens option. - REST endpoints for listing/retrieving stored external tokens.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
OAuth-style consent flow for agents to obtain bearer tokens — no manual token copying needed.
The Flow
Security
redirect_urivalidated: only localhost, same-site, or domains registered viadatamachine_authorize_allowed_domainsfilterFiles
inc/Core/Auth/AgentAuthorize.php— new file, the full authorize flow (GET consent screen + POST handler)data-machine.php— wires up the new class alongside AgentAuthMiddlewareTesting