feat: Add set-token and refresh CLI commands for auth management#848
Merged
feat: Add set-token and refresh CLI commands for auth management#848
Conversation
Add two new abilities and three new CLI subcommands to the core auth system, enabling fully headless authentication management: Abilities (AuthAbilities.php): - datamachine/set-auth-token: Manually inject access_token + account data into any provider. Validates access_token is present, sanitizes input, and schedules proactive refresh if supported. - datamachine/refresh-auth: Force token refresh via get_valid_access_token(). Returns new expiry timestamp on success. CLI (AuthCommand.php): - set-token: Inject credentials via --token/--json flags with optional --refresh-token, --expires, --user-id, --username. Supports both flag-based and full JSON input for migration scenarios. - refresh: Force refresh a single provider's token. - refresh-all: Batch refresh all authenticated OAuth2 providers with per-provider success/failure reporting. These complete the auth CLI surface so agents, CI pipelines, and headless environments can manage auth without browser OAuth flows. Existing commands (status, connect, disconnect, config) are unchanged.
Homeboy Results —
|
Move list-providers business logic from Auth.php REST handler into
AuthAbilities as executeListProviders() with a registered
datamachine/list-auth-providers ability.
Auth.php changes:
- handle_list_providers() now delegates to ability (was inline logic)
- Add handle_set_token() endpoint: PUT /auth/{slug}/token
- Add handle_refresh() endpoint: POST /auth/{slug}/refresh
- Extract shared ability_to_response() helper for consistent error
mapping (replaces per-handler strpos chains)
- Extract handler_slug_args() to DRY route arg definitions
- All handlers are now thin: parse request → call ability → format response
No business logic remains in the REST layer.
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
New CLI Commands
wp datamachine auth set-token <provider>wp datamachine auth refresh <provider>wp datamachine auth refresh-allset-tokenexamplesrefreshexamplesExisting Commands (unchanged)
status [provider]connect <provider>disconnect <provider>config <provider>Architecture
Both new commands route through abilities, consistent with the abilities-first pattern:
Why Core
Auth management is a core concern —
BaseAuthProvider,BaseOAuth2Provider,AuthAbilities, and the OAuth2Handler all live in core. By adding these commands here, every consumer (socials, email, analytics, future extensions) gets headless auth management for free.